source: trunk/gui/scripts/grab.tcl @ 111

Last change on this file since 111 was 52, checked in by mmc, 19 years ago
  • Added a back door so we can debug Rappture applications running in the nanoHUB environment.
  • Added format and label controls to the axes of an XY plot.
  • Added a <molecule><about><emblems> directive, a boolean control indicating whether or not the molecule viewer should show the atom labels by default. If missing or "off", the labels are turned off. To turn labels on by default, this must be set to a boolean true value.
  • Fixed the packing bug that was causing tabbed notebooks to be the wrong size (size of last page, rather than max overall size).
  • Added -state option to comboboxes, so they can be disabled.
  • Added a grab stack, so that when a balloon dialog has the grab and a combobox steals it away, the balloon gets it back.
File size: 3.7 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: grab - improved version of the Tk grab command
3#
4#  This version of "grab" keeps a stack of grab windows, so one
5#  window can steal and release the grab, and the grab will revert
6#  to the previous window.  If things get jammed up, you can press
7#  <Escape> three times to release the grab.
8# ======================================================================
9#  AUTHOR:  Michael McLennan, Purdue University
10#  Copyright (c) 2004-2005
11#  Purdue Research Foundation, West Lafayette, IN
12# ======================================================================
13
14namespace eval Rappture { # forward declaration }
15namespace eval Rappture::grab {
16    variable state ""  ;# local ("") or global ("-global") grab
17    variable stack ""  ;# stack of grab windows
18}
19
20proc Rappture::grab::init {} { # used for autoloading this module }
21
22bind all <Escape><Escape><Escape> Rappture::grab::reset
23
24# ----------------------------------------------------------------------
25# USAGE: grab ?-global? <window>
26# USAGE: grab set ?-global? <window>
27# USAGE: grab release <window>
28# USAGE: grab current ?<window>?
29# USAGE: grab status <window>
30#
31# This is a replacement for the usual Tk grab command.  It works
32# exactly the same way, but supports a stack of grab windows, so
33# one window can steal grab from another, and then give it back
34# later.
35# ----------------------------------------------------------------------
36rename grab _tk_grab
37proc grab {args} {
38    set op [lindex $args 0]
39    if {[winfo exists $op]} {
40        set op "set"
41    } elseif {$op == "-global" && [winfo exists [lindex $args end]]} {
42        set op "set"
43    }
44
45    if {$op == "set"} {
46        #
47        # Handle GRAB SET specially.
48        # Add the new grab window to the grab stack.
49        #
50        set state $::Rappture::grab::state
51        set window [lindex $args end]
52        if {[lsearch -exact $args -global] >= 0} {
53            set state "-global"
54        }
55
56        if {"" != $state} {
57            # if it's a global grab, store the -global flag away for later
58            set window [linsert $window 0 $state]
59
60            # all grabs from now on are global
61            set ::Rappture::grab::state "-global"
62        }
63
64        # add the current configuration to the grab stack
65        set ::Rappture::grab::stack \
66            [linsert $::Rappture::grab::stack 0 $window]
67
68        return [eval _tk_grab set $window]
69
70    } elseif {$op == "release"} {
71        #
72        # Handle GRAB RELEASE specially.
73        # Release the current grab and grab the next window on the stack.
74        # Note that the current grab is on the top of the stack.  The
75        # next one down is the one we want to revert to.
76        #
77        set window [lindex $::Rappture::grab::stack 1]
78        set ::Rappture::grab::stack [lrange $::Rappture::grab::stack 1 end]
79
80        # release the current grab
81        eval _tk_grab $args
82
83        # and set the next one
84        if {"" != $window} {
85            if {[lindex $window 0] != "-global"} {
86                # no more global grabs -- resume local grabs
87                set ::Rappture::grab::state ""
88            }
89            eval _tk_grab $window
90        }
91        return ""
92    }
93
94    # perform any other grab operation as usual...
95    return [eval _tk_grab $args]
96}
97
98# ----------------------------------------------------------------------
99# USAGE: Rappture::grab::reset
100#
101# Used internally to reset the grab whenever the user presses
102# Escape a bunch of times to break out of the grab.
103# ----------------------------------------------------------------------
104proc Rappture::grab::reset {} {
105    set w [_tk_grab current]
106    if {"" != $w} {
107        _tk_grab release $w
108    }
109    set Rappture::grab::stack ""
110    set Rappture::grab::state ""
111}
Note: See TracBrowser for help on using the repository browser.