Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1 | # Tkinter.py -- Tk/Tcl widget wrappers |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 2 | |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 3 | __version__ = "$Revision$" |
| 4 | |
Guido van Rossum | f8d579c | 1999-01-04 18:06:45 +0000 | [diff] [blame] | 5 | import sys |
| 6 | if sys.platform == "win32": |
Guido van Rossum | c55b0ca | 1999-02-08 15:26:49 +0000 | [diff] [blame] | 7 | import FixTk # Attempt to configure Tcl/Tk without requiring PATH |
Guido van Rossum | f8d579c | 1999-01-04 18:06:45 +0000 | [diff] [blame] | 8 | import _tkinter # If this fails your Python may not be configured for Tk |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 9 | tkinter = _tkinter # b/w compat for export |
| 10 | TclError = _tkinter.TclError |
Guido van Rossum | 7e9394a | 1995-03-17 16:21:33 +0000 | [diff] [blame] | 11 | from types import * |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 12 | from Tkconstants import * |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 13 | import string; _string = string; del string |
Guido van Rossum | f0c891a | 1998-04-29 21:43:36 +0000 | [diff] [blame] | 14 | try: |
| 15 | import MacOS; _MacOS = MacOS; del MacOS |
| 16 | except ImportError: |
| 17 | _MacOS = None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 18 | |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 19 | TkVersion = _string.atof(_tkinter.TK_VERSION) |
| 20 | TclVersion = _string.atof(_tkinter.TCL_VERSION) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 21 | |
Guido van Rossum | d6615ab | 1997-08-05 02:35:01 +0000 | [diff] [blame] | 22 | READABLE = _tkinter.READABLE |
| 23 | WRITABLE = _tkinter.WRITABLE |
| 24 | EXCEPTION = _tkinter.EXCEPTION |
Guido van Rossum | f53c86c | 1997-08-14 14:15:54 +0000 | [diff] [blame] | 25 | |
| 26 | # These are not always defined, e.g. not on Win32 with Tk 8.0 :-( |
| 27 | try: _tkinter.createfilehandler |
| 28 | except AttributeError: _tkinter.createfilehandler = None |
| 29 | try: _tkinter.deletefilehandler |
| 30 | except AttributeError: _tkinter.deletefilehandler = None |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 31 | |
| 32 | |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 33 | def _flatten(tuple): |
| 34 | res = () |
| 35 | for item in tuple: |
| 36 | if type(item) in (TupleType, ListType): |
| 37 | res = res + _flatten(item) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 38 | elif item is not None: |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 39 | res = res + (item,) |
| 40 | return res |
| 41 | |
Andrew M. Kuchling | e475e70 | 2000-06-18 18:45:50 +0000 | [diff] [blame^] | 42 | try: _flatten = _tkinter._flatten |
| 43 | except AttributeError: pass |
| 44 | |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 45 | def _cnfmerge(cnfs): |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 46 | if type(cnfs) is DictionaryType: |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 47 | return cnfs |
| 48 | elif type(cnfs) in (NoneType, StringType): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 49 | return cnfs |
| 50 | else: |
| 51 | cnf = {} |
| 52 | for c in _flatten(cnfs): |
Guido van Rossum | 65c78e1 | 1997-07-19 20:02:04 +0000 | [diff] [blame] | 53 | try: |
| 54 | cnf.update(c) |
| 55 | except (AttributeError, TypeError), msg: |
| 56 | print "_cnfmerge: fallback due to:", msg |
| 57 | for k, v in c.items(): |
| 58 | cnf[k] = v |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 59 | return cnf |
| 60 | |
Andrew M. Kuchling | e475e70 | 2000-06-18 18:45:50 +0000 | [diff] [blame^] | 61 | try: _cnfmerge = _tkinter._cnfmerge |
| 62 | except AttributeError: pass |
| 63 | |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 64 | class Event: |
| 65 | pass |
| 66 | |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 67 | _support_default_root = 1 |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 68 | _default_root = None |
| 69 | |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 70 | def NoDefaultRoot(): |
| 71 | global _support_default_root |
| 72 | _support_default_root = 0 |
Guido van Rossum | da65450 | 1998-10-06 19:06:27 +0000 | [diff] [blame] | 73 | global _default_root |
| 74 | _default_root = None |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 75 | del _default_root |
| 76 | |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 77 | def _tkerror(err): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 78 | pass |
| 79 | |
Guido van Rossum | 97aeca1 | 1994-07-07 13:12:12 +0000 | [diff] [blame] | 80 | def _exit(code='0'): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 81 | raise SystemExit, code |
Guido van Rossum | 97aeca1 | 1994-07-07 13:12:12 +0000 | [diff] [blame] | 82 | |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 83 | _varnum = 0 |
| 84 | class Variable: |
Guido van Rossum | e1a7a3b | 1996-09-05 16:45:49 +0000 | [diff] [blame] | 85 | _default = "" |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 86 | def __init__(self, master=None): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 87 | global _varnum |
Guido van Rossum | e2c6e20 | 1998-01-14 16:44:34 +0000 | [diff] [blame] | 88 | if not master: |
| 89 | master = _default_root |
| 90 | self._master = master |
| 91 | self._tk = master.tk |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 92 | self._name = 'PY_VAR' + `_varnum` |
| 93 | _varnum = _varnum + 1 |
Guido van Rossum | e1a7a3b | 1996-09-05 16:45:49 +0000 | [diff] [blame] | 94 | self.set(self._default) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 95 | def __del__(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 96 | self._tk.globalunsetvar(self._name) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 97 | def __str__(self): |
| 98 | return self._name |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 99 | def set(self, value): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 100 | return self._tk.globalsetvar(self._name, value) |
Guido van Rossum | e2c6e20 | 1998-01-14 16:44:34 +0000 | [diff] [blame] | 101 | def trace_variable(self, mode, callback): |
| 102 | cbname = self._master._register(callback) |
| 103 | self._tk.call("trace", "variable", self._name, mode, cbname) |
| 104 | return cbname |
| 105 | trace = trace_variable |
| 106 | def trace_vdelete(self, mode, cbname): |
| 107 | self._tk.call("trace", "vdelete", self._name, mode, cbname) |
Guido van Rossum | 0001a11 | 1998-02-19 21:20:30 +0000 | [diff] [blame] | 108 | self._master.deletecommand(cbname) |
Guido van Rossum | e2c6e20 | 1998-01-14 16:44:34 +0000 | [diff] [blame] | 109 | def trace_vinfo(self): |
| 110 | return map(self._tk.split, self._tk.splitlist( |
| 111 | self._tk.call("trace", "vinfo", self._name))) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 112 | |
| 113 | class StringVar(Variable): |
Guido van Rossum | e1a7a3b | 1996-09-05 16:45:49 +0000 | [diff] [blame] | 114 | _default = "" |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 115 | def __init__(self, master=None): |
| 116 | Variable.__init__(self, master) |
| 117 | def get(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 118 | return self._tk.globalgetvar(self._name) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 119 | |
| 120 | class IntVar(Variable): |
Guido van Rossum | 0b96b94 | 1996-12-27 15:30:20 +0000 | [diff] [blame] | 121 | _default = 0 |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 122 | def __init__(self, master=None): |
| 123 | Variable.__init__(self, master) |
| 124 | def get(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 125 | return getint(self._tk.globalgetvar(self._name)) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 126 | |
| 127 | class DoubleVar(Variable): |
Guido van Rossum | 0b96b94 | 1996-12-27 15:30:20 +0000 | [diff] [blame] | 128 | _default = 0.0 |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 129 | def __init__(self, master=None): |
| 130 | Variable.__init__(self, master) |
| 131 | def get(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 132 | return getdouble(self._tk.globalgetvar(self._name)) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 133 | |
| 134 | class BooleanVar(Variable): |
Guido van Rossum | e1a7a3b | 1996-09-05 16:45:49 +0000 | [diff] [blame] | 135 | _default = "false" |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 136 | def __init__(self, master=None): |
| 137 | Variable.__init__(self, master) |
| 138 | def get(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 139 | return self._tk.getboolean(self._tk.globalgetvar(self._name)) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 140 | |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 141 | def mainloop(n=0): |
| 142 | _default_root.tk.mainloop(n) |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 143 | |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 144 | getint = int |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 145 | |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 146 | getdouble = float |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 147 | |
| 148 | def getboolean(s): |
| 149 | return _default_root.tk.getboolean(s) |
| 150 | |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 151 | # Methods defined on both toplevel and interior widgets |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 152 | class Misc: |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 153 | # XXX font command? |
Fred Drake | 526749b | 1997-05-03 04:16:23 +0000 | [diff] [blame] | 154 | _tclCommands = None |
Guido van Rossum | 103cc6d | 1997-04-14 13:30:24 +0000 | [diff] [blame] | 155 | def destroy(self): |
| 156 | if self._tclCommands is not None: |
| 157 | for name in self._tclCommands: |
| 158 | #print '- Tkinter: deleted command', name |
| 159 | self.tk.deletecommand(name) |
| 160 | self._tclCommands = None |
| 161 | def deletecommand(self, name): |
| 162 | #print '- Tkinter: deleted command', name |
| 163 | self.tk.deletecommand(name) |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 164 | try: |
| 165 | self._tclCommands.remove(name) |
| 166 | except ValueError: |
| 167 | pass |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 168 | def tk_strictMotif(self, boolean=None): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 169 | return self.tk.getboolean(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 170 | 'set', 'tk_strictMotif', boolean)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 171 | def tk_bisque(self): |
| 172 | self.tk.call('tk_bisque') |
| 173 | def tk_setPalette(self, *args, **kw): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 174 | self.tk.call(('tk_setPalette',) |
Fred Drake | 3faf9b4 | 1996-10-04 19:23:04 +0000 | [diff] [blame] | 175 | + _flatten(args) + _flatten(kw.items())) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 176 | def tk_menuBar(self, *args): |
Guido van Rossum | 688bbfc | 1996-09-10 12:39:26 +0000 | [diff] [blame] | 177 | pass # obsolete since Tk 4.0 |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 178 | def wait_variable(self, name='PY_VAR'): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 179 | self.tk.call('tkwait', 'variable', name) |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 180 | waitvar = wait_variable # XXX b/w compat |
Guido van Rossum | 9beb932 | 1994-06-27 23:15:31 +0000 | [diff] [blame] | 181 | def wait_window(self, window=None): |
| 182 | if window == None: |
| 183 | window = self |
| 184 | self.tk.call('tkwait', 'window', window._w) |
| 185 | def wait_visibility(self, window=None): |
| 186 | if window == None: |
| 187 | window = self |
| 188 | self.tk.call('tkwait', 'visibility', window._w) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 189 | def setvar(self, name='PY_VAR', value='1'): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 190 | self.tk.setvar(name, value) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 191 | def getvar(self, name='PY_VAR'): |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 192 | return self.tk.getvar(name) |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 193 | getint = int |
| 194 | getdouble = float |
Guido van Rossum | 1e9e400 | 1994-06-20 09:09:51 +0000 | [diff] [blame] | 195 | def getboolean(self, s): |
| 196 | return self.tk.getboolean(s) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 197 | def focus_set(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 198 | self.tk.call('focus', self._w) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 199 | focus = focus_set # XXX b/w compat? |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 200 | def focus_force(self): |
| 201 | self.tk.call('focus', '-force', self._w) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 202 | def focus_get(self): |
| 203 | name = self.tk.call('focus') |
Guido van Rossum | 5468a7b | 1996-08-08 18:31:42 +0000 | [diff] [blame] | 204 | if name == 'none' or not name: return None |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 205 | return self._nametowidget(name) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 206 | def focus_displayof(self): |
| 207 | name = self.tk.call('focus', '-displayof', self._w) |
| 208 | if name == 'none' or not name: return None |
| 209 | return self._nametowidget(name) |
| 210 | def focus_lastfor(self): |
| 211 | name = self.tk.call('focus', '-lastfor', self._w) |
| 212 | if name == 'none' or not name: return None |
| 213 | return self._nametowidget(name) |
| 214 | def tk_focusFollowsMouse(self): |
| 215 | self.tk.call('tk_focusFollowsMouse') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 216 | def tk_focusNext(self): |
| 217 | name = self.tk.call('tk_focusNext', self._w) |
| 218 | if not name: return None |
| 219 | return self._nametowidget(name) |
| 220 | def tk_focusPrev(self): |
| 221 | name = self.tk.call('tk_focusPrev', self._w) |
| 222 | if not name: return None |
| 223 | return self._nametowidget(name) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 224 | def after(self, ms, func=None, *args): |
| 225 | if not func: |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 226 | # I'd rather use time.sleep(ms*0.001) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 227 | self.tk.call('after', ms) |
| 228 | else: |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 229 | # XXX Disgusting hack to clean up after calling func |
| 230 | tmp = [] |
Guido van Rossum | 103cc6d | 1997-04-14 13:30:24 +0000 | [diff] [blame] | 231 | def callit(func=func, args=args, self=self, tmp=tmp): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 232 | try: |
| 233 | apply(func, args) |
| 234 | finally: |
Guido van Rossum | 0c92000 | 1998-09-14 19:06:39 +0000 | [diff] [blame] | 235 | try: |
| 236 | self.deletecommand(tmp[0]) |
| 237 | except TclError: |
| 238 | pass |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 239 | name = self._register(callit) |
| 240 | tmp.append(name) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 241 | return self.tk.call('after', ms, name) |
| 242 | def after_idle(self, func, *args): |
| 243 | return apply(self.after, ('idle', func) + args) |
| 244 | def after_cancel(self, id): |
| 245 | self.tk.call('after', 'cancel', id) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 246 | def bell(self, displayof=0): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 247 | self.tk.call(('bell',) + self._displayof(displayof)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 248 | # Clipboard handling: |
| 249 | def clipboard_clear(self, **kw): |
| 250 | if not kw.has_key('displayof'): kw['displayof'] = self._w |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 251 | self.tk.call(('clipboard', 'clear') + self._options(kw)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 252 | def clipboard_append(self, string, **kw): |
| 253 | if not kw.has_key('displayof'): kw['displayof'] = self._w |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 254 | self.tk.call(('clipboard', 'append') + self._options(kw) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 255 | + ('--', string)) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 256 | # XXX grab current w/o window argument |
| 257 | def grab_current(self): |
| 258 | name = self.tk.call('grab', 'current', self._w) |
| 259 | if not name: return None |
| 260 | return self._nametowidget(name) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 261 | def grab_release(self): |
| 262 | self.tk.call('grab', 'release', self._w) |
| 263 | def grab_set(self): |
| 264 | self.tk.call('grab', 'set', self._w) |
| 265 | def grab_set_global(self): |
| 266 | self.tk.call('grab', 'set', '-global', self._w) |
| 267 | def grab_status(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 268 | status = self.tk.call('grab', 'status', self._w) |
| 269 | if status == 'none': status = None |
| 270 | return status |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 271 | def lower(self, belowThis=None): |
| 272 | self.tk.call('lower', self._w, belowThis) |
Guido van Rossum | 780044f | 1994-10-20 22:02:27 +0000 | [diff] [blame] | 273 | def option_add(self, pattern, value, priority = None): |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 274 | self.tk.call('option', 'add', pattern, value, priority) |
Guido van Rossum | 780044f | 1994-10-20 22:02:27 +0000 | [diff] [blame] | 275 | def option_clear(self): |
| 276 | self.tk.call('option', 'clear') |
| 277 | def option_get(self, name, className): |
| 278 | return self.tk.call('option', 'get', self._w, name, className) |
| 279 | def option_readfile(self, fileName, priority = None): |
| 280 | self.tk.call('option', 'readfile', fileName, priority) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 281 | def selection_clear(self, **kw): |
| 282 | if not kw.has_key('displayof'): kw['displayof'] = self._w |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 283 | self.tk.call(('selection', 'clear') + self._options(kw)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 284 | def selection_get(self, **kw): |
| 285 | if not kw.has_key('displayof'): kw['displayof'] = self._w |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 286 | return self.tk.call(('selection', 'get') + self._options(kw)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 287 | def selection_handle(self, command, **kw): |
| 288 | name = self._register(command) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 289 | self.tk.call(('selection', 'handle') + self._options(kw) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 290 | + (self._w, name)) |
| 291 | def selection_own(self, **kw): |
| 292 | "Become owner of X selection." |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 293 | self.tk.call(('selection', 'own') + |
| 294 | self._options(kw) + (self._w,)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 295 | def selection_own_get(self, **kw): |
| 296 | "Find owner of X selection." |
| 297 | if not kw.has_key('displayof'): kw['displayof'] = self._w |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 298 | name = self.tk.call(('selection', 'own') + self._options(kw)) |
Guido van Rossum | 76f587b | 1997-01-21 23:22:03 +0000 | [diff] [blame] | 299 | if not name: return None |
| 300 | return self._nametowidget(name) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 301 | def send(self, interp, cmd, *args): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 302 | return self.tk.call(('send', interp, cmd) + args) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 303 | def lower(self, belowThis=None): |
Guido van Rossum | 6e8ec59 | 1996-09-11 14:25:41 +0000 | [diff] [blame] | 304 | self.tk.call('lower', self._w, belowThis) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 305 | def tkraise(self, aboveThis=None): |
| 306 | self.tk.call('raise', self._w, aboveThis) |
| 307 | lift = tkraise |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 308 | def colormodel(self, value=None): |
| 309 | return self.tk.call('tk', 'colormodel', self._w, value) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 310 | def winfo_atom(self, name, displayof=0): |
| 311 | args = ('winfo', 'atom') + self._displayof(displayof) + (name,) |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 312 | return getint(self.tk.call(args)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 313 | def winfo_atomname(self, id, displayof=0): |
| 314 | args = ('winfo', 'atomname') \ |
| 315 | + self._displayof(displayof) + (id,) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 316 | return self.tk.call(args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 317 | def winfo_cells(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 318 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 319 | self.tk.call('winfo', 'cells', self._w)) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 320 | def winfo_children(self): |
| 321 | return map(self._nametowidget, |
| 322 | self.tk.splitlist(self.tk.call( |
| 323 | 'winfo', 'children', self._w))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 324 | def winfo_class(self): |
| 325 | return self.tk.call('winfo', 'class', self._w) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 326 | def winfo_colormapfull(self): |
| 327 | return self.tk.getboolean( |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 328 | self.tk.call('winfo', 'colormapfull', self._w)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 329 | def winfo_containing(self, rootX, rootY, displayof=0): |
| 330 | args = ('winfo', 'containing') \ |
| 331 | + self._displayof(displayof) + (rootX, rootY) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 332 | name = self.tk.call(args) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 333 | if not name: return None |
| 334 | return self._nametowidget(name) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 335 | def winfo_depth(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 336 | return getint(self.tk.call('winfo', 'depth', self._w)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 337 | def winfo_exists(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 338 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 339 | self.tk.call('winfo', 'exists', self._w)) |
| 340 | def winfo_fpixels(self, number): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 341 | return getdouble(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 342 | 'winfo', 'fpixels', self._w, number)) |
| 343 | def winfo_geometry(self): |
| 344 | return self.tk.call('winfo', 'geometry', self._w) |
| 345 | def winfo_height(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 346 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 347 | self.tk.call('winfo', 'height', self._w)) |
| 348 | def winfo_id(self): |
Guido van Rossum | cef4c84 | 1998-06-19 04:35:45 +0000 | [diff] [blame] | 349 | return self.tk.getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 350 | self.tk.call('winfo', 'id', self._w)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 351 | def winfo_interps(self, displayof=0): |
| 352 | args = ('winfo', 'interps') + self._displayof(displayof) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 353 | return self.tk.splitlist(self.tk.call(args)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 354 | def winfo_ismapped(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 355 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 356 | self.tk.call('winfo', 'ismapped', self._w)) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 357 | def winfo_manager(self): |
| 358 | return self.tk.call('winfo', 'manager', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 359 | def winfo_name(self): |
| 360 | return self.tk.call('winfo', 'name', self._w) |
| 361 | def winfo_parent(self): |
| 362 | return self.tk.call('winfo', 'parent', self._w) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 363 | def winfo_pathname(self, id, displayof=0): |
| 364 | args = ('winfo', 'pathname') \ |
| 365 | + self._displayof(displayof) + (id,) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 366 | return self.tk.call(args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 367 | def winfo_pixels(self, number): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 368 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 369 | self.tk.call('winfo', 'pixels', self._w, number)) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 370 | def winfo_pointerx(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 371 | return getint( |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 372 | self.tk.call('winfo', 'pointerx', self._w)) |
| 373 | def winfo_pointerxy(self): |
| 374 | return self._getints( |
| 375 | self.tk.call('winfo', 'pointerxy', self._w)) |
| 376 | def winfo_pointery(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 377 | return getint( |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 378 | self.tk.call('winfo', 'pointery', self._w)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 379 | def winfo_reqheight(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 380 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 381 | self.tk.call('winfo', 'reqheight', self._w)) |
| 382 | def winfo_reqwidth(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 383 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 384 | self.tk.call('winfo', 'reqwidth', self._w)) |
| 385 | def winfo_rgb(self, color): |
| 386 | return self._getints( |
| 387 | self.tk.call('winfo', 'rgb', self._w, color)) |
| 388 | def winfo_rootx(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 389 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 390 | self.tk.call('winfo', 'rootx', self._w)) |
| 391 | def winfo_rooty(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 392 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 393 | self.tk.call('winfo', 'rooty', self._w)) |
| 394 | def winfo_screen(self): |
| 395 | return self.tk.call('winfo', 'screen', self._w) |
| 396 | def winfo_screencells(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 397 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 398 | self.tk.call('winfo', 'screencells', self._w)) |
| 399 | def winfo_screendepth(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 400 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 401 | self.tk.call('winfo', 'screendepth', self._w)) |
| 402 | def winfo_screenheight(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 403 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 404 | self.tk.call('winfo', 'screenheight', self._w)) |
| 405 | def winfo_screenmmheight(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 406 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 407 | self.tk.call('winfo', 'screenmmheight', self._w)) |
| 408 | def winfo_screenmmwidth(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 409 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 410 | self.tk.call('winfo', 'screenmmwidth', self._w)) |
| 411 | def winfo_screenvisual(self): |
| 412 | return self.tk.call('winfo', 'screenvisual', self._w) |
| 413 | def winfo_screenwidth(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 414 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 415 | self.tk.call('winfo', 'screenwidth', self._w)) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 416 | def winfo_server(self): |
| 417 | return self.tk.call('winfo', 'server', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 418 | def winfo_toplevel(self): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 419 | return self._nametowidget(self.tk.call( |
| 420 | 'winfo', 'toplevel', self._w)) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 421 | def winfo_viewable(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 422 | return getint( |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 423 | self.tk.call('winfo', 'viewable', self._w)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 424 | def winfo_visual(self): |
| 425 | return self.tk.call('winfo', 'visual', self._w) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 426 | def winfo_visualid(self): |
| 427 | return self.tk.call('winfo', 'visualid', self._w) |
| 428 | def winfo_visualsavailable(self, includeids=0): |
| 429 | data = self.tk.split( |
| 430 | self.tk.call('winfo', 'visualsavailable', self._w, |
| 431 | includeids and 'includeids' or None)) |
Guido van Rossum | f8d8e07 | 1999-10-18 22:06:38 +0000 | [diff] [blame] | 432 | return map(self.__winfo_parseitem, data) |
| 433 | def __winfo_parseitem(self, t): |
| 434 | return t[:1] + tuple(map(self.__winfo_getint, t[1:])) |
| 435 | def __winfo_getint(self, x): |
| 436 | return _string.atoi(x, 0) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 437 | def winfo_vrootheight(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 438 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 439 | self.tk.call('winfo', 'vrootheight', self._w)) |
| 440 | def winfo_vrootwidth(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 441 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 442 | self.tk.call('winfo', 'vrootwidth', self._w)) |
| 443 | def winfo_vrootx(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 444 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 445 | self.tk.call('winfo', 'vrootx', self._w)) |
| 446 | def winfo_vrooty(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 447 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 448 | self.tk.call('winfo', 'vrooty', self._w)) |
| 449 | def winfo_width(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 450 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 451 | self.tk.call('winfo', 'width', self._w)) |
| 452 | def winfo_x(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 453 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 454 | self.tk.call('winfo', 'x', self._w)) |
| 455 | def winfo_y(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 456 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 457 | self.tk.call('winfo', 'y', self._w)) |
| 458 | def update(self): |
| 459 | self.tk.call('update') |
| 460 | def update_idletasks(self): |
| 461 | self.tk.call('update', 'idletasks') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 462 | def bindtags(self, tagList=None): |
| 463 | if tagList is None: |
| 464 | return self.tk.splitlist( |
| 465 | self.tk.call('bindtags', self._w)) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 466 | else: |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 467 | self.tk.call('bindtags', self._w, tagList) |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 468 | def _bind(self, what, sequence, func, add, needcleanup=1): |
Guido van Rossum | 88b63b8 | 1998-06-25 18:54:49 +0000 | [diff] [blame] | 469 | if type(func) is StringType: |
| 470 | self.tk.call(what + (sequence, func)) |
| 471 | elif func: |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 472 | funcid = self._register(func, self._substitute, |
| 473 | needcleanup) |
Guido van Rossum | dc59340 | 1998-04-29 22:16:57 +0000 | [diff] [blame] | 474 | cmd = ('%sif {"[%s %s]" == "break"} break\n' |
| 475 | % |
| 476 | (add and '+' or '', |
| 477 | funcid, |
| 478 | _string.join(self._subst_format))) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 479 | self.tk.call(what + (sequence, cmd)) |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 480 | return funcid |
Guido van Rossum | c86b7c6 | 1998-08-31 16:54:33 +0000 | [diff] [blame] | 481 | elif sequence: |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 482 | return self.tk.call(what + (sequence,)) |
Guido van Rossum | c86b7c6 | 1998-08-31 16:54:33 +0000 | [diff] [blame] | 483 | else: |
| 484 | return self.tk.splitlist(self.tk.call(what)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 485 | def bind(self, sequence=None, func=None, add=None): |
| 486 | return self._bind(('bind', self._w), sequence, func, add) |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 487 | def unbind(self, sequence, funcid=None): |
Guido van Rossum | ef8f881 | 1994-08-08 12:47:33 +0000 | [diff] [blame] | 488 | self.tk.call('bind', self._w, sequence, '') |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 489 | if funcid: |
| 490 | self.deletecommand(funcid) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 491 | def bind_all(self, sequence=None, func=None, add=None): |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 492 | return self._bind(('bind', 'all'), sequence, func, add, 0) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 493 | def unbind_all(self, sequence): |
| 494 | self.tk.call('bind', 'all' , sequence, '') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 495 | def bind_class(self, className, sequence=None, func=None, add=None): |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 496 | return self._bind(('bind', className), sequence, func, add, 0) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 497 | def unbind_class(self, className, sequence): |
| 498 | self.tk.call('bind', className , sequence, '') |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 499 | def mainloop(self, n=0): |
| 500 | self.tk.mainloop(n) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 501 | def quit(self): |
| 502 | self.tk.quit() |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 503 | def _getints(self, string): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 504 | if string: |
| 505 | return tuple(map(getint, self.tk.splitlist(string))) |
Guido van Rossum | 7e9394a | 1995-03-17 16:21:33 +0000 | [diff] [blame] | 506 | def _getdoubles(self, string): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 507 | if string: |
| 508 | return tuple(map(getdouble, self.tk.splitlist(string))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 509 | def _getboolean(self, string): |
| 510 | if string: |
| 511 | return self.tk.getboolean(string) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 512 | def _displayof(self, displayof): |
| 513 | if displayof: |
| 514 | return ('-displayof', displayof) |
| 515 | if displayof is None: |
| 516 | return ('-displayof', self._w) |
| 517 | return () |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 518 | def _options(self, cnf, kw = None): |
| 519 | if kw: |
| 520 | cnf = _cnfmerge((cnf, kw)) |
| 521 | else: |
| 522 | cnf = _cnfmerge(cnf) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 523 | res = () |
| 524 | for k, v in cnf.items(): |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 525 | if v is not None: |
| 526 | if k[-1] == '_': k = k[:-1] |
| 527 | if callable(v): |
| 528 | v = self._register(v) |
| 529 | res = res + ('-'+k, v) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 530 | return res |
Guido van Rossum | 98b9d77 | 1997-12-12 00:09:34 +0000 | [diff] [blame] | 531 | def nametowidget(self, name): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 532 | w = self |
| 533 | if name[0] == '.': |
| 534 | w = w._root() |
| 535 | name = name[1:] |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 536 | find = _string.find |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 537 | while name: |
| 538 | i = find(name, '.') |
| 539 | if i >= 0: |
| 540 | name, tail = name[:i], name[i+1:] |
| 541 | else: |
| 542 | tail = '' |
| 543 | w = w.children[name] |
| 544 | name = tail |
| 545 | return w |
Guido van Rossum | 98b9d77 | 1997-12-12 00:09:34 +0000 | [diff] [blame] | 546 | _nametowidget = nametowidget |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 547 | def _register(self, func, subst=None, needcleanup=1): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 548 | f = CallWrapper(func, subst, self).__call__ |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 549 | name = `id(f)` |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 550 | try: |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 551 | func = func.im_func |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 552 | except AttributeError: |
| 553 | pass |
| 554 | try: |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 555 | name = name + func.__name__ |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 556 | except AttributeError: |
| 557 | pass |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 558 | self.tk.createcommand(name, f) |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 559 | if needcleanup: |
| 560 | if self._tclCommands is None: |
| 561 | self._tclCommands = [] |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 562 | self._tclCommands.append(name) |
Guido van Rossum | 103cc6d | 1997-04-14 13:30:24 +0000 | [diff] [blame] | 563 | #print '+ Tkinter created command', name |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 564 | return name |
Guido van Rossum | 9beb932 | 1994-06-27 23:15:31 +0000 | [diff] [blame] | 565 | register = _register |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 566 | def _root(self): |
| 567 | w = self |
| 568 | while w.master: w = w.master |
| 569 | return w |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 570 | _subst_format = ('%#', '%b', '%f', '%h', '%k', |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 571 | '%s', '%t', '%w', '%x', '%y', |
| 572 | '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y') |
| 573 | def _substitute(self, *args): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 574 | if len(args) != len(self._subst_format): return args |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 575 | getboolean = self.tk.getboolean |
| 576 | getint = int |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 577 | nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y = args |
| 578 | # Missing: (a, c, d, m, o, v, B, R) |
| 579 | e = Event() |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 580 | e.serial = getint(nsign) |
| 581 | e.num = getint(b) |
| 582 | try: e.focus = getboolean(f) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 583 | except TclError: pass |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 584 | e.height = getint(h) |
| 585 | e.keycode = getint(k) |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 586 | # For Visibility events, event state is a string and |
| 587 | # not an integer: |
| 588 | try: |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 589 | e.state = getint(s) |
Guido van Rossum | fe02efd | 1998-06-09 02:37:45 +0000 | [diff] [blame] | 590 | except ValueError: |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 591 | e.state = s |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 592 | e.time = getint(t) |
| 593 | e.width = getint(w) |
| 594 | e.x = getint(x) |
| 595 | e.y = getint(y) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 596 | e.char = A |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 597 | try: e.send_event = getboolean(E) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 598 | except TclError: pass |
| 599 | e.keysym = K |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 600 | e.keysym_num = getint(N) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 601 | e.type = T |
Guido van Rossum | e86271a | 1998-04-27 19:32:59 +0000 | [diff] [blame] | 602 | try: |
| 603 | e.widget = self._nametowidget(W) |
| 604 | except KeyError: |
| 605 | e.widget = W |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 606 | e.x_root = getint(X) |
| 607 | e.y_root = getint(Y) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 608 | return (e,) |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 609 | def _report_exception(self): |
| 610 | import sys |
| 611 | exc, val, tb = sys.exc_type, sys.exc_value, sys.exc_traceback |
| 612 | root = self._root() |
| 613 | root.report_callback_exception(exc, val, tb) |
Guido van Rossum | 83bd9a9 | 1997-09-29 23:24:52 +0000 | [diff] [blame] | 614 | # These used to be defined in Widget: |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 615 | def configure(self, cnf=None, **kw): |
Guido van Rossum | 83bd9a9 | 1997-09-29 23:24:52 +0000 | [diff] [blame] | 616 | # XXX ought to generalize this so tag_config etc. can use it |
| 617 | if kw: |
| 618 | cnf = _cnfmerge((cnf, kw)) |
| 619 | elif cnf: |
| 620 | cnf = _cnfmerge(cnf) |
| 621 | if cnf is None: |
| 622 | cnf = {} |
| 623 | for x in self.tk.split( |
| 624 | self.tk.call(self._w, 'configure')): |
| 625 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 626 | return cnf |
| 627 | if type(cnf) is StringType: |
| 628 | x = self.tk.split(self.tk.call( |
| 629 | self._w, 'configure', '-'+cnf)) |
| 630 | return (x[0][1:],) + x[1:] |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 631 | self.tk.call((self._w, 'configure') |
Guido van Rossum | 83bd9a9 | 1997-09-29 23:24:52 +0000 | [diff] [blame] | 632 | + self._options(cnf)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 633 | config = configure |
Guido van Rossum | 83bd9a9 | 1997-09-29 23:24:52 +0000 | [diff] [blame] | 634 | def cget(self, key): |
| 635 | return self.tk.call(self._w, 'cget', '-' + key) |
| 636 | __getitem__ = cget |
| 637 | def __setitem__(self, key, value): |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 638 | self.configure({key: value}) |
Guido van Rossum | 83bd9a9 | 1997-09-29 23:24:52 +0000 | [diff] [blame] | 639 | def keys(self): |
| 640 | return map(lambda x: x[0][1:], |
| 641 | self.tk.split(self.tk.call(self._w, 'configure'))) |
| 642 | def __str__(self): |
| 643 | return self._w |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 644 | # Pack methods that apply to the master |
| 645 | _noarg_ = ['_noarg_'] |
| 646 | def pack_propagate(self, flag=_noarg_): |
| 647 | if flag is Misc._noarg_: |
| 648 | return self._getboolean(self.tk.call( |
| 649 | 'pack', 'propagate', self._w)) |
| 650 | else: |
| 651 | self.tk.call('pack', 'propagate', self._w, flag) |
| 652 | propagate = pack_propagate |
| 653 | def pack_slaves(self): |
| 654 | return map(self._nametowidget, |
| 655 | self.tk.splitlist( |
| 656 | self.tk.call('pack', 'slaves', self._w))) |
| 657 | slaves = pack_slaves |
| 658 | # Place method that applies to the master |
| 659 | def place_slaves(self): |
| 660 | return map(self._nametowidget, |
| 661 | self.tk.splitlist( |
| 662 | self.tk.call( |
| 663 | 'place', 'slaves', self._w))) |
| 664 | # Grid methods that apply to the master |
Barry Warsaw | 107e623 | 1998-12-15 00:44:15 +0000 | [diff] [blame] | 665 | def grid_bbox(self, column=None, row=None, col2=None, row2=None): |
| 666 | args = ('grid', 'bbox', self._w) |
| 667 | if column is not None and row is not None: |
| 668 | args = args + (column, row) |
| 669 | if col2 is not None and row2 is not None: |
| 670 | args = args + (col2, row2) |
| 671 | return self._getints(apply(self.tk.call, args)) or None |
| 672 | |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 673 | bbox = grid_bbox |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 674 | def _grid_configure(self, command, index, cnf, kw): |
| 675 | if type(cnf) is StringType and not kw: |
| 676 | if cnf[-1:] == '_': |
| 677 | cnf = cnf[:-1] |
| 678 | if cnf[:1] != '-': |
| 679 | cnf = '-'+cnf |
| 680 | options = (cnf,) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 681 | else: |
| 682 | options = self._options(cnf, kw) |
| 683 | if not options: |
| 684 | res = self.tk.call('grid', |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 685 | command, self._w, index) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 686 | words = self.tk.splitlist(res) |
| 687 | dict = {} |
| 688 | for i in range(0, len(words), 2): |
| 689 | key = words[i][1:] |
| 690 | value = words[i+1] |
| 691 | if not value: |
| 692 | value = None |
| 693 | elif '.' in value: |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 694 | value = getdouble(value) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 695 | else: |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 696 | value = getint(value) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 697 | dict[key] = value |
| 698 | return dict |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 699 | res = self.tk.call( |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 700 | ('grid', command, self._w, index) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 701 | + options) |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 702 | if len(options) == 1: |
| 703 | if not res: return None |
| 704 | # In Tk 7.5, -width can be a float |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 705 | if '.' in res: return getdouble(res) |
| 706 | return getint(res) |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 707 | def grid_columnconfigure(self, index, cnf={}, **kw): |
| 708 | return self._grid_configure('columnconfigure', index, cnf, kw) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 709 | columnconfigure = grid_columnconfigure |
| 710 | def grid_propagate(self, flag=_noarg_): |
| 711 | if flag is Misc._noarg_: |
| 712 | return self._getboolean(self.tk.call( |
| 713 | 'grid', 'propagate', self._w)) |
| 714 | else: |
| 715 | self.tk.call('grid', 'propagate', self._w, flag) |
| 716 | def grid_rowconfigure(self, index, cnf={}, **kw): |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 717 | return self._grid_configure('rowconfigure', index, cnf, kw) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 718 | rowconfigure = grid_rowconfigure |
| 719 | def grid_size(self): |
| 720 | return self._getints( |
| 721 | self.tk.call('grid', 'size', self._w)) or None |
| 722 | size = grid_size |
Guido van Rossum | 1cd6a45 | 1997-12-30 04:07:19 +0000 | [diff] [blame] | 723 | def grid_slaves(self, row=None, column=None): |
| 724 | args = () |
Guido van Rossum | eb354b3 | 1999-03-16 21:54:50 +0000 | [diff] [blame] | 725 | if row is not None: |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 726 | args = args + ('-row', row) |
Guido van Rossum | eb354b3 | 1999-03-16 21:54:50 +0000 | [diff] [blame] | 727 | if column is not None: |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 728 | args = args + ('-column', column) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 729 | return map(self._nametowidget, |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 730 | self.tk.splitlist(self.tk.call( |
| 731 | ('grid', 'slaves', self._w) + args))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 732 | |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 733 | # Support for the "event" command, new in Tk 4.2. |
| 734 | # By Case Roole. |
| 735 | |
Guido van Rossum | 56c04b8 | 1998-04-06 03:10:03 +0000 | [diff] [blame] | 736 | def event_add(self, virtual, *sequences): |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 737 | args = ('event', 'add', virtual) + sequences |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 738 | self.tk.call(args) |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 739 | |
Guido van Rossum | 56c04b8 | 1998-04-06 03:10:03 +0000 | [diff] [blame] | 740 | def event_delete(self, virtual, *sequences): |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 741 | args = ('event', 'delete', virtual) + sequences |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 742 | self.tk.call(args) |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 743 | |
| 744 | def event_generate(self, sequence, **kw): |
| 745 | args = ('event', 'generate', self._w, sequence) |
Guido van Rossum | 56c04b8 | 1998-04-06 03:10:03 +0000 | [diff] [blame] | 746 | for k, v in kw.items(): |
| 747 | args = args + ('-%s' % k, str(v)) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 748 | self.tk.call(args) |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 749 | |
Guido van Rossum | 56c04b8 | 1998-04-06 03:10:03 +0000 | [diff] [blame] | 750 | def event_info(self, virtual=None): |
| 751 | return self.tk.splitlist( |
| 752 | self.tk.call('event', 'info', virtual)) |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 753 | |
Guido van Rossum | c296651 | 1998-04-10 19:16:10 +0000 | [diff] [blame] | 754 | # Image related commands |
| 755 | |
| 756 | def image_names(self): |
| 757 | return self.tk.call('image', 'names') |
| 758 | |
| 759 | def image_types(self): |
| 760 | return self.tk.call('image', 'types') |
| 761 | |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 762 | |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 763 | class CallWrapper: |
| 764 | def __init__(self, func, subst, widget): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 765 | self.func = func |
| 766 | self.subst = subst |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 767 | self.widget = widget |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 768 | def __call__(self, *args): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 769 | try: |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 770 | if self.subst: |
| 771 | args = apply(self.subst, args) |
| 772 | return apply(self.func, args) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 773 | except SystemExit, msg: |
| 774 | raise SystemExit, msg |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 775 | except: |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 776 | self.widget._report_exception() |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 777 | |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 778 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 779 | class Wm: |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 780 | def wm_aspect(self, |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 781 | minNumer=None, minDenom=None, |
| 782 | maxNumer=None, maxDenom=None): |
| 783 | return self._getints( |
| 784 | self.tk.call('wm', 'aspect', self._w, |
| 785 | minNumer, minDenom, |
| 786 | maxNumer, maxDenom)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 787 | aspect = wm_aspect |
| 788 | def wm_client(self, name=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 789 | return self.tk.call('wm', 'client', self._w, name) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 790 | client = wm_client |
| 791 | def wm_colormapwindows(self, *wlist): |
Guido van Rossum | 8fa42af | 1999-10-20 12:29:56 +0000 | [diff] [blame] | 792 | if len(wlist) > 1: |
| 793 | wlist = (wlist,) # Tk needs a list of windows here |
| 794 | args = ('wm', 'colormapwindows', self._w) + wlist |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 795 | return map(self._nametowidget, self.tk.call(args)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 796 | colormapwindows = wm_colormapwindows |
| 797 | def wm_command(self, value=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 798 | return self.tk.call('wm', 'command', self._w, value) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 799 | command = wm_command |
| 800 | def wm_deiconify(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 801 | return self.tk.call('wm', 'deiconify', self._w) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 802 | deiconify = wm_deiconify |
| 803 | def wm_focusmodel(self, model=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 804 | return self.tk.call('wm', 'focusmodel', self._w, model) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 805 | focusmodel = wm_focusmodel |
| 806 | def wm_frame(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 807 | return self.tk.call('wm', 'frame', self._w) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 808 | frame = wm_frame |
| 809 | def wm_geometry(self, newGeometry=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 810 | return self.tk.call('wm', 'geometry', self._w, newGeometry) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 811 | geometry = wm_geometry |
| 812 | def wm_grid(self, |
Guido van Rossum | 21df8f5 | 1998-02-24 23:26:18 +0000 | [diff] [blame] | 813 | baseWidth=None, baseHeight=None, |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 814 | widthInc=None, heightInc=None): |
| 815 | return self._getints(self.tk.call( |
| 816 | 'wm', 'grid', self._w, |
Guido van Rossum | 4d9d3f1 | 1997-12-27 15:14:43 +0000 | [diff] [blame] | 817 | baseWidth, baseHeight, widthInc, heightInc)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 818 | grid = wm_grid |
| 819 | def wm_group(self, pathName=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 820 | return self.tk.call('wm', 'group', self._w, pathName) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 821 | group = wm_group |
| 822 | def wm_iconbitmap(self, bitmap=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 823 | return self.tk.call('wm', 'iconbitmap', self._w, bitmap) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 824 | iconbitmap = wm_iconbitmap |
| 825 | def wm_iconify(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 826 | return self.tk.call('wm', 'iconify', self._w) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 827 | iconify = wm_iconify |
| 828 | def wm_iconmask(self, bitmap=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 829 | return self.tk.call('wm', 'iconmask', self._w, bitmap) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 830 | iconmask = wm_iconmask |
| 831 | def wm_iconname(self, newName=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 832 | return self.tk.call('wm', 'iconname', self._w, newName) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 833 | iconname = wm_iconname |
| 834 | def wm_iconposition(self, x=None, y=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 835 | return self._getints(self.tk.call( |
| 836 | 'wm', 'iconposition', self._w, x, y)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 837 | iconposition = wm_iconposition |
| 838 | def wm_iconwindow(self, pathName=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 839 | return self.tk.call('wm', 'iconwindow', self._w, pathName) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 840 | iconwindow = wm_iconwindow |
| 841 | def wm_maxsize(self, width=None, height=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 842 | return self._getints(self.tk.call( |
| 843 | 'wm', 'maxsize', self._w, width, height)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 844 | maxsize = wm_maxsize |
| 845 | def wm_minsize(self, width=None, height=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 846 | return self._getints(self.tk.call( |
| 847 | 'wm', 'minsize', self._w, width, height)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 848 | minsize = wm_minsize |
| 849 | def wm_overrideredirect(self, boolean=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 850 | return self._getboolean(self.tk.call( |
| 851 | 'wm', 'overrideredirect', self._w, boolean)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 852 | overrideredirect = wm_overrideredirect |
| 853 | def wm_positionfrom(self, who=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 854 | return self.tk.call('wm', 'positionfrom', self._w, who) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 855 | positionfrom = wm_positionfrom |
| 856 | def wm_protocol(self, name=None, func=None): |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 857 | if callable(func): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 858 | command = self._register(func) |
| 859 | else: |
| 860 | command = func |
| 861 | return self.tk.call( |
| 862 | 'wm', 'protocol', self._w, name, command) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 863 | protocol = wm_protocol |
| 864 | def wm_resizable(self, width=None, height=None): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 865 | return self.tk.call('wm', 'resizable', self._w, width, height) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 866 | resizable = wm_resizable |
| 867 | def wm_sizefrom(self, who=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 868 | return self.tk.call('wm', 'sizefrom', self._w, who) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 869 | sizefrom = wm_sizefrom |
| 870 | def wm_state(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 871 | return self.tk.call('wm', 'state', self._w) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 872 | state = wm_state |
| 873 | def wm_title(self, string=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 874 | return self.tk.call('wm', 'title', self._w, string) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 875 | title = wm_title |
| 876 | def wm_transient(self, master=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 877 | return self.tk.call('wm', 'transient', self._w, master) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 878 | transient = wm_transient |
| 879 | def wm_withdraw(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 880 | return self.tk.call('wm', 'withdraw', self._w) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 881 | withdraw = wm_withdraw |
| 882 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 883 | |
| 884 | class Tk(Misc, Wm): |
| 885 | _w = '.' |
| 886 | def __init__(self, screenName=None, baseName=None, className='Tk'): |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 887 | global _default_root |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 888 | self.master = None |
| 889 | self.children = {} |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 890 | if baseName is None: |
| 891 | import sys, os |
| 892 | baseName = os.path.basename(sys.argv[0]) |
Fred Drake | cab3c3b | 1996-10-06 17:55:20 +0000 | [diff] [blame] | 893 | baseName, ext = os.path.splitext(baseName) |
Fred Drake | 182c590 | 1998-07-15 04:36:56 +0000 | [diff] [blame] | 894 | if ext not in ('.py', '.pyc', '.pyo'): |
| 895 | baseName = baseName + ext |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 896 | self.tk = _tkinter.create(screenName, baseName, className) |
Guido van Rossum | f0c891a | 1998-04-29 21:43:36 +0000 | [diff] [blame] | 897 | if _MacOS: |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 898 | # Disable event scanning except for Command-Period |
Guido van Rossum | f0c891a | 1998-04-29 21:43:36 +0000 | [diff] [blame] | 899 | _MacOS.SchedParams(1, 0) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 900 | # Work around nasty MacTk bug |
Guido van Rossum | f0c891a | 1998-04-29 21:43:36 +0000 | [diff] [blame] | 901 | # XXX Is this one still needed? |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 902 | self.update() |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 903 | # Version sanity checks |
| 904 | tk_version = self.tk.getvar('tk_version') |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 905 | if tk_version != _tkinter.TK_VERSION: |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 906 | raise RuntimeError, \ |
| 907 | "tk.h version (%s) doesn't match libtk.a version (%s)" \ |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 908 | % (_tkinter.TK_VERSION, tk_version) |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 909 | tcl_version = self.tk.getvar('tcl_version') |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 910 | if tcl_version != _tkinter.TCL_VERSION: |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 911 | raise RuntimeError, \ |
| 912 | "tcl.h version (%s) doesn't match libtcl.a version (%s)" \ |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 913 | % (_tkinter.TCL_VERSION, tcl_version) |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 914 | if TkVersion < 4.0: |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 915 | raise RuntimeError, \ |
| 916 | "Tk 4.0 or higher is required; found Tk %s" \ |
| 917 | % str(TkVersion) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 918 | self.tk.createcommand('tkerror', _tkerror) |
Guido van Rossum | 97aeca1 | 1994-07-07 13:12:12 +0000 | [diff] [blame] | 919 | self.tk.createcommand('exit', _exit) |
Guido van Rossum | 27b77a4 | 1994-07-12 15:52:32 +0000 | [diff] [blame] | 920 | self.readprofile(baseName, className) |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 921 | if _support_default_root and not _default_root: |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 922 | _default_root = self |
Guido van Rossum | e61e98d | 1999-08-20 18:26:06 +0000 | [diff] [blame] | 923 | self.protocol("WM_DELETE_WINDOW", self.destroy) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 924 | def destroy(self): |
| 925 | for c in self.children.values(): c.destroy() |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 926 | self.tk.call('destroy', self._w) |
Guido van Rossum | 103cc6d | 1997-04-14 13:30:24 +0000 | [diff] [blame] | 927 | Misc.destroy(self) |
Guido van Rossum | d6615ab | 1997-08-05 02:35:01 +0000 | [diff] [blame] | 928 | global _default_root |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 929 | if _support_default_root and _default_root is self: |
Guido van Rossum | d6615ab | 1997-08-05 02:35:01 +0000 | [diff] [blame] | 930 | _default_root = None |
Guido van Rossum | 27b77a4 | 1994-07-12 15:52:32 +0000 | [diff] [blame] | 931 | def readprofile(self, baseName, className): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 932 | import os |
Guido van Rossum | 27b77a4 | 1994-07-12 15:52:32 +0000 | [diff] [blame] | 933 | if os.environ.has_key('HOME'): home = os.environ['HOME'] |
| 934 | else: home = os.curdir |
| 935 | class_tcl = os.path.join(home, '.%s.tcl' % className) |
| 936 | class_py = os.path.join(home, '.%s.py' % className) |
| 937 | base_tcl = os.path.join(home, '.%s.tcl' % baseName) |
| 938 | base_py = os.path.join(home, '.%s.py' % baseName) |
| 939 | dir = {'self': self} |
| 940 | exec 'from Tkinter import *' in dir |
| 941 | if os.path.isfile(class_tcl): |
| 942 | print 'source', `class_tcl` |
| 943 | self.tk.call('source', class_tcl) |
| 944 | if os.path.isfile(class_py): |
| 945 | print 'execfile', `class_py` |
| 946 | execfile(class_py, dir) |
| 947 | if os.path.isfile(base_tcl): |
| 948 | print 'source', `base_tcl` |
| 949 | self.tk.call('source', base_tcl) |
| 950 | if os.path.isfile(base_py): |
| 951 | print 'execfile', `base_py` |
| 952 | execfile(base_py, dir) |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 953 | def report_callback_exception(self, exc, val, tb): |
Guido van Rossum | da65450 | 1998-10-06 19:06:27 +0000 | [diff] [blame] | 954 | import traceback, sys |
| 955 | sys.stderr.write("Exception in Tkinter callback\n") |
Guido van Rossum | 9f1292d | 1998-10-13 20:02:39 +0000 | [diff] [blame] | 956 | sys.last_type = exc |
| 957 | sys.last_value = val |
| 958 | sys.last_traceback = tb |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 959 | traceback.print_exception(exc, val, tb) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 960 | |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 961 | # Ideally, the classes Pack, Place and Grid disappear, the |
| 962 | # pack/place/grid methods are defined on the Widget class, and |
| 963 | # everybody uses w.pack_whatever(...) instead of Pack.whatever(w, |
| 964 | # ...), with pack(), place() and grid() being short for |
| 965 | # pack_configure(), place_configure() and grid_columnconfigure(), and |
| 966 | # forget() being short for pack_forget(). As a practical matter, I'm |
| 967 | # afraid that there is too much code out there that may be using the |
| 968 | # Pack, Place or Grid class, so I leave them intact -- but only as |
| 969 | # backwards compatibility features. Also note that those methods that |
| 970 | # take a master as argument (e.g. pack_propagate) have been moved to |
| 971 | # the Misc class (which now incorporates all methods common between |
| 972 | # toplevel and interior widgets). Again, for compatibility, these are |
| 973 | # copied into the Pack, Place or Grid class. |
| 974 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 975 | class Pack: |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 976 | def pack_configure(self, cnf={}, **kw): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 977 | self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 978 | ('pack', 'configure', self._w) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 979 | + self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 980 | pack = configure = config = pack_configure |
| 981 | def pack_forget(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 982 | self.tk.call('pack', 'forget', self._w) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 983 | forget = pack_forget |
| 984 | def pack_info(self): |
Guido van Rossum | 69170c5 | 1994-07-11 15:21:31 +0000 | [diff] [blame] | 985 | words = self.tk.splitlist( |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 986 | self.tk.call('pack', 'info', self._w)) |
Guido van Rossum | 69170c5 | 1994-07-11 15:21:31 +0000 | [diff] [blame] | 987 | dict = {} |
| 988 | for i in range(0, len(words), 2): |
| 989 | key = words[i][1:] |
| 990 | value = words[i+1] |
Guido van Rossum | a5f875f | 1996-05-16 17:50:07 +0000 | [diff] [blame] | 991 | if value[:1] == '.': |
Guido van Rossum | 69170c5 | 1994-07-11 15:21:31 +0000 | [diff] [blame] | 992 | value = self._nametowidget(value) |
| 993 | dict[key] = value |
| 994 | return dict |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 995 | info = pack_info |
| 996 | propagate = pack_propagate = Misc.pack_propagate |
| 997 | slaves = pack_slaves = Misc.pack_slaves |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 998 | |
| 999 | class Place: |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1000 | def place_configure(self, cnf={}, **kw): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1001 | for k in ['in_']: |
| 1002 | if kw.has_key(k): |
| 1003 | kw[k[:-1]] = kw[k] |
| 1004 | del kw[k] |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1005 | self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1006 | ('place', 'configure', self._w) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1007 | + self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1008 | place = configure = config = place_configure |
| 1009 | def place_forget(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1010 | self.tk.call('place', 'forget', self._w) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1011 | forget = place_forget |
| 1012 | def place_info(self): |
Guido van Rossum | 63e39ae | 1996-05-16 17:53:48 +0000 | [diff] [blame] | 1013 | words = self.tk.splitlist( |
| 1014 | self.tk.call('place', 'info', self._w)) |
| 1015 | dict = {} |
| 1016 | for i in range(0, len(words), 2): |
| 1017 | key = words[i][1:] |
| 1018 | value = words[i+1] |
| 1019 | if value[:1] == '.': |
| 1020 | value = self._nametowidget(value) |
| 1021 | dict[key] = value |
| 1022 | return dict |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1023 | info = place_info |
| 1024 | slaves = place_slaves = Misc.place_slaves |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1025 | |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1026 | class Grid: |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 1027 | # Thanks to Masazumi Yoshikawa (yosikawa@isi.edu) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1028 | def grid_configure(self, cnf={}, **kw): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1029 | self.tk.call( |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1030 | ('grid', 'configure', self._w) |
| 1031 | + self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1032 | grid = configure = config = grid_configure |
| 1033 | bbox = grid_bbox = Misc.grid_bbox |
| 1034 | columnconfigure = grid_columnconfigure = Misc.grid_columnconfigure |
| 1035 | def grid_forget(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1036 | self.tk.call('grid', 'forget', self._w) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1037 | forget = grid_forget |
Guido van Rossum | 8e40759 | 1999-05-05 23:03:48 +0000 | [diff] [blame] | 1038 | def grid_remove(self): |
| 1039 | self.tk.call('grid', 'remove', self._w) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1040 | def grid_info(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1041 | words = self.tk.splitlist( |
| 1042 | self.tk.call('grid', 'info', self._w)) |
| 1043 | dict = {} |
| 1044 | for i in range(0, len(words), 2): |
| 1045 | key = words[i][1:] |
| 1046 | value = words[i+1] |
Guido van Rossum | a5f875f | 1996-05-16 17:50:07 +0000 | [diff] [blame] | 1047 | if value[:1] == '.': |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1048 | value = self._nametowidget(value) |
| 1049 | dict[key] = value |
| 1050 | return dict |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1051 | info = grid_info |
| 1052 | def grid_location(self, x, y): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1053 | return self._getints( |
| 1054 | self.tk.call( |
| 1055 | 'grid', 'location', self._w, x, y)) or None |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1056 | location = grid_location |
| 1057 | propagate = grid_propagate = Misc.grid_propagate |
| 1058 | rowconfigure = grid_rowconfigure = Misc.grid_rowconfigure |
| 1059 | size = grid_size = Misc.grid_size |
| 1060 | slaves = grid_slaves = Misc.grid_slaves |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1061 | |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1062 | class BaseWidget(Misc): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1063 | def _setup(self, master, cnf): |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 1064 | if _support_default_root: |
| 1065 | global _default_root |
| 1066 | if not master: |
| 1067 | if not _default_root: |
| 1068 | _default_root = Tk() |
| 1069 | master = _default_root |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1070 | self.master = master |
| 1071 | self.tk = master.tk |
Fred Drake | c8296db | 1997-05-27 22:45:10 +0000 | [diff] [blame] | 1072 | name = None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1073 | if cnf.has_key('name'): |
| 1074 | name = cnf['name'] |
| 1075 | del cnf['name'] |
Fred Drake | c8296db | 1997-05-27 22:45:10 +0000 | [diff] [blame] | 1076 | if not name: |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1077 | name = `id(self)` |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 1078 | self._name = name |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1079 | if master._w=='.': |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1080 | self._w = '.' + name |
| 1081 | else: |
| 1082 | self._w = master._w + '.' + name |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1083 | self.children = {} |
| 1084 | if self.master.children.has_key(self._name): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 1085 | self.master.children[self._name].destroy() |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1086 | self.master.children[self._name] = self |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1087 | def __init__(self, master, widgetName, cnf={}, kw={}, extra=()): |
| 1088 | if kw: |
| 1089 | cnf = _cnfmerge((cnf, kw)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1090 | self.widgetName = widgetName |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1091 | BaseWidget._setup(self, master, cnf) |
Guido van Rossum | ad8b3ba | 1996-07-21 03:05:05 +0000 | [diff] [blame] | 1092 | classes = [] |
| 1093 | for k in cnf.keys(): |
| 1094 | if type(k) is ClassType: |
| 1095 | classes.append((k, cnf[k])) |
| 1096 | del cnf[k] |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1097 | self.tk.call( |
| 1098 | (widgetName, self._w) + extra + self._options(cnf)) |
Guido van Rossum | ad8b3ba | 1996-07-21 03:05:05 +0000 | [diff] [blame] | 1099 | for k, v in classes: |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1100 | k.configure(self, v) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 1101 | def destroy(self): |
| 1102 | for c in self.children.values(): c.destroy() |
Guido van Rossum | f023ab0 | 1994-08-30 12:13:44 +0000 | [diff] [blame] | 1103 | if self.master.children.has_key(self._name): |
| 1104 | del self.master.children[self._name] |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1105 | self.tk.call('destroy', self._w) |
Guido van Rossum | 103cc6d | 1997-04-14 13:30:24 +0000 | [diff] [blame] | 1106 | Misc.destroy(self) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1107 | def _do(self, name, args=()): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1108 | # XXX Obsolete -- better use self.tk.call directly! |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1109 | return self.tk.call((self._w, name) + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1110 | |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1111 | class Widget(BaseWidget, Pack, Place, Grid): |
| 1112 | pass |
| 1113 | |
| 1114 | class Toplevel(BaseWidget, Wm): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1115 | def __init__(self, master=None, cnf={}, **kw): |
| 1116 | if kw: |
| 1117 | cnf = _cnfmerge((cnf, kw)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1118 | extra = () |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1119 | for wmkey in ['screen', 'class_', 'class', 'visual', |
| 1120 | 'colormap']: |
| 1121 | if cnf.has_key(wmkey): |
| 1122 | val = cnf[wmkey] |
| 1123 | # TBD: a hack needed because some keys |
| 1124 | # are not valid as keyword arguments |
| 1125 | if wmkey[-1] == '_': opt = '-'+wmkey[:-1] |
| 1126 | else: opt = '-'+wmkey |
| 1127 | extra = extra + (opt, val) |
| 1128 | del cnf[wmkey] |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1129 | BaseWidget.__init__(self, master, 'toplevel', cnf, {}, extra) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 1130 | root = self._root() |
| 1131 | self.iconname(root.iconname()) |
| 1132 | self.title(root.title()) |
Guido van Rossum | e61e98d | 1999-08-20 18:26:06 +0000 | [diff] [blame] | 1133 | self.protocol("WM_DELETE_WINDOW", self.destroy) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1134 | |
| 1135 | class Button(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1136 | def __init__(self, master=None, cnf={}, **kw): |
| 1137 | Widget.__init__(self, master, 'button', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1138 | def tkButtonEnter(self, *dummy): |
| 1139 | self.tk.call('tkButtonEnter', self._w) |
| 1140 | def tkButtonLeave(self, *dummy): |
| 1141 | self.tk.call('tkButtonLeave', self._w) |
| 1142 | def tkButtonDown(self, *dummy): |
| 1143 | self.tk.call('tkButtonDown', self._w) |
| 1144 | def tkButtonUp(self, *dummy): |
| 1145 | self.tk.call('tkButtonUp', self._w) |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 1146 | def tkButtonInvoke(self, *dummy): |
| 1147 | self.tk.call('tkButtonInvoke', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1148 | def flash(self): |
| 1149 | self.tk.call(self._w, 'flash') |
| 1150 | def invoke(self): |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 1151 | return self.tk.call(self._w, 'invoke') |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1152 | |
| 1153 | # Indices: |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1154 | # XXX I don't like these -- take them away |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1155 | def AtEnd(): |
| 1156 | return 'end' |
Guido van Rossum | 1e9e400 | 1994-06-20 09:09:51 +0000 | [diff] [blame] | 1157 | def AtInsert(*args): |
| 1158 | s = 'insert' |
| 1159 | for a in args: |
| 1160 | if a: s = s + (' ' + a) |
| 1161 | return s |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1162 | def AtSelFirst(): |
| 1163 | return 'sel.first' |
| 1164 | def AtSelLast(): |
| 1165 | return 'sel.last' |
| 1166 | def At(x, y=None): |
Guido van Rossum | 5e0c25b | 1994-07-12 09:04:41 +0000 | [diff] [blame] | 1167 | if y is None: |
| 1168 | return '@' + `x` |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1169 | else: |
Guido van Rossum | 5e0c25b | 1994-07-12 09:04:41 +0000 | [diff] [blame] | 1170 | return '@' + `x` + ',' + `y` |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1171 | |
| 1172 | class Canvas(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1173 | def __init__(self, master=None, cnf={}, **kw): |
| 1174 | Widget.__init__(self, master, 'canvas', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1175 | def addtag(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1176 | self.tk.call((self._w, 'addtag') + args) |
Guido van Rossum | 5c8c91b | 1996-08-22 23:18:09 +0000 | [diff] [blame] | 1177 | def addtag_above(self, newtag, tagOrId): |
| 1178 | self.addtag(newtag, 'above', tagOrId) |
| 1179 | def addtag_all(self, newtag): |
| 1180 | self.addtag(newtag, 'all') |
| 1181 | def addtag_below(self, newtag, tagOrId): |
| 1182 | self.addtag(newtag, 'below', tagOrId) |
| 1183 | def addtag_closest(self, newtag, x, y, halo=None, start=None): |
| 1184 | self.addtag(newtag, 'closest', x, y, halo, start) |
| 1185 | def addtag_enclosed(self, newtag, x1, y1, x2, y2): |
| 1186 | self.addtag(newtag, 'enclosed', x1, y1, x2, y2) |
| 1187 | def addtag_overlapping(self, newtag, x1, y1, x2, y2): |
| 1188 | self.addtag(newtag, 'overlapping', x1, y1, x2, y2) |
| 1189 | def addtag_withtag(self, newtag, tagOrId): |
| 1190 | self.addtag(newtag, 'withtag', tagOrId) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1191 | def bbox(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1192 | return self._getints( |
| 1193 | self.tk.call((self._w, 'bbox') + args)) or None |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 1194 | def tag_unbind(self, tagOrId, sequence, funcid=None): |
Guido van Rossum | ef8f881 | 1994-08-08 12:47:33 +0000 | [diff] [blame] | 1195 | self.tk.call(self._w, 'bind', tagOrId, sequence, '') |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 1196 | if funcid: |
| 1197 | self.deletecommand(funcid) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1198 | def tag_bind(self, tagOrId, sequence=None, func=None, add=None): |
Guido van Rossum | 42b334d | 1999-07-30 12:22:12 +0000 | [diff] [blame] | 1199 | return self._bind((self._w, 'bind', tagOrId), |
| 1200 | sequence, func, add) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1201 | def canvasx(self, screenx, gridspacing=None): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1202 | return getdouble(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1203 | self._w, 'canvasx', screenx, gridspacing)) |
| 1204 | def canvasy(self, screeny, gridspacing=None): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1205 | return getdouble(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1206 | self._w, 'canvasy', screeny, gridspacing)) |
| 1207 | def coords(self, *args): |
Guido van Rossum | 0001a11 | 1998-02-19 21:20:30 +0000 | [diff] [blame] | 1208 | # XXX Should use _flatten on args |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1209 | return map(getdouble, |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1210 | self.tk.splitlist( |
| 1211 | self.tk.call((self._w, 'coords') + args))) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1212 | def _create(self, itemType, args, kw): # Args: (val, val, ..., cnf={}) |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 1213 | args = _flatten(args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1214 | cnf = args[-1] |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 1215 | if type(cnf) in (DictionaryType, TupleType): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1216 | args = args[:-1] |
| 1217 | else: |
| 1218 | cnf = {} |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1219 | return getint(apply( |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 1220 | self.tk.call, |
| 1221 | (self._w, 'create', itemType) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1222 | + args + self._options(cnf, kw))) |
| 1223 | def create_arc(self, *args, **kw): |
| 1224 | return self._create('arc', args, kw) |
| 1225 | def create_bitmap(self, *args, **kw): |
| 1226 | return self._create('bitmap', args, kw) |
| 1227 | def create_image(self, *args, **kw): |
| 1228 | return self._create('image', args, kw) |
| 1229 | def create_line(self, *args, **kw): |
| 1230 | return self._create('line', args, kw) |
| 1231 | def create_oval(self, *args, **kw): |
| 1232 | return self._create('oval', args, kw) |
| 1233 | def create_polygon(self, *args, **kw): |
| 1234 | return self._create('polygon', args, kw) |
| 1235 | def create_rectangle(self, *args, **kw): |
| 1236 | return self._create('rectangle', args, kw) |
| 1237 | def create_text(self, *args, **kw): |
| 1238 | return self._create('text', args, kw) |
| 1239 | def create_window(self, *args, **kw): |
| 1240 | return self._create('window', args, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1241 | def dchars(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1242 | self.tk.call((self._w, 'dchars') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1243 | def delete(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1244 | self.tk.call((self._w, 'delete') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1245 | def dtag(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1246 | self.tk.call((self._w, 'dtag') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1247 | def find(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1248 | return self._getints( |
| 1249 | self.tk.call((self._w, 'find') + args)) or () |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 1250 | def find_above(self, tagOrId): |
| 1251 | return self.find('above', tagOrId) |
| 1252 | def find_all(self): |
| 1253 | return self.find('all') |
| 1254 | def find_below(self, tagOrId): |
| 1255 | return self.find('below', tagOrId) |
| 1256 | def find_closest(self, x, y, halo=None, start=None): |
| 1257 | return self.find('closest', x, y, halo, start) |
| 1258 | def find_enclosed(self, x1, y1, x2, y2): |
| 1259 | return self.find('enclosed', x1, y1, x2, y2) |
| 1260 | def find_overlapping(self, x1, y1, x2, y2): |
| 1261 | return self.find('overlapping', x1, y1, x2, y2) |
| 1262 | def find_withtag(self, tagOrId): |
| 1263 | return self.find('withtag', tagOrId) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1264 | def focus(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1265 | return self.tk.call((self._w, 'focus') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1266 | def gettags(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1267 | return self.tk.splitlist( |
| 1268 | self.tk.call((self._w, 'gettags') + args)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1269 | def icursor(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1270 | self.tk.call((self._w, 'icursor') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1271 | def index(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1272 | return getint(self.tk.call((self._w, 'index') + args)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1273 | def insert(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1274 | self.tk.call((self._w, 'insert') + args) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1275 | def itemcget(self, tagOrId, option): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1276 | return self.tk.call( |
| 1277 | (self._w, 'itemcget') + (tagOrId, '-'+option)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1278 | def itemconfigure(self, tagOrId, cnf=None, **kw): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1279 | if cnf is None and not kw: |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 1280 | cnf = {} |
| 1281 | for x in self.tk.split( |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1282 | self.tk.call(self._w, |
| 1283 | 'itemconfigure', tagOrId)): |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 1284 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 1285 | return cnf |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1286 | if type(cnf) == StringType and not kw: |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1287 | x = self.tk.split(self.tk.call( |
| 1288 | self._w, 'itemconfigure', tagOrId, '-'+cnf)) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 1289 | return (x[0][1:],) + x[1:] |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1290 | self.tk.call((self._w, 'itemconfigure', tagOrId) + |
| 1291 | self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1292 | itemconfig = itemconfigure |
Guido van Rossum | 0d8d3dd | 1999-04-07 16:25:54 +0000 | [diff] [blame] | 1293 | # lower, tkraise/lift hide Misc.lower, Misc.tkraise/lift, |
| 1294 | # so the preferred name for them is tag_lower, tag_raise |
| 1295 | # (similar to tag_bind, and similar to the Text widget); |
| 1296 | # unfortunately can't delete the old ones yet (maybe in 1.6) |
| 1297 | def tag_lower(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1298 | self.tk.call((self._w, 'lower') + args) |
Guido van Rossum | 0d8d3dd | 1999-04-07 16:25:54 +0000 | [diff] [blame] | 1299 | lower = tag_lower |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1300 | def move(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1301 | self.tk.call((self._w, 'move') + args) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1302 | def postscript(self, cnf={}, **kw): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1303 | return self.tk.call((self._w, 'postscript') + |
| 1304 | self._options(cnf, kw)) |
Guido van Rossum | 0d8d3dd | 1999-04-07 16:25:54 +0000 | [diff] [blame] | 1305 | def tag_raise(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1306 | self.tk.call((self._w, 'raise') + args) |
Guido van Rossum | 0d8d3dd | 1999-04-07 16:25:54 +0000 | [diff] [blame] | 1307 | lift = tkraise = tag_raise |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1308 | def scale(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1309 | self.tk.call((self._w, 'scale') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1310 | def scan_mark(self, x, y): |
| 1311 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 1312 | def scan_dragto(self, x, y): |
| 1313 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
| 1314 | def select_adjust(self, tagOrId, index): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 1315 | self.tk.call(self._w, 'select', 'adjust', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1316 | def select_clear(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1317 | self.tk.call(self._w, 'select', 'clear') |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1318 | def select_from(self, tagOrId, index): |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 1319 | self.tk.call(self._w, 'select', 'from', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1320 | def select_item(self): |
| 1321 | self.tk.call(self._w, 'select', 'item') |
| 1322 | def select_to(self, tagOrId, index): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 1323 | self.tk.call(self._w, 'select', 'to', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1324 | def type(self, tagOrId): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 1325 | return self.tk.call(self._w, 'type', tagOrId) or None |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1326 | def xview(self, *args): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1327 | if not args: |
| 1328 | return self._getdoubles(self.tk.call(self._w, 'xview')) |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1329 | self.tk.call((self._w, 'xview') + args) |
Barry Warsaw | 4eaadf0 | 1998-10-13 19:01:10 +0000 | [diff] [blame] | 1330 | def xview_moveto(self, fraction): |
| 1331 | self.tk.call(self._w, 'xview', 'moveto', fraction) |
| 1332 | def xview_scroll(self, number, what): |
| 1333 | self.tk.call(self._w, 'xview', 'scroll', number, what) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1334 | def yview(self, *args): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1335 | if not args: |
| 1336 | return self._getdoubles(self.tk.call(self._w, 'yview')) |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1337 | self.tk.call((self._w, 'yview') + args) |
Barry Warsaw | 4eaadf0 | 1998-10-13 19:01:10 +0000 | [diff] [blame] | 1338 | def yview_moveto(self, fraction): |
| 1339 | self.tk.call(self._w, 'yview', 'moveto', fraction) |
| 1340 | def yview_scroll(self, number, what): |
| 1341 | self.tk.call(self._w, 'yview', 'scroll', number, what) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1342 | |
| 1343 | class Checkbutton(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1344 | def __init__(self, master=None, cnf={}, **kw): |
| 1345 | Widget.__init__(self, master, 'checkbutton', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1346 | def deselect(self): |
| 1347 | self.tk.call(self._w, 'deselect') |
| 1348 | def flash(self): |
| 1349 | self.tk.call(self._w, 'flash') |
| 1350 | def invoke(self): |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 1351 | return self.tk.call(self._w, 'invoke') |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1352 | def select(self): |
| 1353 | self.tk.call(self._w, 'select') |
| 1354 | def toggle(self): |
| 1355 | self.tk.call(self._w, 'toggle') |
| 1356 | |
| 1357 | class Entry(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1358 | def __init__(self, master=None, cnf={}, **kw): |
| 1359 | Widget.__init__(self, master, 'entry', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1360 | def delete(self, first, last=None): |
| 1361 | self.tk.call(self._w, 'delete', first, last) |
| 1362 | def get(self): |
| 1363 | return self.tk.call(self._w, 'get') |
| 1364 | def icursor(self, index): |
| 1365 | self.tk.call(self._w, 'icursor', index) |
| 1366 | def index(self, index): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1367 | return getint(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1368 | self._w, 'index', index)) |
| 1369 | def insert(self, index, string): |
| 1370 | self.tk.call(self._w, 'insert', index, string) |
| 1371 | def scan_mark(self, x): |
| 1372 | self.tk.call(self._w, 'scan', 'mark', x) |
| 1373 | def scan_dragto(self, x): |
| 1374 | self.tk.call(self._w, 'scan', 'dragto', x) |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 1375 | def selection_adjust(self, index): |
| 1376 | self.tk.call(self._w, 'selection', 'adjust', index) |
| 1377 | select_adjust = selection_adjust |
| 1378 | def selection_clear(self): |
| 1379 | self.tk.call(self._w, 'selection', 'clear') |
| 1380 | select_clear = selection_clear |
| 1381 | def selection_from(self, index): |
Guido van Rossum | 42b78e6 | 1996-09-06 14:20:23 +0000 | [diff] [blame] | 1382 | self.tk.call(self._w, 'selection', 'from', index) |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 1383 | select_from = selection_from |
| 1384 | def selection_present(self): |
Guido van Rossum | 1d59df2 | 1995-08-11 14:21:06 +0000 | [diff] [blame] | 1385 | return self.tk.getboolean( |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 1386 | self.tk.call(self._w, 'selection', 'present')) |
| 1387 | select_present = selection_present |
| 1388 | def selection_range(self, start, end): |
| 1389 | self.tk.call(self._w, 'selection', 'range', start, end) |
| 1390 | select_range = selection_range |
| 1391 | def selection_to(self, index): |
| 1392 | self.tk.call(self._w, 'selection', 'to', index) |
| 1393 | select_to = selection_to |
| 1394 | def xview(self, index): |
| 1395 | self.tk.call(self._w, 'xview', index) |
| 1396 | def xview_moveto(self, fraction): |
| 1397 | self.tk.call(self._w, 'xview', 'moveto', fraction) |
| 1398 | def xview_scroll(self, number, what): |
| 1399 | self.tk.call(self._w, 'xview', 'scroll', number, what) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1400 | |
| 1401 | class Frame(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1402 | def __init__(self, master=None, cnf={}, **kw): |
| 1403 | cnf = _cnfmerge((cnf, kw)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1404 | extra = () |
Fred Drake | 41dc09d | 1997-01-10 15:13:12 +0000 | [diff] [blame] | 1405 | if cnf.has_key('class_'): |
| 1406 | extra = ('-class', cnf['class_']) |
| 1407 | del cnf['class_'] |
| 1408 | elif cnf.has_key('class'): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1409 | extra = ('-class', cnf['class']) |
| 1410 | del cnf['class'] |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1411 | Widget.__init__(self, master, 'frame', cnf, {}, extra) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1412 | |
| 1413 | class Label(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1414 | def __init__(self, master=None, cnf={}, **kw): |
| 1415 | Widget.__init__(self, master, 'label', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1416 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1417 | class Listbox(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1418 | def __init__(self, master=None, cnf={}, **kw): |
| 1419 | Widget.__init__(self, master, 'listbox', cnf, kw) |
Guido van Rossum | 46f92d2 | 1995-10-11 17:41:00 +0000 | [diff] [blame] | 1420 | def activate(self, index): |
| 1421 | self.tk.call(self._w, 'activate', index) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1422 | def bbox(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1423 | return self._getints( |
| 1424 | self.tk.call((self._w, 'bbox') + args)) or None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1425 | def curselection(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1426 | # XXX Ought to apply self._getints()... |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1427 | return self.tk.splitlist(self.tk.call( |
| 1428 | self._w, 'curselection')) |
| 1429 | def delete(self, first, last=None): |
| 1430 | self.tk.call(self._w, 'delete', first, last) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1431 | def get(self, first, last=None): |
| 1432 | if last: |
| 1433 | return self.tk.splitlist(self.tk.call( |
| 1434 | self._w, 'get', first, last)) |
| 1435 | else: |
| 1436 | return self.tk.call(self._w, 'get', first) |
Guido van Rossum | 243ac4f | 1998-10-13 13:37:30 +0000 | [diff] [blame] | 1437 | def index(self, index): |
| 1438 | i = self.tk.call(self._w, 'index', index) |
| 1439 | if i == 'none': return None |
| 1440 | return getint(i) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1441 | def insert(self, index, *elements): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1442 | self.tk.call((self._w, 'insert', index) + elements) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1443 | def nearest(self, y): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1444 | return getint(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1445 | self._w, 'nearest', y)) |
| 1446 | def scan_mark(self, x, y): |
| 1447 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 1448 | def scan_dragto(self, x, y): |
| 1449 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1450 | def see(self, index): |
| 1451 | self.tk.call(self._w, 'see', index) |
Guido van Rossum | 243ac4f | 1998-10-13 13:37:30 +0000 | [diff] [blame] | 1452 | def selection_anchor(self, index): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1453 | self.tk.call(self._w, 'selection', 'anchor', index) |
Guido van Rossum | 243ac4f | 1998-10-13 13:37:30 +0000 | [diff] [blame] | 1454 | select_anchor = selection_anchor |
| 1455 | def selection_clear(self, first, last=None): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1456 | self.tk.call(self._w, |
| 1457 | 'selection', 'clear', first, last) |
Guido van Rossum | 243ac4f | 1998-10-13 13:37:30 +0000 | [diff] [blame] | 1458 | select_clear = selection_clear |
| 1459 | def selection_includes(self, index): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1460 | return self.tk.getboolean(self.tk.call( |
| 1461 | self._w, 'selection', 'includes', index)) |
Guido van Rossum | 243ac4f | 1998-10-13 13:37:30 +0000 | [diff] [blame] | 1462 | select_includes = selection_includes |
| 1463 | def selection_set(self, first, last=None): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1464 | self.tk.call(self._w, 'selection', 'set', first, last) |
Guido van Rossum | 243ac4f | 1998-10-13 13:37:30 +0000 | [diff] [blame] | 1465 | select_set = selection_set |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1466 | def size(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1467 | return getint(self.tk.call(self._w, 'size')) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1468 | def xview(self, *what): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1469 | if not what: |
| 1470 | return self._getdoubles(self.tk.call(self._w, 'xview')) |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1471 | self.tk.call((self._w, 'xview') + what) |
Guido van Rossum | 243ac4f | 1998-10-13 13:37:30 +0000 | [diff] [blame] | 1472 | def xview_moveto(self, fraction): |
| 1473 | self.tk.call(self._w, 'xview', 'moveto', fraction) |
| 1474 | def xview_scroll(self, number, what): |
| 1475 | self.tk.call(self._w, 'xview', 'scroll', number, what) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1476 | def yview(self, *what): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1477 | if not what: |
| 1478 | return self._getdoubles(self.tk.call(self._w, 'yview')) |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1479 | self.tk.call((self._w, 'yview') + what) |
Guido van Rossum | 243ac4f | 1998-10-13 13:37:30 +0000 | [diff] [blame] | 1480 | def yview_moveto(self, fraction): |
| 1481 | self.tk.call(self._w, 'yview', 'moveto', fraction) |
| 1482 | def yview_scroll(self, number, what): |
| 1483 | self.tk.call(self._w, 'yview', 'scroll', number, what) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1484 | |
| 1485 | class Menu(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1486 | def __init__(self, master=None, cnf={}, **kw): |
| 1487 | Widget.__init__(self, master, 'menu', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1488 | def tk_bindForTraversal(self): |
Guido van Rossum | 688bbfc | 1996-09-10 12:39:26 +0000 | [diff] [blame] | 1489 | pass # obsolete since Tk 4.0 |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1490 | def tk_mbPost(self): |
| 1491 | self.tk.call('tk_mbPost', self._w) |
| 1492 | def tk_mbUnpost(self): |
| 1493 | self.tk.call('tk_mbUnpost') |
| 1494 | def tk_traverseToMenu(self, char): |
| 1495 | self.tk.call('tk_traverseToMenu', self._w, char) |
| 1496 | def tk_traverseWithinMenu(self, char): |
| 1497 | self.tk.call('tk_traverseWithinMenu', self._w, char) |
| 1498 | def tk_getMenuButtons(self): |
| 1499 | return self.tk.call('tk_getMenuButtons', self._w) |
| 1500 | def tk_nextMenu(self, count): |
| 1501 | self.tk.call('tk_nextMenu', count) |
| 1502 | def tk_nextMenuEntry(self, count): |
| 1503 | self.tk.call('tk_nextMenuEntry', count) |
| 1504 | def tk_invokeMenu(self): |
| 1505 | self.tk.call('tk_invokeMenu', self._w) |
| 1506 | def tk_firstMenu(self): |
| 1507 | self.tk.call('tk_firstMenu', self._w) |
| 1508 | def tk_mbButtonDown(self): |
| 1509 | self.tk.call('tk_mbButtonDown', self._w) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1510 | def tk_popup(self, x, y, entry=""): |
| 1511 | self.tk.call('tk_popup', self._w, x, y, entry) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1512 | def activate(self, index): |
| 1513 | self.tk.call(self._w, 'activate', index) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1514 | def add(self, itemType, cnf={}, **kw): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1515 | self.tk.call((self._w, 'add', itemType) + |
| 1516 | self._options(cnf, kw)) |
Guido van Rossum | a1db48b | 1995-10-09 22:37:28 +0000 | [diff] [blame] | 1517 | def add_cascade(self, cnf={}, **kw): |
| 1518 | self.add('cascade', cnf or kw) |
| 1519 | def add_checkbutton(self, cnf={}, **kw): |
| 1520 | self.add('checkbutton', cnf or kw) |
| 1521 | def add_command(self, cnf={}, **kw): |
| 1522 | self.add('command', cnf or kw) |
| 1523 | def add_radiobutton(self, cnf={}, **kw): |
| 1524 | self.add('radiobutton', cnf or kw) |
| 1525 | def add_separator(self, cnf={}, **kw): |
| 1526 | self.add('separator', cnf or kw) |
Guido van Rossum | 2caac73 | 1996-09-05 16:46:31 +0000 | [diff] [blame] | 1527 | def insert(self, index, itemType, cnf={}, **kw): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1528 | self.tk.call((self._w, 'insert', index, itemType) + |
| 1529 | self._options(cnf, kw)) |
Guido van Rossum | 2caac73 | 1996-09-05 16:46:31 +0000 | [diff] [blame] | 1530 | def insert_cascade(self, index, cnf={}, **kw): |
| 1531 | self.insert(index, 'cascade', cnf or kw) |
| 1532 | def insert_checkbutton(self, index, cnf={}, **kw): |
| 1533 | self.insert(index, 'checkbutton', cnf or kw) |
| 1534 | def insert_command(self, index, cnf={}, **kw): |
| 1535 | self.insert(index, 'command', cnf or kw) |
| 1536 | def insert_radiobutton(self, index, cnf={}, **kw): |
| 1537 | self.insert(index, 'radiobutton', cnf or kw) |
| 1538 | def insert_separator(self, index, cnf={}, **kw): |
| 1539 | self.insert(index, 'separator', cnf or kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1540 | def delete(self, index1, index2=None): |
| 1541 | self.tk.call(self._w, 'delete', index1, index2) |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 1542 | def entrycget(self, index, option): |
Guido van Rossum | 1cd6a45 | 1997-12-30 04:07:19 +0000 | [diff] [blame] | 1543 | return self.tk.call(self._w, 'entrycget', index, '-' + option) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1544 | def entryconfigure(self, index, cnf=None, **kw): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1545 | if cnf is None and not kw: |
| 1546 | cnf = {} |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1547 | for x in self.tk.split(self.tk.call( |
| 1548 | (self._w, 'entryconfigure', index))): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1549 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 1550 | return cnf |
| 1551 | if type(cnf) == StringType and not kw: |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1552 | x = self.tk.split(self.tk.call( |
| 1553 | (self._w, 'entryconfigure', index, '-'+cnf))) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1554 | return (x[0][1:],) + x[1:] |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1555 | self.tk.call((self._w, 'entryconfigure', index) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1556 | + self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1557 | entryconfig = entryconfigure |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1558 | def index(self, index): |
Guido van Rossum | 535cf0c | 1994-06-27 07:55:59 +0000 | [diff] [blame] | 1559 | i = self.tk.call(self._w, 'index', index) |
| 1560 | if i == 'none': return None |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1561 | return getint(i) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1562 | def invoke(self, index): |
| 1563 | return self.tk.call(self._w, 'invoke', index) |
| 1564 | def post(self, x, y): |
| 1565 | self.tk.call(self._w, 'post', x, y) |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 1566 | def type(self, index): |
| 1567 | return self.tk.call(self._w, 'type', index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1568 | def unpost(self): |
| 1569 | self.tk.call(self._w, 'unpost') |
| 1570 | def yposition(self, index): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1571 | return getint(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1572 | self._w, 'yposition', index)) |
| 1573 | |
| 1574 | class Menubutton(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1575 | def __init__(self, master=None, cnf={}, **kw): |
| 1576 | Widget.__init__(self, master, 'menubutton', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1577 | |
| 1578 | class Message(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1579 | def __init__(self, master=None, cnf={}, **kw): |
| 1580 | Widget.__init__(self, master, 'message', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1581 | |
| 1582 | class Radiobutton(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1583 | def __init__(self, master=None, cnf={}, **kw): |
| 1584 | Widget.__init__(self, master, 'radiobutton', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1585 | def deselect(self): |
| 1586 | self.tk.call(self._w, 'deselect') |
| 1587 | def flash(self): |
| 1588 | self.tk.call(self._w, 'flash') |
| 1589 | def invoke(self): |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 1590 | return self.tk.call(self._w, 'invoke') |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1591 | def select(self): |
| 1592 | self.tk.call(self._w, 'select') |
| 1593 | |
| 1594 | class Scale(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1595 | def __init__(self, master=None, cnf={}, **kw): |
| 1596 | Widget.__init__(self, master, 'scale', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1597 | def get(self): |
Guido van Rossum | 1495747 | 1996-10-23 14:16:28 +0000 | [diff] [blame] | 1598 | value = self.tk.call(self._w, 'get') |
| 1599 | try: |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1600 | return getint(value) |
Guido van Rossum | fe02efd | 1998-06-09 02:37:45 +0000 | [diff] [blame] | 1601 | except ValueError: |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1602 | return getdouble(value) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1603 | def set(self, value): |
| 1604 | self.tk.call(self._w, 'set', value) |
Guido van Rossum | b4750db | 1998-08-11 19:07:14 +0000 | [diff] [blame] | 1605 | def coords(self, value=None): |
| 1606 | return self._getints(self.tk.call(self._w, 'coords', value)) |
| 1607 | def identify(self, x, y): |
| 1608 | return self.tk.call(self._w, 'identify', x, y) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1609 | |
| 1610 | class Scrollbar(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1611 | def __init__(self, master=None, cnf={}, **kw): |
| 1612 | Widget.__init__(self, master, 'scrollbar', cnf, kw) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1613 | def activate(self, index): |
| 1614 | self.tk.call(self._w, 'activate', index) |
| 1615 | def delta(self, deltax, deltay): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1616 | return getdouble( |
| 1617 | self.tk.call(self._w, 'delta', deltax, deltay)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1618 | def fraction(self, x, y): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1619 | return getdouble(self.tk.call(self._w, 'fraction', x, y)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1620 | def identify(self, x, y): |
| 1621 | return self.tk.call(self._w, 'identify', x, y) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1622 | def get(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1623 | return self._getdoubles(self.tk.call(self._w, 'get')) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1624 | def set(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1625 | self.tk.call((self._w, 'set') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1626 | |
| 1627 | class Text(Widget): |
Guido van Rossum | dfaac4d | 1998-12-21 18:25:03 +0000 | [diff] [blame] | 1628 | # XXX Add dump() |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1629 | def __init__(self, master=None, cnf={}, **kw): |
| 1630 | Widget.__init__(self, master, 'text', cnf, kw) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1631 | def bbox(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1632 | return self._getints( |
| 1633 | self.tk.call((self._w, 'bbox') + args)) or None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1634 | def tk_textSelectTo(self, index): |
| 1635 | self.tk.call('tk_textSelectTo', self._w, index) |
| 1636 | def tk_textBackspace(self): |
| 1637 | self.tk.call('tk_textBackspace', self._w) |
| 1638 | def tk_textIndexCloser(self, a, b, c): |
| 1639 | self.tk.call('tk_textIndexCloser', self._w, a, b, c) |
| 1640 | def tk_textResetAnchor(self, index): |
| 1641 | self.tk.call('tk_textResetAnchor', self._w, index) |
| 1642 | def compare(self, index1, op, index2): |
| 1643 | return self.tk.getboolean(self.tk.call( |
| 1644 | self._w, 'compare', index1, op, index2)) |
| 1645 | def debug(self, boolean=None): |
| 1646 | return self.tk.getboolean(self.tk.call( |
| 1647 | self._w, 'debug', boolean)) |
| 1648 | def delete(self, index1, index2=None): |
| 1649 | self.tk.call(self._w, 'delete', index1, index2) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1650 | def dlineinfo(self, index): |
| 1651 | return self._getints(self.tk.call(self._w, 'dlineinfo', index)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1652 | def get(self, index1, index2=None): |
| 1653 | return self.tk.call(self._w, 'get', index1, index2) |
Guido van Rossum | c86b7c6 | 1998-08-31 16:54:33 +0000 | [diff] [blame] | 1654 | # (Image commands are new in 8.0) |
| 1655 | def image_cget(self, index, option): |
| 1656 | if option[:1] != "-": |
| 1657 | option = "-" + option |
| 1658 | if option[-1:] == "_": |
| 1659 | option = option[:-1] |
| 1660 | return self.tk.call(self._w, "image", "cget", index, option) |
| 1661 | def image_configure(self, index, cnf={}, **kw): |
| 1662 | if not cnf and not kw: |
| 1663 | cnf = {} |
| 1664 | for x in self.tk.split( |
| 1665 | self.tk.call( |
| 1666 | self._w, "image", "configure", index)): |
| 1667 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 1668 | return cnf |
| 1669 | apply(self.tk.call, |
| 1670 | (self._w, "image", "configure", index) |
| 1671 | + self._options(cnf, kw)) |
| 1672 | def image_create(self, index, cnf={}, **kw): |
| 1673 | return apply(self.tk.call, |
| 1674 | (self._w, "image", "create", index) |
| 1675 | + self._options(cnf, kw)) |
| 1676 | def image_names(self): |
| 1677 | return self.tk.call(self._w, "image", "names") |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1678 | def index(self, index): |
| 1679 | return self.tk.call(self._w, 'index', index) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1680 | def insert(self, index, chars, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1681 | self.tk.call((self._w, 'insert', index, chars) + args) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1682 | def mark_gravity(self, markName, direction=None): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1683 | return self.tk.call( |
| 1684 | (self._w, 'mark', 'gravity', markName, direction)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1685 | def mark_names(self): |
| 1686 | return self.tk.splitlist(self.tk.call( |
| 1687 | self._w, 'mark', 'names')) |
| 1688 | def mark_set(self, markName, index): |
| 1689 | self.tk.call(self._w, 'mark', 'set', markName, index) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1690 | def mark_unset(self, *markNames): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1691 | self.tk.call((self._w, 'mark', 'unset') + markNames) |
Guido van Rossum | 1a03cf5 | 1999-06-21 14:13:30 +0000 | [diff] [blame] | 1692 | def mark_next(self, index): |
| 1693 | return self.tk.call(self._w, 'mark', 'next', index) or None |
| 1694 | def mark_previous(self, index): |
| 1695 | return self.tk.call(self._w, 'mark', 'previous', index) or None |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1696 | def scan_mark(self, x, y): |
| 1697 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 1698 | def scan_dragto(self, x, y): |
| 1699 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1700 | def search(self, pattern, index, stopindex=None, |
| 1701 | forwards=None, backwards=None, exact=None, |
| 1702 | regexp=None, nocase=None, count=None): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1703 | args = [self._w, 'search'] |
| 1704 | if forwards: args.append('-forwards') |
| 1705 | if backwards: args.append('-backwards') |
| 1706 | if exact: args.append('-exact') |
| 1707 | if regexp: args.append('-regexp') |
| 1708 | if nocase: args.append('-nocase') |
| 1709 | if count: args.append('-count'); args.append(count) |
| 1710 | if pattern[0] == '-': args.append('--') |
| 1711 | args.append(pattern) |
| 1712 | args.append(index) |
| 1713 | if stopindex: args.append(stopindex) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1714 | return self.tk.call(tuple(args)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1715 | def see(self, index): |
| 1716 | self.tk.call(self._w, 'see', index) |
Guido van Rossum | fa8c3ea | 1999-06-01 13:57:15 +0000 | [diff] [blame] | 1717 | def tag_add(self, tagName, index1, *args): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1718 | self.tk.call( |
Guido van Rossum | fa8c3ea | 1999-06-01 13:57:15 +0000 | [diff] [blame] | 1719 | (self._w, 'tag', 'add', tagName, index1) + args) |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 1720 | def tag_unbind(self, tagName, sequence, funcid=None): |
Guido van Rossum | ef8f881 | 1994-08-08 12:47:33 +0000 | [diff] [blame] | 1721 | self.tk.call(self._w, 'tag', 'bind', tagName, sequence, '') |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 1722 | if funcid: |
| 1723 | self.deletecommand(funcid) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1724 | def tag_bind(self, tagName, sequence, func, add=None): |
| 1725 | return self._bind((self._w, 'tag', 'bind', tagName), |
| 1726 | sequence, func, add) |
| 1727 | def tag_cget(self, tagName, option): |
Guido van Rossum | 73eba25 | 1996-11-11 19:10:58 +0000 | [diff] [blame] | 1728 | if option[:1] != '-': |
| 1729 | option = '-' + option |
| 1730 | if option[-1:] == '_': |
| 1731 | option = option[:-1] |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1732 | return self.tk.call(self._w, 'tag', 'cget', tagName, option) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1733 | def tag_configure(self, tagName, cnf={}, **kw): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1734 | if type(cnf) == StringType: |
| 1735 | x = self.tk.split(self.tk.call( |
| 1736 | self._w, 'tag', 'configure', tagName, '-'+cnf)) |
| 1737 | return (x[0][1:],) + x[1:] |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1738 | self.tk.call( |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1739 | (self._w, 'tag', 'configure', tagName) |
| 1740 | + self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1741 | tag_config = tag_configure |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 1742 | def tag_delete(self, *tagNames): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1743 | self.tk.call((self._w, 'tag', 'delete') + tagNames) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1744 | def tag_lower(self, tagName, belowThis=None): |
Guido van Rossum | 97aeca1 | 1994-07-07 13:12:12 +0000 | [diff] [blame] | 1745 | self.tk.call(self._w, 'tag', 'lower', tagName, belowThis) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1746 | def tag_names(self, index=None): |
| 1747 | return self.tk.splitlist( |
| 1748 | self.tk.call(self._w, 'tag', 'names', index)) |
| 1749 | def tag_nextrange(self, tagName, index1, index2=None): |
| 1750 | return self.tk.splitlist(self.tk.call( |
Guido van Rossum | 903abee | 1995-03-20 15:09:13 +0000 | [diff] [blame] | 1751 | self._w, 'tag', 'nextrange', tagName, index1, index2)) |
Guido van Rossum | f0413d4 | 1997-12-15 17:31:52 +0000 | [diff] [blame] | 1752 | def tag_prevrange(self, tagName, index1, index2=None): |
| 1753 | return self.tk.splitlist(self.tk.call( |
| 1754 | self._w, 'tag', 'prevrange', tagName, index1, index2)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1755 | def tag_raise(self, tagName, aboveThis=None): |
| 1756 | self.tk.call( |
| 1757 | self._w, 'tag', 'raise', tagName, aboveThis) |
| 1758 | def tag_ranges(self, tagName): |
| 1759 | return self.tk.splitlist(self.tk.call( |
| 1760 | self._w, 'tag', 'ranges', tagName)) |
| 1761 | def tag_remove(self, tagName, index1, index2=None): |
| 1762 | self.tk.call( |
Guido van Rossum | 5113569 | 1994-07-06 21:16:58 +0000 | [diff] [blame] | 1763 | self._w, 'tag', 'remove', tagName, index1, index2) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1764 | def window_cget(self, index, option): |
Guido van Rossum | 7814ea6 | 1997-12-11 17:08:52 +0000 | [diff] [blame] | 1765 | if option[:1] != '-': |
| 1766 | option = '-' + option |
| 1767 | if option[-1:] == '_': |
| 1768 | option = option[:-1] |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1769 | return self.tk.call(self._w, 'window', 'cget', index, option) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1770 | def window_configure(self, index, cnf={}, **kw): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1771 | if type(cnf) == StringType: |
| 1772 | x = self.tk.split(self.tk.call( |
| 1773 | self._w, 'window', 'configure', |
| 1774 | index, '-'+cnf)) |
| 1775 | return (x[0][1:],) + x[1:] |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1776 | self.tk.call( |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1777 | (self._w, 'window', 'configure', index) |
| 1778 | + self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1779 | window_config = window_configure |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1780 | def window_create(self, index, cnf={}, **kw): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1781 | self.tk.call( |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1782 | (self._w, 'window', 'create', index) |
| 1783 | + self._options(cnf, kw)) |
| 1784 | def window_names(self): |
| 1785 | return self.tk.splitlist( |
| 1786 | self.tk.call(self._w, 'window', 'names')) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1787 | def xview(self, *what): |
| 1788 | if not what: |
| 1789 | return self._getdoubles(self.tk.call(self._w, 'xview')) |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1790 | self.tk.call((self._w, 'xview') + what) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1791 | def yview(self, *what): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1792 | if not what: |
| 1793 | return self._getdoubles(self.tk.call(self._w, 'yview')) |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1794 | self.tk.call((self._w, 'yview') + what) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1795 | def yview_pickplace(self, *what): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame] | 1796 | self.tk.call((self._w, 'yview', '-pickplace') + what) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1797 | |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1798 | class _setit: |
Barry Warsaw | 7d3f27c | 2000-02-25 21:54:19 +0000 | [diff] [blame] | 1799 | def __init__(self, var, value, callback=None): |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1800 | self.__value = value |
| 1801 | self.__var = var |
Barry Warsaw | 7d3f27c | 2000-02-25 21:54:19 +0000 | [diff] [blame] | 1802 | self.__callback = callback |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1803 | def __call__(self, *args): |
Fred Drake | 0c37369 | 1996-10-21 17:09:31 +0000 | [diff] [blame] | 1804 | self.__var.set(self.__value) |
Barry Warsaw | 7d3f27c | 2000-02-25 21:54:19 +0000 | [diff] [blame] | 1805 | if self.__callback: |
| 1806 | apply(self.__callback, (self.__value,)+args) |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1807 | |
| 1808 | class OptionMenu(Menubutton): |
Barry Warsaw | 7d3f27c | 2000-02-25 21:54:19 +0000 | [diff] [blame] | 1809 | def __init__(self, master, variable, value, *values, **kwargs): |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1810 | kw = {"borderwidth": 2, "textvariable": variable, |
| 1811 | "indicatoron": 1, "relief": RAISED, "anchor": "c", |
| 1812 | "highlightthickness": 2} |
| 1813 | Widget.__init__(self, master, "menubutton", kw) |
Guido van Rossum | bf4d8f9 | 1995-09-01 20:35:37 +0000 | [diff] [blame] | 1814 | self.widgetName = 'tk_optionMenu' |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1815 | menu = self.__menu = Menu(self, name="menu", tearoff=0) |
| 1816 | self.menuname = menu._w |
Barry Warsaw | 7d3f27c | 2000-02-25 21:54:19 +0000 | [diff] [blame] | 1817 | # 'command' is the only supported keyword |
| 1818 | callback = kwargs.get('command') |
Guido van Rossum | 0ba3300 | 2000-02-27 15:35:47 +0000 | [diff] [blame] | 1819 | if kwargs.has_key('command'): |
Barry Warsaw | 7d3f27c | 2000-02-25 21:54:19 +0000 | [diff] [blame] | 1820 | del kwargs['command'] |
| 1821 | if kwargs: |
| 1822 | raise TclError, 'unknown option -'+kwargs.keys()[0] |
| 1823 | menu.add_command(label=value, |
| 1824 | command=_setit(variable, value, callback)) |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1825 | for v in values: |
Barry Warsaw | 7d3f27c | 2000-02-25 21:54:19 +0000 | [diff] [blame] | 1826 | menu.add_command(label=v, |
| 1827 | command=_setit(variable, v, callback)) |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1828 | self["menu"] = menu |
| 1829 | |
| 1830 | def __getitem__(self, name): |
| 1831 | if name == 'menu': |
| 1832 | return self.__menu |
| 1833 | return Widget.__getitem__(self, name) |
| 1834 | |
| 1835 | def destroy(self): |
| 1836 | Menubutton.destroy(self) |
| 1837 | self.__menu = None |
Guido van Rossum | bf4d8f9 | 1995-09-01 20:35:37 +0000 | [diff] [blame] | 1838 | |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1839 | class Image: |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 1840 | def __init__(self, imgtype, name=None, cnf={}, master=None, **kw): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1841 | self.name = None |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 1842 | if not master: |
| 1843 | master = _default_root |
| 1844 | if not master: |
| 1845 | raise RuntimeError, 'Too early to create image' |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1846 | self.tk = master.tk |
Guido van Rossum | 58103d3 | 1996-11-20 22:17:38 +0000 | [diff] [blame] | 1847 | if not name: |
| 1848 | name = `id(self)` |
| 1849 | # The following is needed for systems where id(x) |
| 1850 | # can return a negative number, such as Linux/m68k: |
| 1851 | if name[0] == '-': name = '_' + name[1:] |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1852 | if kw and cnf: cnf = _cnfmerge((cnf, kw)) |
| 1853 | elif kw: cnf = kw |
| 1854 | options = () |
| 1855 | for k, v in cnf.items(): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1856 | if callable(v): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1857 | v = self._register(v) |
| 1858 | options = options + ('-'+k, v) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1859 | self.tk.call(('image', 'create', imgtype, name,) + options) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1860 | self.name = name |
| 1861 | def __str__(self): return self.name |
| 1862 | def __del__(self): |
| 1863 | if self.name: |
Guido van Rossum | c55b0ca | 1999-02-08 15:26:49 +0000 | [diff] [blame] | 1864 | try: |
| 1865 | self.tk.call('image', 'delete', self.name) |
| 1866 | except TclError: |
| 1867 | # May happen if the root was destroyed |
| 1868 | pass |
Guido van Rossum | 71b1a90 | 1995-09-18 21:54:35 +0000 | [diff] [blame] | 1869 | def __setitem__(self, key, value): |
| 1870 | self.tk.call(self.name, 'configure', '-'+key, value) |
| 1871 | def __getitem__(self, key): |
| 1872 | return self.tk.call(self.name, 'configure', '-'+key) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1873 | def configure(self, **kw): |
Guido van Rossum | 8371013 | 1996-12-27 15:33:17 +0000 | [diff] [blame] | 1874 | res = () |
| 1875 | for k, v in _cnfmerge(kw).items(): |
| 1876 | if v is not None: |
| 1877 | if k[-1] == '_': k = k[:-1] |
| 1878 | if callable(v): |
| 1879 | v = self._register(v) |
| 1880 | res = res + ('-'+k, v) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1881 | self.tk.call((self.name, 'config') + res) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1882 | config = configure |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1883 | def height(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1884 | return getint( |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1885 | self.tk.call('image', 'height', self.name)) |
| 1886 | def type(self): |
| 1887 | return self.tk.call('image', 'type', self.name) |
| 1888 | def width(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1889 | return getint( |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1890 | self.tk.call('image', 'width', self.name)) |
| 1891 | |
| 1892 | class PhotoImage(Image): |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 1893 | def __init__(self, name=None, cnf={}, master=None, **kw): |
| 1894 | apply(Image.__init__, (self, 'photo', name, cnf, master), kw) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1895 | def blank(self): |
| 1896 | self.tk.call(self.name, 'blank') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1897 | def cget(self, option): |
| 1898 | return self.tk.call(self.name, 'cget', '-' + option) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1899 | # XXX config |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1900 | def __getitem__(self, key): |
| 1901 | return self.tk.call(self.name, 'cget', '-' + key) |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 1902 | # XXX copy -from, -to, ...? |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1903 | def copy(self): |
| 1904 | destImage = PhotoImage() |
| 1905 | self.tk.call(destImage, 'copy', self.name) |
| 1906 | return destImage |
| 1907 | def zoom(self,x,y=''): |
| 1908 | destImage = PhotoImage() |
| 1909 | if y=='': y=x |
| 1910 | self.tk.call(destImage, 'copy', self.name, '-zoom',x,y) |
| 1911 | return destImage |
| 1912 | def subsample(self,x,y=''): |
| 1913 | destImage = PhotoImage() |
| 1914 | if y=='': y=x |
| 1915 | self.tk.call(destImage, 'copy', self.name, '-subsample',x,y) |
| 1916 | return destImage |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1917 | def get(self, x, y): |
| 1918 | return self.tk.call(self.name, 'get', x, y) |
| 1919 | def put(self, data, to=None): |
| 1920 | args = (self.name, 'put', data) |
| 1921 | if to: |
Fred Drake | b532399 | 1997-12-16 15:03:43 +0000 | [diff] [blame] | 1922 | if to[0] == '-to': |
| 1923 | to = to[1:] |
| 1924 | args = args + ('-to',) + tuple(to) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1925 | self.tk.call(args) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1926 | # XXX read |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1927 | def write(self, filename, format=None, from_coords=None): |
| 1928 | args = (self.name, 'write', filename) |
| 1929 | if format: |
| 1930 | args = args + ('-format', format) |
| 1931 | if from_coords: |
| 1932 | args = args + ('-from',) + tuple(from_coords) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1933 | self.tk.call(args) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1934 | |
| 1935 | class BitmapImage(Image): |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 1936 | def __init__(self, name=None, cnf={}, master=None, **kw): |
| 1937 | apply(Image.__init__, (self, 'bitmap', name, cnf, master), kw) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1938 | |
| 1939 | def image_names(): return _default_root.tk.call('image', 'names') |
| 1940 | def image_types(): return _default_root.tk.call('image', 'types') |
| 1941 | |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1942 | ###################################################################### |
| 1943 | # Extensions: |
| 1944 | |
| 1945 | class Studbutton(Button): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1946 | def __init__(self, master=None, cnf={}, **kw): |
| 1947 | Widget.__init__(self, master, 'studbutton', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1948 | self.bind('<Any-Enter>', self.tkButtonEnter) |
| 1949 | self.bind('<Any-Leave>', self.tkButtonLeave) |
| 1950 | self.bind('<1>', self.tkButtonDown) |
| 1951 | self.bind('<ButtonRelease-1>', self.tkButtonUp) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1952 | |
| 1953 | class Tributton(Button): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1954 | def __init__(self, master=None, cnf={}, **kw): |
| 1955 | Widget.__init__(self, master, 'tributton', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1956 | self.bind('<Any-Enter>', self.tkButtonEnter) |
| 1957 | self.bind('<Any-Leave>', self.tkButtonLeave) |
| 1958 | self.bind('<1>', self.tkButtonDown) |
| 1959 | self.bind('<ButtonRelease-1>', self.tkButtonUp) |
| 1960 | self['fg'] = self['bg'] |
| 1961 | self['activebackground'] = self['bg'] |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1962 | |
Guido van Rossum | c417ef8 | 1996-08-21 23:38:59 +0000 | [diff] [blame] | 1963 | ###################################################################### |
| 1964 | # Test: |
| 1965 | |
| 1966 | def _test(): |
| 1967 | root = Tk() |
Guido van Rossum | 2ab9082 | 2000-03-30 23:19:44 +0000 | [diff] [blame] | 1968 | text = "This is Tcl/Tk version %s" % TclVersion |
| 1969 | if TclVersion >= 8.1: |
| 1970 | text = text + u"\nThis should be a cedilla: \347" |
| 1971 | label = Label(root, text=text) |
Guido van Rossum | c417ef8 | 1996-08-21 23:38:59 +0000 | [diff] [blame] | 1972 | label.pack() |
| 1973 | test = Button(root, text="Click me!", |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1974 | command=lambda root=root: root.test.configure( |
Guido van Rossum | c417ef8 | 1996-08-21 23:38:59 +0000 | [diff] [blame] | 1975 | text="[%s]" % root.test['text'])) |
| 1976 | test.pack() |
| 1977 | root.test = test |
| 1978 | quit = Button(root, text="QUIT", command=root.destroy) |
| 1979 | quit.pack() |
Guido van Rossum | 268824e | 1998-06-19 04:34:19 +0000 | [diff] [blame] | 1980 | # The following three commands are needed so the window pops |
| 1981 | # up on top on Windows... |
| 1982 | root.iconify() |
| 1983 | root.update() |
| 1984 | root.deiconify() |
Guido van Rossum | c417ef8 | 1996-08-21 23:38:59 +0000 | [diff] [blame] | 1985 | root.mainloop() |
| 1986 | |
| 1987 | if __name__ == '__main__': |
| 1988 | _test() |