[Xotcl] XOTcl as a megawidget framework
Schofield, Bryan (GE Transportation)
Bryan.Schofield at trans.ge.com
Tue Jun 8 14:52:45 CEST 2004
Hullo -
This is my first posting to this mailing list. I recently started playing around with XOTcl. I had been using IncrTcl for quite a while, but XOTcl has seemed to get a lot publicity in a few other mailing lists, so I decided to give it a try.
My first impression of XOTcl is very good. I'm finding myself growing very fond of how classes are defined in XOTcl and I'm loving the dynamic nature of classes and objects in general. Though I have to admit, the "instproc", "instvar", and "my" took a little getting used to and I do miss the protection levels available in IncrTcl, but only a little. Anyway, that's not the real reason I'm posting.
Has any work gone into making a TK megawidget framework with XOTcl? I spent a little time and came up with a couple of classes that make this possible. Even though this is just a prototype, I'd be very interested in getting some XOTcl'ers feed back on this.
I've attached a file called xowidget.tcl that contains the megawidget framework package and an example of using it, SearchableListbox.tcl.
This package, which I've cleverly been calling "xowidget", provides the ability to create an XOTcl object that behaves like a TK widget. It also provides Snit-like method & option delegation to the basewidget, subcomponents, and other objects. Furthermore, the method & option delegation can be multiplexed such that a method or option is propogated to multiple objects and/or tk widgets. I've tried to document how to xowidget in source file, but if something is missing or not clear, please feel free to ask me. Here is a small example of what the syntax is like.
WidgetClass LabeledButton \
-tkwidget frame \
-parameter { {foo bar} }
LabeledButton instproc init args {
next
my instvar widgetpath
# create a label and button in the frame
label $widgetpath.l
button $widgetpath.b
pack $widgetpath.l $widgetpath.b -side left
# make the foo parameter an configurable option
my tkoption add foo parameter -object [self]
# add borderwidth & relief option for the basewidget
my tkoption add frameborderwidth widgetproc \
-object [self] -asoption borderwidth
my tkoption add framerelief widgetproc \
-object [self] -asoption relief
# add option for the text on the label
my tkoption add labeltext tkwidget \
-widgetpath $widgetpath.l -asotion text
# multiplex background option to the frame, label, and button
my tkoption add background widgetproc -object [self]
my tkoption add background tkwidget -widgetpath $widgetpath.l
my tkoption add background tkwidget -widgetpath $widgetpath.b
# wildcard all other options to the button
my tkoption add * tkwidget \
-widgetpath $widgetpath.b
# make the foo parameter command available
my tkcommand add foo
# wildcard all other commands to the button
my tkcommand add * "$widgetpath.b"
}
pack [LabeledButton .lb -labeltext Foo -text "Press me" -command doSomething]
puts [.lb configure]
.lb invoke
.lb foo "ack"
I'm very open to suggestions and comments, critical or otherwise. If there is some interest, I'd be open to enhancing this expiriment to something more.
Thanks in advance.
-- bryan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SearchableListbox.tcl
Type: application/octet-stream
Size: 6106 bytes
Desc: SearchableListbox.tcl
Url : http://alice.wu-wien.ac.at/pipermail/xotcl/attachments/20040608/495006ea/SearchableListbox.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xowidget.tcl
Type: application/octet-stream
Size: 27188 bytes
Desc: xowidget.tcl
Url : http://alice.wu-wien.ac.at/pipermail/xotcl/attachments/20040608/495006ea/xowidget.obj
More information about the Xotcl
mailing list