Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1 | # Tkinter.py -- Tk/Tcl widget wrappers |
| 2 | import tkinter |
| 3 | from tkinter import TclError |
| 4 | |
| 5 | class _Dummy: |
| 6 | def meth(self): return |
| 7 | |
| 8 | def _isfunctype(func): |
| 9 | return type(func) in (type(_Dummy.meth), type(_isfunctype)) |
| 10 | |
| 11 | FunctionType = type(_isfunctype) |
| 12 | ClassType = type(_Dummy) |
| 13 | MethodType = type(_Dummy.meth) |
| 14 | |
| 15 | def tkerror(err): |
| 16 | pass |
| 17 | |
| 18 | class Event: |
| 19 | pass |
| 20 | |
| 21 | class Misc: |
| 22 | def tk_strictMotif(self, boolean=None): |
| 23 | self.tk.getboolean(self.tk.call( |
| 24 | 'set', 'tk_strictMotif', boolean)) |
| 25 | def waitvar(self, name='VAR'): |
| 26 | self.tk.call('tkwait', 'variable', name) |
| 27 | def setvar(self, name='VAR', value='1'): |
| 28 | self.tk.setvar(name, value) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame^] | 29 | def getvar(self, name='VAR'): |
| 30 | return self.tk.getvar(name) |
| 31 | def getint(self, s): |
| 32 | return self.tk.getint(s) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 33 | def focus(self): |
| 34 | self.tk.call('focus', self._w) |
| 35 | def focus_default(self): |
| 36 | self.tk.call('focus', 'default', self._w) |
| 37 | def focus_none(self): |
| 38 | self.tk.call('focus', 'none') |
| 39 | #XXX focus_get? |
| 40 | def after(self, ms, func=None, *args): |
| 41 | if not func: |
| 42 | self.tk.call('after', ms) |
| 43 | else: |
| 44 | name = self._register(func) |
| 45 | apply(self.tk.call, ('after', ms, name) + args) |
| 46 | #XXX grab_current |
| 47 | def grab_release(self): |
| 48 | self.tk.call('grab', 'release', self._w) |
| 49 | def grab_set(self): |
| 50 | self.tk.call('grab', 'set', self._w) |
| 51 | def grab_set_global(self): |
| 52 | self.tk.call('grab', 'set', '-global', self._w) |
| 53 | def grab_status(self): |
| 54 | self.tk.call('grab', 'status', self._w) |
| 55 | def lower(self, belowThis=None): |
| 56 | self.tk.call('lower', self._w, belowThis) |
| 57 | def selection_clear(self): |
| 58 | self.tk.call('selection', 'clear', self._w) |
| 59 | def selection_get(self, type=None): |
| 60 | self.tk.call('selection', 'get', type) |
| 61 | def selection_handle(self, func, type=None, format=None): |
| 62 | name = self._register(func) |
| 63 | self.tk.call('selection', 'handle', |
| 64 | self._w, name, type, format) |
| 65 | #XXX def selection_own(self): |
| 66 | # self.tk.call('selection', 'own', self._w) |
| 67 | def send(self, interp, cmd, *args): #XXX |
| 68 | return apply(self.tk.call, ('send', interp, cmd) + args) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame^] | 69 | def lower(self, belowThis=None): |
| 70 | self.tk.call('lift', self._w, belowThis) |
| 71 | def tkraise(self, aboveThis=None): |
| 72 | self.tk.call('raise', self._w, aboveThis) |
| 73 | lift = tkraise |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 74 | def colormodel(self, value=None): |
| 75 | return self.tk.call('tk', 'colormodel', self._w, value) |
| 76 | def winfo_atom(self, name): |
| 77 | return self.tk.getint(self.tk.call('winfo', 'atom', name)) |
| 78 | def winfo_atomname(self, id): |
| 79 | return self.tk.call('winfo', 'atomname', id) |
| 80 | def winfo_cells(self): |
| 81 | return self.tk.getint( |
| 82 | self.tk.call('winfo', 'cells', self._w)) |
| 83 | #XXX winfo_children |
| 84 | def winfo_class(self): |
| 85 | return self.tk.call('winfo', 'class', self._w) |
| 86 | def winfo_containing(self, rootX, rootY): |
| 87 | return self.tk.call('winfo', 'containing', rootx, rootY) |
| 88 | def winfo_depth(self): |
| 89 | return self.tk.getint(self.tk.call('winfo', 'depth', self._w)) |
| 90 | def winfo_exists(self): |
| 91 | return self.tk.getint( |
| 92 | self.tk.call('winfo', 'exists', self._w)) |
| 93 | def winfo_fpixels(self, number): |
| 94 | return self.tk.getdouble(self.tk.call( |
| 95 | 'winfo', 'fpixels', self._w, number)) |
| 96 | def winfo_geometry(self): |
| 97 | return self.tk.call('winfo', 'geometry', self._w) |
| 98 | def winfo_height(self): |
| 99 | return self.tk.getint( |
| 100 | self.tk.call('winfo', 'height', self._w)) |
| 101 | def winfo_id(self): |
| 102 | return self.tk.getint( |
| 103 | self.tk.call('winfo', 'id', self._w)) |
| 104 | def winfo_interps(self): |
| 105 | return self.tk.splitlist( |
| 106 | self.tk.call('winfo', 'interps')) |
| 107 | def winfo_ismapped(self): |
| 108 | return self.tk.getint( |
| 109 | self.tk.call('winfo', 'ismapped', self._w)) |
| 110 | def winfo_name(self): |
| 111 | return self.tk.call('winfo', 'name', self._w) |
| 112 | def winfo_parent(self): |
| 113 | return self.tk.call('winfo', 'parent', self._w) |
| 114 | def winfo_pathname(self, id): |
| 115 | return self.tk.call('winfo', 'pathname', id) |
| 116 | def winfo_pixels(self, number): |
| 117 | return self.tk.getint( |
| 118 | self.tk.call('winfo', 'pixels', self._w, number)) |
| 119 | def winfo_reqheight(self): |
| 120 | return self.tk.getint( |
| 121 | self.tk.call('winfo', 'reqheight', self._w)) |
| 122 | def winfo_reqwidth(self): |
| 123 | return self.tk.getint( |
| 124 | self.tk.call('winfo', 'reqwidth', self._w)) |
| 125 | def winfo_rgb(self, color): |
| 126 | return self._getints( |
| 127 | self.tk.call('winfo', 'rgb', self._w, color)) |
| 128 | def winfo_rootx(self): |
| 129 | return self.tk.getint( |
| 130 | self.tk.call('winfo', 'rootx', self._w)) |
| 131 | def winfo_rooty(self): |
| 132 | return self.tk.getint( |
| 133 | self.tk.call('winfo', 'rooty', self._w)) |
| 134 | def winfo_screen(self): |
| 135 | return self.tk.call('winfo', 'screen', self._w) |
| 136 | def winfo_screencells(self): |
| 137 | return self.tk.getint( |
| 138 | self.tk.call('winfo', 'screencells', self._w)) |
| 139 | def winfo_screendepth(self): |
| 140 | return self.tk.getint( |
| 141 | self.tk.call('winfo', 'screendepth', self._w)) |
| 142 | def winfo_screenheight(self): |
| 143 | return self.tk.getint( |
| 144 | self.tk.call('winfo', 'screenheight', self._w)) |
| 145 | def winfo_screenmmheight(self): |
| 146 | return self.tk.getint( |
| 147 | self.tk.call('winfo', 'screenmmheight', self._w)) |
| 148 | def winfo_screenmmwidth(self): |
| 149 | return self.tk.getint( |
| 150 | self.tk.call('winfo', 'screenmmwidth', self._w)) |
| 151 | def winfo_screenvisual(self): |
| 152 | return self.tk.call('winfo', 'screenvisual', self._w) |
| 153 | def winfo_screenwidth(self): |
| 154 | return self.tk.getint( |
| 155 | self.tk.call('winfo', 'screenwidth', self._w)) |
| 156 | def winfo_toplevel(self): |
| 157 | return self.tk.call('winfo', 'toplevel', self._w) |
| 158 | def winfo_visual(self): |
| 159 | return self.tk.call('winfo', 'visual', self._w) |
| 160 | def winfo_vrootheight(self): |
| 161 | return self.tk.getint( |
| 162 | self.tk.call('winfo', 'vrootheight', self._w)) |
| 163 | def winfo_vrootwidth(self): |
| 164 | return self.tk.getint( |
| 165 | self.tk.call('winfo', 'vrootwidth', self._w)) |
| 166 | def winfo_vrootx(self): |
| 167 | return self.tk.getint( |
| 168 | self.tk.call('winfo', 'vrootx', self._w)) |
| 169 | def winfo_vrooty(self): |
| 170 | return self.tk.getint( |
| 171 | self.tk.call('winfo', 'vrooty', self._w)) |
| 172 | def winfo_width(self): |
| 173 | return self.tk.getint( |
| 174 | self.tk.call('winfo', 'width', self._w)) |
| 175 | def winfo_x(self): |
| 176 | return self.tk.getint( |
| 177 | self.tk.call('winfo', 'x', self._w)) |
| 178 | def winfo_y(self): |
| 179 | return self.tk.getint( |
| 180 | self.tk.call('winfo', 'y', self._w)) |
| 181 | def update(self): |
| 182 | self.tk.call('update') |
| 183 | def update_idletasks(self): |
| 184 | self.tk.call('update', 'idletasks') |
| 185 | def bind(self, sequence, func, add=''): |
| 186 | global _substitute, _subst_prefix |
| 187 | if add: add = '+' |
| 188 | name = self._register(func, _substitute) |
| 189 | self.tk.call('bind', self._w, sequence, |
| 190 | (add + name,) + _subst_prefix) |
| 191 | def bind_all(self, sequence, func, add=''): |
| 192 | global _substitute, _subst_prefix |
| 193 | if add: add = '+' |
| 194 | name = self._register(func, _substitute) |
| 195 | self.tk.call('bind', 'all' , sequence, |
| 196 | (add + `name`,) + _subst_prefix) |
| 197 | def bind_class(self, className, sequence, func, add=''): |
| 198 | global _substitute, _subst_prefix |
| 199 | if add: add = '+' |
| 200 | name = self._register(func, _substitute) |
| 201 | self.tk.call('bind', className , sequence, |
| 202 | (add + name,) + _subst_prefix) |
| 203 | def mainloop(self): |
| 204 | self.tk.mainloop() |
| 205 | def quit(self): |
| 206 | self.tk.quit() |
| 207 | # Utilities |
| 208 | def _getints(self, string): |
| 209 | if string: |
| 210 | res = () |
| 211 | for v in self.tk.split(string): |
| 212 | res = res + (self.tk.getint(v),) |
| 213 | return res |
| 214 | else: |
| 215 | return string |
| 216 | def _getboolean(self, string): |
| 217 | if string: |
| 218 | return self.tk.getboolean(string) |
| 219 | else: |
| 220 | return string |
| 221 | def _options(self, cnf): |
| 222 | res = () |
| 223 | for k, v in cnf.items(): |
| 224 | if _isfunctype(v): |
| 225 | v = self._register(v) |
| 226 | res = res + ('-'+k, v) |
| 227 | return res |
| 228 | def _register(self, func, subst=None): |
| 229 | f = func |
| 230 | f = _CallSafely(func, subst).__call__ |
| 231 | name = `id(f)` |
| 232 | if hasattr(func, 'im_func'): |
| 233 | func = func.im_func |
| 234 | if hasattr(func, 'func_name') and \ |
| 235 | type(func.func_name) == type(''): |
| 236 | name = name + func.func_name |
| 237 | self.tk.createcommand(name, f) |
| 238 | return name |
| 239 | |
| 240 | _subst_prefix = ('%#', '%b', '%f', '%h', '%k', |
| 241 | '%s', '%t', '%w', '%x', '%y', |
| 242 | '%A', '%E', '%K', '%N', '%T', '%X', '%Y') |
| 243 | |
| 244 | def _substitute(*args): |
| 245 | global default_root |
| 246 | global _subst_prefix |
| 247 | tk = default_root.tk |
| 248 | if len(args) != len(_subst_prefix): return args |
| 249 | nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, T, X, Y = args |
| 250 | # Missing: (a, c, d, m, o, v, B, R, W) |
| 251 | #XXX Convert %W (_w) to class instance? |
| 252 | e = Event() |
| 253 | e.serial = tk.getint(nsign) |
| 254 | e.num = tk.getint(b) |
| 255 | try: e.focus = tk.getboolean(f) |
| 256 | except TclError: pass |
| 257 | e.height = tk.getint(h) |
| 258 | e.keycode = tk.getint(k) |
| 259 | e.state = tk.getint(s) |
| 260 | e.time = tk.getint(t) |
| 261 | e.width = tk.getint(w) |
| 262 | e.x = tk.getint(x) |
| 263 | e.y = tk.getint(y) |
| 264 | e.char = A |
| 265 | try: e.send_event = tk.getboolean(E) |
| 266 | except TclError: pass |
| 267 | e.keysym = K |
| 268 | e.keysym_num = tk.getint(N) |
| 269 | e.type = T |
| 270 | #XXX %W stuff |
| 271 | e.x_root = tk.getint(X) |
| 272 | e.y_root = tk.getint(Y) |
| 273 | return (e,) |
| 274 | |
| 275 | class _CallSafely: |
| 276 | def __init__(self, func, subst=None): |
| 277 | self.func = func |
| 278 | self.subst = subst |
| 279 | def __call__(self, *args): |
| 280 | if self.subst: |
| 281 | args = self.apply_func(self.subst, args) |
| 282 | args = self.apply_func(self.func, args) |
| 283 | def apply_func(self, func, args): |
| 284 | import sys |
| 285 | try: |
| 286 | return apply(func, args) |
| 287 | except: |
| 288 | try: |
| 289 | try: |
| 290 | t = sys.exc_traceback |
| 291 | while t: |
| 292 | sys.stderr.write( |
| 293 | ' %s, line %s\n' % |
| 294 | (t.tb_frame.f_code, |
| 295 | t.tb_lineno)) |
| 296 | t = t.tb_next |
| 297 | finally: |
| 298 | sys.stderr.write('%s: %s\n' % |
| 299 | (sys.exc_type, |
| 300 | sys.exc_value)) |
| 301 | except: |
| 302 | print '*** Error in error handling ***' |
| 303 | print sys.exc_type, ':', sys.exc_value |
| 304 | |
| 305 | class Wm: |
| 306 | def aspect(self, |
| 307 | minNumer=None, minDenom=None, |
| 308 | maxNumer=None, maxDenom=None): |
| 309 | return self._getints( |
| 310 | self.tk.call('wm', 'aspect', self._w, |
| 311 | minNumer, minDenom, |
| 312 | maxNumer, maxDenom)) |
| 313 | def client(self, name=None): |
| 314 | return self.tk.call('wm', 'client', self._w, name) |
| 315 | def command(self, value=None): |
| 316 | return self.tk.call('wm', 'command', self._w, value) |
| 317 | def deiconify(self): |
| 318 | return self.tk.call('wm', 'deiconify', self._w) |
| 319 | def focusmodel(self, model=None): |
| 320 | return self.tk.call('wm', 'focusmodel', self._w, model) |
| 321 | def frame(self): |
| 322 | return self.tk.call('wm', 'frame', self._w) |
| 323 | def geometry(self, newGeometry=None): |
| 324 | return self.tk.call('wm', 'geometry', self._w, newGeometry) |
| 325 | def grid(self, |
| 326 | baseWidht=None, baseHeight=None, |
| 327 | widthInc=None, heightInc=None): |
| 328 | return self._getints(self.tk.call( |
| 329 | 'wm', 'grid', self._w, |
| 330 | baseWidht, baseHeight, widthInc, heightInc)) |
| 331 | def group(self, pathName=None): |
| 332 | return self.tk.call('wm', 'group', self._w, pathName) |
| 333 | def iconbitmap(self, bitmap=None): |
| 334 | return self.tk.call('wm', 'iconbitmap', self._w, bitmap) |
| 335 | def iconify(self): |
| 336 | return self.tk.call('wm', 'iconify', self._w) |
| 337 | def iconmask(self, bitmap=None): |
| 338 | return self.tk.call('wm', 'iconmask', self._w, bitmap) |
| 339 | def iconname(self, newName=None): |
| 340 | return self.tk.call('wm', 'iconname', self._w, newName) |
| 341 | def iconposition(self, x=None, y=None): |
| 342 | return self._getints(self.tk.call( |
| 343 | 'wm', 'iconposition', self._w, x, y)) |
| 344 | def iconwindow(self, pathName=None): |
| 345 | return self.tk.call('wm', 'iconwindow', self._w, pathName) |
| 346 | def maxsize(self, width=None, height=None): |
| 347 | return self._getints(self.tk.call( |
| 348 | 'wm', 'maxsize', self._w, width, height)) |
| 349 | def minsize(self, width=None, height=None): |
| 350 | return self._getints(self.tk.call( |
| 351 | 'wm', 'minsize', self._w, width, height)) |
| 352 | def overrideredirect(self, boolean=None): |
| 353 | return self._getboolean(self.tk.call( |
| 354 | 'wm', 'overrideredirect', self._w, boolean)) |
| 355 | def positionfrom(self, who=None): |
| 356 | return self.tk.call('wm', 'positionfrom', self._w, who) |
| 357 | def protocol(self, name=None, func=None): |
| 358 | if _isfunctype(func): |
| 359 | command = self._register(func) |
| 360 | else: |
| 361 | command = func |
| 362 | return self.tk.call( |
| 363 | 'wm', 'protocol', self._w, name, command) |
| 364 | def sizefrom(self, who=None): |
| 365 | return self.tk.call('wm', 'sizefrom', self._w, who) |
| 366 | def state(self): |
| 367 | return self.tk.call('wm', 'state', self._w) |
| 368 | def title(self, string=None): |
| 369 | return self.tk.call('wm', 'title', self._w, string) |
| 370 | def transient(self, master=None): |
| 371 | return self.tk.call('wm', 'transient', self._w, master) |
| 372 | def withdraw(self): |
| 373 | return self.tk.call('wm', 'withdraw', self._w) |
| 374 | |
| 375 | class Tk(Misc, Wm): |
| 376 | _w = '.' |
| 377 | def __init__(self, screenName=None, baseName=None, className='Tk'): |
| 378 | if baseName is None: |
| 379 | import sys, os |
| 380 | baseName = os.path.basename(sys.argv[0]) |
| 381 | if baseName[-3:] == '.py': baseName = baseName[:-3] |
| 382 | self.tk = tkinter.create(screenName, baseName, className) |
| 383 | self.tk.createcommand('tkerror', tkerror) |
| 384 | def __del__(self): |
| 385 | self.tk.call('destroy', '.') |
| 386 | def __str__(self): |
| 387 | return '.' |
| 388 | |
| 389 | class Pack: |
| 390 | def config(self, cnf={}): |
| 391 | apply(self.tk.call, |
| 392 | ('pack', 'configure', self._w) |
| 393 | + self._options(cnf)) |
| 394 | pack = config |
| 395 | def __setitem__(self, key, value): |
| 396 | Pack.config({key: value}) |
| 397 | def forget(self): |
| 398 | self.tk.call('pack', 'forget', self._w) |
| 399 | def newinfo(self): |
| 400 | return self.tk.call('pack', 'newinfo', self._w) |
| 401 | info = newinfo |
| 402 | def propagate(self, boolean=None): |
| 403 | if boolean: |
| 404 | self.tk.call('pack', 'propagate', self._w) |
| 405 | else: |
| 406 | return self._getboolean(self.tk.call( |
| 407 | 'pack', 'propagate', self._w)) |
| 408 | def slaves(self): |
| 409 | return self.tk.splitlist(self.tk.call( |
| 410 | 'pack', 'slaves', self._w)) |
| 411 | |
| 412 | class Place: |
| 413 | def config(self, cnf={}): |
| 414 | apply(self.tk.call, |
| 415 | ('place', 'configure', self._w) |
| 416 | + self._options(cnf)) |
| 417 | place = config |
| 418 | def __setitem__(self, key, value): |
| 419 | Place.config({key: value}) |
| 420 | def forget(self): |
| 421 | self.tk.call('place', 'forget', self._w) |
| 422 | def info(self): |
| 423 | return self.tk.call('place', 'info', self._w) |
| 424 | def slaves(self): |
| 425 | return self.tk.splitlist(self.tk.call( |
| 426 | 'place', 'slaves', self._w)) |
| 427 | |
| 428 | default_root = None |
| 429 | |
| 430 | class Widget(Misc, Pack, Place): |
| 431 | def __init__(self, master, widgetName, cnf={}, extra=()): |
| 432 | global default_root |
| 433 | if not master: |
| 434 | if not default_root: |
| 435 | default_root = Tk() |
| 436 | master = default_root |
| 437 | if not default_root: |
| 438 | default_root = master |
| 439 | self.master = master |
| 440 | self.tk = master.tk |
| 441 | if cnf.has_key('name'): |
| 442 | name = cnf['name'] |
| 443 | del cnf['name'] |
| 444 | else: |
| 445 | name = `id(self)` |
| 446 | if master._w=='.': |
| 447 | self._w = '.' + name |
| 448 | else: |
| 449 | self._w = master._w + '.' + name |
| 450 | self.widgetName = widgetName |
| 451 | apply(self.tk.call, (widgetName, self._w) + extra) |
| 452 | Widget.config(self, cnf) |
| 453 | def config(self, cnf={}): |
| 454 | for k in cnf.keys(): |
| 455 | if type(k) == ClassType: |
| 456 | k.config(self, cnf[k]) |
| 457 | del cnf[k] |
| 458 | apply(self.tk.call, (self._w, 'configure') |
| 459 | + self._options(cnf)) |
| 460 | def __getitem__(self, key): |
| 461 | v = self.tk.split(self.tk.call( |
| 462 | self._w, 'configure', '-' + key)) |
| 463 | return v[4] |
| 464 | def __setitem__(self, key, value): |
| 465 | Widget.config(self, {key: value}) |
| 466 | def __str__(self): |
| 467 | return self._w |
| 468 | def __del__(self): |
| 469 | self.tk.call('destroy', self._w) |
| 470 | destroy = __del__ |
| 471 | def _do(self, name, args=()): |
| 472 | apply(self.tk.call, (self._w, name) + args) |
| 473 | |
| 474 | class Toplevel(Widget, Wm): |
| 475 | def __init__(self, master=None, cnf={}): |
| 476 | extra = () |
| 477 | if cnf.has_key('screen'): |
| 478 | extra = ('-screen', cnf['screen']) |
| 479 | del cnf['screen'] |
| 480 | if cnf.has_key('class'): |
| 481 | extra = extra + ('-class', cnf['class']) |
| 482 | del cnf['class'] |
| 483 | Widget.__init__(self, master, 'toplevel', cnf, extra) |
| 484 | self.iconname(self.tk.call('wm', 'iconname', '.')) |
| 485 | self.title(self.tk.call('wm', 'title', '.')) |
| 486 | |
| 487 | class Button(Widget): |
| 488 | def __init__(self, master=None, cnf={}): |
| 489 | Widget.__init__(self, master, 'button', cnf) |
| 490 | def tk_butEnter(self): |
| 491 | self.tk.call('tk_butEnter', self._w) |
| 492 | def tk_butLeave(self): |
| 493 | self.tk.call('tk_butLeave', self._w) |
| 494 | def tk_butDown(self): |
| 495 | self.tk.call('tk_butDown', self._w) |
| 496 | def tk_butUp(self): |
| 497 | self.tk.call('tk_butUp', self._w) |
| 498 | def flash(self): |
| 499 | self.tk.call(self._w, 'flash') |
| 500 | def invoke(self): |
| 501 | self.tk.call(self._w, 'invoke') |
| 502 | |
| 503 | # Indices: |
| 504 | def AtEnd(): |
| 505 | return 'end' |
| 506 | def AtInsert(): |
| 507 | return 'insert' |
| 508 | def AtSelFirst(): |
| 509 | return 'sel.first' |
| 510 | def AtSelLast(): |
| 511 | return 'sel.last' |
| 512 | def At(x, y=None): |
| 513 | if y: |
| 514 | return '@' + `x` + ',' + `y` |
| 515 | else: |
| 516 | return '@' + `x` |
| 517 | |
| 518 | class Canvas(Widget): |
| 519 | def __init__(self, master=None, cnf={}): |
| 520 | Widget.__init__(self, master, 'canvas', cnf) |
| 521 | def addtag(self, *args): |
| 522 | self._do('addtag', args) |
| 523 | def bbox(self, *args): |
| 524 | return self._getints(self._do('bbox', args)) |
| 525 | def bind(self, tagOrId, sequence, func, add=''): |
| 526 | global _substitute, _subst_prefix |
| 527 | if add: add='+' |
| 528 | name = self._register(func, _substitute) |
| 529 | self.tk.call(self._w, 'bind', tagOrId, sequence, |
| 530 | (add + name,) + _subst_prefix) |
| 531 | def canvasx(self, screenx, gridspacing=None): |
| 532 | return self.tk.getint(self.tk.call( |
| 533 | self._w, 'canvasx', screenx, gridspacing)) |
| 534 | def canvasy(self, screeny, gridspacing=None): |
| 535 | return self.tk.getint(self.tk.call( |
| 536 | self._w, 'canvasy', screeny, gridspacing)) |
| 537 | def coords(self, *args): |
| 538 | return self._do('coords', args) |
| 539 | def _create(self, itemType, args): # Args: (value, value, ..., cnf={}) |
| 540 | cnf = args[-1] |
| 541 | if type(cnf) == type({}): |
| 542 | args = args[:-1] |
| 543 | else: |
| 544 | cnf = {} |
| 545 | v = (self._w, 'create', itemType) + args |
| 546 | for k in cnf.keys(): |
| 547 | v = v + ('-' + k, cnf[k]) |
| 548 | return self.tk.getint(apply(self.tk.call, v)) |
| 549 | def create_arc(self, *args): |
| 550 | Canvas._create(self, 'arc', args) |
| 551 | def create_bitmap(self, *args): |
| 552 | Canvas._create(self, 'bitmap', args) |
| 553 | def create_line(self, *args): |
| 554 | Canvas._create(self, 'line', args) |
| 555 | def create_oval(self, *args): |
| 556 | Canvas._create(self, 'oval', args) |
| 557 | def create_polygon(self, *args): |
| 558 | Canvas._create(self, 'polygon', args) |
| 559 | def create_rectangle(self, *args): |
| 560 | Canvas._create(self, 'rectangle', args) |
| 561 | def create_text(self, *args): |
| 562 | Canvas._create(self, 'text', args) |
| 563 | def create_window(self, *args): |
| 564 | Canvas._create(self, 'window', args) |
| 565 | def dchars(self, *args): |
| 566 | self._do('dchars', args) |
| 567 | def delete(self, *args): |
| 568 | self._do('delete', args) |
| 569 | def dtag(self, *args): |
| 570 | self._do('dtag', args) |
| 571 | def find(self, *args): |
| 572 | self.tk.splitlist(self._do('find', args)) |
| 573 | def focus(self, *args): |
| 574 | return self._do('focus', args) |
| 575 | def gettags(self, *args): |
| 576 | return self.tk.splitlist(self._do('gettags', args)) |
| 577 | def icursor(self, *args): |
| 578 | self._do('icursor', args) |
| 579 | def index(self, *args): |
| 580 | return self.tk.getint(self._do('index', args)) |
| 581 | def insert(self, *args): |
| 582 | self._do('insert', args) |
| 583 | def itemconfig(self, tagOrId, cnf={}): |
| 584 | self._do('itemconfigure', (tagOrId,) + self._options(cnf)) |
| 585 | def lower(self, *args): |
| 586 | self._do('lower', args) |
| 587 | def move(self, *args): |
| 588 | self._do('move', args) |
| 589 | def postscript(self, cnf={}): |
| 590 | return self._do('postscript', self._options(cnf)) |
| 591 | def tkraise(self, *args): |
| 592 | self._do('raise', args) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame^] | 593 | lift = tkraise |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 594 | def scale(self, *args): |
| 595 | self._do('scale', args) |
| 596 | def scan_mark(self, x, y): |
| 597 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 598 | def scan_dragto(self, x, y): |
| 599 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
| 600 | def select_adjust(self, tagOrId, index): |
| 601 | self.tk.call( |
| 602 | self._w, 'select', 'adjust', tagOrId, index) |
| 603 | def select_clear(self): |
| 604 | self.tk.call(self._w, 'select', 'clear') |
| 605 | def select_from(self, tagOrId, index): |
| 606 | self.tk.call( |
| 607 | self._w, 'select', 'from', tagOrId, index) |
| 608 | def select_item(self): |
| 609 | self.tk.call(self._w, 'select', 'item') |
| 610 | def select_to(self, tagOrId, index): |
| 611 | self.tk.call( |
| 612 | self._w, 'select', 'to', tagOrId, index) |
| 613 | def type(self, tagOrId): |
| 614 | return self.tk.splitlist(self.tk.call( |
| 615 | self._w, 'type', tagOrId)) |
| 616 | def xview(self, index): |
| 617 | self.tk.call(self._w, 'xview', index) |
| 618 | def yview(self, index): |
| 619 | self.tk.call(self._w, 'yview', index) |
| 620 | |
| 621 | class Checkbutton(Widget): |
| 622 | def __init__(self, master=None, cnf={}): |
| 623 | Widget.__init__(self, master, 'checkbutton', cnf) |
| 624 | def deselect(self): |
| 625 | self.tk.call(self._w, 'deselect') |
| 626 | def flash(self): |
| 627 | self.tk.call(self._w, 'flash') |
| 628 | def invoke(self): |
| 629 | self.tk.call(self._w, 'invoke') |
| 630 | def select(self): |
| 631 | self.tk.call(self._w, 'select') |
| 632 | def toggle(self): |
| 633 | self.tk.call(self._w, 'toggle') |
| 634 | |
| 635 | class Entry(Widget): |
| 636 | def __init__(self, master=None, cnf={}): |
| 637 | Widget.__init__(self, master, 'entry', cnf) |
| 638 | def tk_entryBackspace(self): |
| 639 | self.tk.call('tk_entryBackspace', self._w) |
| 640 | def tk_entryBackword(self): |
| 641 | self.tk.call('tk_entryBackword', self._w) |
| 642 | def tk_entrySeeCaret(self): |
| 643 | self.tk.call('tk_entrySeeCaret', self._w) |
| 644 | def delete(self, first, last=None): |
| 645 | self.tk.call(self._w, 'delete', first, last) |
| 646 | def get(self): |
| 647 | return self.tk.call(self._w, 'get') |
| 648 | def icursor(self, index): |
| 649 | self.tk.call(self._w, 'icursor', index) |
| 650 | def index(self, index): |
| 651 | return self.tk.getint(self.tk.call( |
| 652 | self._w, 'index', index)) |
| 653 | def insert(self, index, string): |
| 654 | self.tk.call(self._w, 'insert', index, string) |
| 655 | def scan_mark(self, x): |
| 656 | self.tk.call(self._w, 'scan', 'mark', x) |
| 657 | def scan_dragto(self, x): |
| 658 | self.tk.call(self._w, 'scan', 'dragto', x) |
| 659 | def select_adjust(self, index): |
| 660 | self.tk.call(self._w, 'select', 'adjust', index) |
| 661 | def select_clear(self): |
| 662 | self.tk.call(self._w, 'select', 'clear') |
| 663 | def select_from(self, index): |
| 664 | self.tk.call(self._w, 'select', 'from', index) |
| 665 | def select_to(self, index): |
| 666 | self.tk.call(self._w, 'select', 'to', index) |
| 667 | def select_view(self, index): |
| 668 | self.tk.call(self._w, 'select', 'view', index) |
| 669 | |
| 670 | class Frame(Widget): |
| 671 | def __init__(self, master=None, cnf={}): |
| 672 | extra = () |
| 673 | if cnf.has_key('class'): |
| 674 | extra = ('-class', cnf['class']) |
| 675 | del cnf['class'] |
| 676 | Widget.__init__(self, master, 'frame', cnf, extra) |
| 677 | def tk_menuBar(self, *args): |
| 678 | apply(self.tk.call, ('tk_menuBar', self._w) + args) |
| 679 | |
| 680 | class Label(Widget): |
| 681 | def __init__(self, master=None, cnf={}): |
| 682 | Widget.__init__(self, master, 'label', cnf) |
| 683 | |
| 684 | class Listbox(Widget): |
| 685 | def __init__(self, master=None, cnf={}): |
| 686 | Widget.__init__(self, master, 'listbox', cnf) |
| 687 | def tk_listboxSingleSelect(self): |
| 688 | self.tk.call('tk_listboxSingleSelect', self._w) |
| 689 | def curselection(self): |
| 690 | return self.tk.splitlist(self.tk.call( |
| 691 | self._w, 'curselection')) |
| 692 | def delete(self, first, last=None): |
| 693 | self.tk.call(self._w, 'delete', first, last) |
| 694 | def get(self, index): |
| 695 | return self.tk.call(self._w, 'get', index) |
| 696 | def insert(self, index, *elements): |
| 697 | apply(self.tk.call, |
| 698 | (self._w, 'insert', index) + elements) |
| 699 | def nearest(self, y): |
| 700 | return self.tk.getint(self.tk.call( |
| 701 | self._w, 'nearest', y)) |
| 702 | def scan_mark(self, x, y): |
| 703 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 704 | def scan_dragto(self, x, y): |
| 705 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
| 706 | def select_adjust(self, index): |
| 707 | self.tk.call(self._w, 'select', 'adjust', index) |
| 708 | def select_clear(self): |
| 709 | self.tk.call(self._w, 'select', 'clear') |
| 710 | def select_from(self, index): |
| 711 | self.tk.call(self._w, 'select', 'from', index) |
| 712 | def select_to(self, index): |
| 713 | self.tk.call(self._w, 'select', 'to', index) |
| 714 | def size(self): |
| 715 | return self.tk.getint(self.tk.call(self._w, 'size')) |
| 716 | def xview(self, index): |
| 717 | self.tk.call(self._w, 'xview', index) |
| 718 | def yview(self, index): |
| 719 | self.tk.call(self._w, 'yview', index) |
| 720 | |
| 721 | class Menu(Widget): |
| 722 | def __init__(self, master=None, cnf={}): |
| 723 | Widget.__init__(self, master, 'menu', cnf) |
| 724 | def tk_menuBar(self, *args): |
| 725 | apply(self.tk.call, ('tk_menuBar', self._w) + args) |
| 726 | def tk_bindForTraversal(self): |
| 727 | self.tk.call('tk_bindForTraversal', self._w) |
| 728 | def tk_mbPost(self): |
| 729 | self.tk.call('tk_mbPost', self._w) |
| 730 | def tk_mbUnpost(self): |
| 731 | self.tk.call('tk_mbUnpost') |
| 732 | def tk_traverseToMenu(self, char): |
| 733 | self.tk.call('tk_traverseToMenu', self._w, char) |
| 734 | def tk_traverseWithinMenu(self, char): |
| 735 | self.tk.call('tk_traverseWithinMenu', self._w, char) |
| 736 | def tk_getMenuButtons(self): |
| 737 | return self.tk.call('tk_getMenuButtons', self._w) |
| 738 | def tk_nextMenu(self, count): |
| 739 | self.tk.call('tk_nextMenu', count) |
| 740 | def tk_nextMenuEntry(self, count): |
| 741 | self.tk.call('tk_nextMenuEntry', count) |
| 742 | def tk_invokeMenu(self): |
| 743 | self.tk.call('tk_invokeMenu', self._w) |
| 744 | def tk_firstMenu(self): |
| 745 | self.tk.call('tk_firstMenu', self._w) |
| 746 | def tk_mbButtonDown(self): |
| 747 | self.tk.call('tk_mbButtonDown', self._w) |
| 748 | def activate(self, index): |
| 749 | self.tk.call(self._w, 'activate', index) |
| 750 | def add(self, itemType, cnf={}): |
| 751 | apply(self.tk.call, (self._w, 'add', itemType) |
| 752 | + self._options(cnf)) |
| 753 | def delete(self, index1, index2=None): |
| 754 | self.tk.call(self._w, 'delete', index1, index2) |
| 755 | def entryconfig(self, index, cnf={}): |
| 756 | apply(self.tk.call, (self._w, 'entryconfigure', index) |
| 757 | + self._options(cnf)) |
| 758 | def index(self, index): |
| 759 | return self.tk.call(self._w, 'index', index) |
| 760 | def invoke(self, index): |
| 761 | return self.tk.call(self._w, 'invoke', index) |
| 762 | def post(self, x, y): |
| 763 | self.tk.call(self._w, 'post', x, y) |
| 764 | def unpost(self): |
| 765 | self.tk.call(self._w, 'unpost') |
| 766 | def yposition(self, index): |
| 767 | return self.tk.getint(self.tk.call( |
| 768 | self._w, 'yposition', index)) |
| 769 | |
| 770 | class Menubutton(Widget): |
| 771 | def __init__(self, master=None, cnf={}): |
| 772 | Widget.__init__(self, master, 'menubutton', cnf) |
| 773 | |
| 774 | class Message(Widget): |
| 775 | def __init__(self, master=None, cnf={}): |
| 776 | Widget.__init__(self, master, 'message', cnf) |
| 777 | |
| 778 | class Radiobutton(Widget): |
| 779 | def __init__(self, master=None, cnf={}): |
| 780 | Widget.__init__(self, master, 'radiobutton', cnf) |
| 781 | def deselect(self): |
| 782 | self.tk.call(self._w, 'deselect') |
| 783 | def flash(self): |
| 784 | self.tk.call(self._w, 'flash') |
| 785 | def invoke(self): |
| 786 | self.tk.call(self._w, 'invoke') |
| 787 | def select(self): |
| 788 | self.tk.call(self._w, 'select') |
| 789 | |
| 790 | class Scale(Widget): |
| 791 | def __init__(self, master=None, cnf={}): |
| 792 | Widget.__init__(self, master, 'scale', cnf) |
| 793 | def get(self): |
| 794 | return self.tk.getint(self.tk.call(self._w, 'get')) |
| 795 | def set(self, value): |
| 796 | self.tk.call(self._w, 'set', value) |
| 797 | |
| 798 | class Scrollbar(Widget): |
| 799 | def __init__(self, master=None, cnf={}): |
| 800 | Widget.__init__(self, master, 'scrollbar', cnf) |
| 801 | def get(self): |
| 802 | return self.tk.getints(self.tk.call(self._w, 'get')) |
| 803 | def set(self, totalUnits, windowUnits, firstUnit, lastUnit): |
| 804 | self.tk.call(self._w, 'set', |
| 805 | totalUnits, windowUnits, firstUnit, lastUnit) |
| 806 | |
| 807 | class Text(Widget): |
| 808 | def __init__(self, master=None, cnf={}): |
| 809 | Widget.__init__(self, master, 'text', cnf) |
| 810 | def tk_textSelectTo(self, index): |
| 811 | self.tk.call('tk_textSelectTo', self._w, index) |
| 812 | def tk_textBackspace(self): |
| 813 | self.tk.call('tk_textBackspace', self._w) |
| 814 | def tk_textIndexCloser(self, a, b, c): |
| 815 | self.tk.call('tk_textIndexCloser', self._w, a, b, c) |
| 816 | def tk_textResetAnchor(self, index): |
| 817 | self.tk.call('tk_textResetAnchor', self._w, index) |
| 818 | def compare(self, index1, op, index2): |
| 819 | return self.tk.getboolean(self.tk.call( |
| 820 | self._w, 'compare', index1, op, index2)) |
| 821 | def debug(self, boolean=None): |
| 822 | return self.tk.getboolean(self.tk.call( |
| 823 | self._w, 'debug', boolean)) |
| 824 | def delete(self, index1, index2=None): |
| 825 | self.tk.call(self._w, 'delete', index1, index2) |
| 826 | def get(self, index1, index2=None): |
| 827 | return self.tk.call(self._w, 'get', index1, index2) |
| 828 | def index(self, index): |
| 829 | return self.tk.call(self._w, 'index', index) |
| 830 | def insert(self, index, chars): |
| 831 | self.tk.call(self._w, 'insert', index, chars) |
| 832 | def mark_names(self): |
| 833 | return self.tk.splitlist(self.tk.call( |
| 834 | self._w, 'mark', 'names')) |
| 835 | def mark_set(self, markName, index): |
| 836 | self.tk.call(self._w, 'mark', 'set', markName, index) |
| 837 | def mark_unset(self, markNames): |
| 838 | apply(self.tk.call, (self._w, 'mark', 'unset') + markNames) |
| 839 | def scan_mark(self, y): |
| 840 | self.tk.call(self._w, 'scan', 'mark', y) |
| 841 | def scan_dragto(self, y): |
| 842 | self.tk.call(self._w, 'scan', 'dragto', y) |
| 843 | def tag_add(self, tagName, index1, index2=None): |
| 844 | self.tk.call( |
| 845 | self._w, 'tag', 'add', tagName, index1, index2) |
| 846 | def tag_bind(self, tagName, sequence, func, add=''): |
| 847 | global _substitute, _subst_prefix |
| 848 | if add: add='+' |
| 849 | name = self._register(func, _substitute) |
| 850 | self.tk.call(self._w, 'tag', 'bind', |
| 851 | tagName, sequence, |
| 852 | (add + name,) + _subst_prefix) |
| 853 | def tag_config(self, tagName, cnf={}): |
| 854 | apply(self.tk.call, |
| 855 | (self._w, 'tag', 'configure', tagName) |
| 856 | + self._options(cnf)) |
| 857 | def tag_delete(self, tagNames): |
| 858 | apply(self.tk.call, (self._w, 'tag', 'delete') |
| 859 | + tagNames) |
| 860 | def tag_lower(self, tagName, belowThis=None): |
| 861 | self.tk.call(self._w, 'tag', 'lower', |
| 862 | tagName, belowThis) |
| 863 | def tag_names(self, index=None): |
| 864 | return self.tk.splitlist( |
| 865 | self.tk.call(self._w, 'tag', 'names', index)) |
| 866 | def tag_nextrange(self, tagName, index1, index2=None): |
| 867 | return self.tk.splitlist(self.tk.call( |
| 868 | self._w, 'tag', 'nextrange', index1, index2)) |
| 869 | def tag_raise(self, tagName, aboveThis=None): |
| 870 | self.tk.call( |
| 871 | self._w, 'tag', 'raise', tagName, aboveThis) |
| 872 | def tag_ranges(self, tagName): |
| 873 | return self.tk.splitlist(self.tk.call( |
| 874 | self._w, 'tag', 'ranges', tagName)) |
| 875 | def tag_remove(self, tagName, index1, index2=None): |
| 876 | self.tk.call( |
| 877 | self._w, 'tag', 'remove', index1, index2) |
| 878 | def yview(self, what): |
| 879 | self.tk.call(self._w, 'yview', what) |
| 880 | def yview_pickplace(self, what): |
| 881 | self.tk.call(self._w, 'yview', '-pickplace', what) |
| 882 | |
| 883 | #class Dialog: |
| 884 | |