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

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

From: Uwe Zdun <uwe.zdun_at_wu-wien.ac.at>
Date: Sat, 15 Nov 2003 10:09:59 +0100

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_at_{xotcl,computer,acm}.org, uwe.zdun_at_wu-wien.ac.at