From: Twylite <tw...@cr...> - 2009-04-17 16:32:07
|
Hi, > TIP #349: NEW "-CARGO" OPTION FOR EVERY TK WIDGET > Why an option, rather than a common command? It strikes me that an option is rather limited -- give it about 2 months and we will see reusable bits of code on the wiki that do cool things (like tooltips) using -cargo, and suddenly its not really available for "the script author" because (s)he is trying to juggle the 5 cool extensions that all want to use it. Only then (too late) does someone suggest a protocol for using -cargo (e.g. make it a dict), but there are already incompatible uses around. A "cargo" subcommand that is set up as a key/value mechanism would surely be a more generic solution? e.g. button .b .b cargo ;# lists cargo keys .b cargo key ;# returns the value for "key" .b cargo key val ;# sets the value for "key" This specific interface doesn't deal with deleting cargo values; one could assume that the value {} is effectively a delete; one could also specify whether ".b cargo key" returns empty or throws an error if key does not exist. Finally, it is worth pointing out that it is sometimes desirable for the "cargo" to be accessible as a variable name that can be used by -variable, trace, etc. This is especially useful in the absence of a OO megawidget framework, as you can easily attach arbitrary "instance data" to a specific widget. Regards, Twylite |