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