[Xotcl] NX direct variable access
Victor Mayevski
vitick at gmail.com
Fri Jan 21 00:09:13 CET 2011
Excellent. Thank you Gustaf.
On Wed, Jan 19, 2011 at 4:50 AM, Gustaf Neumann <neumann at wu.ac.at> wrote:
> Am 19.01.11 10:19, schrieb Victor Mayevski:
>>
>> In NX, what is the correct way to give a direct access to an object
>> variable for outside caller, just like we used to do with XOTcl's
>> [myvar varname]?
>>
> I assume, you want to obtain a fully qualified variable handle for an
> instance variable. Essentially, it works in nx very similar to XOTcl.
> See below for the method "bindvar" which obtains the fully
> qualified name and shows its usage in the context of Tk.
>
> -gustaf neumann
>
> ==================================================
> #
> # Tiny Tk example with bindvar and callback
> #
> # -gustaf neumann
>
> package require nx
> package require Tk
>
> nx::Class create Callbacks {
> #
> # A small support class to ease syntactically the reference to
> # instance variables and the registration of callbacks.
> #
> :method bindvar {name} {
> :require namespace
> return [nx::self]::$name
> }
> :method callback {name args} {
> return [list [nx::self] $name {*}$args]
> }
> }
>
> nx::Class create Myclass {
>
> #
> # A sample application class that creates a text entry field bound
> # to an instance variable. When the provided button is pressed, the
> # content of the variable is placed into an additional output label.
> #
>
> :mixin Callbacks
>
> :public method button-pressed {} {
> .label configure -text ${:myvar}
> }
>
> :method init {} {
> wm geometry . -500+500
> pack [label .title -text "Type something and press start button...."]
> pack [entry .text -textvariable [:bindvar myvar]]
> pack [label .label]
> pack [button .button -text start -command [:callback button-pressed]]
> }
> }
>
> Myclass new
> ==================================================
>
>
> --
> Univ.Prof. Dr. Gustaf Neumann
> Institute of Information Systems and New Media
> WU Vienna
> Augasse 2-6, A-1090 Vienna, AUSTRIA
>
> _______________________________________________
> Xotcl mailing list
> Xotcl at alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
>
More information about the Xotcl
mailing list