Subject: Re: Setting up grab and focus for two toplevels... - DN [1]


"Donal K. Fellows" <donal@ugglan.demon.co.uk> - 20 Jan 2000 - comp.lang.tcl

 In article <388635F6.4C30A8D8@cisco.com>, Peter V. Morch
 <pmorch@cisco.com> writes
 >We have an application, where there is one main toplevel. Currently when
 >any dialog opens, it { catch {grab $win} ; focus $win }
 >
 >We would like to add another toplevel for statistics, and allow the user
 >to interact with that window regardless of whether there are dialogs
 >open or not since statistics don't configure anything, and since it
 >would be nice to be able to e.g. hit "Refresh" on the statistics to see
 >the effect of changing a setting or two immediately. But still restrict
 >the user from being able to interact with the main toplevel.

 If you only have one dialog tree open at a time, then you could try
 making *all* dialogs into children of the statistics toplevel.  But this
 is probably much harder than the simple technique.  Which is to create a
 new interpreter and load a new Tk session in it!  Now, this is dead easy
 to do:

     interp create foobar
     load {} Tk foobar

 Now, you'll have a new window hierarchy to use, and the (local) grab
 system is distinct between the two.  As you can see:

     # continued from above
     pack [button .b -text foo]
     toplevel .t; wm transient .t .
     pack [button .t.b -text bar]
     foobar eval {pack [button .t -text wibble]}
     update
     grab .t
     # Now you should be able to interact with the buttons labelled
     # bar and wibble, but not the one labelled foo.

 Of course, there is a bit more to it than that (communicating from the
 foobar interpreter to the main one, etc.) but you should be able to look
 that up in either the online documentation on [interp] or one of the
 many good textbooks on Tcl.

 Donal.
 --
 Donal K. Fellows (at home)
 --
 FOOLED you!  Absorb EGO SHATTERING impulse rays, polyester poltroon!!

Last modified
2000-02-10

(195.108.246.50)

Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated