Re: GUI, namespaces and OO
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: GUI, namespaces and OO

From: Eckhard Lehmann <ecky-l@web.de>
Date: Sun Oct 30 2005 - 11:23:02 CET

Silas Justiniano schrieb:
> Hello all.
>
> I don't know much about namespaces. I know only to write the following
> code:
>
> #start ---
> namespace eval my {}
>
> toplevel .t
> entry .t.b -textvariable my::myentry
> #end ---
>
> If I [destroy .t], the namespace [my] still exists. I could learn some
> of the namespace commands to destroy them when the toplevel is
> destroyed, or unset all variables automaticaly.
>
> I would like just to know if one of the available OO extensions could
> make it automatically for me.

Besides the fact that namespaces come from Itcl, Itk has such a
mechanism. The translation of your code to Itk:

class My {
     inherit itk::Toplevel

     variable myentry

     constructor {args} {
         itk_component add b {
             entry $itk_interior.b -textvariable [scope myentry]
         }
         ...

         eval itk_initialize $args
     }
}

# later
My .m
pack .m -expand yes -fill both

# again later
destroy .m

Learn more here: http://wiki.tcl.tk/63

BTW, is it planned to use [scope] with (public) variables from other
Itk/Itcl classes? Like in this short example:

class A {
     public variable avar ""
     ...
}

class B {
     inherit itk::Widget

     protected variable aobj ""

     constructor {args} {
         set aobj [A ::#auto]

         itk_component add e {
             entry $itk_interior.e -textvariable [scope $aobj avar]
         }
         ...
         eval itk_initialize $args
     }
}

At this moment this does not work, or I've overlooked something. I
managed only to [scope] variables in the current Itk class.

Eckhard
Received on Mon Nov 21 00:37:10 2005