auto-named widgets (was Tcl-URL! - weekly Tcl news and links (Jun 12))

auto-named widgets (was Tcl-URL! - weekly Tcl news and links (Jun 12))

Post by Bryan Oakl » Sat, 16 Jun 2007 02:01:20



Why would it make it impossible? The auto-naming only applies to widgets
and would not be used in any other context (if I understand the TIP).

In thinking about this more (but not much more...), maybe a better
solution is to not use a special character and instead change the
behavior of the widget commands.

For example, give each widget a "-parent" option that defines its parent
widget. Then, allow the widget command to be called without an explicit
widget path (or maybe a null path?), in which case it creates an
auto-named child of the parent.

For example:

# create a container
frame .f

# create an auto-named button in .f
set b [button -parent .f -borderwidth 2 ...]

The use of -parent and an explicit pathname would be mutually exclusive.
That is, you can do "button .b" or "button -parent .f" but not "button
.b -parent .f". Though, come to think of it, "button .b -parent .f"
could just as easily create a widget named ".f.b".

... just offering some food for thought.


--
Bryan Oakley
http://www.yqcomputer.com/
 
 
 

auto-named widgets (was Tcl-URL! - weekly Tcl news and links (Jun 12))

Post by Ramon Ri » Sat, 16 Jun 2007 02:34:21


Hello,

Another detail to take into consideration is that some existing TCL
packages
already use something similar.

For example, it is possible in snit:

set d [dog obj_%AUTO%]

suffix %AUTO% is longer to write than '%' but should avoid other type
of difficulties.



En Thu, 14 Jun 2007 19:01:20 +0200, Bryan Oakley
< XXXX@XXXXX.COM > escribi

>>> On Jun 12, 11:20 am, "Donal K. Fellows"<< XXXX@XXXXX.COM >>
>>> >>>> A correction: there has been a new TIP published (#306: Auto-Naming >>>> Widgets) but the publication is stuck because of a mailing list outage >>>> at SourceForge. >>> My worry about this tip is that it makes yet another >>> character magical, and thus making future syntax >>> enhancements more difficult. >>> One of the big hurdles for the new {*} feature was >>> trying to find some syntax that wasn't already taken. >>> As just one possible example, I could envision a >>> time when "%" would be used, as a shorthand >>> for lindex, e.g %myList{3}. This tip would make this >>> impossible. >>> >> >> Why would it make it impossible? The auto-naming only applies to widgets >> and would not be used in any other context (if I understand the TIP). >> >> In thinking about this more (but not much more...), maybe a better >> solution is to not use a special character and instead change the >> behavior of the widget commands. >> >> For example, give each widget a "-parent" option that defines its parent >> widget. Then, allow the widget command to be called without an explicit >> widget path (or maybe a null path?), in which case it creates an >> auto-named child of the parent. >> >> For example: >> >> # create a container >> frame .f >> >> # create an auto-named button in .f >> set b [button -parent .f -borderwidth 2 ...] >> >> The use of -parent and an explicit pathname would be mutually exclusive. >> That is, you can do "button .b" or "button -parent .f" but not "button >> .b -parent .f". Though, come to think of it, "button .b -parent .f" >> could just as easily create a widget named ".f.b". >> >> ... just offering some food for thought. >> >>



--
Compass Ing. y Sistemas Dr. Ramon Ribo
http://www.yqcomputer.com/ XXXX@XXXXX.COM
c/ Tuset, 8 7-2 tel. +34 93 218 19 89
08006 Barcelona, Spain fax. +34 93 396 97 l/

 
 
 

auto-named widgets (was Tcl-URL! - weekly Tcl news and links (Jun 12))

Post by Alexandre » Sat, 16 Jun 2007 02:40:10


If you blend this with my external-autoname proposal a few millimeters
higher up in this thread, you can even do:

set b [newchildof .f button -borderwidth 2 ...]

<TIP-kill>
Needless to say, [newchildof] can be written in pure Tcl (and has been
able to since 7.x...).
</TIP-kill>

-Alex
 
 
 

auto-named widgets (was Tcl-URL! - weekly Tcl news and links (Jun 12))

Post by Alexandre » Sat, 16 Jun 2007 02:50:21

On Jun 14, 7:40 pm, Alexandre Ferrieux < XXXX@XXXXX.COM >


*and* it also works with megawidgets without effort.

-Alex
 
 
 

auto-named widgets (was Tcl-URL! - weekly Tcl news and links (Jun 12))

Post by Koen Danck » Sat, 16 Jun 2007 19:05:16


Indeed, it would not be used in any other context.

Note that "%" character in Tcl is already associated with the notion of substitution, e.g. in bindings and in string formatting. This would not conflict with its use in this TIP, because its not followed by another character here.
On the other hand, using it as a shorthand for lindex, would more likely lead to conflicts.


Then there are two different syntaxes for creating widgets. I don't think this would be good for code readability. For example, when mixing normal and auto-naming, the proposal of the TIP would give code like:

set top [frame $f.%]
set main [frame $f.main]
set bottom [frame $f.%]

Also, when using -parent as an option, should it appear in the configure list of the widget ([$b configure -parent])? Also for widgets created with a manual name?

I still think the syntax proposed in the TIP is the most consistent and the most convenient.

Koen
 
 
 

auto-named widgets (was Tcl-URL! - weekly Tcl news and links (Jun 12))

Post by Bryan Oakl » Sat, 16 Jun 2007 20:19:52


Yes, I would expect -parent to work like any other option in that it
would return the value that was set. If you don't set -parent, it would
return an empty string.