[Xotcl] Linking object instance variables to a widget -textvariable?

Uwe Zdun uwe.zdun at wu-wien.ac.at
Sat Nov 15 10:09:59 CET 2003


Hi Ken,

perhaps others use other styles, but a simple way to bind variables,commands, 
or other callbacks from TK into XOTcl is replacement of "self" (or "my") from 
within a XOTcl method. Example:

Class BrowserTree
BrowserTree instproc init args {
   ...
   set tree  [Tree $sw.tree \
                   -relief flat -borderwidth 0 -width 15 -highlightthickness 
0\
		   -redraw 0 -dropenabled 1 -dragenabled 1 \
                   -dragevent 3 \
                   -droptypes {
                       TREE_NODE    {copy {} move {} link {}}
                       LISTBOX_ITEM {copy {} move {} link {}}
                   } \
                   -opencmd   "[self] modifyTree 1 $sw.tree" \
                   -closecmd  "[self] modifyTree 0 $sw.tree"]
    ...
    $tree bindText  <ButtonPress-1>        "[self] selectTreeElement $tree"
    $tree bindText  <Double-ButtonPress-1> "[self] openTreeElement $tree"
    ...
}

note that you cannot use curly brackets {} here, because then self would 
not be replaced within the object's scope and would likely have a wrong value 
or raise an exception.

this style of binding works nicely together with XOTcl's inheritance and 
mixins

Uwe





On Saturday 15 November 2003 00:04, Ken Jones wrote:
> Hi. I've just starting tinkering around with XOTcl the past few days,
> trying to add it to my repertoire of Tcl OO extensions. It's definitely
> quite an interesting contrast to others like [incr Tcl] or Snit. While I
> won't be abandoning either of those, XOTcl is currently my leading
> candidate for a project I'm likely to be working on through the rest of the
> year, in large part because of its mixin support.
>
> But one issue I couldn't figure out from my reading of the documentation or
> examples is whether it's possible to use an object's instance variable as a
> widget's -textvariable or -listvariable. For example, [incr Tcl] supports
> the [itcl::scope] command, so I can do something like this:
>
> package require Itcl
>
> ::itcl::class Toggle {
>
>     private variable _state "normal"
>
>     constructor {} {
>         checkbutton .cb -text Enable \
>             -variable [::itcl::scope _state] \
>             -onvalue "normal" -offvalue "disabled" \
>             -command [::itcl::code $this toggle]
>         .cb select  ;# The checkbutton is initially on
>
>         # ...
>     }
>
>     private method toggle {} {
>         # ...
>     }
> }
>
> Is there a similar feature for XOTcl?
>
> Thanks,
>
> - Ken Jones
>
> _______________________________________________
> Xotcl mailing list  -  Xotcl at alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl

-- 
Uwe Zdun
Department of Information Systems, Vienna University of Economics
Phone: +43 1 313 36 4796, Fax: +43 1 313 36 746
zdun@{xotcl,computer,acm}.org, uwe.zdun at wu-wien.ac.at





More information about the Xotcl mailing list