From: Michael K. <mi...@mu...> - 2008-11-26 02:08:15
|
On the auto-naming of widgets, I've long felt that it's a bit silly we have to name them ourselves at all. I don't care what the widget names are, only that I know what they are so I can interact with them. If I'm caring what the actual name is, it probably means I've hardcoded it in several places, which is going to make it a hassle to modify the code later to restructure/extend the GUI. I'd prefer to let the parent in the hierarchy do the naming. Perhaps this would largely be a matter just of convention, or perhaps there would be a wrapper around Tcl_CreateObjCommand to create widget commands that handle this automatically, but I would suggest: 1. A widget creation command (e.g. "frame"), when given no arguments or the first argument doesn't start with ".", gets a fully automatic name assignment that's a child of "." (or a child of nothing if a toplevel). e.g., set top [toplevel] ;# -> .toplevel1 set frame [frame] ;# -> .frame1 set frame [frame] ;# -> .frame2 set frame [frame .f] ;# -> .f 2. The parent should be capable of creating widgets and assigning names to them in its hierarchy itself. Maybe this would be done with a subcommand specified to that Tcl_CreateObjCommand wrapper (Tk_CreateWindowObjCommand?), or maybe something like "." as a subcommand is suitably unique and (pardon the pun) on point: set top [toplevel] ;# -> .toplevel1 set frame [$top . frame] ;# -> .toplevel1.frame1 set button [$frame . button] ;# -> .toplevel1.frame1.button1 The wrapper would see that "." is the first argument and treat the second argument as a widget creation command (no matter what it is), inserting a unique name as its first argument (or, I guess, treat the first two as ensembles). 3. Maybe, for cases where you actually do care what the name is, extend (1) and (2) a little bit such that if the first argument doesn't start with "-" and doesn't contain any dots, then it's a parent-relative name: set bob [frame bob] ;# -> .bob set top [toplevel] ;# -> .toplevel1 set bob [$top . frame bob] ;# -> .toplevel1.bob set ok [$bob . button ok] ;# -> .toplevel1.bob.ok -- Michael Kirkham President & CEO Muonics, Inc. http://www.muonics.com/ |