No registered users in community xowiki
in last 10 minutes
in last 10 minutes
[Xotcl] XOTcl as a megawidget framework
From: Schofield, Bryan \(GE Transportation\) <"Schofield,>
Date: Tue, 8 Jun 2004 08:52:45 -0400
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
Date: Tue, 8 Jun 2004 08:52:45 -0400
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