No registered users in community xowiki
in last 10 minutes
in last 10 minutes
Re: [Xotcl] Linking object instance variables to a widget -textvariable?
From: Catherine Letondal <letondal_at_pasteur.fr>
Date: Sat, 15 Nov 2003 10:23:51 +0100
Uwe Zdun wrote:
> 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
>
This work perfectly for commands, and I use it all the time, but it does not
work for variables.
In fact, I believe Tk always expect a Tcl global variable and an XOtcl
object instance variable is not a global variable, right?
So the issue is maybe : how to bind an Xotcl object instance variable
to a Tcl global variable?
Catherine
Date: Sat, 15 Nov 2003 10:23:51 +0100
Uwe Zdun wrote:
> 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
>
This work perfectly for commands, and I use it all the time, but it does not
work for variables.
In fact, I believe Tk always expect a Tcl global variable and an XOtcl
object instance variable is not a global variable, right?
So the issue is maybe : how to bind an Xotcl object instance variable
to a Tcl global variable?
Catherine