Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Little doubts with Snit

8 views
Skip to first unread message

Silas Justiniano

unread,
Nov 26, 2005, 5:19:54 AM11/26/05
to
Hello ppl. I started my first OO project using Snit... See the
beggining of the project:

# principal.tcl - tipos da janela principal
# iniciado em 2005-11-24
# por Silas Justiniano - silasdb(nospam)gmail.com
#------------------------------------------------------------------------------

package require snit

snit::widget principal {
hulltype toplevel
expose btnIncluir
expose btnAlterar
expose btnExcluir
expose btnFiltrar
expose frEsquerdo

#sVer: dar uma olhada na ordem dos botoes lá do programa
constructor {args} {
wm withdraw $win

#posiciona os buttons no frame
install frEsquerdo using frame $win.frEsquerdo
install btnIncluir using button $win.frEsquerdo.btnIncluir -text
Incluir
install btnAlterar using button $win.frEsquerdo.btnAlterar -text
Alterar
install btnExcluir using button $win.frEsquerdo.btnExcluir -text
Excluir
install btnFiltrar using button $win.frEsquerdo.btnFiltrar -text
Filtrar
pack $btnIncluir $btnAlterar $btnExcluir $btnFiltrar
grid $frEsquerdo -row 2

#$self configurelist $args

wm deiconify $win
}
}

principal .principal

#---- end ----

My questions are:

1. I've read in snit's faq that to use install is a good practice. For
me it's redundand, considering I could put a [label] or [entry]
directly in code. So why to use it?

2. I tried to run this code (without [expose] commands) and I received
the following error:

Error in startup script: can't read "btnIncluir": no such variable

So I *MUST* put [expose btnIncluir] in code, right? I thought it
weren't necessary, because as I read in snit's faq, [expose] is
necessary to "show" the this "outside" the snit::widget, right? So why
to use that?

Thank you very much. Bye!

Aric Bills

unread,
Nov 26, 2005, 9:19:37 PM11/26/05
to
I'm going to answer your questions in reverse order:

You probably want to use [component] rather than [expose] for all those
parts of your interface. [component] declares an instance variable
that will automatically be visible in all methods in your snit widget.
It won't be visible outside the widget, though. Making something a
component also means that you can delegate methods and options to it,
which can be really helpful. You can probably change all the [expose]s
in your code to [component]s without having to change any other part of
your code.

As far as why to use [install], I don't have a really good answer. For
one thing, it sets the variable you declared with the [component]
command, but you could also do that yourself:

set frEsquerdo [frame $win.frEsquerdo]

Maybe someone else can give you a better reason to use it. I
personally use it just because the documentation says I should :)

By the way, I don't think you need to withdraw your window while you
construct it--the end user won't see it until it's completely
constructed, unless you call [update] somewhere in your constructor.
Also, with all those buttons that are children of the frame, you can
do:

install btnIncluir using button $frEsquerdo.btnIncluir etc.

It saves on typing, and it also can help your code scale up better (if,
for example, you decide later to put frEsquerdo inside another frame).

Congratulations on your first Snit project! Best of luck.

Aric

Silas Justiniano

unread,
Nov 27, 2005, 2:48:31 PM11/27/05
to
Thank you again Aric! You helped me to clean my mind! Thank you! Bye!

Silas Justiniano

unread,
Nov 27, 2005, 7:22:17 PM11/27/05
to
Another question:

I tried snit::widget constructor:

$win configure -menu $win menu

with a previous menu made with:

install menuPrincipal using menu $win.menu
$win.menu add cascade -label Arquivo -underline 0

It didn't worked, and it returned me:

Error in startup script: ".principal configure" is not defined
while executing
"$win configure -menu $win.menu"
(procedure "::principal::Snit_constructor" line 20)

I was skimming through snitbrowser code
(http://wiki.tcl.tk/snitbrowser), and I saw it configures the menu
outside snit::widget (see the end of the code).

Is it the only way? Can't I put inside?

Thank you! Bye!

Aric Bills

unread,
Nov 28, 2005, 2:45:36 PM11/28/05
to
I had this same problem just a little while ago. What I discovered is
that snit widgets include an implicit component called "hull". I think
in general you want to use $win to refer to the hull widget, but in
this case you need to use $hull to get the menu to work right:

$hull configure -menu $menuPrincipal

More info on the snit man page in the "snit::widget" section.

Hope that helps!

Neil Madden

unread,
Nov 28, 2005, 9:06:22 PM11/28/05
to

Hmm.. can you not just delegate the -menu option to the hull?

delegate option -menu to hull
...
$self configure -menu $menuPrincipal

That seems to work for me:

snit::widget mytop {
hulltype toplevel
delegate option -menu to hull
constructor args {
menu $win.menu
$win.menu add cascade -label "Test"
$self configure -menu $win.menu
}
}
mytop .foo

Using snit 0.97.

-- Neil

Aric Bills

unread,
Nov 30, 2005, 3:03:58 AM11/30/05
to
Neil, your elegant solution definitely shows up my clunky one :) I
guess the point remains the same, though--that (unintuitively) you have
to resort to $hull rather than $win or $self to handle this issue.

0 new messages