View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] RE: XOTcl as a megawidget framework

From: Schofield, Bryan \(GE Transportation\) <"Schofield,>
Date: Thu, 10 Jun 2004 08:51:16 -0400

For anyone that is interested, I've been working on the option handling stuff a little more. The original method of adding tk configurable options is still available, but is now done via the [tkoption addexplicit] command. The new [tkoption add] takes a type and a source object (XOTcl, TK, or other depending on the type) and a series of options. This allows options to be added more easily.

tk option add tkwidget $ \
   -except { yscrollcommand xscrollcommand } \
   -translate { background listbackground }

As I'm thinking about this, I think it might be a good idea to extract the tk option handling code in to it's own class for better reusability, maybe ConfigurableOptionManager or something.

-- bryan

> -----Original Message-----
> From: Schofield, Bryan (GE Transportation)
> Sent: Tuesday, June 08, 2004 8:53 AM
> To: ''
> Subject: XOTcl as a megawidget framework
> 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