From: Damon C. <da...@tc...> - 2009-04-17 17:39:41
|
> 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. I would go one further and say why add a "cargo" method to every widget when you can just add a cargo command to attach data to a widget? I argued this same point in the referenced thread, and no one listened. By the way, I prefer clientdata or something like that. clientdata .b "foo" clientdata .e [dict create foo bar] Whatever. If you REALLY wanted to implement this in C, you could, but it's quite easy in Tcl. I would just use a simple command trace on the deletion of the widget. Binding to <Destroy>, as some in the original thread had suggested, has the side-effect of being easy to wipe out by the developer if they choose to bind <Destroy> themselves. D |