home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Python 1.1 / Lib / tkinter / Tkinter.py < prev   
Encoding:
Python Source  |  1994-08-30  |  35.9 KB  |  1,166 lines  |  [TEXT/R*ch]

  1. # Tkinter.py -- Tk/Tcl widget wrappers
  2.  
  3. import tkinter
  4. from tkinter import TclError
  5.  
  6. class _Dummy:
  7.     def meth(self):    return
  8.  
  9. def _func():
  10.     pass
  11.  
  12. FunctionType = type(_func)
  13. ClassType = type(_Dummy)
  14. MethodType = type(_Dummy.meth)
  15. StringType = type('')
  16. TupleType = type(())
  17. ListType = type([])
  18. DictionaryType = type({})
  19. NoneType = type(None)
  20. CallableTypes = (FunctionType, MethodType)
  21.  
  22. def _flatten(tuple):
  23.     res = ()
  24.     for item in tuple:
  25.         if type(item) in (TupleType, ListType):
  26.             res = res + _flatten(item)
  27.         else:
  28.             res = res + (item,)
  29.     return res
  30.  
  31. def _cnfmerge(cnfs):
  32.     if type(cnfs) in (NoneType, DictionaryType, StringType):
  33.         return cnfs
  34.     else:
  35.         cnf = {}
  36.         for c in _flatten(cnfs):
  37.             for k, v in c.items():
  38.                 cnf[k] = v
  39.         return cnf
  40.  
  41. class Event:
  42.     pass
  43.  
  44. _default_root = None
  45.  
  46. def _tkerror(err):
  47.     pass
  48.  
  49. def _exit(code='0'):
  50.     import sys
  51.     sys.exit(getint(code))
  52.  
  53. _varnum = 0
  54. class Variable:
  55.     def __init__(self, master=None):
  56.         global _default_root
  57.         global _varnum
  58.         if master:
  59.             self._tk = master.tk
  60.         else:
  61.             self._tk = _default_root.tk
  62.         self._name = 'PY_VAR' + `_varnum`
  63.         _varnum = _varnum + 1
  64.     def __del__(self):
  65.         self._tk.unsetvar(self._name)
  66.     def __str__(self):
  67.         return self._name
  68.     def __call__(self, value=None):
  69.         if value == None:
  70.             return self.get()
  71.         else:
  72.             self.set(value)
  73.     def set(self, value):
  74.         return self._tk.setvar(self._name, value)
  75.  
  76. class StringVar(Variable):
  77.     def __init__(self, master=None):
  78.         Variable.__init__(self, master)
  79.     def get(self):
  80.         return self._tk.getvar(self._name)
  81.  
  82. class IntVar(Variable):
  83.     def __init__(self, master=None):
  84.         Variable.__init__(self, master)
  85.     def get(self):
  86.         return self._tk.getint(self._tk.getvar(self._name))
  87.  
  88. class DoubleVar(Variable):
  89.     def __init__(self, master=None):
  90.         Variable.__init__(self, master)
  91.     def get(self):
  92.         return self._tk.getdouble(self._tk.getvar(self._name))
  93.  
  94. class BooleanVar(Variable):
  95.     def __init__(self, master=None):
  96.         Variable.__init__(self, master)
  97.     def get(self):
  98.         return self._tk.getboolean(self._tk.getvar(self._name))
  99.  
  100. def mainloop():
  101.     _default_root.tk.mainloop()
  102.  
  103. def getint(s):
  104.     return _default_root.tk.getint(s)
  105.  
  106. def getdouble(s):
  107.     return _default_root.tk.getdouble(s)
  108.  
  109. def getboolean(s):
  110.     return _default_root.tk.getboolean(s)
  111.  
  112. class Misc:
  113.     def tk_strictMotif(self, boolean=None):
  114.         return self.tk.getboolean(self.tk.call(
  115.             'set', 'tk_strictMotif', boolean))
  116.     def tk_menuBar(self, *args):
  117.         apply(self.tk.call, ('tk_menuBar', self._w) + args)
  118.     def wait_variable(self, name='PY_VAR'):
  119.         self.tk.call('tkwait', 'variable', name)
  120.     waitvar = wait_variable # XXX b/w compat
  121.     def wait_window(self, window=None):
  122.         if window == None:
  123.             window = self
  124.         self.tk.call('tkwait', 'window', window._w)
  125.     def wait_visibility(self, window=None):
  126.         if window == None:
  127.             window = self
  128.         self.tk.call('tkwait', 'visibility', window._w)
  129.     def setvar(self, name='PY_VAR', value='1'):
  130.         self.tk.setvar(name, value)
  131.     def getvar(self, name='PY_VAR'):
  132.         return self.tk.getvar(name)
  133.     def getint(self, s):
  134.         return self.tk.getint(s)
  135.     def getdouble(self, s):
  136.         return self.tk.getdouble(s)
  137.     def getboolean(self, s):
  138.         return self.tk.getboolean(s)
  139.     def focus_set(self):
  140.         self.tk.call('focus', self._w)
  141.     focus = focus_set # XXX b/w compat?
  142.     def focus_default_set(self):
  143.         self.tk.call('focus', 'default', self._w)
  144.     def focus_default_none(self):
  145.         self.tk.call('focus', 'default', 'none')
  146.     focus_default = focus_default_set
  147.     def focus_none(self):
  148.         self.tk.call('focus', 'none')
  149.     def focus_get(self):
  150.         name = self.tk.call('focus')
  151.         if name == 'none': return None
  152.         return self._nametowidget(name)
  153.     def after(self, ms, func=None, *args):
  154.         if not func:
  155.             self.tk.call('after', ms)
  156.         else:
  157.             # XXX Disgusting hack to clean up after calling func
  158.             tmp = []
  159.             def callit(func=func, args=args, tk=self.tk, tmp=tmp):
  160.                 try:
  161.                     apply(func, args)
  162.                 finally:
  163.                     tk.deletecommand(tmp[0])
  164.             name = self._register(callit)
  165.             tmp.append(name)
  166.             self.tk.call('after', ms, name)
  167.     # XXX grab current w/o window argument
  168.     def grab_current(self):
  169.         name = self.tk.call('grab', 'current', self._w)
  170.         if not name: return None
  171.         return self._nametowidget(name)
  172.     def grab_release(self):
  173.         self.tk.call('grab', 'release', self._w)
  174.     def grab_set(self):
  175.         self.tk.call('grab', 'set', self._w)
  176.     def grab_set_global(self):
  177.         self.tk.call('grab', 'set', '-global', self._w)
  178.     def grab_status(self):
  179.         status = self.tk.call('grab', 'status', self._w)
  180.         if status == 'none': status = None
  181.         return status
  182.     def lower(self, belowThis=None):
  183.         self.tk.call('lower', self._w, belowThis)
  184.     def selection_clear(self):
  185.         self.tk.call('selection', 'clear', self._w)
  186.     def selection_get(self, type=None):
  187.         return self.tk.call('selection', 'get', type)
  188.     def selection_handle(self, func, type=None, format=None):
  189.         name = self._register(func)
  190.         self.tk.call('selection', 'handle', self._w, 
  191.                  name, type, format)
  192.     def selection_own(self, func=None):
  193.         name = self._register(func)
  194.         self.tk.call('selection', 'own', self._w, name)
  195.     def selection_own_get(self):
  196.         return self._nametowidget(self.tk.call('selection', 'own'))
  197.     def send(self, interp, cmd, *args):
  198.         return apply(self.tk.call, ('send', interp, cmd) + args)
  199.     def lower(self, belowThis=None):
  200.         self.tk.call('lift', self._w, belowThis)
  201.     def tkraise(self, aboveThis=None):
  202.         self.tk.call('raise', self._w, aboveThis)
  203.     lift = tkraise
  204.     def colormodel(self, value=None):
  205.         return self.tk.call('tk', 'colormodel', self._w, value)
  206.     def winfo_atom(self, name):
  207.         return self.tk.getint(self.tk.call('winfo', 'atom', name))
  208.     def winfo_atomname(self, id):
  209.         return self.tk.call('winfo', 'atomname', id)
  210.     def winfo_cells(self):
  211.         return self.tk.getint(
  212.             self.tk.call('winfo', 'cells', self._w))
  213.     def winfo_children(self):
  214.         return map(self._nametowidget,
  215.                self.tk.splitlist(self.tk.call(
  216.                    'winfo', 'children', self._w)))
  217.     def winfo_class(self):
  218.         return self.tk.call('winfo', 'class', self._w)
  219.     def winfo_containing(self, rootX, rootY):
  220.         return self.tk.call('winfo', 'containing', rootx, rootY)
  221.     def winfo_depth(self):
  222.         return self.tk.getint(self.tk.call('winfo', 'depth', self._w))
  223.     def winfo_exists(self):
  224.         return self.tk.getint(
  225.             self.tk.call('winfo', 'exists', self._w))
  226.     def winfo_fpixels(self, number):
  227.         return self.tk.getdouble(self.tk.call(
  228.             'winfo', 'fpixels', self._w, number))
  229.     def winfo_geometry(self):
  230.         return self.tk.call('winfo', 'geometry', self._w)
  231.     def winfo_height(self):
  232.         return self.tk.getint(
  233.             self.tk.call('winfo', 'height', self._w))
  234.     def winfo_id(self):
  235.         return self.tk.getint(
  236.             self.tk.call('winfo', 'id', self._w))
  237.     def winfo_interps(self):
  238.         return self.tk.splitlist(
  239.             self.tk.call('winfo', 'interps'))
  240.     def winfo_ismapped(self):
  241.         return self.tk.getint(
  242.             self.tk.call('winfo', 'ismapped', self._w))
  243.     def winfo_name(self):
  244.         return self.tk.call('winfo', 'name', self._w)
  245.     def winfo_parent(self):
  246.         return self.tk.call('winfo', 'parent', self._w)
  247.     def winfo_pathname(self, id):
  248.         return self.tk.call('winfo', 'pathname', id)
  249.     def winfo_pixels(self, number):
  250.         return self.tk.getint(
  251.             self.tk.call('winfo', 'pixels', self._w, number))
  252.     def winfo_reqheight(self):
  253.         return self.tk.getint(
  254.             self.tk.call('winfo', 'reqheight', self._w))
  255.     def winfo_reqwidth(self):
  256.         return self.tk.getint(
  257.             self.tk.call('winfo', 'reqwidth', self._w))
  258.     def winfo_rgb(self, color):
  259.         return self._getints(
  260.             self.tk.call('winfo', 'rgb', self._w, color))
  261.     def winfo_rootx(self):
  262.         return self.tk.getint(
  263.             self.tk.call('winfo', 'rootx', self._w))
  264.     def winfo_rooty(self):
  265.         return self.tk.getint(
  266.             self.tk.call('winfo', 'rooty', self._w))
  267.     def winfo_screen(self):
  268.         return self.tk.call('winfo', 'screen', self._w)
  269.     def winfo_screencells(self):
  270.         return self.tk.getint(
  271.             self.tk.call('winfo', 'screencells', self._w))
  272.     def winfo_screendepth(self):
  273.         return self.tk.getint(
  274.             self.tk.call('winfo', 'screendepth', self._w))
  275.     def winfo_screenheight(self):
  276.         return self.tk.getint(
  277.             self.tk.call('winfo', 'screenheight', self._w))
  278.     def winfo_screenmmheight(self):
  279.         return self.tk.getint(
  280.             self.tk.call('winfo', 'screenmmheight', self._w))
  281.     def winfo_screenmmwidth(self):
  282.         return self.tk.getint(
  283.             self.tk.call('winfo', 'screenmmwidth', self._w))
  284.     def winfo_screenvisual(self):
  285.         return self.tk.call('winfo', 'screenvisual', self._w)
  286.     def winfo_screenwidth(self):
  287.         return self.tk.getint(
  288.             self.tk.call('winfo', 'screenwidth', self._w))
  289.     def winfo_toplevel(self):
  290.         return self._nametowidget(self.tk.call(
  291.             'winfo', 'toplevel', self._w))
  292.     def winfo_visual(self):
  293.         return self.tk.call('winfo', 'visual', self._w)
  294.     def winfo_vrootheight(self):
  295.         return self.tk.getint(
  296.             self.tk.call('winfo', 'vrootheight', self._w))
  297.     def winfo_vrootwidth(self):
  298.         return self.tk.getint(
  299.             self.tk.call('winfo', 'vrootwidth', self._w))
  300.     def winfo_vrootx(self):
  301.         return self.tk.getint(
  302.             self.tk.call('winfo', 'vrootx', self._w))
  303.     def winfo_vrooty(self):
  304.         return self.tk.getint(
  305.             self.tk.call('winfo', 'vrooty', self._w))
  306.     def winfo_width(self):
  307.         return self.tk.getint(
  308.             self.tk.call('winfo', 'width', self._w))
  309.     def winfo_x(self):
  310.         return self.tk.getint(
  311.             self.tk.call('winfo', 'x', self._w))
  312.     def winfo_y(self):
  313.         return self.tk.getint(
  314.             self.tk.call('winfo', 'y', self._w))
  315.     def update(self):
  316.         self.tk.call('update')
  317.     def update_idletasks(self):
  318.         self.tk.call('update', 'idletasks')
  319.     def unbind(self, sequence):
  320.         self.tk.call('bind', self._w, sequence, '')
  321.     def bind(self, sequence, func, add=''):
  322.         if add: add = '+'
  323.         name = self._register(func, self._substitute)
  324.         self.tk.call('bind', self._w, sequence, 
  325.                  (add + name,) + self._subst_format)
  326.     def bind_all(self, sequence, func, add=''):
  327.         if add: add = '+'
  328.         name = self._register(func, self._substitute)
  329.         self.tk.call('bind', 'all' , sequence, 
  330.                  (add + name,) + self._subst_format)
  331.     def bind_class(self, className, sequence, func, add=''):
  332.         if add: add = '+'
  333.         name = self._register(func, self._substitute)
  334.         self.tk.call('bind', className , sequence, 
  335.                  (add + name,) + self._subst_format)
  336.     def mainloop(self):
  337.         self.tk.mainloop()
  338.     def quit(self):
  339.         self.tk.quit()
  340.     def _getints(self, string):
  341.         if not string: return None
  342.         res = ()
  343.         for v in self.tk.splitlist(string):
  344.             res = res +  (self.tk.getint(v),)
  345.         return res
  346.     def _getboolean(self, string):
  347.         if string:
  348.             return self.tk.getboolean(string)
  349.     def _options(self, cnf):
  350.         cnf = _cnfmerge(cnf)
  351.         res = ()
  352.         for k, v in cnf.items():
  353.             if type(v) in CallableTypes:
  354.                 v = self._register(v)
  355.             res = res + ('-'+k, v)
  356.         return res
  357.     def _nametowidget(self, name):
  358.         w = self
  359.         if name[0] == '.':
  360.             w = w._root()
  361.             name = name[1:]
  362.         from string import find
  363.         while name:
  364.             i = find(name, '.')
  365.             if i >= 0:
  366.                 name, tail = name[:i], name[i+1:]
  367.             else:
  368.                 tail = ''
  369.             w = w.children[name]
  370.             name = tail
  371.         return w
  372.     def _register(self, func, subst=None):
  373.         f = _CallSafely(func, subst).__call__
  374.         name = `id(f)`
  375.         if hasattr(func, 'im_func'):
  376.             func = func.im_func
  377.         if hasattr(func, 'func_name') and \
  378.            type(func.func_name) == type(''):
  379.             name = name + func.func_name
  380.         self.tk.createcommand(name, f)
  381.         return name
  382.     register = _register
  383.     def _root(self):
  384.         w = self
  385.         while w.master: w = w.master
  386.         return w
  387.     _subst_format = ('%#', '%b', '%f', '%h', '%k', 
  388.              '%s', '%t', '%w', '%x', '%y',
  389.              '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y')
  390.     def _substitute(self, *args):
  391.         tk = self.tk
  392.         if len(args) != len(self._subst_format): return args
  393.         nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y = args
  394.         # Missing: (a, c, d, m, o, v, B, R)
  395.         e = Event()
  396.         e.serial = tk.getint(nsign)
  397.         e.num = tk.getint(b)
  398.         try: e.focus = tk.getboolean(f)
  399.         except TclError: pass
  400.         e.height = tk.getint(h)
  401.         e.keycode = tk.getint(k)
  402.         e.state = tk.getint(s)
  403.         e.time = tk.getint(t)
  404.         e.width = tk.getint(w)
  405.         e.x = tk.getint(x)
  406.         e.y = tk.getint(y)
  407.         e.char = A
  408.         try: e.send_event = tk.getboolean(E)
  409.         except TclError: pass
  410.         e.keysym = K
  411.         e.keysym_num = tk.getint(N)
  412.         e.type = T
  413.         e.widget = self._nametowidget(W)
  414.         e.x_root = tk.getint(X)
  415.         e.y_root = tk.getint(Y)
  416.         return (e,)
  417.  
  418. class _CallSafely:
  419.     def __init__(self, func, subst=None):
  420.         self.func = func
  421.         self.subst = subst
  422.     def __call__(self, *args):
  423.         if self.subst:
  424.             args = self.apply_func(self.subst, args)
  425.         args = self.apply_func(self.func, args)
  426.     def apply_func(self, func, args):
  427.         import sys
  428.         try:
  429.             return apply(func, args)
  430.         except SystemExit, msg:
  431.             raise SystemExit, msg
  432.         except:
  433.             try:
  434.                 try:
  435.                     t = sys.exc_traceback
  436.                     while t:
  437.                         sys.stderr.write(
  438.                             '  %s, line %s\n' %
  439.                             (t.tb_frame.f_code,
  440.                              t.tb_lineno))
  441.                         t = t.tb_next
  442.                 finally:
  443.                     sys.stderr.write('%s: %s\n' %
  444.                              (sys.exc_type,
  445.                               sys.exc_value))
  446.                 (sys.last_type,
  447.                  sys.last_value,
  448.                  sys.last_traceback) = (sys.exc_type,
  449.                             sys.exc_value,
  450.                             sys.exc_traceback)
  451.                 import pdb
  452.                 pdb.pm()
  453.             except:
  454.                 print '*** Error in error handling ***'
  455.                 print sys.exc_type, ':', sys.exc_value
  456.  
  457. class Wm:
  458.     def aspect(self, 
  459.            minNumer=None, minDenom=None, 
  460.            maxNumer=None, maxDenom=None):
  461.         return self._getints(
  462.             self.tk.call('wm', 'aspect', self._w, 
  463.                      minNumer, minDenom, 
  464.                      maxNumer, maxDenom))
  465.     def client(self, name=None):
  466.         return self.tk.call('wm', 'client', self._w, name)
  467.     def command(self, value=None):
  468.         return self.tk.call('wm', 'command', self._w, value)
  469.     def deiconify(self):
  470.         return self.tk.call('wm', 'deiconify', self._w)
  471.     def focusmodel(self, model=None):
  472.         return self.tk.call('wm', 'focusmodel', self._w, model)
  473.     def frame(self):
  474.         return self.tk.call('wm', 'frame', self._w)
  475.     def geometry(self, newGeometry=None):
  476.         return self.tk.call('wm', 'geometry', self._w, newGeometry)
  477.     def grid(self,
  478.          baseWidht=None, baseHeight=None, 
  479.          widthInc=None, heightInc=None):
  480.         return self._getints(self.tk.call(
  481.             'wm', 'grid', self._w,
  482.             baseWidht, baseHeight, widthInc, heightInc))
  483.     def group(self, pathName=None):
  484.         return self.tk.call('wm', 'group', self._w, pathName)
  485.     def iconbitmap(self, bitmap=None):
  486.         return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
  487.     def iconify(self):
  488.         return self.tk.call('wm', 'iconify', self._w)
  489.     def iconmask(self, bitmap=None):
  490.         return self.tk.call('wm', 'iconmask', self._w, bitmap)
  491.     def iconname(self, newName=None):
  492.         return self.tk.call('wm', 'iconname', self._w, newName)
  493.     def iconposition(self, x=None, y=None):
  494.         return self._getints(self.tk.call(
  495.             'wm', 'iconposition', self._w, x, y))
  496.     def iconwindow(self, pathName=None):
  497.         return self.tk.call('wm', 'iconwindow', self._w, pathName)
  498.     def maxsize(self, width=None, height=None):
  499.         return self._getints(self.tk.call(
  500.             'wm', 'maxsize', self._w, width, height))
  501.     def minsize(self, width=None, height=None):
  502.         return self._getints(self.tk.call(
  503.             'wm', 'minsize', self._w, width, height))
  504.     def overrideredirect(self, boolean=None):
  505.         return self._getboolean(self.tk.call(
  506.             'wm', 'overrideredirect', self._w, boolean))
  507.     def positionfrom(self, who=None):
  508.         return self.tk.call('wm', 'positionfrom', self._w, who)
  509.     def protocol(self, name=None, func=None):
  510.         if type(func) in CallableTypes:
  511.             command = self._register(func)
  512.         else:
  513.             command = func
  514.         return self.tk.call(
  515.             'wm', 'protocol', self._w, name, command)
  516.     def sizefrom(self, who=None):
  517.         return self.tk.call('wm', 'sizefrom', self._w, who)
  518.     def state(self):
  519.         return self.tk.call('wm', 'state', self._w)
  520.     def title(self, string=None):
  521.         return self.tk.call('wm', 'title', self._w, string)
  522.     def transient(self, master=None):
  523.         return self.tk.call('wm', 'transient', self._w, master)
  524.     def withdraw(self):
  525.         return self.tk.call('wm', 'withdraw', self._w)
  526.  
  527. class Tk(Misc, Wm):
  528.     _w = '.'
  529.     def __init__(self, screenName=None, baseName=None, className='Tk'):
  530.         self.master = None
  531.         self.children = {}
  532.         if baseName is None:
  533.             import sys, os
  534.             baseName = os.path.basename(sys.argv[0])
  535.             if baseName[-3:] == '.py': baseName = baseName[:-3]
  536.         self.tk = tkinter.create(screenName, baseName, className)
  537.         self.tk.createcommand('tkerror', _tkerror)
  538.         self.tk.createcommand('exit', _exit)
  539.         self.readprofile(baseName, className)
  540.     def destroy(self):
  541.         for c in self.children.values(): c.destroy()
  542.         self.tk.call('destroy', self._w)
  543.     def __str__(self):
  544.         return self._w
  545.     def readprofile(self, baseName, className):
  546.         import os
  547.         if os.environ.has_key('HOME'): home = os.environ['HOME']
  548.         else: home = os.curdir
  549.         class_tcl = os.path.join(home, '.%s.tcl' % className)
  550.         class_py = os.path.join(home, '.%s.py' % className)
  551.         base_tcl = os.path.join(home, '.%s.tcl' % baseName)
  552.         base_py = os.path.join(home, '.%s.py' % baseName)
  553.         dir = {'self': self}
  554.         exec 'from Tkinter import *' in dir
  555.         if os.path.isfile(class_tcl):
  556.             print 'source', `class_tcl`
  557.             self.tk.call('source', class_tcl)
  558.         if os.path.isfile(class_py):
  559.             print 'execfile', `class_py`
  560.             execfile(class_py, dir)
  561.         if os.path.isfile(base_tcl):
  562.             print 'source', `base_tcl`
  563.             self.tk.call('source', base_tcl)
  564.         if os.path.isfile(base_py):
  565.             print 'execfile', `base_py`
  566.             execfile(base_py, dir)
  567.  
  568. class Pack:
  569.     def config(self, cnf={}):
  570.         apply(self.tk.call, 
  571.               ('pack', 'configure', self._w) 
  572.               + self._options(cnf))
  573.     pack = config
  574.     def __setitem__(self, key, value):
  575.         Pack.config({key: value})
  576.     def forget(self):
  577.         self.tk.call('pack', 'forget', self._w)
  578.     def newinfo(self):
  579.         words = self.tk.splitlist(
  580.             self.tk.call('pack', 'newinfo', self._w))
  581.         dict = {}
  582.         for i in range(0, len(words), 2):
  583.             key = words[i][1:]
  584.             value = words[i+1]
  585.             if value[0] == '.':
  586.                 value = self._nametowidget(value)
  587.             dict[key] = value
  588.         return dict
  589.     info = newinfo
  590.     def propagate(self, boolean=None):
  591.         if boolean:
  592.             self.tk.call('pack', 'propagate', self._w)
  593.         else:
  594.             return self._getboolean(self.tk.call(
  595.                 'pack', 'propagate', self._w))
  596.     def slaves(self):
  597.         return map(self._nametowidget,
  598.                self.tk.splitlist(
  599.                    self.tk.call('pack', 'slaves', self._w)))
  600.  
  601. class Place:
  602.     def config(self, cnf={}):
  603.         apply(self.tk.call, 
  604.               ('place', 'configure', self._w) 
  605.               + self._options(cnf))
  606.     place = config
  607.     def __setitem__(self, key, value):
  608.         Place.config({key: value})
  609.     def forget(self):
  610.         self.tk.call('place', 'forget', self._w)
  611.     def info(self):
  612.         return self.tk.call('place', 'info', self._w)
  613.     def slaves(self):
  614.         return map(self._nametowidget,
  615.                self.tk.splitlist(
  616.                    self.tk.call(
  617.                        'place', 'slaves', self._w)))
  618.  
  619. class Widget(Misc, Pack, Place):
  620.     def _setup(self, master, cnf):
  621.         global _default_root
  622.         if not master:
  623.             if not _default_root:
  624.                 _default_root = Tk()
  625.             master = _default_root
  626.         if not _default_root:
  627.             _default_root = master
  628.         self.master = master
  629.         self.tk = master.tk
  630.         if cnf.has_key('name'):
  631.             name = cnf['name']
  632.             del cnf['name']
  633.         else:
  634.             name = `id(self)`
  635.         self._name = name
  636.         if master._w=='.':
  637.             self._w = '.' + name
  638.         else:
  639.             self._w = master._w + '.' + name
  640.         self.children = {}
  641.         if self.master.children.has_key(self._name):
  642.             self.master.children[self._name].destroy()
  643.         self.master.children[self._name] = self
  644.     def __init__(self, master, widgetName, cnf={}, extra=()):
  645.         cnf = _cnfmerge(cnf)
  646.         Widget._setup(self, master, cnf)
  647.         self.widgetName = widgetName
  648.         apply(self.tk.call, (widgetName, self._w) + extra)
  649.         if cnf:
  650.             Widget.config(self, cnf)
  651.     def config(self, cnf=None):
  652.         cnf = _cnfmerge(cnf)
  653.         if cnf is None:
  654.             cnf = {}
  655.             for x in self.tk.split(
  656.                 self.tk.call(self._w, 'configure')):
  657.                 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
  658.             return cnf
  659.         if type(cnf) == StringType:
  660.             x = self.tk.split(self.tk.call(
  661.                 self._w, 'configure', '-'+cnf))
  662.             return (x[0][1:],) + x[1:]
  663.         for k in cnf.keys():
  664.             if type(k) == ClassType:
  665.                 k.config(self, cnf[k])
  666.                 del cnf[k]
  667.         apply(self.tk.call, (self._w, 'configure')
  668.               + self._options(cnf))
  669.     def __getitem__(self, key):
  670.         v = self.tk.splitlist(self.tk.call(
  671.             self._w, 'configure', '-' + key))
  672.         return v[4]
  673.     def __setitem__(self, key, value):
  674.         Widget.config(self, {key: value})
  675.     def keys(self):
  676.         return map(lambda x: x[0][1:],
  677.                self.tk.split(self.tk.call(self._w, 'configure')))
  678.     def __str__(self):
  679.         return self._w
  680.     def destroy(self):
  681.         for c in self.children.values(): c.destroy()
  682.         if self.master.children.has_key(self._name):
  683.             del self.master.children[self._name]
  684.         self.tk.call('destroy', self._w)
  685.     def _do(self, name, args=()):
  686.         return apply(self.tk.call, (self._w, name) + args) 
  687.  
  688. class Toplevel(Widget, Wm):
  689.     def __init__(self, master=None, cnf={}):
  690.         extra = ()
  691.         if cnf.has_key('screen'):
  692.             extra = ('-screen', cnf['screen'])
  693.             del cnf['screen']
  694.         if cnf.has_key('class'):
  695.             extra = extra + ('-class', cnf['class'])
  696.             del cnf['class']
  697.         Widget.__init__(self, master, 'toplevel', cnf, extra)
  698.         root = self._root()
  699.         self.iconname(root.iconname())
  700.         self.title(root.title())
  701.  
  702. class Button(Widget):
  703.     def __init__(self, master=None, cnf={}):
  704.         Widget.__init__(self, master, 'button', cnf)
  705.     def tk_butEnter(self, *dummy):
  706.         self.tk.call('tk_butEnter', self._w)
  707.     def tk_butLeave(self, *dummy):
  708.         self.tk.call('tk_butLeave', self._w)
  709.     def tk_butDown(self, *dummy):
  710.         self.tk.call('tk_butDown', self._w)
  711.     def tk_butUp(self, *dummy):
  712.         self.tk.call('tk_butUp', self._w)
  713.     def flash(self):
  714.         self.tk.call(self._w, 'flash')
  715.     def invoke(self):
  716.         self.tk.call(self._w, 'invoke')
  717.  
  718. # Indices:
  719. def AtEnd():
  720.     return 'end'
  721. def AtInsert(*args):
  722.     s = 'insert'
  723.     for a in args:
  724.         if a: s = s + (' ' + a)
  725.     return s
  726. def AtSelFirst():
  727.     return 'sel.first'
  728. def AtSelLast():
  729.     return 'sel.last'
  730. def At(x, y=None):
  731.     if y is None:
  732.         return '@' + `x`        
  733.     else:
  734.         return '@' + `x` + ',' + `y`
  735.  
  736. class Canvas(Widget):
  737.     def __init__(self, master=None, cnf={}):
  738.         Widget.__init__(self, master, 'canvas', cnf)
  739.     def addtag(self, *args):
  740.         self._do('addtag', args)
  741.     def addtag_above(self, tagOrId):
  742.         self.addtag('above', tagOrId)
  743.     def addtag_all(self):
  744.         self.addtag('all')
  745.     def addtag_below(self, tagOrId):
  746.         self.addtag('below', tagOrId)
  747.     def addtag_closest(self, x, y, halo=None, start=None):
  748.         self.addtag('closest', x, y, halo, start)
  749.     def addtag_enclosed(self, x1, y1, x2, y2):
  750.         self.addtag('enclosed', x1, y1, x2, y2)
  751.     def addtag_overlapping(self, x1, y1, x2, y2):
  752.         self.addtag('overlapping', x1, y1, x2, y2)
  753.     def addtag_withtag(self, tagOrId):
  754.         self.addtag('withtag', tagOrId)
  755.     def bbox(self, *args):
  756.         return self._getints(self._do('bbox', args)) or None
  757.     def tag_unbind(self, tagOrId, sequence):
  758.         self.tk.call(self._w, 'bind', tagOrId, sequence, '')
  759.     def tag_bind(self, tagOrId, sequence, func, add=''):
  760.         if add: add='+'
  761.         name = self._register(func, self._substitute)
  762.         self.tk.call(self._w, 'bind', tagOrId, sequence, 
  763.                  (add + name,) + self._subst_format)
  764.     def canvasx(self, screenx, gridspacing=None):
  765.         return self.tk.getint(self.tk.call(
  766.             self._w, 'canvasx', screenx, gridspacing))
  767.     def canvasy(self, screeny, gridspacing=None):
  768.         return self.tk.getint(self.tk.call(
  769.             self._w, 'canvasy', screeny, gridspacing))
  770.     def coords(self, *args):
  771.         return self._do('coords', args)
  772.     def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
  773.         args = _flatten(args)
  774.         cnf = args[-1]
  775.         if type(cnf) in (DictionaryType, TupleType):
  776.             args = args[:-1]
  777.         else:
  778.             cnf = {}
  779.         return self.tk.getint(apply(
  780.             self.tk.call,
  781.             (self._w, 'create', itemType) 
  782.             + args + self._options(cnf)))
  783.     def create_arc(self, *args):
  784.         return Canvas._create(self, 'arc', args)
  785.     def create_bitmap(self, *args):
  786.         return Canvas._create(self, 'bitmap', args)
  787.     def create_line(self, *args):
  788.         return Canvas._create(self, 'line', args)
  789.     def create_oval(self, *args):
  790.         return Canvas._create(self, 'oval', args)
  791.     def create_polygon(self, *args):
  792.         return Canvas._create(self, 'polygon', args)
  793.     def create_rectangle(self, *args):
  794.         return Canvas._create(self, 'rectangle', args)
  795.     def create_text(self, *args):
  796.         return Canvas._create(self, 'text', args)
  797.     def create_window(self, *args):
  798.         return Canvas._create(self, 'window', args)
  799.     def dchars(self, *args):
  800.         self._do('dchars', args)
  801.     def delete(self, *args):
  802.         self._do('delete', args)
  803.     def dtag(self, *args):
  804.         self._do('dtag', args)
  805.     def find(self, *args):
  806.         return self._getints(self._do('find', args))
  807.     def find_above(self, tagOrId):
  808.         return self.find('above', tagOrId)
  809.     def find_all(self):
  810.         return self.find('all')
  811.     def find_below(self, tagOrId):
  812.         return self.find('below', tagOrId)
  813.     def find_closest(self, x, y, halo=None, start=None):
  814.         return self.find('closest', x, y, halo, start)
  815.     def find_enclosed(self, x1, y1, x2, y2):
  816.         return self.find('enclosed', x1, y1, x2, y2)
  817.     def find_overlapping(self, x1, y1, x2, y2):
  818.         return self.find('overlapping', x1, y1, x2, y2)
  819.     def find_withtag(self, tagOrId):
  820.         return self.find('withtag', tagOrId)
  821.     def focus(self, *args):
  822.         return self._do('focus', args)
  823.     def gettags(self, *args):
  824.         return self.tk.splitlist(self._do('gettags', args))
  825.     def icursor(self, *args):
  826.         self._do('icursor', args)
  827.     def index(self, *args):
  828.         return self.tk.getint(self._do('index', args))
  829.     def insert(self, *args):
  830.         self._do('insert', args)
  831.     def itemconfig(self, tagOrId, cnf=None):
  832.         if cnf is None:
  833.             cnf = {}
  834.             for x in self.tk.split(
  835.                 self._do('itemconfigure', (tagOrId))):
  836.                 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
  837.             return cnf
  838.         if type(cnf) == StringType:
  839.             x = self.tk.split(self._do('itemconfigure',
  840.                            (tagOrId, '-'+cnf,)))
  841.             return (x[0][1:],) + x[1:]
  842.         self._do('itemconfigure', (tagOrId,) + self._options(cnf))
  843.     def lower(self, *args):
  844.         self._do('lower', args)
  845.     def move(self, *args):
  846.         self._do('move', args)
  847.     def postscript(self, cnf={}):
  848.         return self._do('postscript', self._options(cnf))
  849.     def tkraise(self, *args):
  850.         self._do('raise', args)
  851.     lift = tkraise
  852.     def scale(self, *args):
  853.         self._do('scale', args)
  854.     def scan_mark(self, x, y):
  855.         self.tk.call(self._w, 'scan', 'mark', x, y)
  856.     def scan_dragto(self, x, y):
  857.         self.tk.call(self._w, 'scan', 'dragto', x, y)
  858.     def select_adjust(self, tagOrId, index):
  859.         self.tk.call(self._w, 'select', 'adjust', tagOrId, index)
  860.     def select_clear(self):
  861.         self.tk.call(self._w, 'select', 'clear')
  862.     def select_from(self, tagOrId, index):
  863.         self.tk.call(self._w, 'select', 'from', tagOrId, index)
  864.     def select_item(self):
  865.         self.tk.call(self._w, 'select', 'item')
  866.     def select_to(self, tagOrId, index):
  867.         self.tk.call(self._w, 'select', 'to', tagOrId, index)
  868.     def type(self, tagOrId):
  869.         return self.tk.call(self._w, 'type', tagOrId) or None
  870.     def xview(self, index):
  871.         self.tk.call(self._w, 'xview', index)
  872.     def yview(self, index):
  873.         self.tk.call(self._w, 'yview', index)
  874.  
  875. class Checkbutton(Widget):
  876.     def __init__(self, master=None, cnf={}):
  877.         Widget.__init__(self, master, 'checkbutton', cnf)
  878.     def deselect(self):
  879.         self.tk.call(self._w, 'deselect')
  880.     def flash(self):
  881.         self.tk.call(self._w, 'flash')
  882.     def invoke(self):
  883.         self.tk.call(self._w, 'invoke')
  884.     def select(self):
  885.         self.tk.call(self._w, 'select')
  886.     def toggle(self):
  887.         self.tk.call(self._w, 'toggle')
  888.  
  889. class Entry(Widget):
  890.     def __init__(self, master=None, cnf={}):
  891.         Widget.__init__(self, master, 'entry', cnf)
  892.     def tk_entryBackspace(self):
  893.         self.tk.call('tk_entryBackspace', self._w)
  894.     def tk_entryBackword(self):
  895.         self.tk.call('tk_entryBackword', self._w)
  896.     def tk_entrySeeCaret(self):
  897.         self.tk.call('tk_entrySeeCaret', self._w)
  898.     def delete(self, first, last=None):
  899.         self.tk.call(self._w, 'delete', first, last)
  900.     def get(self):
  901.         return self.tk.call(self._w, 'get')
  902.     def icursor(self, index):
  903.         self.tk.call(self._w, 'icursor', index)
  904.     def index(self, index):
  905.         return self.tk.getint(self.tk.call(
  906.             self._w, 'index', index))
  907.     def insert(self, index, string):
  908.         self.tk.call(self._w, 'insert', index, string)
  909.     def scan_mark(self, x):
  910.         self.tk.call(self._w, 'scan', 'mark', x)
  911.     def scan_dragto(self, x):
  912.         self.tk.call(self._w, 'scan', 'dragto', x)
  913.     def select_adjust(self, index):
  914.         self.tk.call(self._w, 'select', 'adjust', index)
  915.     def select_clear(self):
  916.         self.tk.call(self._w, 'select', 'clear')
  917.     def select_from(self, index):
  918.         self.tk.call(self._w, 'select', 'from', index)
  919.     def select_to(self, index):
  920.         self.tk.call(self._w, 'select', 'to', index)
  921.     def select_view(self, index):
  922.         self.tk.call(self._w, 'select', 'view', index)
  923.  
  924. class Frame(Widget):
  925.     def __init__(self, master=None, cnf={}):
  926.         cnf = _cnfmerge(cnf)
  927.         extra = ()
  928.         if cnf.has_key('class'):
  929.             extra = ('-class', cnf['class'])
  930.             del cnf['class']
  931.         Widget.__init__(self, master, 'frame', cnf, extra)
  932.     def tk_menuBar(self, *args):
  933.         apply(self.tk.call, ('tk_menuBar', self._w) + args)
  934.  
  935. class Label(Widget):
  936.     def __init__(self, master=None, cnf={}):
  937.         Widget.__init__(self, master, 'label', cnf)
  938.  
  939. class Listbox(Widget):
  940.     def __init__(self, master=None, cnf={}):
  941.         Widget.__init__(self, master, 'listbox', cnf)
  942.     def tk_listboxSingleSelect(self):
  943.         self.tk.call('tk_listboxSingleSelect', self._w) 
  944.     def curselection(self):
  945.         return self.tk.splitlist(self.tk.call(
  946.             self._w, 'curselection'))
  947.     def delete(self, first, last=None):
  948.         self.tk.call(self._w, 'delete', first, last)
  949.     def get(self, index):
  950.         return self.tk.call(self._w, 'get', index)
  951.     def insert(self, index, *elements):
  952.         apply(self.tk.call,
  953.               (self._w, 'insert', index) + elements)
  954.     def nearest(self, y):
  955.         return self.tk.getint(self.tk.call(
  956.             self._w, 'nearest', y))
  957.     def scan_mark(self, x, y):
  958.         self.tk.call(self._w, 'scan', 'mark', x, y)
  959.     def scan_dragto(self, x, y):
  960.         self.tk.call(self._w, 'scan', 'dragto', x, y)
  961.     def select_adjust(self, index):
  962.         self.tk.call(self._w, 'select', 'adjust', index)
  963.     def select_clear(self):
  964.         self.tk.call(self._w, 'select', 'clear')
  965.     def select_from(self, index):
  966.         self.tk.call(self._w, 'select', 'from', index)
  967.     def select_to(self, index):
  968.         self.tk.call(self._w, 'select', 'to', index)
  969.     def size(self):
  970.         return self.tk.getint(self.tk.call(self._w, 'size'))
  971.     def xview(self, index):
  972.         self.tk.call(self._w, 'xview', index)
  973.     def yview(self, index):
  974.         self.tk.call(self._w, 'yview', index)
  975.  
  976. class Menu(Widget):
  977.     def __init__(self, master=None, cnf={}):
  978.         Widget.__init__(self, master, 'menu', cnf)
  979.     def tk_bindForTraversal(self):
  980.         self.tk.call('tk_bindForTraversal', self._w)
  981.     def tk_mbPost(self):
  982.         self.tk.call('tk_mbPost', self._w)
  983.     def tk_mbUnpost(self):
  984.         self.tk.call('tk_mbUnpost')
  985.     def tk_traverseToMenu(self, char):
  986.         self.tk.call('tk_traverseToMenu', self._w, char)
  987.     def tk_traverseWithinMenu(self, char):
  988.         self.tk.call('tk_traverseWithinMenu', self._w, char)
  989.     def tk_getMenuButtons(self):
  990.         return self.tk.call('tk_getMenuButtons', self._w)
  991.     def tk_nextMenu(self, count):
  992.         self.tk.call('tk_nextMenu', count)
  993.     def tk_nextMenuEntry(self, count):
  994.         self.tk.call('tk_nextMenuEntry', count)
  995.     def tk_invokeMenu(self):
  996.         self.tk.call('tk_invokeMenu', self._w)
  997.     def tk_firstMenu(self):
  998.         self.tk.call('tk_firstMenu', self._w)
  999.     def tk_mbButtonDown(self):
  1000.         self.tk.call('tk_mbButtonDown', self._w)
  1001.     def activate(self, index):
  1002.         self.tk.call(self._w, 'activate', index)
  1003.     def add(self, itemType, cnf={}):
  1004.         apply(self.tk.call, (self._w, 'add', itemType) 
  1005.               + self._options(cnf))
  1006.     def add_cascade(self, cnf={}):
  1007.         self.add('cascade', cnf)
  1008.     def add_checkbutton(self, cnf={}):
  1009.         self.add('checkbutton', cnf)
  1010.     def add_command(self, cnf={}):
  1011.         self.add('command', cnf)
  1012.     def add_radiobutton(self, cnf={}):
  1013.         self.add('radiobutton', cnf)
  1014.     def add_separator(self, cnf={}):
  1015.         self.add('separator', cnf)
  1016.     def delete(self, index1, index2=None):
  1017.         self.tk.call(self._w, 'delete', index1, index2)
  1018.     def entryconfig(self, index, cnf={}):
  1019.         apply(self.tk.call, (self._w, 'entryconfigure', index)
  1020.               + self._options(cnf))
  1021.     def index(self, index):
  1022.         i = self.tk.call(self._w, 'index', index)
  1023.         if i == 'none': return None
  1024.         return self.tk.getint(i)
  1025.     def invoke(self, index):
  1026.         return self.tk.call(self._w, 'invoke', index)
  1027.     def post(self, x, y):
  1028.         self.tk.call(self._w, 'post', x, y)
  1029.     def unpost(self):
  1030.         self.tk.call(self._w, 'unpost')
  1031.     def yposition(self, index):
  1032.         return self.tk.getint(self.tk.call(
  1033.             self._w, 'yposition', index))
  1034.  
  1035. class Menubutton(Widget):
  1036.     def __init__(self, master=None, cnf={}):
  1037.         Widget.__init__(self, master, 'menubutton', cnf)
  1038.  
  1039. class Message(Widget):
  1040.     def __init__(self, master=None, cnf={}):
  1041.         Widget.__init__(self, master, 'message', cnf)
  1042.  
  1043. class Radiobutton(Widget):
  1044.     def __init__(self, master=None, cnf={}):
  1045.         Widget.__init__(self, master, 'radiobutton', cnf)
  1046.     def deselect(self):
  1047.         self.tk.call(self._w, 'deselect')
  1048.     def flash(self):
  1049.         self.tk.call(self._w, 'flash')
  1050.     def invoke(self):
  1051.         self.tk.call(self._w, 'invoke')
  1052.     def select(self):
  1053.         self.tk.call(self._w, 'select')
  1054.  
  1055. class Scale(Widget):
  1056.     def __init__(self, master=None, cnf={}):
  1057.         Widget.__init__(self, master, 'scale', cnf)
  1058.     def get(self):
  1059.         return self.tk.getint(self.tk.call(self._w, 'get'))
  1060.     def set(self, value):
  1061.         self.tk.call(self._w, 'set', value)
  1062.  
  1063. class Scrollbar(Widget):
  1064.     def __init__(self, master=None, cnf={}):
  1065.         Widget.__init__(self, master, 'scrollbar', cnf)
  1066.     def get(self):
  1067.         return self._getints(self.tk.call(self._w, 'get'))
  1068.     def set(self, totalUnits, windowUnits, firstUnit, lastUnit):
  1069.         self.tk.call(self._w, 'set', 
  1070.                  totalUnits, windowUnits, firstUnit, lastUnit)
  1071.  
  1072. class Text(Widget):
  1073.     def __init__(self, master=None, cnf={}):
  1074.         Widget.__init__(self, master, 'text', cnf)
  1075.     def tk_textSelectTo(self, index):
  1076.         self.tk.call('tk_textSelectTo', self._w, index)
  1077.     def tk_textBackspace(self):
  1078.         self.tk.call('tk_textBackspace', self._w)
  1079.     def tk_textIndexCloser(self, a, b, c):
  1080.         self.tk.call('tk_textIndexCloser', self._w, a, b, c)
  1081.     def tk_textResetAnchor(self, index):
  1082.         self.tk.call('tk_textResetAnchor', self._w, index)
  1083.     def compare(self, index1, op, index2):
  1084.         return self.tk.getboolean(self.tk.call(
  1085.             self._w, 'compare', index1, op, index2))
  1086.     def debug(self, boolean=None):
  1087.         return self.tk.getboolean(self.tk.call(
  1088.             self._w, 'debug', boolean))
  1089.     def delete(self, index1, index2=None):
  1090.         self.tk.call(self._w, 'delete', index1, index2)
  1091.     def get(self, index1, index2=None):
  1092.         return self.tk.call(self._w, 'get', index1, index2)
  1093.     def index(self, index):
  1094.         return self.tk.call(self._w, 'index', index)
  1095.     def insert(self, index, chars):
  1096.         self.tk.call(self._w, 'insert', index, chars)
  1097.     def mark_names(self):
  1098.         return self.tk.splitlist(self.tk.call(
  1099.             self._w, 'mark', 'names'))
  1100.     def mark_set(self, markName, index):
  1101.         self.tk.call(self._w, 'mark', 'set', markName, index)
  1102.     def mark_unset(self, markNames):
  1103.         apply(self.tk.call, (self._w, 'mark', 'unset') + markNames)
  1104.     def scan_mark(self, y):
  1105.         self.tk.call(self._w, 'scan', 'mark', y)
  1106.     def scan_dragto(self, y):
  1107.         self.tk.call(self._w, 'scan', 'dragto', y)
  1108.     def tag_add(self, tagName, index1, index2=None):
  1109.         self.tk.call(
  1110.             self._w, 'tag', 'add', tagName, index1, index2)
  1111.     def tag_unbind(self, tagName, sequence):
  1112.         self.tk.call(self._w, 'tag', 'bind', tagName, sequence, '')
  1113.     def tag_bind(self, tagName, sequence, func, add=''):
  1114.         if add: add='+'
  1115.         name = self._register(func, self._substitute)
  1116.         self.tk.call(self._w, 'tag', 'bind', 
  1117.                  tagName, sequence, 
  1118.                  (add + name,) + self._subst_format)
  1119.     def tag_config(self, tagName, cnf={}):
  1120.         apply(self.tk.call, 
  1121.               (self._w, 'tag', 'configure', tagName) 
  1122.               + self._options(cnf))
  1123.     def tag_delete(self, *tagNames):
  1124.         apply(self.tk.call, (self._w, 'tag', 'delete') + tagNames)
  1125.     def tag_lower(self, tagName, belowThis=None):
  1126.         self.tk.call(self._w, 'tag', 'lower', tagName, belowThis)
  1127.     def tag_names(self, index=None):
  1128.         return self.tk.splitlist(
  1129.             self.tk.call(self._w, 'tag', 'names', index))
  1130.     def tag_nextrange(self, tagName, index1, index2=None):
  1131.         return self.tk.splitlist(self.tk.call(
  1132.             self._w, 'tag', 'nextrange', index1, index2))
  1133.     def tag_raise(self, tagName, aboveThis=None):
  1134.         self.tk.call(
  1135.             self._w, 'tag', 'raise', tagName, aboveThis)
  1136.     def tag_ranges(self, tagName):
  1137.         return self.tk.splitlist(self.tk.call(
  1138.             self._w, 'tag', 'ranges', tagName))
  1139.     def tag_remove(self, tagName, index1, index2=None):
  1140.         self.tk.call(
  1141.             self._w, 'tag', 'remove', tagName, index1, index2)
  1142.     def yview(self, what):
  1143.         self.tk.call(self._w, 'yview', what)
  1144.     def yview_pickplace(self, what):
  1145.         self.tk.call(self._w, 'yview', '-pickplace', what)
  1146.  
  1147. ######################################################################
  1148. # Extensions:
  1149.  
  1150. class Studbutton(Button):
  1151.     def __init__(self, master=None, cnf={}):
  1152.         Widget.__init__(self, master, 'studbutton', cnf)
  1153.         self.bind('<Any-Enter>',       self.tk_butEnter)
  1154.         self.bind('<Any-Leave>',       self.tk_butLeave)
  1155.         self.bind('<1>',               self.tk_butDown)
  1156.         self.bind('<ButtonRelease-1>', self.tk_butUp)
  1157.  
  1158. class Tributton(Button):
  1159.     def __init__(self, master=None, cnf={}):
  1160.         Widget.__init__(self, master, 'tributton', cnf)
  1161.         self.bind('<Any-Enter>',       self.tk_butEnter)
  1162.         self.bind('<Any-Leave>',       self.tk_butLeave)
  1163.         self.bind('<1>',               self.tk_butDown)
  1164.         self.bind('<ButtonRelease-1>', self.tk_butUp)
  1165.  
  1166.