home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / python2.5 / lib-tk / Tkinter.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-05-11  |  183.4 KB  |  4,821 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. '''Wrapper functions for Tcl/Tk.
  5.  
  6. Tkinter provides classes which allow the display, positioning and
  7. control of widgets. Toplevel widgets are Tk and Toplevel. Other
  8. widgets are Frame, Label, Entry, Text, Canvas, Button, Radiobutton,
  9. Checkbutton, Scale, Listbox, Scrollbar, OptionMenu, Spinbox
  10. LabelFrame and PanedWindow.
  11.  
  12. Properties of the widgets are specified with keyword arguments.
  13. Keyword arguments have the same name as the corresponding resource
  14. under Tk.
  15.  
  16. Widgets are positioned with one of the geometry managers Place, Pack
  17. or Grid. These managers can be called with methods place, pack, grid
  18. available in every Widget.
  19.  
  20. Actions are bound to events by resources (e.g. keyword argument
  21. command) or with the method bind.
  22.  
  23. Example (Hello, World):
  24. import Tkinter
  25. from Tkconstants import *
  26. tk = Tkinter.Tk()
  27. frame = Tkinter.Frame(tk, relief=RIDGE, borderwidth=2)
  28. frame.pack(fill=BOTH,expand=1)
  29. label = Tkinter.Label(frame, text="Hello, World")
  30. label.pack(fill=X, expand=1)
  31. button = Tkinter.Button(frame,text="Exit",command=tk.destroy)
  32. button.pack(side=BOTTOM)
  33. tk.mainloop()
  34. '''
  35. __version__ = '$Revision: 50704 $'
  36. import sys
  37. if sys.platform == 'win32':
  38.     import FixTk
  39.  
  40.  
  41. try:
  42.     import _tkinter
  43. except ImportError:
  44.     msg = None
  45.     raise ImportError, str(msg) + ', please install the python-tk package'
  46.  
  47. tkinter = _tkinter
  48. TclError = _tkinter.TclError
  49. from types import *
  50. from Tkconstants import *
  51.  
  52. try:
  53.     import MacOS
  54.     _MacOS = MacOS
  55.     del MacOS
  56. except ImportError:
  57.     _MacOS = None
  58.  
  59. wantobjects = 1
  60. TkVersion = float(_tkinter.TK_VERSION)
  61. TclVersion = float(_tkinter.TCL_VERSION)
  62. READABLE = _tkinter.READABLE
  63. WRITABLE = _tkinter.WRITABLE
  64. EXCEPTION = _tkinter.EXCEPTION
  65.  
  66. try:
  67.     _tkinter.createfilehandler
  68. except AttributeError:
  69.     _tkinter.createfilehandler = None
  70.  
  71.  
  72. try:
  73.     _tkinter.deletefilehandler
  74. except AttributeError:
  75.     _tkinter.deletefilehandler = None
  76.  
  77.  
  78. def _flatten(tuple):
  79.     '''Internal function.'''
  80.     res = ()
  81.     for item in tuple:
  82.         if type(item) in (TupleType, ListType):
  83.             res = res + _flatten(item)
  84.             continue
  85.         if item is not None:
  86.             res = res + (item,)
  87.             continue
  88.     
  89.     return res
  90.  
  91.  
  92. try:
  93.     _flatten = _tkinter._flatten
  94. except AttributeError:
  95.     pass
  96.  
  97.  
  98. def _cnfmerge(cnfs):
  99.     '''Internal function.'''
  100.     if type(cnfs) is DictionaryType:
  101.         return cnfs
  102.     elif type(cnfs) in (NoneType, StringType):
  103.         return cnfs
  104.     else:
  105.         cnf = { }
  106.         for c in _flatten(cnfs):
  107.             
  108.             try:
  109.                 cnf.update(c)
  110.             continue
  111.             except (AttributeError, TypeError):
  112.                 msg = None
  113.                 print '_cnfmerge: fallback due to:', msg
  114.                 for k, v in c.items():
  115.                     cnf[k] = v
  116.                 
  117.             
  118.  
  119.         
  120.         return cnf
  121.  
  122.  
  123. try:
  124.     _cnfmerge = _tkinter._cnfmerge
  125. except AttributeError:
  126.     pass
  127.  
  128.  
  129. class Event:
  130.     '''Container for the properties of an event.
  131.  
  132.     Instances of this type are generated if one of the following events occurs:
  133.  
  134.     KeyPress, KeyRelease - for keyboard events
  135.     ButtonPress, ButtonRelease, Motion, Enter, Leave, MouseWheel - for mouse events
  136.     Visibility, Unmap, Map, Expose, FocusIn, FocusOut, Circulate,
  137.     Colormap, Gravity, Reparent, Property, Destroy, Activate,
  138.     Deactivate - for window events.
  139.  
  140.     If a callback function for one of these events is registered
  141.     using bind, bind_all, bind_class, or tag_bind, the callback is
  142.     called with an Event as first argument. It will have the
  143.     following attributes (in braces are the event types for which
  144.     the attribute is valid):
  145.  
  146.         serial - serial number of event
  147.     num - mouse button pressed (ButtonPress, ButtonRelease)
  148.     focus - whether the window has the focus (Enter, Leave)
  149.     height - height of the exposed window (Configure, Expose)
  150.     width - width of the exposed window (Configure, Expose)
  151.     keycode - keycode of the pressed key (KeyPress, KeyRelease)
  152.     state - state of the event as a number (ButtonPress, ButtonRelease,
  153.                             Enter, KeyPress, KeyRelease,
  154.                             Leave, Motion)
  155.     state - state as a string (Visibility)
  156.     time - when the event occurred
  157.     x - x-position of the mouse
  158.     y - y-position of the mouse
  159.     x_root - x-position of the mouse on the screen
  160.              (ButtonPress, ButtonRelease, KeyPress, KeyRelease, Motion)
  161.     y_root - y-position of the mouse on the screen
  162.              (ButtonPress, ButtonRelease, KeyPress, KeyRelease, Motion)
  163.     char - pressed character (KeyPress, KeyRelease)
  164.     send_event - see X/Windows documentation
  165.     keysym - keysym of the event as a string (KeyPress, KeyRelease)
  166.     keysym_num - keysym of the event as a number (KeyPress, KeyRelease)
  167.     type - type of the event as a number
  168.     widget - widget in which the event occurred
  169.     delta - delta of wheel movement (MouseWheel)
  170.     '''
  171.     pass
  172.  
  173. _support_default_root = 1
  174. _default_root = None
  175.  
  176. def NoDefaultRoot():
  177.     '''Inhibit setting of default root window.
  178.  
  179.     Call this function to inhibit that the first instance of
  180.     Tk is used for windows without an explicit parent window.
  181.     '''
  182.     global _support_default_root, _default_root, _default_root
  183.     _support_default_root = 0
  184.     _default_root = None
  185.     del _default_root
  186.  
  187.  
  188. def _tkerror(err):
  189.     '''Internal function.'''
  190.     pass
  191.  
  192.  
  193. def _exit(code = '0'):
  194.     '''Internal function. Calling it will throw the exception SystemExit.'''
  195.     raise SystemExit, code
  196.  
  197. _varnum = 0
  198.  
  199. class Variable:
  200.     '''Class to define value holders for e.g. buttons.
  201.  
  202.     Subclasses StringVar, IntVar, DoubleVar, BooleanVar are specializations
  203.     that constrain the type of the value returned from get().'''
  204.     _default = ''
  205.     
  206.     def __init__(self, master = None, value = None, name = None):
  207.         '''Construct a variable
  208.  
  209.         MASTER can be given as master widget.
  210.         VALUE is an optional value (defaults to "")
  211.         NAME is an optional Tcl name (defaults to PY_VARnum).
  212.  
  213.         If NAME matches an existing variable and VALUE is omitted
  214.         then the existing value is retained.
  215.         '''
  216.         global _varnum
  217.         if not master:
  218.             master = _default_root
  219.         
  220.         self._master = master
  221.         self._tk = master.tk
  222.         if name:
  223.             self._name = name
  224.         else:
  225.             self._name = 'PY_VAR' + repr(_varnum)
  226.             _varnum += 1
  227.         if value != None:
  228.             self.set(value)
  229.         elif not self._tk.call('info', 'exists', self._name):
  230.             self.set(self._default)
  231.         
  232.  
  233.     
  234.     def __del__(self):
  235.         '''Unset the variable in Tcl.'''
  236.         self._tk.globalunsetvar(self._name)
  237.  
  238.     
  239.     def __str__(self):
  240.         '''Return the name of the variable in Tcl.'''
  241.         return self._name
  242.  
  243.     
  244.     def set(self, value):
  245.         '''Set the variable to VALUE.'''
  246.         return self._tk.globalsetvar(self._name, value)
  247.  
  248.     
  249.     def get(self):
  250.         '''Return value of variable.'''
  251.         return self._tk.globalgetvar(self._name)
  252.  
  253.     
  254.     def trace_variable(self, mode, callback):
  255.         '''Define a trace callback for the variable.
  256.  
  257.         MODE is one of "r", "w", "u" for read, write, undefine.
  258.         CALLBACK must be a function which is called when
  259.         the variable is read, written or undefined.
  260.  
  261.         Return the name of the callback.
  262.         '''
  263.         cbname = self._master._register(callback)
  264.         self._tk.call('trace', 'variable', self._name, mode, cbname)
  265.         return cbname
  266.  
  267.     trace = trace_variable
  268.     
  269.     def trace_vdelete(self, mode, cbname):
  270.         '''Delete the trace callback for a variable.
  271.  
  272.         MODE is one of "r", "w", "u" for read, write, undefine.
  273.         CBNAME is the name of the callback returned from trace_variable or trace.
  274.         '''
  275.         self._tk.call('trace', 'vdelete', self._name, mode, cbname)
  276.         self._master.deletecommand(cbname)
  277.  
  278.     
  279.     def trace_vinfo(self):
  280.         '''Return all trace callback information.'''
  281.         return map(self._tk.split, self._tk.splitlist(self._tk.call('trace', 'vinfo', self._name)))
  282.  
  283.     
  284.     def __eq__(self, other):
  285.         """Comparison for equality (==).
  286.  
  287.         Note: if the Variable's master matters to behavior
  288.         also compare self._master == other._master
  289.         """
  290.         if self.__class__.__name__ == other.__class__.__name__:
  291.             pass
  292.         return self._name == other._name
  293.  
  294.  
  295.  
  296. class StringVar(Variable):
  297.     '''Value holder for strings variables.'''
  298.     _default = ''
  299.     
  300.     def __init__(self, master = None, value = None, name = None):
  301.         '''Construct a string variable.
  302.  
  303.         MASTER can be given as master widget.
  304.         VALUE is an optional value (defaults to "")
  305.         NAME is an optional Tcl name (defaults to PY_VARnum).
  306.  
  307.         If NAME matches an existing variable and VALUE is omitted
  308.         then the existing value is retained.
  309.         '''
  310.         Variable.__init__(self, master, value, name)
  311.  
  312.     
  313.     def get(self):
  314.         '''Return value of variable as string.'''
  315.         value = self._tk.globalgetvar(self._name)
  316.         if isinstance(value, basestring):
  317.             return value
  318.         
  319.         return str(value)
  320.  
  321.  
  322.  
  323. class IntVar(Variable):
  324.     '''Value holder for integer variables.'''
  325.     _default = 0
  326.     
  327.     def __init__(self, master = None, value = None, name = None):
  328.         '''Construct an integer variable.
  329.  
  330.         MASTER can be given as master widget.
  331.         VALUE is an optional value (defaults to 0)
  332.         NAME is an optional Tcl name (defaults to PY_VARnum).
  333.  
  334.         If NAME matches an existing variable and VALUE is omitted
  335.         then the existing value is retained.
  336.         '''
  337.         Variable.__init__(self, master, value, name)
  338.  
  339.     
  340.     def set(self, value):
  341.         '''Set the variable to value, converting booleans to integers.'''
  342.         if isinstance(value, bool):
  343.             value = int(value)
  344.         
  345.         return Variable.set(self, value)
  346.  
  347.     
  348.     def get(self):
  349.         '''Return the value of the variable as an integer.'''
  350.         return getint(self._tk.globalgetvar(self._name))
  351.  
  352.  
  353.  
  354. class DoubleVar(Variable):
  355.     '''Value holder for float variables.'''
  356.     _default = 0
  357.     
  358.     def __init__(self, master = None, value = None, name = None):
  359.         '''Construct a float variable.
  360.  
  361.         MASTER can be given as master widget.
  362.         VALUE is an optional value (defaults to 0.0)
  363.         NAME is an optional Tcl name (defaults to PY_VARnum).
  364.  
  365.         If NAME matches an existing variable and VALUE is omitted
  366.         then the existing value is retained.
  367.         '''
  368.         Variable.__init__(self, master, value, name)
  369.  
  370.     
  371.     def get(self):
  372.         '''Return the value of the variable as a float.'''
  373.         return getdouble(self._tk.globalgetvar(self._name))
  374.  
  375.  
  376.  
  377. class BooleanVar(Variable):
  378.     '''Value holder for boolean variables.'''
  379.     _default = False
  380.     
  381.     def __init__(self, master = None, value = None, name = None):
  382.         '''Construct a boolean variable.
  383.  
  384.         MASTER can be given as master widget.
  385.         VALUE is an optional value (defaults to False)
  386.         NAME is an optional Tcl name (defaults to PY_VARnum).
  387.  
  388.         If NAME matches an existing variable and VALUE is omitted
  389.         then the existing value is retained.
  390.         '''
  391.         Variable.__init__(self, master, value, name)
  392.  
  393.     
  394.     def get(self):
  395.         '''Return the value of the variable as a bool.'''
  396.         return self._tk.getboolean(self._tk.globalgetvar(self._name))
  397.  
  398.  
  399.  
  400. def mainloop(n = 0):
  401.     '''Run the main loop of Tcl.'''
  402.     _default_root.tk.mainloop(n)
  403.  
  404. getint = int
  405. getdouble = float
  406.  
  407. def getboolean(s):
  408.     '''Convert true and false to integer values 1 and 0.'''
  409.     return _default_root.tk.getboolean(s)
  410.  
  411.  
  412. class Misc:
  413.     '''Internal class.
  414.  
  415.     Base class which defines methods common for interior widgets.'''
  416.     _tclCommands = None
  417.     
  418.     def destroy(self):
  419.         '''Internal function.
  420.  
  421.         Delete all Tcl commands created for
  422.         this widget in the Tcl interpreter.'''
  423.         if self._tclCommands is not None:
  424.             for name in self._tclCommands:
  425.                 self.tk.deletecommand(name)
  426.             
  427.             self._tclCommands = None
  428.         
  429.  
  430.     
  431.     def deletecommand(self, name):
  432.         '''Internal function.
  433.  
  434.         Delete the Tcl command provided in NAME.'''
  435.         self.tk.deletecommand(name)
  436.         
  437.         try:
  438.             self._tclCommands.remove(name)
  439.         except ValueError:
  440.             pass
  441.  
  442.  
  443.     
  444.     def tk_strictMotif(self, boolean = None):
  445.         '''Set Tcl internal variable, whether the look and feel
  446.         should adhere to Motif.
  447.  
  448.         A parameter of 1 means adhere to Motif (e.g. no color
  449.         change if mouse passes over slider).
  450.         Returns the set value.'''
  451.         return self.tk.getboolean(self.tk.call('set', 'tk_strictMotif', boolean))
  452.  
  453.     
  454.     def tk_bisque(self):
  455.         '''Change the color scheme to light brown as used in Tk 3.6 and before.'''
  456.         self.tk.call('tk_bisque')
  457.  
  458.     
  459.     def tk_setPalette(self, *args, **kw):
  460.         '''Set a new color scheme for all widget elements.
  461.  
  462.         A single color as argument will cause that all colors of Tk
  463.         widget elements are derived from this.
  464.         Alternatively several keyword parameters and its associated
  465.         colors can be given. The following keywords are valid:
  466.         activeBackground, foreground, selectColor,
  467.         activeForeground, highlightBackground, selectBackground,
  468.         background, highlightColor, selectForeground,
  469.         disabledForeground, insertBackground, troughColor.'''
  470.         self.tk.call(('tk_setPalette',) + _flatten(args) + _flatten(kw.items()))
  471.  
  472.     
  473.     def tk_menuBar(self, *args):
  474.         '''Do not use. Needed in Tk 3.6 and earlier.'''
  475.         pass
  476.  
  477.     
  478.     def wait_variable(self, name = 'PY_VAR'):
  479.         '''Wait until the variable is modified.
  480.  
  481.         A parameter of type IntVar, StringVar, DoubleVar or
  482.         BooleanVar must be given.'''
  483.         self.tk.call('tkwait', 'variable', name)
  484.  
  485.     waitvar = wait_variable
  486.     
  487.     def wait_window(self, window = None):
  488.         '''Wait until a WIDGET is destroyed.
  489.  
  490.         If no parameter is given self is used.'''
  491.         if window is None:
  492.             window = self
  493.         
  494.         self.tk.call('tkwait', 'window', window._w)
  495.  
  496.     
  497.     def wait_visibility(self, window = None):
  498.         '''Wait until the visibility of a WIDGET changes
  499.         (e.g. it appears).
  500.  
  501.         If no parameter is given self is used.'''
  502.         if window is None:
  503.             window = self
  504.         
  505.         self.tk.call('tkwait', 'visibility', window._w)
  506.  
  507.     
  508.     def setvar(self, name = 'PY_VAR', value = '1'):
  509.         '''Set Tcl variable NAME to VALUE.'''
  510.         self.tk.setvar(name, value)
  511.  
  512.     
  513.     def getvar(self, name = 'PY_VAR'):
  514.         '''Return value of Tcl variable NAME.'''
  515.         return self.tk.getvar(name)
  516.  
  517.     getint = int
  518.     getdouble = float
  519.     
  520.     def getboolean(self, s):
  521.         '''Return a boolean value for Tcl boolean values true and false given as parameter.'''
  522.         return self.tk.getboolean(s)
  523.  
  524.     
  525.     def focus_set(self):
  526.         '''Direct input focus to this widget.
  527.  
  528.         If the application currently does not have the focus
  529.         this widget will get the focus if the application gets
  530.         the focus through the window manager.'''
  531.         self.tk.call('focus', self._w)
  532.  
  533.     focus = focus_set
  534.     
  535.     def focus_force(self):
  536.         '''Direct input focus to this widget even if the
  537.         application does not have the focus. Use with
  538.         caution!'''
  539.         self.tk.call('focus', '-force', self._w)
  540.  
  541.     
  542.     def focus_get(self):
  543.         '''Return the widget which has currently the focus in the
  544.         application.
  545.  
  546.         Use focus_displayof to allow working with several
  547.         displays. Return None if application does not have
  548.         the focus.'''
  549.         name = self.tk.call('focus')
  550.         if name == 'none' or not name:
  551.             return None
  552.         
  553.         return self._nametowidget(name)
  554.  
  555.     
  556.     def focus_displayof(self):
  557.         '''Return the widget which has currently the focus on the
  558.         display where this widget is located.
  559.  
  560.         Return None if the application does not have the focus.'''
  561.         name = self.tk.call('focus', '-displayof', self._w)
  562.         if name == 'none' or not name:
  563.             return None
  564.         
  565.         return self._nametowidget(name)
  566.  
  567.     
  568.     def focus_lastfor(self):
  569.         '''Return the widget which would have the focus if top level
  570.         for this widget gets the focus from the window manager.'''
  571.         name = self.tk.call('focus', '-lastfor', self._w)
  572.         if name == 'none' or not name:
  573.             return None
  574.         
  575.         return self._nametowidget(name)
  576.  
  577.     
  578.     def tk_focusFollowsMouse(self):
  579.         '''The widget under mouse will get automatically focus. Can not
  580.         be disabled easily.'''
  581.         self.tk.call('tk_focusFollowsMouse')
  582.  
  583.     
  584.     def tk_focusNext(self):
  585.         '''Return the next widget in the focus order which follows
  586.         widget which has currently the focus.
  587.  
  588.         The focus order first goes to the next child, then to
  589.         the children of the child recursively and then to the
  590.         next sibling which is higher in the stacking order.  A
  591.         widget is omitted if it has the takefocus resource set
  592.         to 0.'''
  593.         name = self.tk.call('tk_focusNext', self._w)
  594.         if not name:
  595.             return None
  596.         
  597.         return self._nametowidget(name)
  598.  
  599.     
  600.     def tk_focusPrev(self):
  601.         '''Return previous widget in the focus order. See tk_focusNext for details.'''
  602.         name = self.tk.call('tk_focusPrev', self._w)
  603.         if not name:
  604.             return None
  605.         
  606.         return self._nametowidget(name)
  607.  
  608.     
  609.     def after(self, ms, func = None, *args):
  610.         '''Call function once after given time.
  611.  
  612.         MS specifies the time in milliseconds. FUNC gives the
  613.         function which shall be called. Additional parameters
  614.         are given as parameters to the function call.  Return
  615.         identifier to cancel scheduling with after_cancel.'''
  616.         pass
  617.  
  618.     
  619.     def after_idle(self, func, *args):
  620.         '''Call FUNC once if the Tcl main loop has no event to
  621.         process.
  622.  
  623.         Return an identifier to cancel the scheduling with
  624.         after_cancel.'''
  625.         return self.after('idle', func, *args)
  626.  
  627.     
  628.     def after_cancel(self, id):
  629.         '''Cancel scheduling of function identified with ID.
  630.  
  631.         Identifier returned by after or after_idle must be
  632.         given as first parameter.'''
  633.         
  634.         try:
  635.             data = self.tk.call('after', 'info', id)
  636.             script = self.tk.splitlist(data)[0]
  637.             self.deletecommand(script)
  638.         except TclError:
  639.             pass
  640.  
  641.         self.tk.call('after', 'cancel', id)
  642.  
  643.     
  644.     def bell(self, displayof = 0):
  645.         """Ring a display's bell."""
  646.         self.tk.call(('bell',) + self._displayof(displayof))
  647.  
  648.     
  649.     def clipboard_get(self, **kw):
  650.         """Retrieve data from the clipboard on window's display.
  651.  
  652.         The window keyword defaults to the root window of the Tkinter
  653.         application.
  654.  
  655.         The type keyword specifies the form in which the data is
  656.         to be returned and should be an atom name such as STRING
  657.         or FILE_NAME.  Type defaults to STRING.
  658.  
  659.         This command is equivalent to:
  660.  
  661.         selection_get(CLIPBOARD)
  662.         """
  663.         return self.tk.call(('clipboard', 'get') + self._options(kw))
  664.  
  665.     
  666.     def clipboard_clear(self, **kw):
  667.         '''Clear the data in the Tk clipboard.
  668.  
  669.         A widget specified for the optional displayof keyword
  670.         argument specifies the target display.'''
  671.         if not kw.has_key('displayof'):
  672.             kw['displayof'] = self._w
  673.         
  674.         self.tk.call(('clipboard', 'clear') + self._options(kw))
  675.  
  676.     
  677.     def clipboard_append(self, string, **kw):
  678.         '''Append STRING to the Tk clipboard.
  679.  
  680.         A widget specified at the optional displayof keyword
  681.         argument specifies the target display. The clipboard
  682.         can be retrieved with selection_get.'''
  683.         if not kw.has_key('displayof'):
  684.             kw['displayof'] = self._w
  685.         
  686.         self.tk.call(('clipboard', 'append') + self._options(kw) + ('--', string))
  687.  
  688.     
  689.     def grab_current(self):
  690.         '''Return widget which has currently the grab in this application
  691.         or None.'''
  692.         name = self.tk.call('grab', 'current', self._w)
  693.         if not name:
  694.             return None
  695.         
  696.         return self._nametowidget(name)
  697.  
  698.     
  699.     def grab_release(self):
  700.         '''Release grab for this widget if currently set.'''
  701.         self.tk.call('grab', 'release', self._w)
  702.  
  703.     
  704.     def grab_set(self):
  705.         '''Set grab for this widget.
  706.  
  707.         A grab directs all events to this and descendant
  708.         widgets in the application.'''
  709.         self.tk.call('grab', 'set', self._w)
  710.  
  711.     
  712.     def grab_set_global(self):
  713.         '''Set global grab for this widget.
  714.  
  715.         A global grab directs all events to this and
  716.         descendant widgets on the display. Use with caution -
  717.         other applications do not get events anymore.'''
  718.         self.tk.call('grab', 'set', '-global', self._w)
  719.  
  720.     
  721.     def grab_status(self):
  722.         '''Return None, "local" or "global" if this widget has
  723.         no, a local or a global grab.'''
  724.         status = self.tk.call('grab', 'status', self._w)
  725.         if status == 'none':
  726.             status = None
  727.         
  728.         return status
  729.  
  730.     
  731.     def lower(self, belowThis = None):
  732.         '''Lower this widget in the stacking order.'''
  733.         self.tk.call('lower', self._w, belowThis)
  734.  
  735.     
  736.     def option_add(self, pattern, value, priority = None):
  737.         '''Set a VALUE (second parameter) for an option
  738.         PATTERN (first parameter).
  739.  
  740.         An optional third parameter gives the numeric priority
  741.         (defaults to 80).'''
  742.         self.tk.call('option', 'add', pattern, value, priority)
  743.  
  744.     
  745.     def option_clear(self):
  746.         '''Clear the option database.
  747.  
  748.         It will be reloaded if option_add is called.'''
  749.         self.tk.call('option', 'clear')
  750.  
  751.     
  752.     def option_get(self, name, className):
  753.         '''Return the value for an option NAME for this widget
  754.         with CLASSNAME.
  755.  
  756.         Values with higher priority override lower values.'''
  757.         return self.tk.call('option', 'get', self._w, name, className)
  758.  
  759.     
  760.     def option_readfile(self, fileName, priority = None):
  761.         '''Read file FILENAME into the option database.
  762.  
  763.         An optional second parameter gives the numeric
  764.         priority.'''
  765.         self.tk.call('option', 'readfile', fileName, priority)
  766.  
  767.     
  768.     def selection_clear(self, **kw):
  769.         '''Clear the current X selection.'''
  770.         if not kw.has_key('displayof'):
  771.             kw['displayof'] = self._w
  772.         
  773.         self.tk.call(('selection', 'clear') + self._options(kw))
  774.  
  775.     
  776.     def selection_get(self, **kw):
  777.         '''Return the contents of the current X selection.
  778.  
  779.         A keyword parameter selection specifies the name of
  780.         the selection and defaults to PRIMARY.  A keyword
  781.         parameter displayof specifies a widget on the display
  782.         to use.'''
  783.         if not kw.has_key('displayof'):
  784.             kw['displayof'] = self._w
  785.         
  786.         return self.tk.call(('selection', 'get') + self._options(kw))
  787.  
  788.     
  789.     def selection_handle(self, command, **kw):
  790.         '''Specify a function COMMAND to call if the X
  791.         selection owned by this widget is queried by another
  792.         application.
  793.  
  794.         This function must return the contents of the
  795.         selection. The function will be called with the
  796.         arguments OFFSET and LENGTH which allows the chunking
  797.         of very long selections. The following keyword
  798.         parameters can be provided:
  799.         selection - name of the selection (default PRIMARY),
  800.         type - type of the selection (e.g. STRING, FILE_NAME).'''
  801.         name = self._register(command)
  802.         self.tk.call(('selection', 'handle') + self._options(kw) + (self._w, name))
  803.  
  804.     
  805.     def selection_own(self, **kw):
  806.         '''Become owner of X selection.
  807.  
  808.         A keyword parameter selection specifies the name of
  809.         the selection (default PRIMARY).'''
  810.         self.tk.call(('selection', 'own') + self._options(kw) + (self._w,))
  811.  
  812.     
  813.     def selection_own_get(self, **kw):
  814.         '''Return owner of X selection.
  815.  
  816.         The following keyword parameter can
  817.         be provided:
  818.         selection - name of the selection (default PRIMARY),
  819.         type - type of the selection (e.g. STRING, FILE_NAME).'''
  820.         if not kw.has_key('displayof'):
  821.             kw['displayof'] = self._w
  822.         
  823.         name = self.tk.call(('selection', 'own') + self._options(kw))
  824.         if not name:
  825.             return None
  826.         
  827.         return self._nametowidget(name)
  828.  
  829.     
  830.     def send(self, interp, cmd, *args):
  831.         '''Send Tcl command CMD to different interpreter INTERP to be executed.'''
  832.         return self.tk.call(('send', interp, cmd) + args)
  833.  
  834.     
  835.     def lower(self, belowThis = None):
  836.         '''Lower this widget in the stacking order.'''
  837.         self.tk.call('lower', self._w, belowThis)
  838.  
  839.     
  840.     def tkraise(self, aboveThis = None):
  841.         '''Raise this widget in the stacking order.'''
  842.         self.tk.call('raise', self._w, aboveThis)
  843.  
  844.     lift = tkraise
  845.     
  846.     def colormodel(self, value = None):
  847.         '''Useless. Not implemented in Tk.'''
  848.         return self.tk.call('tk', 'colormodel', self._w, value)
  849.  
  850.     
  851.     def winfo_atom(self, name, displayof = 0):
  852.         '''Return integer which represents atom NAME.'''
  853.         args = ('winfo', 'atom') + self._displayof(displayof) + (name,)
  854.         return getint(self.tk.call(args))
  855.  
  856.     
  857.     def winfo_atomname(self, id, displayof = 0):
  858.         '''Return name of atom with identifier ID.'''
  859.         args = ('winfo', 'atomname') + self._displayof(displayof) + (id,)
  860.         return self.tk.call(args)
  861.  
  862.     
  863.     def winfo_cells(self):
  864.         '''Return number of cells in the colormap for this widget.'''
  865.         return getint(self.tk.call('winfo', 'cells', self._w))
  866.  
  867.     
  868.     def winfo_children(self):
  869.         '''Return a list of all widgets which are children of this widget.'''
  870.         result = []
  871.         for child in self.tk.splitlist(self.tk.call('winfo', 'children', self._w)):
  872.             
  873.             try:
  874.                 result.append(self._nametowidget(child))
  875.             continue
  876.             except KeyError:
  877.                 continue
  878.             
  879.  
  880.         
  881.         return result
  882.  
  883.     
  884.     def winfo_class(self):
  885.         '''Return window class name of this widget.'''
  886.         return self.tk.call('winfo', 'class', self._w)
  887.  
  888.     
  889.     def winfo_colormapfull(self):
  890.         '''Return true if at the last color request the colormap was full.'''
  891.         return self.tk.getboolean(self.tk.call('winfo', 'colormapfull', self._w))
  892.  
  893.     
  894.     def winfo_containing(self, rootX, rootY, displayof = 0):
  895.         '''Return the widget which is at the root coordinates ROOTX, ROOTY.'''
  896.         args = ('winfo', 'containing') + self._displayof(displayof) + (rootX, rootY)
  897.         name = self.tk.call(args)
  898.         if not name:
  899.             return None
  900.         
  901.         return self._nametowidget(name)
  902.  
  903.     
  904.     def winfo_depth(self):
  905.         '''Return the number of bits per pixel.'''
  906.         return getint(self.tk.call('winfo', 'depth', self._w))
  907.  
  908.     
  909.     def winfo_exists(self):
  910.         '''Return true if this widget exists.'''
  911.         return getint(self.tk.call('winfo', 'exists', self._w))
  912.  
  913.     
  914.     def winfo_fpixels(self, number):
  915.         '''Return the number of pixels for the given distance NUMBER
  916.         (e.g. "3c") as float.'''
  917.         return getdouble(self.tk.call('winfo', 'fpixels', self._w, number))
  918.  
  919.     
  920.     def winfo_geometry(self):
  921.         '''Return geometry string for this widget in the form "widthxheight+X+Y".'''
  922.         return self.tk.call('winfo', 'geometry', self._w)
  923.  
  924.     
  925.     def winfo_height(self):
  926.         '''Return height of this widget.'''
  927.         return getint(self.tk.call('winfo', 'height', self._w))
  928.  
  929.     
  930.     def winfo_id(self):
  931.         '''Return identifier ID for this widget.'''
  932.         return self.tk.getint(self.tk.call('winfo', 'id', self._w))
  933.  
  934.     
  935.     def winfo_interps(self, displayof = 0):
  936.         '''Return the name of all Tcl interpreters for this display.'''
  937.         args = ('winfo', 'interps') + self._displayof(displayof)
  938.         return self.tk.splitlist(self.tk.call(args))
  939.  
  940.     
  941.     def winfo_ismapped(self):
  942.         '''Return true if this widget is mapped.'''
  943.         return getint(self.tk.call('winfo', 'ismapped', self._w))
  944.  
  945.     
  946.     def winfo_manager(self):
  947.         '''Return the window mananger name for this widget.'''
  948.         return self.tk.call('winfo', 'manager', self._w)
  949.  
  950.     
  951.     def winfo_name(self):
  952.         '''Return the name of this widget.'''
  953.         return self.tk.call('winfo', 'name', self._w)
  954.  
  955.     
  956.     def winfo_parent(self):
  957.         '''Return the name of the parent of this widget.'''
  958.         return self.tk.call('winfo', 'parent', self._w)
  959.  
  960.     
  961.     def winfo_pathname(self, id, displayof = 0):
  962.         '''Return the pathname of the widget given by ID.'''
  963.         args = ('winfo', 'pathname') + self._displayof(displayof) + (id,)
  964.         return self.tk.call(args)
  965.  
  966.     
  967.     def winfo_pixels(self, number):
  968.         '''Rounded integer value of winfo_fpixels.'''
  969.         return getint(self.tk.call('winfo', 'pixels', self._w, number))
  970.  
  971.     
  972.     def winfo_pointerx(self):
  973.         '''Return the x coordinate of the pointer on the root window.'''
  974.         return getint(self.tk.call('winfo', 'pointerx', self._w))
  975.  
  976.     
  977.     def winfo_pointerxy(self):
  978.         '''Return a tuple of x and y coordinates of the pointer on the root window.'''
  979.         return self._getints(self.tk.call('winfo', 'pointerxy', self._w))
  980.  
  981.     
  982.     def winfo_pointery(self):
  983.         '''Return the y coordinate of the pointer on the root window.'''
  984.         return getint(self.tk.call('winfo', 'pointery', self._w))
  985.  
  986.     
  987.     def winfo_reqheight(self):
  988.         '''Return requested height of this widget.'''
  989.         return getint(self.tk.call('winfo', 'reqheight', self._w))
  990.  
  991.     
  992.     def winfo_reqwidth(self):
  993.         '''Return requested width of this widget.'''
  994.         return getint(self.tk.call('winfo', 'reqwidth', self._w))
  995.  
  996.     
  997.     def winfo_rgb(self, color):
  998.         '''Return tuple of decimal values for red, green, blue for
  999.         COLOR in this widget.'''
  1000.         return self._getints(self.tk.call('winfo', 'rgb', self._w, color))
  1001.  
  1002.     
  1003.     def winfo_rootx(self):
  1004.         '''Return x coordinate of upper left corner of this widget on the
  1005.         root window.'''
  1006.         return getint(self.tk.call('winfo', 'rootx', self._w))
  1007.  
  1008.     
  1009.     def winfo_rooty(self):
  1010.         '''Return y coordinate of upper left corner of this widget on the
  1011.         root window.'''
  1012.         return getint(self.tk.call('winfo', 'rooty', self._w))
  1013.  
  1014.     
  1015.     def winfo_screen(self):
  1016.         '''Return the screen name of this widget.'''
  1017.         return self.tk.call('winfo', 'screen', self._w)
  1018.  
  1019.     
  1020.     def winfo_screencells(self):
  1021.         '''Return the number of the cells in the colormap of the screen
  1022.         of this widget.'''
  1023.         return getint(self.tk.call('winfo', 'screencells', self._w))
  1024.  
  1025.     
  1026.     def winfo_screendepth(self):
  1027.         '''Return the number of bits per pixel of the root window of the
  1028.         screen of this widget.'''
  1029.         return getint(self.tk.call('winfo', 'screendepth', self._w))
  1030.  
  1031.     
  1032.     def winfo_screenheight(self):
  1033.         '''Return the number of pixels of the height of the screen of this widget
  1034.         in pixel.'''
  1035.         return getint(self.tk.call('winfo', 'screenheight', self._w))
  1036.  
  1037.     
  1038.     def winfo_screenmmheight(self):
  1039.         '''Return the number of pixels of the height of the screen of
  1040.         this widget in mm.'''
  1041.         return getint(self.tk.call('winfo', 'screenmmheight', self._w))
  1042.  
  1043.     
  1044.     def winfo_screenmmwidth(self):
  1045.         '''Return the number of pixels of the width of the screen of
  1046.         this widget in mm.'''
  1047.         return getint(self.tk.call('winfo', 'screenmmwidth', self._w))
  1048.  
  1049.     
  1050.     def winfo_screenvisual(self):
  1051.         '''Return one of the strings directcolor, grayscale, pseudocolor,
  1052.         staticcolor, staticgray, or truecolor for the default
  1053.         colormodel of this screen.'''
  1054.         return self.tk.call('winfo', 'screenvisual', self._w)
  1055.  
  1056.     
  1057.     def winfo_screenwidth(self):
  1058.         '''Return the number of pixels of the width of the screen of
  1059.         this widget in pixel.'''
  1060.         return getint(self.tk.call('winfo', 'screenwidth', self._w))
  1061.  
  1062.     
  1063.     def winfo_server(self):
  1064.         '''Return information of the X-Server of the screen of this widget in
  1065.         the form "XmajorRminor vendor vendorVersion".'''
  1066.         return self.tk.call('winfo', 'server', self._w)
  1067.  
  1068.     
  1069.     def winfo_toplevel(self):
  1070.         '''Return the toplevel widget of this widget.'''
  1071.         return self._nametowidget(self.tk.call('winfo', 'toplevel', self._w))
  1072.  
  1073.     
  1074.     def winfo_viewable(self):
  1075.         '''Return true if the widget and all its higher ancestors are mapped.'''
  1076.         return getint(self.tk.call('winfo', 'viewable', self._w))
  1077.  
  1078.     
  1079.     def winfo_visual(self):
  1080.         '''Return one of the strings directcolor, grayscale, pseudocolor,
  1081.         staticcolor, staticgray, or truecolor for the
  1082.         colormodel of this widget.'''
  1083.         return self.tk.call('winfo', 'visual', self._w)
  1084.  
  1085.     
  1086.     def winfo_visualid(self):
  1087.         '''Return the X identifier for the visual for this widget.'''
  1088.         return self.tk.call('winfo', 'visualid', self._w)
  1089.  
  1090.     
  1091.     def winfo_visualsavailable(self, includeids = 0):
  1092.         '''Return a list of all visuals available for the screen
  1093.         of this widget.
  1094.  
  1095.         Each item in the list consists of a visual name (see winfo_visual), a
  1096.         depth and if INCLUDEIDS=1 is given also the X identifier.'''
  1097.         if not includeids or 'includeids':
  1098.             pass
  1099.         data = self.tk.split(self.tk.call('winfo', 'visualsavailable', self._w, None))
  1100.         if type(data) is StringType:
  1101.             data = [
  1102.                 self.tk.split(data)]
  1103.         
  1104.         return map(self._Misc__winfo_parseitem, data)
  1105.  
  1106.     
  1107.     def __winfo_parseitem(self, t):
  1108.         '''Internal function.'''
  1109.         return t[:1] + tuple(map(self._Misc__winfo_getint, t[1:]))
  1110.  
  1111.     
  1112.     def __winfo_getint(self, x):
  1113.         '''Internal function.'''
  1114.         return int(x, 0)
  1115.  
  1116.     
  1117.     def winfo_vrootheight(self):
  1118.         '''Return the height of the virtual root window associated with this
  1119.         widget in pixels. If there is no virtual root window return the
  1120.         height of the screen.'''
  1121.         return getint(self.tk.call('winfo', 'vrootheight', self._w))
  1122.  
  1123.     
  1124.     def winfo_vrootwidth(self):
  1125.         '''Return the width of the virtual root window associated with this
  1126.         widget in pixel. If there is no virtual root window return the
  1127.         width of the screen.'''
  1128.         return getint(self.tk.call('winfo', 'vrootwidth', self._w))
  1129.  
  1130.     
  1131.     def winfo_vrootx(self):
  1132.         '''Return the x offset of the virtual root relative to the root
  1133.         window of the screen of this widget.'''
  1134.         return getint(self.tk.call('winfo', 'vrootx', self._w))
  1135.  
  1136.     
  1137.     def winfo_vrooty(self):
  1138.         '''Return the y offset of the virtual root relative to the root
  1139.         window of the screen of this widget.'''
  1140.         return getint(self.tk.call('winfo', 'vrooty', self._w))
  1141.  
  1142.     
  1143.     def winfo_width(self):
  1144.         '''Return the width of this widget.'''
  1145.         return getint(self.tk.call('winfo', 'width', self._w))
  1146.  
  1147.     
  1148.     def winfo_x(self):
  1149.         '''Return the x coordinate of the upper left corner of this widget
  1150.         in the parent.'''
  1151.         return getint(self.tk.call('winfo', 'x', self._w))
  1152.  
  1153.     
  1154.     def winfo_y(self):
  1155.         '''Return the y coordinate of the upper left corner of this widget
  1156.         in the parent.'''
  1157.         return getint(self.tk.call('winfo', 'y', self._w))
  1158.  
  1159.     
  1160.     def update(self):
  1161.         '''Enter event loop until all pending events have been processed by Tcl.'''
  1162.         self.tk.call('update')
  1163.  
  1164.     
  1165.     def update_idletasks(self):
  1166.         '''Enter event loop until all idle callbacks have been called. This
  1167.         will update the display of windows but not process events caused by
  1168.         the user.'''
  1169.         self.tk.call('update', 'idletasks')
  1170.  
  1171.     
  1172.     def bindtags(self, tagList = None):
  1173.         '''Set or get the list of bindtags for this widget.
  1174.  
  1175.         With no argument return the list of all bindtags associated with
  1176.         this widget. With a list of strings as argument the bindtags are
  1177.         set to this list. The bindtags determine in which order events are
  1178.         processed (see bind).'''
  1179.         if tagList is None:
  1180.             return self.tk.splitlist(self.tk.call('bindtags', self._w))
  1181.         else:
  1182.             self.tk.call('bindtags', self._w, tagList)
  1183.  
  1184.     
  1185.     def _bind(self, what, sequence, func, add, needcleanup = 1):
  1186.         '''Internal function.'''
  1187.         if type(func) is StringType:
  1188.             self.tk.call(what + (sequence, func))
  1189.         elif func:
  1190.             funcid = self._register(func, self._substitute, needcleanup)
  1191.             if not add or '+':
  1192.                 pass
  1193.             cmd = '%sif {"[%s %s]" == "break"} break\n' % ('', funcid, self._subst_format_str)
  1194.             self.tk.call(what + (sequence, cmd))
  1195.             return funcid
  1196.         elif sequence:
  1197.             return self.tk.call(what + (sequence,))
  1198.         else:
  1199.             return self.tk.splitlist(self.tk.call(what))
  1200.  
  1201.     
  1202.     def bind(self, sequence = None, func = None, add = None):
  1203.         '''Bind to this widget at event SEQUENCE a call to function FUNC.
  1204.  
  1205.         SEQUENCE is a string of concatenated event
  1206.         patterns. An event pattern is of the form
  1207.         <MODIFIER-MODIFIER-TYPE-DETAIL> where MODIFIER is one
  1208.         of Control, Mod2, M2, Shift, Mod3, M3, Lock, Mod4, M4,
  1209.         Button1, B1, Mod5, M5 Button2, B2, Meta, M, Button3,
  1210.         B3, Alt, Button4, B4, Double, Button5, B5 Triple,
  1211.         Mod1, M1. TYPE is one of Activate, Enter, Map,
  1212.         ButtonPress, Button, Expose, Motion, ButtonRelease
  1213.         FocusIn, MouseWheel, Circulate, FocusOut, Property,
  1214.         Colormap, Gravity Reparent, Configure, KeyPress, Key,
  1215.         Unmap, Deactivate, KeyRelease Visibility, Destroy,
  1216.         Leave and DETAIL is the button number for ButtonPress,
  1217.         ButtonRelease and DETAIL is the Keysym for KeyPress and
  1218.         KeyRelease. Examples are
  1219.         <Control-Button-1> for pressing Control and mouse button 1 or
  1220.         <Alt-A> for pressing A and the Alt key (KeyPress can be omitted).
  1221.         An event pattern can also be a virtual event of the form
  1222.         <<AString>> where AString can be arbitrary. This
  1223.         event can be generated by event_generate.
  1224.         If events are concatenated they must appear shortly
  1225.         after each other.
  1226.  
  1227.         FUNC will be called if the event sequence occurs with an
  1228.         instance of Event as argument. If the return value of FUNC is
  1229.         "break" no further bound function is invoked.
  1230.  
  1231.         An additional boolean parameter ADD specifies whether FUNC will
  1232.         be called additionally to the other bound function or whether
  1233.         it will replace the previous function.
  1234.  
  1235.         Bind will return an identifier to allow deletion of the bound function with
  1236.         unbind without memory leak.
  1237.  
  1238.         If FUNC or SEQUENCE is omitted the bound function or list
  1239.         of bound events are returned.'''
  1240.         return self._bind(('bind', self._w), sequence, func, add)
  1241.  
  1242.     
  1243.     def unbind(self, sequence, funcid = None):
  1244.         '''Unbind for this widget for event SEQUENCE  the
  1245.         function identified with FUNCID.'''
  1246.         self.tk.call('bind', self._w, sequence, '')
  1247.         if funcid:
  1248.             self.deletecommand(funcid)
  1249.         
  1250.  
  1251.     
  1252.     def bind_all(self, sequence = None, func = None, add = None):
  1253.         '''Bind to all widgets at an event SEQUENCE a call to function FUNC.
  1254.         An additional boolean parameter ADD specifies whether FUNC will
  1255.         be called additionally to the other bound function or whether
  1256.         it will replace the previous function. See bind for the return value.'''
  1257.         return self._bind(('bind', 'all'), sequence, func, add, 0)
  1258.  
  1259.     
  1260.     def unbind_all(self, sequence):
  1261.         '''Unbind for all widgets for event SEQUENCE all functions.'''
  1262.         self.tk.call('bind', 'all', sequence, '')
  1263.  
  1264.     
  1265.     def bind_class(self, className, sequence = None, func = None, add = None):
  1266.         '''Bind to widgets with bindtag CLASSNAME at event
  1267.         SEQUENCE a call of function FUNC. An additional
  1268.         boolean parameter ADD specifies whether FUNC will be
  1269.         called additionally to the other bound function or
  1270.         whether it will replace the previous function. See bind for
  1271.         the return value.'''
  1272.         return self._bind(('bind', className), sequence, func, add, 0)
  1273.  
  1274.     
  1275.     def unbind_class(self, className, sequence):
  1276.         '''Unbind for a all widgets with bindtag CLASSNAME for event SEQUENCE
  1277.         all functions.'''
  1278.         self.tk.call('bind', className, sequence, '')
  1279.  
  1280.     
  1281.     def mainloop(self, n = 0):
  1282.         '''Call the mainloop of Tk.'''
  1283.         self.tk.mainloop(n)
  1284.  
  1285.     
  1286.     def quit(self):
  1287.         '''Quit the Tcl interpreter. All widgets will be destroyed.'''
  1288.         self.tk.quit()
  1289.  
  1290.     
  1291.     def _getints(self, string):
  1292.         '''Internal function.'''
  1293.         if string:
  1294.             return tuple(map(getint, self.tk.splitlist(string)))
  1295.         
  1296.  
  1297.     
  1298.     def _getdoubles(self, string):
  1299.         '''Internal function.'''
  1300.         if string:
  1301.             return tuple(map(getdouble, self.tk.splitlist(string)))
  1302.         
  1303.  
  1304.     
  1305.     def _getboolean(self, string):
  1306.         '''Internal function.'''
  1307.         if string:
  1308.             return self.tk.getboolean(string)
  1309.         
  1310.  
  1311.     
  1312.     def _displayof(self, displayof):
  1313.         '''Internal function.'''
  1314.         if displayof:
  1315.             return ('-displayof', displayof)
  1316.         
  1317.         if displayof is None:
  1318.             return ('-displayof', self._w)
  1319.         
  1320.         return ()
  1321.  
  1322.     
  1323.     def _options(self, cnf, kw = None):
  1324.         '''Internal function.'''
  1325.         if kw:
  1326.             cnf = _cnfmerge((cnf, kw))
  1327.         else:
  1328.             cnf = _cnfmerge(cnf)
  1329.         res = ()
  1330.         for k, v in cnf.items():
  1331.             if v is not None:
  1332.                 if k[-1] == '_':
  1333.                     k = k[:-1]
  1334.                 
  1335.                 if callable(v):
  1336.                     v = self._register(v)
  1337.                 
  1338.                 res = res + ('-' + k, v)
  1339.                 continue
  1340.         
  1341.         return res
  1342.  
  1343.     
  1344.     def nametowidget(self, name):
  1345.         '''Return the Tkinter instance of a widget identified by
  1346.         its Tcl name NAME.'''
  1347.         w = self
  1348.         if name[0] == '.':
  1349.             w = w._root()
  1350.             name = name[1:]
  1351.         
  1352.         while name:
  1353.             i = name.find('.')
  1354.             if i >= 0:
  1355.                 name = name[:i]
  1356.                 tail = name[i + 1:]
  1357.             else:
  1358.                 tail = ''
  1359.             w = w.children[name]
  1360.             name = tail
  1361.         return w
  1362.  
  1363.     _nametowidget = nametowidget
  1364.     
  1365.     def _register(self, func, subst = None, needcleanup = 1):
  1366.         '''Return a newly created Tcl function. If this
  1367.         function is called, the Python function FUNC will
  1368.         be executed. An optional function SUBST can
  1369.         be given which will be executed before FUNC.'''
  1370.         f = CallWrapper(func, subst, self).__call__
  1371.         name = repr(id(f))
  1372.         
  1373.         try:
  1374.             func = func.im_func
  1375.         except AttributeError:
  1376.             pass
  1377.  
  1378.         
  1379.         try:
  1380.             name = name + func.__name__
  1381.         except AttributeError:
  1382.             pass
  1383.  
  1384.         self.tk.createcommand(name, f)
  1385.         if needcleanup:
  1386.             if self._tclCommands is None:
  1387.                 self._tclCommands = []
  1388.             
  1389.             self._tclCommands.append(name)
  1390.         
  1391.         return name
  1392.  
  1393.     register = _register
  1394.     
  1395.     def _root(self):
  1396.         '''Internal function.'''
  1397.         w = self
  1398.         while w.master:
  1399.             w = w.master
  1400.         return w
  1401.  
  1402.     _subst_format = ('%#', '%b', '%f', '%h', '%k', '%s', '%t', '%w', '%x', '%y', '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y', '%D')
  1403.     _subst_format_str = ' '.join(_subst_format)
  1404.     
  1405.     def _substitute(self, *args):
  1406.         '''Internal function.'''
  1407.         if len(args) != len(self._subst_format):
  1408.             return args
  1409.         
  1410.         getboolean = self.tk.getboolean
  1411.         getint = int
  1412.         
  1413.         def getint_event(s):
  1414.             '''Tk changed behavior in 8.4.2, returning "??" rather more often.'''
  1415.             
  1416.             try:
  1417.                 return int(s)
  1418.             except ValueError:
  1419.                 return s
  1420.  
  1421.  
  1422.         (nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y, D) = args
  1423.         e = Event()
  1424.         e.serial = getint(nsign)
  1425.         e.num = getint_event(b)
  1426.         
  1427.         try:
  1428.             e.focus = getboolean(f)
  1429.         except TclError:
  1430.             pass
  1431.  
  1432.         e.height = getint_event(h)
  1433.         e.keycode = getint_event(k)
  1434.         e.state = getint_event(s)
  1435.         e.time = getint_event(t)
  1436.         e.width = getint_event(w)
  1437.         e.x = getint_event(x)
  1438.         e.y = getint_event(y)
  1439.         e.char = A
  1440.         
  1441.         try:
  1442.             e.send_event = getboolean(E)
  1443.         except TclError:
  1444.             pass
  1445.  
  1446.         e.keysym = K
  1447.         e.keysym_num = getint_event(N)
  1448.         e.type = T
  1449.         
  1450.         try:
  1451.             e.widget = self._nametowidget(W)
  1452.         except KeyError:
  1453.             e.widget = W
  1454.  
  1455.         e.x_root = getint_event(X)
  1456.         e.y_root = getint_event(Y)
  1457.         
  1458.         try:
  1459.             e.delta = getint(D)
  1460.         except ValueError:
  1461.             e.delta = 0
  1462.  
  1463.         return (e,)
  1464.  
  1465.     
  1466.     def _report_exception(self):
  1467.         '''Internal function.'''
  1468.         import sys
  1469.         exc = sys.exc_type
  1470.         val = sys.exc_value
  1471.         tb = sys.exc_traceback
  1472.         root = self._root()
  1473.         root.report_callback_exception(exc, val, tb)
  1474.  
  1475.     
  1476.     def _configure(self, cmd, cnf, kw):
  1477.         '''Internal function.'''
  1478.         if kw:
  1479.             cnf = _cnfmerge((cnf, kw))
  1480.         elif cnf:
  1481.             cnf = _cnfmerge(cnf)
  1482.         
  1483.         if cnf is None:
  1484.             cnf = { }
  1485.             for x in self.tk.split(self.tk.call(_flatten((self._w, cmd)))):
  1486.                 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
  1487.             
  1488.             return cnf
  1489.         
  1490.         if type(cnf) is StringType:
  1491.             x = self.tk.split(self.tk.call(_flatten((self._w, cmd, '-' + cnf))))
  1492.             return (x[0][1:],) + x[1:]
  1493.         
  1494.         self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
  1495.  
  1496.     
  1497.     def configure(self, cnf = None, **kw):
  1498.         '''Configure resources of a widget.
  1499.  
  1500.         The values for resources are specified as keyword
  1501.         arguments. To get an overview about
  1502.         the allowed keyword arguments call the method keys.
  1503.         '''
  1504.         return self._configure('configure', cnf, kw)
  1505.  
  1506.     config = configure
  1507.     
  1508.     def cget(self, key):
  1509.         '''Return the resource value for a KEY given as string.'''
  1510.         return self.tk.call(self._w, 'cget', '-' + key)
  1511.  
  1512.     __getitem__ = cget
  1513.     
  1514.     def __setitem__(self, key, value):
  1515.         self.configure({
  1516.             key: value })
  1517.  
  1518.     
  1519.     def keys(self):
  1520.         '''Return a list of all resource names of this widget.'''
  1521.         return map((lambda x: x[0][1:]), self.tk.split(self.tk.call(self._w, 'configure')))
  1522.  
  1523.     
  1524.     def __str__(self):
  1525.         '''Return the window path name of this widget.'''
  1526.         return self._w
  1527.  
  1528.     _noarg_ = [
  1529.         '_noarg_']
  1530.     
  1531.     def pack_propagate(self, flag = _noarg_):
  1532.         '''Set or get the status for propagation of geometry information.
  1533.  
  1534.         A boolean argument specifies whether the geometry information
  1535.         of the slaves will determine the size of this widget. If no argument
  1536.         is given the current setting will be returned.
  1537.         '''
  1538.         if flag is Misc._noarg_:
  1539.             return self._getboolean(self.tk.call('pack', 'propagate', self._w))
  1540.         else:
  1541.             self.tk.call('pack', 'propagate', self._w, flag)
  1542.  
  1543.     propagate = pack_propagate
  1544.     
  1545.     def pack_slaves(self):
  1546.         '''Return a list of all slaves of this widget
  1547.         in its packing order.'''
  1548.         return map(self._nametowidget, self.tk.splitlist(self.tk.call('pack', 'slaves', self._w)))
  1549.  
  1550.     slaves = pack_slaves
  1551.     
  1552.     def place_slaves(self):
  1553.         '''Return a list of all slaves of this widget
  1554.         in its packing order.'''
  1555.         return map(self._nametowidget, self.tk.splitlist(self.tk.call('place', 'slaves', self._w)))
  1556.  
  1557.     
  1558.     def grid_bbox(self, column = None, row = None, col2 = None, row2 = None):
  1559.         '''Return a tuple of integer coordinates for the bounding
  1560.         box of this widget controlled by the geometry manager grid.
  1561.  
  1562.         If COLUMN, ROW is given the bounding box applies from
  1563.         the cell with row and column 0 to the specified
  1564.         cell. If COL2 and ROW2 are given the bounding box
  1565.         starts at that cell.
  1566.  
  1567.         The returned integers specify the offset of the upper left
  1568.         corner in the master widget and the width and height.
  1569.         '''
  1570.         args = ('grid', 'bbox', self._w)
  1571.         if column is not None and row is not None:
  1572.             args = args + (column, row)
  1573.         
  1574.         if col2 is not None and row2 is not None:
  1575.             args = args + (col2, row2)
  1576.         
  1577.         if not self._getints(self.tk.call(*args)):
  1578.             pass
  1579.  
  1580.     bbox = grid_bbox
  1581.     
  1582.     def _grid_configure(self, command, index, cnf, kw):
  1583.         '''Internal function.'''
  1584.         if type(cnf) is StringType and not kw:
  1585.             if cnf[-1:] == '_':
  1586.                 cnf = cnf[:-1]
  1587.             
  1588.             if cnf[:1] != '-':
  1589.                 cnf = '-' + cnf
  1590.             
  1591.             options = (cnf,)
  1592.         else:
  1593.             options = self._options(cnf, kw)
  1594.         if not options:
  1595.             res = self.tk.call('grid', command, self._w, index)
  1596.             words = self.tk.splitlist(res)
  1597.             dict = { }
  1598.             for i in range(0, len(words), 2):
  1599.                 key = words[i][1:]
  1600.                 value = words[i + 1]
  1601.                 if not value:
  1602.                     value = None
  1603.                 elif '.' in value:
  1604.                     value = getdouble(value)
  1605.                 else:
  1606.                     value = getint(value)
  1607.                 dict[key] = value
  1608.             
  1609.             return dict
  1610.         
  1611.         res = self.tk.call(('grid', command, self._w, index) + options)
  1612.         if len(options) == 1:
  1613.             if not res:
  1614.                 return None
  1615.             
  1616.             if '.' in res:
  1617.                 return getdouble(res)
  1618.             
  1619.             return getint(res)
  1620.         
  1621.  
  1622.     
  1623.     def grid_columnconfigure(self, index, cnf = { }, **kw):
  1624.         '''Configure column INDEX of a grid.
  1625.  
  1626.         Valid resources are minsize (minimum size of the column),
  1627.         weight (how much does additional space propagate to this column)
  1628.         and pad (how much space to let additionally).'''
  1629.         return self._grid_configure('columnconfigure', index, cnf, kw)
  1630.  
  1631.     columnconfigure = grid_columnconfigure
  1632.     
  1633.     def grid_location(self, x, y):
  1634.         '''Return a tuple of column and row which identify the cell
  1635.         at which the pixel at position X and Y inside the master
  1636.         widget is located.'''
  1637.         if not self._getints(self.tk.call('grid', 'location', self._w, x, y)):
  1638.             pass
  1639.  
  1640.     
  1641.     def grid_propagate(self, flag = _noarg_):
  1642.         '''Set or get the status for propagation of geometry information.
  1643.  
  1644.         A boolean argument specifies whether the geometry information
  1645.         of the slaves will determine the size of this widget. If no argument
  1646.         is given, the current setting will be returned.
  1647.         '''
  1648.         if flag is Misc._noarg_:
  1649.             return self._getboolean(self.tk.call('grid', 'propagate', self._w))
  1650.         else:
  1651.             self.tk.call('grid', 'propagate', self._w, flag)
  1652.  
  1653.     
  1654.     def grid_rowconfigure(self, index, cnf = { }, **kw):
  1655.         '''Configure row INDEX of a grid.
  1656.  
  1657.         Valid resources are minsize (minimum size of the row),
  1658.         weight (how much does additional space propagate to this row)
  1659.         and pad (how much space to let additionally).'''
  1660.         return self._grid_configure('rowconfigure', index, cnf, kw)
  1661.  
  1662.     rowconfigure = grid_rowconfigure
  1663.     
  1664.     def grid_size(self):
  1665.         '''Return a tuple of the number of column and rows in the grid.'''
  1666.         if not self._getints(self.tk.call('grid', 'size', self._w)):
  1667.             pass
  1668.  
  1669.     size = grid_size
  1670.     
  1671.     def grid_slaves(self, row = None, column = None):
  1672.         '''Return a list of all slaves of this widget
  1673.         in its packing order.'''
  1674.         args = ()
  1675.         if row is not None:
  1676.             args = args + ('-row', row)
  1677.         
  1678.         if column is not None:
  1679.             args = args + ('-column', column)
  1680.         
  1681.         return map(self._nametowidget, self.tk.splitlist(self.tk.call(('grid', 'slaves', self._w) + args)))
  1682.  
  1683.     
  1684.     def event_add(self, virtual, *sequences):
  1685.         '''Bind a virtual event VIRTUAL (of the form <<Name>>)
  1686.         to an event SEQUENCE such that the virtual event is triggered
  1687.         whenever SEQUENCE occurs.'''
  1688.         args = ('event', 'add', virtual) + sequences
  1689.         self.tk.call(args)
  1690.  
  1691.     
  1692.     def event_delete(self, virtual, *sequences):
  1693.         '''Unbind a virtual event VIRTUAL from SEQUENCE.'''
  1694.         args = ('event', 'delete', virtual) + sequences
  1695.         self.tk.call(args)
  1696.  
  1697.     
  1698.     def event_generate(self, sequence, **kw):
  1699.         '''Generate an event SEQUENCE. Additional
  1700.         keyword arguments specify parameter of the event
  1701.         (e.g. x, y, rootx, rooty).'''
  1702.         args = ('event', 'generate', self._w, sequence)
  1703.         for k, v in kw.items():
  1704.             args = args + ('-%s' % k, str(v))
  1705.         
  1706.         self.tk.call(args)
  1707.  
  1708.     
  1709.     def event_info(self, virtual = None):
  1710.         '''Return a list of all virtual events or the information
  1711.         about the SEQUENCE bound to the virtual event VIRTUAL.'''
  1712.         return self.tk.splitlist(self.tk.call('event', 'info', virtual))
  1713.  
  1714.     
  1715.     def image_names(self):
  1716.         '''Return a list of all existing image names.'''
  1717.         return self.tk.call('image', 'names')
  1718.  
  1719.     
  1720.     def image_types(self):
  1721.         '''Return a list of all available image types (e.g. phote bitmap).'''
  1722.         return self.tk.call('image', 'types')
  1723.  
  1724.  
  1725.  
  1726. class CallWrapper:
  1727.     '''Internal class. Stores function to call when some user
  1728.     defined Tcl function is called e.g. after an event occurred.'''
  1729.     
  1730.     def __init__(self, func, subst, widget):
  1731.         '''Store FUNC, SUBST and WIDGET as members.'''
  1732.         self.func = func
  1733.         self.subst = subst
  1734.         self.widget = widget
  1735.  
  1736.     
  1737.     def __call__(self, *args):
  1738.         '''Apply first function SUBST to arguments, than FUNC.'''
  1739.         
  1740.         try:
  1741.             if self.subst:
  1742.                 args = self.subst(*args)
  1743.             
  1744.             return self.func(*args)
  1745.         except SystemExit:
  1746.             msg = None
  1747.             raise SystemExit, msg
  1748.         except:
  1749.             self.widget._report_exception()
  1750.  
  1751.  
  1752.  
  1753.  
  1754. class Wm:
  1755.     '''Provides functions for the communication with the window manager.'''
  1756.     
  1757.     def wm_aspect(self, minNumer = None, minDenom = None, maxNumer = None, maxDenom = None):
  1758.         '''Instruct the window manager to set the aspect ratio (width/height)
  1759.         of this widget to be between MINNUMER/MINDENOM and MAXNUMER/MAXDENOM. Return a tuple
  1760.         of the actual values if no argument is given.'''
  1761.         return self._getints(self.tk.call('wm', 'aspect', self._w, minNumer, minDenom, maxNumer, maxDenom))
  1762.  
  1763.     aspect = wm_aspect
  1764.     
  1765.     def wm_attributes(self, *args):
  1766.         '''This subcommand returns or sets platform specific attributes
  1767.  
  1768.         The first form returns a list of the platform specific flags and
  1769.         their values. The second form returns the value for the specific
  1770.         option. The third form sets one or more of the values. The values
  1771.         are as follows:
  1772.  
  1773.         On Windows, -disabled gets or sets whether the window is in a
  1774.         disabled state. -toolwindow gets or sets the style of the window
  1775.         to toolwindow (as defined in the MSDN). -topmost gets or sets
  1776.         whether this is a topmost window (displays above all other
  1777.         windows).
  1778.  
  1779.         On Macintosh, XXXXX
  1780.  
  1781.         On Unix, there are currently no special attribute values.
  1782.         '''
  1783.         args = ('wm', 'attributes', self._w) + args
  1784.         return self.tk.call(args)
  1785.  
  1786.     attributes = wm_attributes
  1787.     
  1788.     def wm_client(self, name = None):
  1789.         '''Store NAME in WM_CLIENT_MACHINE property of this widget. Return
  1790.         current value.'''
  1791.         return self.tk.call('wm', 'client', self._w, name)
  1792.  
  1793.     client = wm_client
  1794.     
  1795.     def wm_colormapwindows(self, *wlist):
  1796.         '''Store list of window names (WLIST) into WM_COLORMAPWINDOWS property
  1797.         of this widget. This list contains windows whose colormaps differ from their
  1798.         parents. Return current list of widgets if WLIST is empty.'''
  1799.         if len(wlist) > 1:
  1800.             wlist = (wlist,)
  1801.         
  1802.         args = ('wm', 'colormapwindows', self._w) + wlist
  1803.         return map(self._nametowidget, self.tk.call(args))
  1804.  
  1805.     colormapwindows = wm_colormapwindows
  1806.     
  1807.     def wm_command(self, value = None):
  1808.         '''Store VALUE in WM_COMMAND property. It is the command
  1809.         which shall be used to invoke the application. Return current
  1810.         command if VALUE is None.'''
  1811.         return self.tk.call('wm', 'command', self._w, value)
  1812.  
  1813.     command = wm_command
  1814.     
  1815.     def wm_deiconify(self):
  1816.         '''Deiconify this widget. If it was never mapped it will not be mapped.
  1817.         On Windows it will raise this widget and give it the focus.'''
  1818.         return self.tk.call('wm', 'deiconify', self._w)
  1819.  
  1820.     deiconify = wm_deiconify
  1821.     
  1822.     def wm_focusmodel(self, model = None):
  1823.         '''Set focus model to MODEL. "active" means that this widget will claim
  1824.         the focus itself, "passive" means that the window manager shall give
  1825.         the focus. Return current focus model if MODEL is None.'''
  1826.         return self.tk.call('wm', 'focusmodel', self._w, model)
  1827.  
  1828.     focusmodel = wm_focusmodel
  1829.     
  1830.     def wm_frame(self):
  1831.         '''Return identifier for decorative frame of this widget if present.'''
  1832.         return self.tk.call('wm', 'frame', self._w)
  1833.  
  1834.     frame = wm_frame
  1835.     
  1836.     def wm_geometry(self, newGeometry = None):
  1837.         '''Set geometry to NEWGEOMETRY of the form =widthxheight+x+y. Return
  1838.         current value if None is given.'''
  1839.         return self.tk.call('wm', 'geometry', self._w, newGeometry)
  1840.  
  1841.     geometry = wm_geometry
  1842.     
  1843.     def wm_grid(self, baseWidth = None, baseHeight = None, widthInc = None, heightInc = None):
  1844.         '''Instruct the window manager that this widget shall only be
  1845.         resized on grid boundaries. WIDTHINC and HEIGHTINC are the width and
  1846.         height of a grid unit in pixels. BASEWIDTH and BASEHEIGHT are the
  1847.         number of grid units requested in Tk_GeometryRequest.'''
  1848.         return self._getints(self.tk.call('wm', 'grid', self._w, baseWidth, baseHeight, widthInc, heightInc))
  1849.  
  1850.     grid = wm_grid
  1851.     
  1852.     def wm_group(self, pathName = None):
  1853.         '''Set the group leader widgets for related widgets to PATHNAME. Return
  1854.         the group leader of this widget if None is given.'''
  1855.         return self.tk.call('wm', 'group', self._w, pathName)
  1856.  
  1857.     group = wm_group
  1858.     
  1859.     def wm_iconbitmap(self, bitmap = None, default = None):
  1860.         """Set bitmap for the iconified widget to BITMAP. Return
  1861.         the bitmap if None is given.
  1862.  
  1863.         Under Windows, the DEFAULT parameter can be used to set the icon
  1864.         for the widget and any descendents that don't have an icon set
  1865.         explicitly.  DEFAULT can be the relative path to a .ico file
  1866.         (example: root.iconbitmap(default='myicon.ico') ).  See Tk
  1867.         documentation for more information."""
  1868.         if default:
  1869.             return self.tk.call('wm', 'iconbitmap', self._w, '-default', default)
  1870.         else:
  1871.             return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
  1872.  
  1873.     iconbitmap = wm_iconbitmap
  1874.     
  1875.     def wm_iconify(self):
  1876.         '''Display widget as icon.'''
  1877.         return self.tk.call('wm', 'iconify', self._w)
  1878.  
  1879.     iconify = wm_iconify
  1880.     
  1881.     def wm_iconmask(self, bitmap = None):
  1882.         '''Set mask for the icon bitmap of this widget. Return the
  1883.         mask if None is given.'''
  1884.         return self.tk.call('wm', 'iconmask', self._w, bitmap)
  1885.  
  1886.     iconmask = wm_iconmask
  1887.     
  1888.     def wm_iconname(self, newName = None):
  1889.         '''Set the name of the icon for this widget. Return the name if
  1890.         None is given.'''
  1891.         return self.tk.call('wm', 'iconname', self._w, newName)
  1892.  
  1893.     iconname = wm_iconname
  1894.     
  1895.     def wm_iconposition(self, x = None, y = None):
  1896.         '''Set the position of the icon of this widget to X and Y. Return
  1897.         a tuple of the current values of X and X if None is given.'''
  1898.         return self._getints(self.tk.call('wm', 'iconposition', self._w, x, y))
  1899.  
  1900.     iconposition = wm_iconposition
  1901.     
  1902.     def wm_iconwindow(self, pathName = None):
  1903.         '''Set widget PATHNAME to be displayed instead of icon. Return the current
  1904.         value if None is given.'''
  1905.         return self.tk.call('wm', 'iconwindow', self._w, pathName)
  1906.  
  1907.     iconwindow = wm_iconwindow
  1908.     
  1909.     def wm_maxsize(self, width = None, height = None):
  1910.         '''Set max WIDTH and HEIGHT for this widget. If the window is gridded
  1911.         the values are given in grid units. Return the current values if None
  1912.         is given.'''
  1913.         return self._getints(self.tk.call('wm', 'maxsize', self._w, width, height))
  1914.  
  1915.     maxsize = wm_maxsize
  1916.     
  1917.     def wm_minsize(self, width = None, height = None):
  1918.         '''Set min WIDTH and HEIGHT for this widget. If the window is gridded
  1919.         the values are given in grid units. Return the current values if None
  1920.         is given.'''
  1921.         return self._getints(self.tk.call('wm', 'minsize', self._w, width, height))
  1922.  
  1923.     minsize = wm_minsize
  1924.     
  1925.     def wm_overrideredirect(self, boolean = None):
  1926.         '''Instruct the window manager to ignore this widget
  1927.         if BOOLEAN is given with 1. Return the current value if None
  1928.         is given.'''
  1929.         return self._getboolean(self.tk.call('wm', 'overrideredirect', self._w, boolean))
  1930.  
  1931.     overrideredirect = wm_overrideredirect
  1932.     
  1933.     def wm_positionfrom(self, who = None):
  1934.         '''Instruct the window manager that the position of this widget shall
  1935.         be defined by the user if WHO is "user", and by its own policy if WHO is
  1936.         "program".'''
  1937.         return self.tk.call('wm', 'positionfrom', self._w, who)
  1938.  
  1939.     positionfrom = wm_positionfrom
  1940.     
  1941.     def wm_protocol(self, name = None, func = None):
  1942.         '''Bind function FUNC to command NAME for this widget.
  1943.         Return the function bound to NAME if None is given. NAME could be
  1944.         e.g. "WM_SAVE_YOURSELF" or "WM_DELETE_WINDOW".'''
  1945.         if callable(func):
  1946.             command = self._register(func)
  1947.         else:
  1948.             command = func
  1949.         return self.tk.call('wm', 'protocol', self._w, name, command)
  1950.  
  1951.     protocol = wm_protocol
  1952.     
  1953.     def wm_resizable(self, width = None, height = None):
  1954.         '''Instruct the window manager whether this width can be resized
  1955.         in WIDTH or HEIGHT. Both values are boolean values.'''
  1956.         return self.tk.call('wm', 'resizable', self._w, width, height)
  1957.  
  1958.     resizable = wm_resizable
  1959.     
  1960.     def wm_sizefrom(self, who = None):
  1961.         '''Instruct the window manager that the size of this widget shall
  1962.         be defined by the user if WHO is "user", and by its own policy if WHO is
  1963.         "program".'''
  1964.         return self.tk.call('wm', 'sizefrom', self._w, who)
  1965.  
  1966.     sizefrom = wm_sizefrom
  1967.     
  1968.     def wm_state(self, newstate = None):
  1969.         '''Query or set the state of this widget as one of normal, icon,
  1970.         iconic (see wm_iconwindow), withdrawn, or zoomed (Windows only).'''
  1971.         return self.tk.call('wm', 'state', self._w, newstate)
  1972.  
  1973.     state = wm_state
  1974.     
  1975.     def wm_title(self, string = None):
  1976.         '''Set the title of this widget.'''
  1977.         return self.tk.call('wm', 'title', self._w, string)
  1978.  
  1979.     title = wm_title
  1980.     
  1981.     def wm_transient(self, master = None):
  1982.         '''Instruct the window manager that this widget is transient
  1983.         with regard to widget MASTER.'''
  1984.         return self.tk.call('wm', 'transient', self._w, master)
  1985.  
  1986.     transient = wm_transient
  1987.     
  1988.     def wm_withdraw(self):
  1989.         '''Withdraw this widget from the screen such that it is unmapped
  1990.         and forgotten by the window manager. Re-draw it with wm_deiconify.'''
  1991.         return self.tk.call('wm', 'withdraw', self._w)
  1992.  
  1993.     withdraw = wm_withdraw
  1994.  
  1995.  
  1996. class Tk(Misc, Wm):
  1997.     '''Toplevel widget of Tk which represents mostly the main window
  1998.     of an appliation. It has an associated Tcl interpreter.'''
  1999.     _w = '.'
  2000.     
  2001.     def __init__(self, screenName = None, baseName = None, className = 'Tk', useTk = 1, sync = 0, use = None):
  2002.         '''Return a new Toplevel widget on screen SCREENNAME. A new Tcl interpreter will
  2003.         be created. BASENAME will be used for the identification of the profile file (see
  2004.         readprofile).
  2005.         It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME
  2006.         is the name of the widget class.'''
  2007.         self.master = None
  2008.         self.children = { }
  2009.         self._tkloaded = 0
  2010.         self.tk = None
  2011.         if baseName is None:
  2012.             import sys
  2013.             import os
  2014.             baseName = os.path.basename(sys.argv[0])
  2015.             (baseName, ext) = os.path.splitext(baseName)
  2016.             if ext not in ('.py', '.pyc', '.pyo'):
  2017.                 baseName = baseName + ext
  2018.             
  2019.         
  2020.         interactive = 0
  2021.         self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
  2022.         if useTk:
  2023.             self._loadtk()
  2024.         
  2025.         self.readprofile(baseName, className)
  2026.  
  2027.     
  2028.     def loadtk(self):
  2029.         if not self._tkloaded:
  2030.             self.tk.loadtk()
  2031.             self._loadtk()
  2032.         
  2033.  
  2034.     
  2035.     def _loadtk(self):
  2036.         global _default_root
  2037.         self._tkloaded = 1
  2038.         if _MacOS and hasattr(_MacOS, 'SchedParams'):
  2039.             _MacOS.SchedParams(1, 0)
  2040.             self.update()
  2041.         
  2042.         tk_version = self.tk.getvar('tk_version')
  2043.         if tk_version != _tkinter.TK_VERSION:
  2044.             raise RuntimeError, "tk.h version (%s) doesn't match libtk.a version (%s)" % (_tkinter.TK_VERSION, tk_version)
  2045.         
  2046.         tcl_version = str(self.tk.getvar('tcl_version'))
  2047.         if tcl_version != _tkinter.TCL_VERSION:
  2048.             raise RuntimeError, "tcl.h version (%s) doesn't match libtcl.a version (%s)" % (_tkinter.TCL_VERSION, tcl_version)
  2049.         
  2050.         if TkVersion < 4:
  2051.             raise RuntimeError, 'Tk 4.0 or higher is required; found Tk %s' % str(TkVersion)
  2052.         
  2053.         if self._tclCommands is None:
  2054.             self._tclCommands = []
  2055.         
  2056.         self.tk.createcommand('tkerror', _tkerror)
  2057.         self.tk.createcommand('exit', _exit)
  2058.         self._tclCommands.append('tkerror')
  2059.         self._tclCommands.append('exit')
  2060.         if _support_default_root and not _default_root:
  2061.             _default_root = self
  2062.         
  2063.         self.protocol('WM_DELETE_WINDOW', self.destroy)
  2064.  
  2065.     
  2066.     def destroy(self):
  2067.         '''Destroy this and all descendants widgets. This will
  2068.         end the application of this Tcl interpreter.'''
  2069.         global _default_root
  2070.         for c in self.children.values():
  2071.             c.destroy()
  2072.         
  2073.         self.tk.call('destroy', self._w)
  2074.         Misc.destroy(self)
  2075.         if _support_default_root and _default_root is self:
  2076.             _default_root = None
  2077.         
  2078.  
  2079.     
  2080.     def readprofile(self, baseName, className):
  2081.         '''Internal function. It reads BASENAME.tcl and CLASSNAME.tcl into
  2082.         the Tcl Interpreter and calls execfile on BASENAME.py and CLASSNAME.py if
  2083.         such a file exists in the home directory.'''
  2084.         import os
  2085.         if os.environ.has_key('HOME'):
  2086.             home = os.environ['HOME']
  2087.         else:
  2088.             home = os.curdir
  2089.         class_tcl = os.path.join(home, '.%s.tcl' % className)
  2090.         class_py = os.path.join(home, '.%s.py' % className)
  2091.         base_tcl = os.path.join(home, '.%s.tcl' % baseName)
  2092.         base_py = os.path.join(home, '.%s.py' % baseName)
  2093.         dir = {
  2094.             'self': self }
  2095.         exec 'from Tkinter import *' in dir
  2096.         if os.path.isfile(class_tcl):
  2097.             self.tk.call('source', class_tcl)
  2098.         
  2099.         if os.path.isfile(class_py):
  2100.             execfile(class_py, dir)
  2101.         
  2102.         if os.path.isfile(base_tcl):
  2103.             self.tk.call('source', base_tcl)
  2104.         
  2105.         if os.path.isfile(base_py):
  2106.             execfile(base_py, dir)
  2107.         
  2108.  
  2109.     
  2110.     def report_callback_exception(self, exc, val, tb):
  2111.         '''Internal function. It reports exception on sys.stderr.'''
  2112.         import traceback
  2113.         import sys
  2114.         sys.stderr.write('Exception in Tkinter callback\n')
  2115.         sys.last_type = exc
  2116.         sys.last_value = val
  2117.         sys.last_traceback = tb
  2118.         traceback.print_exception(exc, val, tb)
  2119.  
  2120.     
  2121.     def __getattr__(self, attr):
  2122.         '''Delegate attribute access to the interpreter object'''
  2123.         return getattr(self.tk, attr)
  2124.  
  2125.  
  2126.  
  2127. def Tcl(screenName = None, baseName = None, className = 'Tk', useTk = 0):
  2128.     return Tk(screenName, baseName, className, useTk)
  2129.  
  2130.  
  2131. class Pack:
  2132.     '''Geometry manager Pack.
  2133.  
  2134.     Base class to use the methods pack_* in every widget.'''
  2135.     
  2136.     def pack_configure(self, cnf = { }, **kw):
  2137.         '''Pack a widget in the parent widget. Use as options:
  2138.         after=widget - pack it after you have packed widget
  2139.         anchor=NSEW (or subset) - position widget according to
  2140.                                   given direction
  2141.                 before=widget - pack it before you will pack widget
  2142.         expand=bool - expand widget if parent size grows
  2143.         fill=NONE or X or Y or BOTH - fill widget if widget grows
  2144.         in=master - use master to contain this widget
  2145.         ipadx=amount - add internal padding in x direction
  2146.         ipady=amount - add internal padding in y direction
  2147.         padx=amount - add padding in x direction
  2148.         pady=amount - add padding in y direction
  2149.         side=TOP or BOTTOM or LEFT or RIGHT -  where to add this widget.
  2150.         '''
  2151.         self.tk.call(('pack', 'configure', self._w) + self._options(cnf, kw))
  2152.  
  2153.     pack = configure = config = pack_configure
  2154.     
  2155.     def pack_forget(self):
  2156.         '''Unmap this widget and do not use it for the packing order.'''
  2157.         self.tk.call('pack', 'forget', self._w)
  2158.  
  2159.     forget = pack_forget
  2160.     
  2161.     def pack_info(self):
  2162.         '''Return information about the packing options
  2163.         for this widget.'''
  2164.         words = self.tk.splitlist(self.tk.call('pack', 'info', self._w))
  2165.         dict = { }
  2166.         for i in range(0, len(words), 2):
  2167.             key = words[i][1:]
  2168.             value = words[i + 1]
  2169.             if value[:1] == '.':
  2170.                 value = self._nametowidget(value)
  2171.             
  2172.             dict[key] = value
  2173.         
  2174.         return dict
  2175.  
  2176.     info = pack_info
  2177.     propagate = pack_propagate = Misc.pack_propagate
  2178.     slaves = pack_slaves = Misc.pack_slaves
  2179.  
  2180.  
  2181. class Place:
  2182.     '''Geometry manager Place.
  2183.  
  2184.     Base class to use the methods place_* in every widget.'''
  2185.     
  2186.     def place_configure(self, cnf = { }, **kw):
  2187.         '''Place a widget in the parent widget. Use as options:
  2188.         in=master - master relative to which the widget is placed.
  2189.         x=amount - locate anchor of this widget at position x of master
  2190.         y=amount - locate anchor of this widget at position y of master
  2191.         relx=amount - locate anchor of this widget between 0.0 and 1.0
  2192.                       relative to width of master (1.0 is right edge)
  2193.             rely=amount - locate anchor of this widget between 0.0 and 1.0
  2194.                       relative to height of master (1.0 is bottom edge)
  2195.             anchor=NSEW (or subset) - position anchor according to given direction
  2196.         width=amount - width of this widget in pixel
  2197.         height=amount - height of this widget in pixel
  2198.         relwidth=amount - width of this widget between 0.0 and 1.0
  2199.                           relative to width of master (1.0 is the same width
  2200.                   as the master)
  2201.             relheight=amount - height of this widget between 0.0 and 1.0
  2202.                            relative to height of master (1.0 is the same
  2203.                    height as the master)
  2204.             bordermode="inside" or "outside" - whether to take border width of master widget
  2205.                                                into account
  2206.             '''
  2207.         for k in [
  2208.             'in_']:
  2209.             if kw.has_key(k):
  2210.                 kw[k[:-1]] = kw[k]
  2211.                 del kw[k]
  2212.                 continue
  2213.         
  2214.         self.tk.call(('place', 'configure', self._w) + self._options(cnf, kw))
  2215.  
  2216.     place = configure = config = place_configure
  2217.     
  2218.     def place_forget(self):
  2219.         '''Unmap this widget.'''
  2220.         self.tk.call('place', 'forget', self._w)
  2221.  
  2222.     forget = place_forget
  2223.     
  2224.     def place_info(self):
  2225.         '''Return information about the placing options
  2226.         for this widget.'''
  2227.         words = self.tk.splitlist(self.tk.call('place', 'info', self._w))
  2228.         dict = { }
  2229.         for i in range(0, len(words), 2):
  2230.             key = words[i][1:]
  2231.             value = words[i + 1]
  2232.             if value[:1] == '.':
  2233.                 value = self._nametowidget(value)
  2234.             
  2235.             dict[key] = value
  2236.         
  2237.         return dict
  2238.  
  2239.     info = place_info
  2240.     slaves = place_slaves = Misc.place_slaves
  2241.  
  2242.  
  2243. class Grid:
  2244.     '''Geometry manager Grid.
  2245.  
  2246.     Base class to use the methods grid_* in every widget.'''
  2247.     
  2248.     def grid_configure(self, cnf = { }, **kw):
  2249.         '''Position a widget in the parent widget in a grid. Use as options:
  2250.         column=number - use cell identified with given column (starting with 0)
  2251.         columnspan=number - this widget will span several columns
  2252.         in=master - use master to contain this widget
  2253.         ipadx=amount - add internal padding in x direction
  2254.         ipady=amount - add internal padding in y direction
  2255.         padx=amount - add padding in x direction
  2256.         pady=amount - add padding in y direction
  2257.         row=number - use cell identified with given row (starting with 0)
  2258.         rowspan=number - this widget will span several rows
  2259.         sticky=NSEW - if cell is larger on which sides will this
  2260.                       widget stick to the cell boundary
  2261.         '''
  2262.         self.tk.call(('grid', 'configure', self._w) + self._options(cnf, kw))
  2263.  
  2264.     grid = configure = config = grid_configure
  2265.     bbox = grid_bbox = Misc.grid_bbox
  2266.     columnconfigure = grid_columnconfigure = Misc.grid_columnconfigure
  2267.     
  2268.     def grid_forget(self):
  2269.         '''Unmap this widget.'''
  2270.         self.tk.call('grid', 'forget', self._w)
  2271.  
  2272.     forget = grid_forget
  2273.     
  2274.     def grid_remove(self):
  2275.         '''Unmap this widget but remember the grid options.'''
  2276.         self.tk.call('grid', 'remove', self._w)
  2277.  
  2278.     
  2279.     def grid_info(self):
  2280.         '''Return information about the options
  2281.         for positioning this widget in a grid.'''
  2282.         words = self.tk.splitlist(self.tk.call('grid', 'info', self._w))
  2283.         dict = { }
  2284.         for i in range(0, len(words), 2):
  2285.             key = words[i][1:]
  2286.             value = words[i + 1]
  2287.             if value[:1] == '.':
  2288.                 value = self._nametowidget(value)
  2289.             
  2290.             dict[key] = value
  2291.         
  2292.         return dict
  2293.  
  2294.     info = grid_info
  2295.     location = grid_location = Misc.grid_location
  2296.     propagate = grid_propagate = Misc.grid_propagate
  2297.     rowconfigure = grid_rowconfigure = Misc.grid_rowconfigure
  2298.     size = grid_size = Misc.grid_size
  2299.     slaves = grid_slaves = Misc.grid_slaves
  2300.  
  2301.  
  2302. class BaseWidget(Misc):
  2303.     '''Internal class.'''
  2304.     
  2305.     def _setup(self, master, cnf):
  2306.         '''Internal function. Sets up information about children.'''
  2307.         global _default_root
  2308.         if _support_default_root:
  2309.             if not master:
  2310.                 if not _default_root:
  2311.                     _default_root = Tk()
  2312.                 
  2313.                 master = _default_root
  2314.             
  2315.         
  2316.         self.master = master
  2317.         self.tk = master.tk
  2318.         name = None
  2319.         if cnf.has_key('name'):
  2320.             name = cnf['name']
  2321.             del cnf['name']
  2322.         
  2323.         if not name:
  2324.             name = repr(id(self))
  2325.         
  2326.         self._name = name
  2327.         if master._w == '.':
  2328.             self._w = '.' + name
  2329.         else:
  2330.             self._w = master._w + '.' + name
  2331.         self.children = { }
  2332.         if self.master.children.has_key(self._name):
  2333.             self.master.children[self._name].destroy()
  2334.         
  2335.         self.master.children[self._name] = self
  2336.  
  2337.     
  2338.     def __init__(self, master, widgetName, cnf = { }, kw = { }, extra = ()):
  2339.         '''Construct a widget with the parent widget MASTER, a name WIDGETNAME
  2340.         and appropriate options.'''
  2341.         if kw:
  2342.             cnf = _cnfmerge((cnf, kw))
  2343.         
  2344.         self.widgetName = widgetName
  2345.         BaseWidget._setup(self, master, cnf)
  2346.         classes = []
  2347.         for k in cnf.keys():
  2348.             if type(k) is ClassType:
  2349.                 classes.append((k, cnf[k]))
  2350.                 del cnf[k]
  2351.                 continue
  2352.         
  2353.         self.tk.call((widgetName, self._w) + extra + self._options(cnf))
  2354.         for k, v in classes:
  2355.             k.configure(self, v)
  2356.         
  2357.  
  2358.     
  2359.     def destroy(self):
  2360.         '''Destroy this and all descendants widgets.'''
  2361.         for c in self.children.values():
  2362.             c.destroy()
  2363.         
  2364.         self.tk.call('destroy', self._w)
  2365.         if self.master.children.has_key(self._name):
  2366.             del self.master.children[self._name]
  2367.         
  2368.         Misc.destroy(self)
  2369.  
  2370.     
  2371.     def _do(self, name, args = ()):
  2372.         return self.tk.call((self._w, name) + args)
  2373.  
  2374.  
  2375.  
  2376. class Widget(BaseWidget, Pack, Place, Grid):
  2377.     '''Internal class.
  2378.  
  2379.     Base class for a widget which can be positioned with the geometry managers
  2380.     Pack, Place or Grid.'''
  2381.     pass
  2382.  
  2383.  
  2384. class Toplevel(BaseWidget, Wm):
  2385.     '''Toplevel widget, e.g. for dialogs.'''
  2386.     
  2387.     def __init__(self, master = None, cnf = { }, **kw):
  2388.         '''Construct a toplevel widget with the parent MASTER.
  2389.  
  2390.         Valid resource names: background, bd, bg, borderwidth, class,
  2391.         colormap, container, cursor, height, highlightbackground,
  2392.         highlightcolor, highlightthickness, menu, relief, screen, takefocus,
  2393.         use, visual, width.'''
  2394.         if kw:
  2395.             cnf = _cnfmerge((cnf, kw))
  2396.         
  2397.         extra = ()
  2398.         for wmkey in [
  2399.             'screen',
  2400.             'class_',
  2401.             'class',
  2402.             'visual',
  2403.             'colormap']:
  2404.             if cnf.has_key(wmkey):
  2405.                 val = cnf[wmkey]
  2406.                 if wmkey[-1] == '_':
  2407.                     opt = '-' + wmkey[:-1]
  2408.                 else:
  2409.                     opt = '-' + wmkey
  2410.                 extra = extra + (opt, val)
  2411.                 del cnf[wmkey]
  2412.                 continue
  2413.         
  2414.         BaseWidget.__init__(self, master, 'toplevel', cnf, { }, extra)
  2415.         root = self._root()
  2416.         self.iconname(root.iconname())
  2417.         self.title(root.title())
  2418.         self.protocol('WM_DELETE_WINDOW', self.destroy)
  2419.  
  2420.  
  2421.  
  2422. class Button(Widget):
  2423.     '''Button widget.'''
  2424.     
  2425.     def __init__(self, master = None, cnf = { }, **kw):
  2426.         '''Construct a button widget with the parent MASTER.
  2427.  
  2428.         STANDARD OPTIONS
  2429.  
  2430.             activebackground, activeforeground, anchor,
  2431.             background, bitmap, borderwidth, cursor,
  2432.             disabledforeground, font, foreground
  2433.             highlightbackground, highlightcolor,
  2434.             highlightthickness, image, justify,
  2435.             padx, pady, relief, repeatdelay,
  2436.             repeatinterval, takefocus, text,
  2437.             textvariable, underline, wraplength
  2438.  
  2439.         WIDGET-SPECIFIC OPTIONS
  2440.  
  2441.             command, compound, default, height,
  2442.             overrelief, state, width
  2443.         '''
  2444.         Widget.__init__(self, master, 'button', cnf, kw)
  2445.  
  2446.     
  2447.     def tkButtonEnter(self, *dummy):
  2448.         self.tk.call('tkButtonEnter', self._w)
  2449.  
  2450.     
  2451.     def tkButtonLeave(self, *dummy):
  2452.         self.tk.call('tkButtonLeave', self._w)
  2453.  
  2454.     
  2455.     def tkButtonDown(self, *dummy):
  2456.         self.tk.call('tkButtonDown', self._w)
  2457.  
  2458.     
  2459.     def tkButtonUp(self, *dummy):
  2460.         self.tk.call('tkButtonUp', self._w)
  2461.  
  2462.     
  2463.     def tkButtonInvoke(self, *dummy):
  2464.         self.tk.call('tkButtonInvoke', self._w)
  2465.  
  2466.     
  2467.     def flash(self):
  2468.         """Flash the button.
  2469.  
  2470.         This is accomplished by redisplaying
  2471.         the button several times, alternating between active and
  2472.         normal colors. At the end of the flash the button is left
  2473.         in the same normal/active state as when the command was
  2474.         invoked. This command is ignored if the button's state is
  2475.         disabled.
  2476.         """
  2477.         self.tk.call(self._w, 'flash')
  2478.  
  2479.     
  2480.     def invoke(self):
  2481.         """Invoke the command associated with the button.
  2482.  
  2483.         The return value is the return value from the command,
  2484.         or an empty string if there is no command associated with
  2485.         the button. This command is ignored if the button's state
  2486.         is disabled.
  2487.         """
  2488.         return self.tk.call(self._w, 'invoke')
  2489.  
  2490.  
  2491.  
  2492. def AtEnd():
  2493.     return 'end'
  2494.  
  2495.  
  2496. def AtInsert(*args):
  2497.     s = 'insert'
  2498.     for a in args:
  2499.         if a:
  2500.             s = s + ' ' + a
  2501.             continue
  2502.     
  2503.     return s
  2504.  
  2505.  
  2506. def AtSelFirst():
  2507.     return 'sel.first'
  2508.  
  2509.  
  2510. def AtSelLast():
  2511.     return 'sel.last'
  2512.  
  2513.  
  2514. def At(x, y = None):
  2515.     if y is None:
  2516.         return '@%r' % (x,)
  2517.     else:
  2518.         return '@%r,%r' % (x, y)
  2519.  
  2520.  
  2521. class Canvas(Widget):
  2522.     '''Canvas widget to display graphical elements like lines or text.'''
  2523.     
  2524.     def __init__(self, master = None, cnf = { }, **kw):
  2525.         '''Construct a canvas widget with the parent MASTER.
  2526.  
  2527.         Valid resource names: background, bd, bg, borderwidth, closeenough,
  2528.         confine, cursor, height, highlightbackground, highlightcolor,
  2529.         highlightthickness, insertbackground, insertborderwidth,
  2530.         insertofftime, insertontime, insertwidth, offset, relief,
  2531.         scrollregion, selectbackground, selectborderwidth, selectforeground,
  2532.         state, takefocus, width, xscrollcommand, xscrollincrement,
  2533.         yscrollcommand, yscrollincrement.'''
  2534.         Widget.__init__(self, master, 'canvas', cnf, kw)
  2535.  
  2536.     
  2537.     def addtag(self, *args):
  2538.         '''Internal function.'''
  2539.         self.tk.call((self._w, 'addtag') + args)
  2540.  
  2541.     
  2542.     def addtag_above(self, newtag, tagOrId):
  2543.         '''Add tag NEWTAG to all items above TAGORID.'''
  2544.         self.addtag(newtag, 'above', tagOrId)
  2545.  
  2546.     
  2547.     def addtag_all(self, newtag):
  2548.         '''Add tag NEWTAG to all items.'''
  2549.         self.addtag(newtag, 'all')
  2550.  
  2551.     
  2552.     def addtag_below(self, newtag, tagOrId):
  2553.         '''Add tag NEWTAG to all items below TAGORID.'''
  2554.         self.addtag(newtag, 'below', tagOrId)
  2555.  
  2556.     
  2557.     def addtag_closest(self, newtag, x, y, halo = None, start = None):
  2558.         '''Add tag NEWTAG to item which is closest to pixel at X, Y.
  2559.         If several match take the top-most.
  2560.         All items closer than HALO are considered overlapping (all are
  2561.         closests). If START is specified the next below this tag is taken.'''
  2562.         self.addtag(newtag, 'closest', x, y, halo, start)
  2563.  
  2564.     
  2565.     def addtag_enclosed(self, newtag, x1, y1, x2, y2):
  2566.         '''Add tag NEWTAG to all items in the rectangle defined
  2567.         by X1,Y1,X2,Y2.'''
  2568.         self.addtag(newtag, 'enclosed', x1, y1, x2, y2)
  2569.  
  2570.     
  2571.     def addtag_overlapping(self, newtag, x1, y1, x2, y2):
  2572.         '''Add tag NEWTAG to all items which overlap the rectangle
  2573.         defined by X1,Y1,X2,Y2.'''
  2574.         self.addtag(newtag, 'overlapping', x1, y1, x2, y2)
  2575.  
  2576.     
  2577.     def addtag_withtag(self, newtag, tagOrId):
  2578.         '''Add tag NEWTAG to all items with TAGORID.'''
  2579.         self.addtag(newtag, 'withtag', tagOrId)
  2580.  
  2581.     
  2582.     def bbox(self, *args):
  2583.         '''Return a tuple of X1,Y1,X2,Y2 coordinates for a rectangle
  2584.         which encloses all items with tags specified as arguments.'''
  2585.         if not self._getints(self.tk.call((self._w, 'bbox') + args)):
  2586.             pass
  2587.  
  2588.     
  2589.     def tag_unbind(self, tagOrId, sequence, funcid = None):
  2590.         '''Unbind for all items with TAGORID for event SEQUENCE  the
  2591.         function identified with FUNCID.'''
  2592.         self.tk.call(self._w, 'bind', tagOrId, sequence, '')
  2593.         if funcid:
  2594.             self.deletecommand(funcid)
  2595.         
  2596.  
  2597.     
  2598.     def tag_bind(self, tagOrId, sequence = None, func = None, add = None):
  2599.         '''Bind to all items with TAGORID at event SEQUENCE a call to function FUNC.
  2600.  
  2601.         An additional boolean parameter ADD specifies whether FUNC will be
  2602.         called additionally to the other bound function or whether it will
  2603.         replace the previous function. See bind for the return value.'''
  2604.         return self._bind((self._w, 'bind', tagOrId), sequence, func, add)
  2605.  
  2606.     
  2607.     def canvasx(self, screenx, gridspacing = None):
  2608.         '''Return the canvas x coordinate of pixel position SCREENX rounded
  2609.         to nearest multiple of GRIDSPACING units.'''
  2610.         return getdouble(self.tk.call(self._w, 'canvasx', screenx, gridspacing))
  2611.  
  2612.     
  2613.     def canvasy(self, screeny, gridspacing = None):
  2614.         '''Return the canvas y coordinate of pixel position SCREENY rounded
  2615.         to nearest multiple of GRIDSPACING units.'''
  2616.         return getdouble(self.tk.call(self._w, 'canvasy', screeny, gridspacing))
  2617.  
  2618.     
  2619.     def coords(self, *args):
  2620.         '''Return a list of coordinates for the item given in ARGS.'''
  2621.         return map(getdouble, self.tk.splitlist(self.tk.call((self._w, 'coords') + args)))
  2622.  
  2623.     
  2624.     def _create(self, itemType, args, kw):
  2625.         '''Internal function.'''
  2626.         args = _flatten(args)
  2627.         cnf = args[-1]
  2628.         if type(cnf) in (DictionaryType, TupleType):
  2629.             args = args[:-1]
  2630.         else:
  2631.             cnf = { }
  2632.         return getint(self.tk.call(self._w, 'create', itemType, *args + self._options(cnf, kw)))
  2633.  
  2634.     
  2635.     def create_arc(self, *args, **kw):
  2636.         '''Create arc shaped region with coordinates x1,y1,x2,y2.'''
  2637.         return self._create('arc', args, kw)
  2638.  
  2639.     
  2640.     def create_bitmap(self, *args, **kw):
  2641.         '''Create bitmap with coordinates x1,y1.'''
  2642.         return self._create('bitmap', args, kw)
  2643.  
  2644.     
  2645.     def create_image(self, *args, **kw):
  2646.         '''Create image item with coordinates x1,y1.'''
  2647.         return self._create('image', args, kw)
  2648.  
  2649.     
  2650.     def create_line(self, *args, **kw):
  2651.         '''Create line with coordinates x1,y1,...,xn,yn.'''
  2652.         return self._create('line', args, kw)
  2653.  
  2654.     
  2655.     def create_oval(self, *args, **kw):
  2656.         '''Create oval with coordinates x1,y1,x2,y2.'''
  2657.         return self._create('oval', args, kw)
  2658.  
  2659.     
  2660.     def create_polygon(self, *args, **kw):
  2661.         '''Create polygon with coordinates x1,y1,...,xn,yn.'''
  2662.         return self._create('polygon', args, kw)
  2663.  
  2664.     
  2665.     def create_rectangle(self, *args, **kw):
  2666.         '''Create rectangle with coordinates x1,y1,x2,y2.'''
  2667.         return self._create('rectangle', args, kw)
  2668.  
  2669.     
  2670.     def create_text(self, *args, **kw):
  2671.         '''Create text with coordinates x1,y1.'''
  2672.         return self._create('text', args, kw)
  2673.  
  2674.     
  2675.     def create_window(self, *args, **kw):
  2676.         '''Create window with coordinates x1,y1,x2,y2.'''
  2677.         return self._create('window', args, kw)
  2678.  
  2679.     
  2680.     def dchars(self, *args):
  2681.         '''Delete characters of text items identified by tag or id in ARGS (possibly
  2682.         several times) from FIRST to LAST character (including).'''
  2683.         self.tk.call((self._w, 'dchars') + args)
  2684.  
  2685.     
  2686.     def delete(self, *args):
  2687.         '''Delete items identified by all tag or ids contained in ARGS.'''
  2688.         self.tk.call((self._w, 'delete') + args)
  2689.  
  2690.     
  2691.     def dtag(self, *args):
  2692.         '''Delete tag or id given as last arguments in ARGS from items
  2693.         identified by first argument in ARGS.'''
  2694.         self.tk.call((self._w, 'dtag') + args)
  2695.  
  2696.     
  2697.     def find(self, *args):
  2698.         '''Internal function.'''
  2699.         if not self._getints(self.tk.call((self._w, 'find') + args)):
  2700.             pass
  2701.         return ()
  2702.  
  2703.     
  2704.     def find_above(self, tagOrId):
  2705.         '''Return items above TAGORID.'''
  2706.         return self.find('above', tagOrId)
  2707.  
  2708.     
  2709.     def find_all(self):
  2710.         '''Return all items.'''
  2711.         return self.find('all')
  2712.  
  2713.     
  2714.     def find_below(self, tagOrId):
  2715.         '''Return all items below TAGORID.'''
  2716.         return self.find('below', tagOrId)
  2717.  
  2718.     
  2719.     def find_closest(self, x, y, halo = None, start = None):
  2720.         '''Return item which is closest to pixel at X, Y.
  2721.         If several match take the top-most.
  2722.         All items closer than HALO are considered overlapping (all are
  2723.         closests). If START is specified the next below this tag is taken.'''
  2724.         return self.find('closest', x, y, halo, start)
  2725.  
  2726.     
  2727.     def find_enclosed(self, x1, y1, x2, y2):
  2728.         '''Return all items in rectangle defined
  2729.         by X1,Y1,X2,Y2.'''
  2730.         return self.find('enclosed', x1, y1, x2, y2)
  2731.  
  2732.     
  2733.     def find_overlapping(self, x1, y1, x2, y2):
  2734.         '''Return all items which overlap the rectangle
  2735.         defined by X1,Y1,X2,Y2.'''
  2736.         return self.find('overlapping', x1, y1, x2, y2)
  2737.  
  2738.     
  2739.     def find_withtag(self, tagOrId):
  2740.         '''Return all items with TAGORID.'''
  2741.         return self.find('withtag', tagOrId)
  2742.  
  2743.     
  2744.     def focus(self, *args):
  2745.         '''Set focus to the first item specified in ARGS.'''
  2746.         return self.tk.call((self._w, 'focus') + args)
  2747.  
  2748.     
  2749.     def gettags(self, *args):
  2750.         '''Return tags associated with the first item specified in ARGS.'''
  2751.         return self.tk.splitlist(self.tk.call((self._w, 'gettags') + args))
  2752.  
  2753.     
  2754.     def icursor(self, *args):
  2755.         '''Set cursor at position POS in the item identified by TAGORID.
  2756.         In ARGS TAGORID must be first.'''
  2757.         self.tk.call((self._w, 'icursor') + args)
  2758.  
  2759.     
  2760.     def index(self, *args):
  2761.         '''Return position of cursor as integer in item specified in ARGS.'''
  2762.         return getint(self.tk.call((self._w, 'index') + args))
  2763.  
  2764.     
  2765.     def insert(self, *args):
  2766.         '''Insert TEXT in item TAGORID at position POS. ARGS must
  2767.         be TAGORID POS TEXT.'''
  2768.         self.tk.call((self._w, 'insert') + args)
  2769.  
  2770.     
  2771.     def itemcget(self, tagOrId, option):
  2772.         '''Return the resource value for an OPTION for item TAGORID.'''
  2773.         return self.tk.call((self._w, 'itemcget') + (tagOrId, '-' + option))
  2774.  
  2775.     
  2776.     def itemconfigure(self, tagOrId, cnf = None, **kw):
  2777.         '''Configure resources of an item TAGORID.
  2778.  
  2779.         The values for resources are specified as keyword
  2780.         arguments. To get an overview about
  2781.         the allowed keyword arguments call the method without arguments.
  2782.         '''
  2783.         return self._configure(('itemconfigure', tagOrId), cnf, kw)
  2784.  
  2785.     itemconfig = itemconfigure
  2786.     
  2787.     def tag_lower(self, *args):
  2788.         '''Lower an item TAGORID given in ARGS
  2789.         (optional below another item).'''
  2790.         self.tk.call((self._w, 'lower') + args)
  2791.  
  2792.     lower = tag_lower
  2793.     
  2794.     def move(self, *args):
  2795.         '''Move an item TAGORID given in ARGS.'''
  2796.         self.tk.call((self._w, 'move') + args)
  2797.  
  2798.     
  2799.     def postscript(self, cnf = { }, **kw):
  2800.         '''Print the contents of the canvas to a postscript
  2801.         file. Valid options: colormap, colormode, file, fontmap,
  2802.         height, pageanchor, pageheight, pagewidth, pagex, pagey,
  2803.         rotate, witdh, x, y.'''
  2804.         return self.tk.call((self._w, 'postscript') + self._options(cnf, kw))
  2805.  
  2806.     
  2807.     def tag_raise(self, *args):
  2808.         '''Raise an item TAGORID given in ARGS
  2809.         (optional above another item).'''
  2810.         self.tk.call((self._w, 'raise') + args)
  2811.  
  2812.     lift = tkraise = tag_raise
  2813.     
  2814.     def scale(self, *args):
  2815.         '''Scale item TAGORID with XORIGIN, YORIGIN, XSCALE, YSCALE.'''
  2816.         self.tk.call((self._w, 'scale') + args)
  2817.  
  2818.     
  2819.     def scan_mark(self, x, y):
  2820.         '''Remember the current X, Y coordinates.'''
  2821.         self.tk.call(self._w, 'scan', 'mark', x, y)
  2822.  
  2823.     
  2824.     def scan_dragto(self, x, y, gain = 10):
  2825.         '''Adjust the view of the canvas to GAIN times the
  2826.         difference between X and Y and the coordinates given in
  2827.         scan_mark.'''
  2828.         self.tk.call(self._w, 'scan', 'dragto', x, y, gain)
  2829.  
  2830.     
  2831.     def select_adjust(self, tagOrId, index):
  2832.         '''Adjust the end of the selection near the cursor of an item TAGORID to index.'''
  2833.         self.tk.call(self._w, 'select', 'adjust', tagOrId, index)
  2834.  
  2835.     
  2836.     def select_clear(self):
  2837.         '''Clear the selection if it is in this widget.'''
  2838.         self.tk.call(self._w, 'select', 'clear')
  2839.  
  2840.     
  2841.     def select_from(self, tagOrId, index):
  2842.         '''Set the fixed end of a selection in item TAGORID to INDEX.'''
  2843.         self.tk.call(self._w, 'select', 'from', tagOrId, index)
  2844.  
  2845.     
  2846.     def select_item(self):
  2847.         '''Return the item which has the selection.'''
  2848.         if not self.tk.call(self._w, 'select', 'item'):
  2849.             pass
  2850.  
  2851.     
  2852.     def select_to(self, tagOrId, index):
  2853.         '''Set the variable end of a selection in item TAGORID to INDEX.'''
  2854.         self.tk.call(self._w, 'select', 'to', tagOrId, index)
  2855.  
  2856.     
  2857.     def type(self, tagOrId):
  2858.         '''Return the type of the item TAGORID.'''
  2859.         if not self.tk.call(self._w, 'type', tagOrId):
  2860.             pass
  2861.  
  2862.     
  2863.     def xview(self, *args):
  2864.         '''Query and change horizontal position of the view.'''
  2865.         if not args:
  2866.             return self._getdoubles(self.tk.call(self._w, 'xview'))
  2867.         
  2868.         self.tk.call((self._w, 'xview') + args)
  2869.  
  2870.     
  2871.     def xview_moveto(self, fraction):
  2872.         '''Adjusts the view in the window so that FRACTION of the
  2873.         total width of the canvas is off-screen to the left.'''
  2874.         self.tk.call(self._w, 'xview', 'moveto', fraction)
  2875.  
  2876.     
  2877.     def xview_scroll(self, number, what):
  2878.         '''Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT).'''
  2879.         self.tk.call(self._w, 'xview', 'scroll', number, what)
  2880.  
  2881.     
  2882.     def yview(self, *args):
  2883.         '''Query and change vertical position of the view.'''
  2884.         if not args:
  2885.             return self._getdoubles(self.tk.call(self._w, 'yview'))
  2886.         
  2887.         self.tk.call((self._w, 'yview') + args)
  2888.  
  2889.     
  2890.     def yview_moveto(self, fraction):
  2891.         '''Adjusts the view in the window so that FRACTION of the
  2892.         total height of the canvas is off-screen to the top.'''
  2893.         self.tk.call(self._w, 'yview', 'moveto', fraction)
  2894.  
  2895.     
  2896.     def yview_scroll(self, number, what):
  2897.         '''Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT).'''
  2898.         self.tk.call(self._w, 'yview', 'scroll', number, what)
  2899.  
  2900.  
  2901.  
  2902. class Checkbutton(Widget):
  2903.     '''Checkbutton widget which is either in on- or off-state.'''
  2904.     
  2905.     def __init__(self, master = None, cnf = { }, **kw):
  2906.         '''Construct a checkbutton widget with the parent MASTER.
  2907.  
  2908.         Valid resource names: activebackground, activeforeground, anchor,
  2909.         background, bd, bg, bitmap, borderwidth, command, cursor,
  2910.         disabledforeground, fg, font, foreground, height,
  2911.         highlightbackground, highlightcolor, highlightthickness, image,
  2912.         indicatoron, justify, offvalue, onvalue, padx, pady, relief,
  2913.         selectcolor, selectimage, state, takefocus, text, textvariable,
  2914.         underline, variable, width, wraplength.'''
  2915.         Widget.__init__(self, master, 'checkbutton', cnf, kw)
  2916.  
  2917.     
  2918.     def deselect(self):
  2919.         '''Put the button in off-state.'''
  2920.         self.tk.call(self._w, 'deselect')
  2921.  
  2922.     
  2923.     def flash(self):
  2924.         '''Flash the button.'''
  2925.         self.tk.call(self._w, 'flash')
  2926.  
  2927.     
  2928.     def invoke(self):
  2929.         '''Toggle the button and invoke a command if given as resource.'''
  2930.         return self.tk.call(self._w, 'invoke')
  2931.  
  2932.     
  2933.     def select(self):
  2934.         '''Put the button in on-state.'''
  2935.         self.tk.call(self._w, 'select')
  2936.  
  2937.     
  2938.     def toggle(self):
  2939.         '''Toggle the button.'''
  2940.         self.tk.call(self._w, 'toggle')
  2941.  
  2942.  
  2943.  
  2944. class Entry(Widget):
  2945.     '''Entry widget which allows to display simple text.'''
  2946.     
  2947.     def __init__(self, master = None, cnf = { }, **kw):
  2948.         '''Construct an entry widget with the parent MASTER.
  2949.  
  2950.         Valid resource names: background, bd, bg, borderwidth, cursor,
  2951.         exportselection, fg, font, foreground, highlightbackground,
  2952.         highlightcolor, highlightthickness, insertbackground,
  2953.         insertborderwidth, insertofftime, insertontime, insertwidth,
  2954.         invalidcommand, invcmd, justify, relief, selectbackground,
  2955.         selectborderwidth, selectforeground, show, state, takefocus,
  2956.         textvariable, validate, validatecommand, vcmd, width,
  2957.         xscrollcommand.'''
  2958.         Widget.__init__(self, master, 'entry', cnf, kw)
  2959.  
  2960.     
  2961.     def delete(self, first, last = None):
  2962.         '''Delete text from FIRST to LAST (not included).'''
  2963.         self.tk.call(self._w, 'delete', first, last)
  2964.  
  2965.     
  2966.     def get(self):
  2967.         '''Return the text.'''
  2968.         return self.tk.call(self._w, 'get')
  2969.  
  2970.     
  2971.     def icursor(self, index):
  2972.         '''Insert cursor at INDEX.'''
  2973.         self.tk.call(self._w, 'icursor', index)
  2974.  
  2975.     
  2976.     def index(self, index):
  2977.         '''Return position of cursor.'''
  2978.         return getint(self.tk.call(self._w, 'index', index))
  2979.  
  2980.     
  2981.     def insert(self, index, string):
  2982.         '''Insert STRING at INDEX.'''
  2983.         self.tk.call(self._w, 'insert', index, string)
  2984.  
  2985.     
  2986.     def scan_mark(self, x):
  2987.         '''Remember the current X, Y coordinates.'''
  2988.         self.tk.call(self._w, 'scan', 'mark', x)
  2989.  
  2990.     
  2991.     def scan_dragto(self, x):
  2992.         '''Adjust the view of the canvas to 10 times the
  2993.         difference between X and Y and the coordinates given in
  2994.         scan_mark.'''
  2995.         self.tk.call(self._w, 'scan', 'dragto', x)
  2996.  
  2997.     
  2998.     def selection_adjust(self, index):
  2999.         '''Adjust the end of the selection near the cursor to INDEX.'''
  3000.         self.tk.call(self._w, 'selection', 'adjust', index)
  3001.  
  3002.     select_adjust = selection_adjust
  3003.     
  3004.     def selection_clear(self):
  3005.         '''Clear the selection if it is in this widget.'''
  3006.         self.tk.call(self._w, 'selection', 'clear')
  3007.  
  3008.     select_clear = selection_clear
  3009.     
  3010.     def selection_from(self, index):
  3011.         '''Set the fixed end of a selection to INDEX.'''
  3012.         self.tk.call(self._w, 'selection', 'from', index)
  3013.  
  3014.     select_from = selection_from
  3015.     
  3016.     def selection_present(self):
  3017.         '''Return whether the widget has the selection.'''
  3018.         return self.tk.getboolean(self.tk.call(self._w, 'selection', 'present'))
  3019.  
  3020.     select_present = selection_present
  3021.     
  3022.     def selection_range(self, start, end):
  3023.         '''Set the selection from START to END (not included).'''
  3024.         self.tk.call(self._w, 'selection', 'range', start, end)
  3025.  
  3026.     select_range = selection_range
  3027.     
  3028.     def selection_to(self, index):
  3029.         '''Set the variable end of a selection to INDEX.'''
  3030.         self.tk.call(self._w, 'selection', 'to', index)
  3031.  
  3032.     select_to = selection_to
  3033.     
  3034.     def xview(self, index):
  3035.         '''Query and change horizontal position of the view.'''
  3036.         self.tk.call(self._w, 'xview', index)
  3037.  
  3038.     
  3039.     def xview_moveto(self, fraction):
  3040.         '''Adjust the view in the window so that FRACTION of the
  3041.         total width of the entry is off-screen to the left.'''
  3042.         self.tk.call(self._w, 'xview', 'moveto', fraction)
  3043.  
  3044.     
  3045.     def xview_scroll(self, number, what):
  3046.         '''Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT).'''
  3047.         self.tk.call(self._w, 'xview', 'scroll', number, what)
  3048.  
  3049.  
  3050.  
  3051. class Frame(Widget):
  3052.     '''Frame widget which may contain other widgets and can have a 3D border.'''
  3053.     
  3054.     def __init__(self, master = None, cnf = { }, **kw):
  3055.         '''Construct a frame widget with the parent MASTER.
  3056.  
  3057.         Valid resource names: background, bd, bg, borderwidth, class,
  3058.         colormap, container, cursor, height, highlightbackground,
  3059.         highlightcolor, highlightthickness, relief, takefocus, visual, width.'''
  3060.         cnf = _cnfmerge((cnf, kw))
  3061.         extra = ()
  3062.         if cnf.has_key('class_'):
  3063.             extra = ('-class', cnf['class_'])
  3064.             del cnf['class_']
  3065.         elif cnf.has_key('class'):
  3066.             extra = ('-class', cnf['class'])
  3067.             del cnf['class']
  3068.         
  3069.         Widget.__init__(self, master, 'frame', cnf, { }, extra)
  3070.  
  3071.  
  3072.  
  3073. class Label(Widget):
  3074.     '''Label widget which can display text and bitmaps.'''
  3075.     
  3076.     def __init__(self, master = None, cnf = { }, **kw):
  3077.         '''Construct a label widget with the parent MASTER.
  3078.  
  3079.         STANDARD OPTIONS
  3080.  
  3081.             activebackground, activeforeground, anchor,
  3082.             background, bitmap, borderwidth, cursor,
  3083.             disabledforeground, font, foreground,
  3084.             highlightbackground, highlightcolor,
  3085.             highlightthickness, image, justify,
  3086.             padx, pady, relief, takefocus, text,
  3087.             textvariable, underline, wraplength
  3088.  
  3089.         WIDGET-SPECIFIC OPTIONS
  3090.  
  3091.             height, state, width
  3092.  
  3093.         '''
  3094.         Widget.__init__(self, master, 'label', cnf, kw)
  3095.  
  3096.  
  3097.  
  3098. class Listbox(Widget):
  3099.     '''Listbox widget which can display a list of strings.'''
  3100.     
  3101.     def __init__(self, master = None, cnf = { }, **kw):
  3102.         '''Construct a listbox widget with the parent MASTER.
  3103.  
  3104.         Valid resource names: background, bd, bg, borderwidth, cursor,
  3105.         exportselection, fg, font, foreground, height, highlightbackground,
  3106.         highlightcolor, highlightthickness, relief, selectbackground,
  3107.         selectborderwidth, selectforeground, selectmode, setgrid, takefocus,
  3108.         width, xscrollcommand, yscrollcommand, listvariable.'''
  3109.         Widget.__init__(self, master, 'listbox', cnf, kw)
  3110.  
  3111.     
  3112.     def activate(self, index):
  3113.         '''Activate item identified by INDEX.'''
  3114.         self.tk.call(self._w, 'activate', index)
  3115.  
  3116.     
  3117.     def bbox(self, *args):
  3118.         '''Return a tuple of X1,Y1,X2,Y2 coordinates for a rectangle
  3119.         which encloses the item identified by index in ARGS.'''
  3120.         if not self._getints(self.tk.call((self._w, 'bbox') + args)):
  3121.             pass
  3122.  
  3123.     
  3124.     def curselection(self):
  3125.         '''Return list of indices of currently selected item.'''
  3126.         return self.tk.splitlist(self.tk.call(self._w, 'curselection'))
  3127.  
  3128.     
  3129.     def delete(self, first, last = None):
  3130.         '''Delete items from FIRST to LAST (not included).'''
  3131.         self.tk.call(self._w, 'delete', first, last)
  3132.  
  3133.     
  3134.     def get(self, first, last = None):
  3135.         '''Get list of items from FIRST to LAST (not included).'''
  3136.         if last:
  3137.             return self.tk.splitlist(self.tk.call(self._w, 'get', first, last))
  3138.         else:
  3139.             return self.tk.call(self._w, 'get', first)
  3140.  
  3141.     
  3142.     def index(self, index):
  3143.         '''Return index of item identified with INDEX.'''
  3144.         i = self.tk.call(self._w, 'index', index)
  3145.         if i == 'none':
  3146.             return None
  3147.         
  3148.         return getint(i)
  3149.  
  3150.     
  3151.     def insert(self, index, *elements):
  3152.         '''Insert ELEMENTS at INDEX.'''
  3153.         self.tk.call((self._w, 'insert', index) + elements)
  3154.  
  3155.     
  3156.     def nearest(self, y):
  3157.         '''Get index of item which is nearest to y coordinate Y.'''
  3158.         return getint(self.tk.call(self._w, 'nearest', y))
  3159.  
  3160.     
  3161.     def scan_mark(self, x, y):
  3162.         '''Remember the current X, Y coordinates.'''
  3163.         self.tk.call(self._w, 'scan', 'mark', x, y)
  3164.  
  3165.     
  3166.     def scan_dragto(self, x, y):
  3167.         '''Adjust the view of the listbox to 10 times the
  3168.         difference between X and Y and the coordinates given in
  3169.         scan_mark.'''
  3170.         self.tk.call(self._w, 'scan', 'dragto', x, y)
  3171.  
  3172.     
  3173.     def see(self, index):
  3174.         '''Scroll such that INDEX is visible.'''
  3175.         self.tk.call(self._w, 'see', index)
  3176.  
  3177.     
  3178.     def selection_anchor(self, index):
  3179.         '''Set the fixed end oft the selection to INDEX.'''
  3180.         self.tk.call(self._w, 'selection', 'anchor', index)
  3181.  
  3182.     select_anchor = selection_anchor
  3183.     
  3184.     def selection_clear(self, first, last = None):
  3185.         '''Clear the selection from FIRST to LAST (not included).'''
  3186.         self.tk.call(self._w, 'selection', 'clear', first, last)
  3187.  
  3188.     select_clear = selection_clear
  3189.     
  3190.     def selection_includes(self, index):
  3191.         '''Return 1 if INDEX is part of the selection.'''
  3192.         return self.tk.getboolean(self.tk.call(self._w, 'selection', 'includes', index))
  3193.  
  3194.     select_includes = selection_includes
  3195.     
  3196.     def selection_set(self, first, last = None):
  3197.         '''Set the selection from FIRST to LAST (not included) without
  3198.         changing the currently selected elements.'''
  3199.         self.tk.call(self._w, 'selection', 'set', first, last)
  3200.  
  3201.     select_set = selection_set
  3202.     
  3203.     def size(self):
  3204.         '''Return the number of elements in the listbox.'''
  3205.         return getint(self.tk.call(self._w, 'size'))
  3206.  
  3207.     
  3208.     def xview(self, *what):
  3209.         '''Query and change horizontal position of the view.'''
  3210.         if not what:
  3211.             return self._getdoubles(self.tk.call(self._w, 'xview'))
  3212.         
  3213.         self.tk.call((self._w, 'xview') + what)
  3214.  
  3215.     
  3216.     def xview_moveto(self, fraction):
  3217.         '''Adjust the view in the window so that FRACTION of the
  3218.         total width of the entry is off-screen to the left.'''
  3219.         self.tk.call(self._w, 'xview', 'moveto', fraction)
  3220.  
  3221.     
  3222.     def xview_scroll(self, number, what):
  3223.         '''Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT).'''
  3224.         self.tk.call(self._w, 'xview', 'scroll', number, what)
  3225.  
  3226.     
  3227.     def yview(self, *what):
  3228.         '''Query and change vertical position of the view.'''
  3229.         if not what:
  3230.             return self._getdoubles(self.tk.call(self._w, 'yview'))
  3231.         
  3232.         self.tk.call((self._w, 'yview') + what)
  3233.  
  3234.     
  3235.     def yview_moveto(self, fraction):
  3236.         '''Adjust the view in the window so that FRACTION of the
  3237.         total width of the entry is off-screen to the top.'''
  3238.         self.tk.call(self._w, 'yview', 'moveto', fraction)
  3239.  
  3240.     
  3241.     def yview_scroll(self, number, what):
  3242.         '''Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT).'''
  3243.         self.tk.call(self._w, 'yview', 'scroll', number, what)
  3244.  
  3245.     
  3246.     def itemcget(self, index, option):
  3247.         '''Return the resource value for an ITEM and an OPTION.'''
  3248.         return self.tk.call((self._w, 'itemcget') + (index, '-' + option))
  3249.  
  3250.     
  3251.     def itemconfigure(self, index, cnf = None, **kw):
  3252.         '''Configure resources of an ITEM.
  3253.  
  3254.         The values for resources are specified as keyword arguments.
  3255.         To get an overview about the allowed keyword arguments
  3256.         call the method without arguments.
  3257.         Valid resource names: background, bg, foreground, fg,
  3258.         selectbackground, selectforeground.'''
  3259.         return self._configure(('itemconfigure', index), cnf, kw)
  3260.  
  3261.     itemconfig = itemconfigure
  3262.  
  3263.  
  3264. class Menu(Widget):
  3265.     '''Menu widget which allows to display menu bars, pull-down menus and pop-up menus.'''
  3266.     
  3267.     def __init__(self, master = None, cnf = { }, **kw):
  3268.         '''Construct menu widget with the parent MASTER.
  3269.  
  3270.         Valid resource names: activebackground, activeborderwidth,
  3271.         activeforeground, background, bd, bg, borderwidth, cursor,
  3272.         disabledforeground, fg, font, foreground, postcommand, relief,
  3273.         selectcolor, takefocus, tearoff, tearoffcommand, title, type.'''
  3274.         Widget.__init__(self, master, 'menu', cnf, kw)
  3275.  
  3276.     
  3277.     def tk_bindForTraversal(self):
  3278.         pass
  3279.  
  3280.     
  3281.     def tk_mbPost(self):
  3282.         self.tk.call('tk_mbPost', self._w)
  3283.  
  3284.     
  3285.     def tk_mbUnpost(self):
  3286.         self.tk.call('tk_mbUnpost')
  3287.  
  3288.     
  3289.     def tk_traverseToMenu(self, char):
  3290.         self.tk.call('tk_traverseToMenu', self._w, char)
  3291.  
  3292.     
  3293.     def tk_traverseWithinMenu(self, char):
  3294.         self.tk.call('tk_traverseWithinMenu', self._w, char)
  3295.  
  3296.     
  3297.     def tk_getMenuButtons(self):
  3298.         return self.tk.call('tk_getMenuButtons', self._w)
  3299.  
  3300.     
  3301.     def tk_nextMenu(self, count):
  3302.         self.tk.call('tk_nextMenu', count)
  3303.  
  3304.     
  3305.     def tk_nextMenuEntry(self, count):
  3306.         self.tk.call('tk_nextMenuEntry', count)
  3307.  
  3308.     
  3309.     def tk_invokeMenu(self):
  3310.         self.tk.call('tk_invokeMenu', self._w)
  3311.  
  3312.     
  3313.     def tk_firstMenu(self):
  3314.         self.tk.call('tk_firstMenu', self._w)
  3315.  
  3316.     
  3317.     def tk_mbButtonDown(self):
  3318.         self.tk.call('tk_mbButtonDown', self._w)
  3319.  
  3320.     
  3321.     def tk_popup(self, x, y, entry = ''):
  3322.         '''Post the menu at position X,Y with entry ENTRY.'''
  3323.         self.tk.call('tk_popup', self._w, x, y, entry)
  3324.  
  3325.     
  3326.     def activate(self, index):
  3327.         '''Activate entry at INDEX.'''
  3328.         self.tk.call(self._w, 'activate', index)
  3329.  
  3330.     
  3331.     def add(self, itemType, cnf = { }, **kw):
  3332.         '''Internal function.'''
  3333.         self.tk.call((self._w, 'add', itemType) + self._options(cnf, kw))
  3334.  
  3335.     
  3336.     def add_cascade(self, cnf = { }, **kw):
  3337.         '''Add hierarchical menu item.'''
  3338.         if not cnf:
  3339.             pass
  3340.         self.add('cascade', kw)
  3341.  
  3342.     
  3343.     def add_checkbutton(self, cnf = { }, **kw):
  3344.         '''Add checkbutton menu item.'''
  3345.         if not cnf:
  3346.             pass
  3347.         self.add('checkbutton', kw)
  3348.  
  3349.     
  3350.     def add_command(self, cnf = { }, **kw):
  3351.         '''Add command menu item.'''
  3352.         if not cnf:
  3353.             pass
  3354.         self.add('command', kw)
  3355.  
  3356.     
  3357.     def add_radiobutton(self, cnf = { }, **kw):
  3358.         '''Addd radio menu item.'''
  3359.         if not cnf:
  3360.             pass
  3361.         self.add('radiobutton', kw)
  3362.  
  3363.     
  3364.     def add_separator(self, cnf = { }, **kw):
  3365.         '''Add separator.'''
  3366.         if not cnf:
  3367.             pass
  3368.         self.add('separator', kw)
  3369.  
  3370.     
  3371.     def insert(self, index, itemType, cnf = { }, **kw):
  3372.         '''Internal function.'''
  3373.         self.tk.call((self._w, 'insert', index, itemType) + self._options(cnf, kw))
  3374.  
  3375.     
  3376.     def insert_cascade(self, index, cnf = { }, **kw):
  3377.         '''Add hierarchical menu item at INDEX.'''
  3378.         if not cnf:
  3379.             pass
  3380.         self.insert(index, 'cascade', kw)
  3381.  
  3382.     
  3383.     def insert_checkbutton(self, index, cnf = { }, **kw):
  3384.         '''Add checkbutton menu item at INDEX.'''
  3385.         if not cnf:
  3386.             pass
  3387.         self.insert(index, 'checkbutton', kw)
  3388.  
  3389.     
  3390.     def insert_command(self, index, cnf = { }, **kw):
  3391.         '''Add command menu item at INDEX.'''
  3392.         if not cnf:
  3393.             pass
  3394.         self.insert(index, 'command', kw)
  3395.  
  3396.     
  3397.     def insert_radiobutton(self, index, cnf = { }, **kw):
  3398.         '''Addd radio menu item at INDEX.'''
  3399.         if not cnf:
  3400.             pass
  3401.         self.insert(index, 'radiobutton', kw)
  3402.  
  3403.     
  3404.     def insert_separator(self, index, cnf = { }, **kw):
  3405.         '''Add separator at INDEX.'''
  3406.         if not cnf:
  3407.             pass
  3408.         self.insert(index, 'separator', kw)
  3409.  
  3410.     
  3411.     def delete(self, index1, index2 = None):
  3412.         '''Delete menu items between INDEX1 and INDEX2 (not included).'''
  3413.         self.tk.call(self._w, 'delete', index1, index2)
  3414.  
  3415.     
  3416.     def entrycget(self, index, option):
  3417.         '''Return the resource value of an menu item for OPTION at INDEX.'''
  3418.         return self.tk.call(self._w, 'entrycget', index, '-' + option)
  3419.  
  3420.     
  3421.     def entryconfigure(self, index, cnf = None, **kw):
  3422.         '''Configure a menu item at INDEX.'''
  3423.         return self._configure(('entryconfigure', index), cnf, kw)
  3424.  
  3425.     entryconfig = entryconfigure
  3426.     
  3427.     def index(self, index):
  3428.         '''Return the index of a menu item identified by INDEX.'''
  3429.         i = self.tk.call(self._w, 'index', index)
  3430.         if i == 'none':
  3431.             return None
  3432.         
  3433.         return getint(i)
  3434.  
  3435.     
  3436.     def invoke(self, index):
  3437.         '''Invoke a menu item identified by INDEX and execute
  3438.         the associated command.'''
  3439.         return self.tk.call(self._w, 'invoke', index)
  3440.  
  3441.     
  3442.     def post(self, x, y):
  3443.         '''Display a menu at position X,Y.'''
  3444.         self.tk.call(self._w, 'post', x, y)
  3445.  
  3446.     
  3447.     def type(self, index):
  3448.         '''Return the type of the menu item at INDEX.'''
  3449.         return self.tk.call(self._w, 'type', index)
  3450.  
  3451.     
  3452.     def unpost(self):
  3453.         '''Unmap a menu.'''
  3454.         self.tk.call(self._w, 'unpost')
  3455.  
  3456.     
  3457.     def yposition(self, index):
  3458.         '''Return the y-position of the topmost pixel of the menu item at INDEX.'''
  3459.         return getint(self.tk.call(self._w, 'yposition', index))
  3460.  
  3461.  
  3462.  
  3463. class Menubutton(Widget):
  3464.     '''Menubutton widget, obsolete since Tk8.0.'''
  3465.     
  3466.     def __init__(self, master = None, cnf = { }, **kw):
  3467.         Widget.__init__(self, master, 'menubutton', cnf, kw)
  3468.  
  3469.  
  3470.  
  3471. class Message(Widget):
  3472.     '''Message widget to display multiline text. Obsolete since Label does it too.'''
  3473.     
  3474.     def __init__(self, master = None, cnf = { }, **kw):
  3475.         Widget.__init__(self, master, 'message', cnf, kw)
  3476.  
  3477.  
  3478.  
  3479. class Radiobutton(Widget):
  3480.     '''Radiobutton widget which shows only one of several buttons in on-state.'''
  3481.     
  3482.     def __init__(self, master = None, cnf = { }, **kw):
  3483.         '''Construct a radiobutton widget with the parent MASTER.
  3484.  
  3485.         Valid resource names: activebackground, activeforeground, anchor,
  3486.         background, bd, bg, bitmap, borderwidth, command, cursor,
  3487.         disabledforeground, fg, font, foreground, height,
  3488.         highlightbackground, highlightcolor, highlightthickness, image,
  3489.         indicatoron, justify, padx, pady, relief, selectcolor, selectimage,
  3490.         state, takefocus, text, textvariable, underline, value, variable,
  3491.         width, wraplength.'''
  3492.         Widget.__init__(self, master, 'radiobutton', cnf, kw)
  3493.  
  3494.     
  3495.     def deselect(self):
  3496.         '''Put the button in off-state.'''
  3497.         self.tk.call(self._w, 'deselect')
  3498.  
  3499.     
  3500.     def flash(self):
  3501.         '''Flash the button.'''
  3502.         self.tk.call(self._w, 'flash')
  3503.  
  3504.     
  3505.     def invoke(self):
  3506.         '''Toggle the button and invoke a command if given as resource.'''
  3507.         return self.tk.call(self._w, 'invoke')
  3508.  
  3509.     
  3510.     def select(self):
  3511.         '''Put the button in on-state.'''
  3512.         self.tk.call(self._w, 'select')
  3513.  
  3514.  
  3515.  
  3516. class Scale(Widget):
  3517.     '''Scale widget which can display a numerical scale.'''
  3518.     
  3519.     def __init__(self, master = None, cnf = { }, **kw):
  3520.         '''Construct a scale widget with the parent MASTER.
  3521.  
  3522.         Valid resource names: activebackground, background, bigincrement, bd,
  3523.         bg, borderwidth, command, cursor, digits, fg, font, foreground, from,
  3524.         highlightbackground, highlightcolor, highlightthickness, label,
  3525.         length, orient, relief, repeatdelay, repeatinterval, resolution,
  3526.         showvalue, sliderlength, sliderrelief, state, takefocus,
  3527.         tickinterval, to, troughcolor, variable, width.'''
  3528.         Widget.__init__(self, master, 'scale', cnf, kw)
  3529.  
  3530.     
  3531.     def get(self):
  3532.         '''Get the current value as integer or float.'''
  3533.         value = self.tk.call(self._w, 'get')
  3534.         
  3535.         try:
  3536.             return getint(value)
  3537.         except ValueError:
  3538.             return getdouble(value)
  3539.  
  3540.  
  3541.     
  3542.     def set(self, value):
  3543.         '''Set the value to VALUE.'''
  3544.         self.tk.call(self._w, 'set', value)
  3545.  
  3546.     
  3547.     def coords(self, value = None):
  3548.         '''Return a tuple (X,Y) of the point along the centerline of the
  3549.         trough that corresponds to VALUE or the current value if None is
  3550.         given.'''
  3551.         return self._getints(self.tk.call(self._w, 'coords', value))
  3552.  
  3553.     
  3554.     def identify(self, x, y):
  3555.         '''Return where the point X,Y lies. Valid return values are "slider",
  3556.         "though1" and "though2".'''
  3557.         return self.tk.call(self._w, 'identify', x, y)
  3558.  
  3559.  
  3560.  
  3561. class Scrollbar(Widget):
  3562.     '''Scrollbar widget which displays a slider at a certain position.'''
  3563.     
  3564.     def __init__(self, master = None, cnf = { }, **kw):
  3565.         '''Construct a scrollbar widget with the parent MASTER.
  3566.  
  3567.         Valid resource names: activebackground, activerelief,
  3568.         background, bd, bg, borderwidth, command, cursor,
  3569.         elementborderwidth, highlightbackground,
  3570.         highlightcolor, highlightthickness, jump, orient,
  3571.         relief, repeatdelay, repeatinterval, takefocus,
  3572.         troughcolor, width.'''
  3573.         Widget.__init__(self, master, 'scrollbar', cnf, kw)
  3574.  
  3575.     
  3576.     def activate(self, index):
  3577.         '''Display the element at INDEX with activebackground and activerelief.
  3578.         INDEX can be "arrow1","slider" or "arrow2".'''
  3579.         self.tk.call(self._w, 'activate', index)
  3580.  
  3581.     
  3582.     def delta(self, deltax, deltay):
  3583.         '''Return the fractional change of the scrollbar setting if it
  3584.         would be moved by DELTAX or DELTAY pixels.'''
  3585.         return getdouble(self.tk.call(self._w, 'delta', deltax, deltay))
  3586.  
  3587.     
  3588.     def fraction(self, x, y):
  3589.         '''Return the fractional value which corresponds to a slider
  3590.         position of X,Y.'''
  3591.         return getdouble(self.tk.call(self._w, 'fraction', x, y))
  3592.  
  3593.     
  3594.     def identify(self, x, y):
  3595.         '''Return the element under position X,Y as one of
  3596.         "arrow1","slider","arrow2" or "".'''
  3597.         return self.tk.call(self._w, 'identify', x, y)
  3598.  
  3599.     
  3600.     def get(self):
  3601.         '''Return the current fractional values (upper and lower end)
  3602.         of the slider position.'''
  3603.         return self._getdoubles(self.tk.call(self._w, 'get'))
  3604.  
  3605.     
  3606.     def set(self, *args):
  3607.         '''Set the fractional values of the slider position (upper and
  3608.         lower ends as value between 0 and 1).'''
  3609.         self.tk.call((self._w, 'set') + args)
  3610.  
  3611.  
  3612.  
  3613. class Text(Widget):
  3614.     '''Text widget which can display text in various forms.'''
  3615.     
  3616.     def __init__(self, master = None, cnf = { }, **kw):
  3617.         '''Construct a text widget with the parent MASTER.
  3618.  
  3619.         STANDARD OPTIONS
  3620.  
  3621.             background, borderwidth, cursor,
  3622.             exportselection, font, foreground,
  3623.             highlightbackground, highlightcolor,
  3624.             highlightthickness, insertbackground,
  3625.             insertborderwidth, insertofftime,
  3626.             insertontime, insertwidth, padx, pady,
  3627.             relief, selectbackground,
  3628.             selectborderwidth, selectforeground,
  3629.             setgrid, takefocus,
  3630.             xscrollcommand, yscrollcommand,
  3631.  
  3632.         WIDGET-SPECIFIC OPTIONS
  3633.  
  3634.             autoseparators, height, maxundo,
  3635.             spacing1, spacing2, spacing3,
  3636.             state, tabs, undo, width, wrap,
  3637.  
  3638.         '''
  3639.         Widget.__init__(self, master, 'text', cnf, kw)
  3640.  
  3641.     
  3642.     def bbox(self, *args):
  3643.         '''Return a tuple of (x,y,width,height) which gives the bounding
  3644.         box of the visible part of the character at the index in ARGS.'''
  3645.         if not self._getints(self.tk.call((self._w, 'bbox') + args)):
  3646.             pass
  3647.  
  3648.     
  3649.     def tk_textSelectTo(self, index):
  3650.         self.tk.call('tk_textSelectTo', self._w, index)
  3651.  
  3652.     
  3653.     def tk_textBackspace(self):
  3654.         self.tk.call('tk_textBackspace', self._w)
  3655.  
  3656.     
  3657.     def tk_textIndexCloser(self, a, b, c):
  3658.         self.tk.call('tk_textIndexCloser', self._w, a, b, c)
  3659.  
  3660.     
  3661.     def tk_textResetAnchor(self, index):
  3662.         self.tk.call('tk_textResetAnchor', self._w, index)
  3663.  
  3664.     
  3665.     def compare(self, index1, op, index2):
  3666.         '''Return whether between index INDEX1 and index INDEX2 the
  3667.         relation OP is satisfied. OP is one of <, <=, ==, >=, >, or !=.'''
  3668.         return self.tk.getboolean(self.tk.call(self._w, 'compare', index1, op, index2))
  3669.  
  3670.     
  3671.     def debug(self, boolean = None):
  3672.         '''Turn on the internal consistency checks of the B-Tree inside the text
  3673.         widget according to BOOLEAN.'''
  3674.         return self.tk.getboolean(self.tk.call(self._w, 'debug', boolean))
  3675.  
  3676.     
  3677.     def delete(self, index1, index2 = None):
  3678.         '''Delete the characters between INDEX1 and INDEX2 (not included).'''
  3679.         self.tk.call(self._w, 'delete', index1, index2)
  3680.  
  3681.     
  3682.     def dlineinfo(self, index):
  3683.         '''Return tuple (x,y,width,height,baseline) giving the bounding box
  3684.         and baseline position of the visible part of the line containing
  3685.         the character at INDEX.'''
  3686.         return self._getints(self.tk.call(self._w, 'dlineinfo', index))
  3687.  
  3688.     
  3689.     def dump(self, index1, index2 = None, command = None, **kw):
  3690.         """Return the contents of the widget between index1 and index2.
  3691.  
  3692.         The type of contents returned in filtered based on the keyword
  3693.         parameters; if 'all', 'image', 'mark', 'tag', 'text', or 'window' are
  3694.         given and true, then the corresponding items are returned. The result
  3695.         is a list of triples of the form (key, value, index). If none of the
  3696.         keywords are true then 'all' is used by default.
  3697.  
  3698.         If the 'command' argument is given, it is called once for each element
  3699.         of the list of triples, with the values of each triple serving as the
  3700.         arguments to the function. In this case the list is not returned."""
  3701.         args = []
  3702.         func_name = None
  3703.         result = None
  3704.         if not command:
  3705.             result = []
  3706.             
  3707.             def append_triple(key, value, index, result = result):
  3708.                 result.append((key, value, index))
  3709.  
  3710.             command = append_triple
  3711.         
  3712.         
  3713.         try:
  3714.             if not isinstance(command, str):
  3715.                 func_name = command = self._register(command)
  3716.             
  3717.             args += [
  3718.                 '-command',
  3719.                 command]
  3720.             for key in kw:
  3721.                 if kw[key]:
  3722.                     args.append('-' + key)
  3723.                     continue
  3724.             
  3725.             args.append(index1)
  3726.             if index2:
  3727.                 args.append(index2)
  3728.             
  3729.             self.tk.call(self._w, 'dump', *args)
  3730.             return result
  3731.         finally:
  3732.             if func_name:
  3733.                 self.deletecommand(func_name)
  3734.             
  3735.  
  3736.  
  3737.     
  3738.     def edit(self, *args):
  3739.         '''Internal method
  3740.  
  3741.         This method controls the undo mechanism and
  3742.         the modified flag. The exact behavior of the
  3743.         command depends on the option argument that
  3744.         follows the edit argument. The following forms
  3745.         of the command are currently supported:
  3746.  
  3747.         edit_modified, edit_redo, edit_reset, edit_separator
  3748.         and edit_undo
  3749.  
  3750.         '''
  3751.         if not self._getints(self.tk.call((self._w, 'edit') + args)):
  3752.             pass
  3753.         return ()
  3754.  
  3755.     
  3756.     def edit_modified(self, arg = None):
  3757.         '''Get or Set the modified flag
  3758.  
  3759.         If arg is not specified, returns the modified
  3760.         flag of the widget. The insert, delete, edit undo and
  3761.         edit redo commands or the user can set or clear the
  3762.         modified flag. If boolean is specified, sets the
  3763.         modified flag of the widget to arg.
  3764.         '''
  3765.         return self.edit('modified', arg)
  3766.  
  3767.     
  3768.     def edit_redo(self):
  3769.         '''Redo the last undone edit
  3770.  
  3771.         When the undo option is true, reapplies the last
  3772.         undone edits provided no other edits were done since
  3773.         then. Generates an error when the redo stack is empty.
  3774.         Does nothing when the undo option is false.
  3775.         '''
  3776.         return self.edit('redo')
  3777.  
  3778.     
  3779.     def edit_reset(self):
  3780.         '''Clears the undo and redo stacks
  3781.         '''
  3782.         return self.edit('reset')
  3783.  
  3784.     
  3785.     def edit_separator(self):
  3786.         '''Inserts a separator (boundary) on the undo stack.
  3787.  
  3788.         Does nothing when the undo option is false
  3789.         '''
  3790.         return self.edit('separator')
  3791.  
  3792.     
  3793.     def edit_undo(self):
  3794.         '''Undoes the last edit action
  3795.  
  3796.         If the undo option is true. An edit action is defined
  3797.         as all the insert and delete commands that are recorded
  3798.         on the undo stack in between two separators. Generates
  3799.         an error when the undo stack is empty. Does nothing
  3800.         when the undo option is false
  3801.         '''
  3802.         return self.edit('undo')
  3803.  
  3804.     
  3805.     def get(self, index1, index2 = None):
  3806.         '''Return the text from INDEX1 to INDEX2 (not included).'''
  3807.         return self.tk.call(self._w, 'get', index1, index2)
  3808.  
  3809.     
  3810.     def image_cget(self, index, option):
  3811.         '''Return the value of OPTION of an embedded image at INDEX.'''
  3812.         if option[:1] != '-':
  3813.             option = '-' + option
  3814.         
  3815.         if option[-1:] == '_':
  3816.             option = option[:-1]
  3817.         
  3818.         return self.tk.call(self._w, 'image', 'cget', index, option)
  3819.  
  3820.     
  3821.     def image_configure(self, index, cnf = None, **kw):
  3822.         '''Configure an embedded image at INDEX.'''
  3823.         return self._configure(('image', 'configure', index), cnf, kw)
  3824.  
  3825.     
  3826.     def image_create(self, index, cnf = { }, **kw):
  3827.         '''Create an embedded image at INDEX.'''
  3828.         return self.tk.call(self._w, 'image', 'create', index, *self._options(cnf, kw))
  3829.  
  3830.     
  3831.     def image_names(self):
  3832.         '''Return all names of embedded images in this widget.'''
  3833.         return self.tk.call(self._w, 'image', 'names')
  3834.  
  3835.     
  3836.     def index(self, index):
  3837.         '''Return the index in the form line.char for INDEX.'''
  3838.         return self.tk.call(self._w, 'index', index)
  3839.  
  3840.     
  3841.     def insert(self, index, chars, *args):
  3842.         '''Insert CHARS before the characters at INDEX. An additional
  3843.         tag can be given in ARGS. Additional CHARS and tags can follow in ARGS.'''
  3844.         self.tk.call((self._w, 'insert', index, chars) + args)
  3845.  
  3846.     
  3847.     def mark_gravity(self, markName, direction = None):
  3848.         '''Change the gravity of a mark MARKNAME to DIRECTION (LEFT or RIGHT).
  3849.         Return the current value if None is given for DIRECTION.'''
  3850.         return self.tk.call((self._w, 'mark', 'gravity', markName, direction))
  3851.  
  3852.     
  3853.     def mark_names(self):
  3854.         '''Return all mark names.'''
  3855.         return self.tk.splitlist(self.tk.call(self._w, 'mark', 'names'))
  3856.  
  3857.     
  3858.     def mark_set(self, markName, index):
  3859.         '''Set mark MARKNAME before the character at INDEX.'''
  3860.         self.tk.call(self._w, 'mark', 'set', markName, index)
  3861.  
  3862.     
  3863.     def mark_unset(self, *markNames):
  3864.         '''Delete all marks in MARKNAMES.'''
  3865.         self.tk.call((self._w, 'mark', 'unset') + markNames)
  3866.  
  3867.     
  3868.     def mark_next(self, index):
  3869.         '''Return the name of the next mark after INDEX.'''
  3870.         if not self.tk.call(self._w, 'mark', 'next', index):
  3871.             pass
  3872.  
  3873.     
  3874.     def mark_previous(self, index):
  3875.         '''Return the name of the previous mark before INDEX.'''
  3876.         if not self.tk.call(self._w, 'mark', 'previous', index):
  3877.             pass
  3878.  
  3879.     
  3880.     def scan_mark(self, x, y):
  3881.         '''Remember the current X, Y coordinates.'''
  3882.         self.tk.call(self._w, 'scan', 'mark', x, y)
  3883.  
  3884.     
  3885.     def scan_dragto(self, x, y):
  3886.         '''Adjust the view of the text to 10 times the
  3887.         difference between X and Y and the coordinates given in
  3888.         scan_mark.'''
  3889.         self.tk.call(self._w, 'scan', 'dragto', x, y)
  3890.  
  3891.     
  3892.     def search(self, pattern, index, stopindex = None, forwards = None, backwards = None, exact = None, regexp = None, nocase = None, count = None):
  3893.         '''Search PATTERN beginning from INDEX until STOPINDEX.
  3894.         Return the index of the first character of a match or an empty string.'''
  3895.         args = [
  3896.             self._w,
  3897.             'search']
  3898.         if forwards:
  3899.             args.append('-forwards')
  3900.         
  3901.         if backwards:
  3902.             args.append('-backwards')
  3903.         
  3904.         if exact:
  3905.             args.append('-exact')
  3906.         
  3907.         if regexp:
  3908.             args.append('-regexp')
  3909.         
  3910.         if nocase:
  3911.             args.append('-nocase')
  3912.         
  3913.         if count:
  3914.             args.append('-count')
  3915.             args.append(count)
  3916.         
  3917.         if pattern[0] == '-':
  3918.             args.append('--')
  3919.         
  3920.         args.append(pattern)
  3921.         args.append(index)
  3922.         if stopindex:
  3923.             args.append(stopindex)
  3924.         
  3925.         return self.tk.call(tuple(args))
  3926.  
  3927.     
  3928.     def see(self, index):
  3929.         '''Scroll such that the character at INDEX is visible.'''
  3930.         self.tk.call(self._w, 'see', index)
  3931.  
  3932.     
  3933.     def tag_add(self, tagName, index1, *args):
  3934.         '''Add tag TAGNAME to all characters between INDEX1 and index2 in ARGS.
  3935.         Additional pairs of indices may follow in ARGS.'''
  3936.         self.tk.call((self._w, 'tag', 'add', tagName, index1) + args)
  3937.  
  3938.     
  3939.     def tag_unbind(self, tagName, sequence, funcid = None):
  3940.         '''Unbind for all characters with TAGNAME for event SEQUENCE  the
  3941.         function identified with FUNCID.'''
  3942.         self.tk.call(self._w, 'tag', 'bind', tagName, sequence, '')
  3943.         if funcid:
  3944.             self.deletecommand(funcid)
  3945.         
  3946.  
  3947.     
  3948.     def tag_bind(self, tagName, sequence, func, add = None):
  3949.         '''Bind to all characters with TAGNAME at event SEQUENCE a call to function FUNC.
  3950.  
  3951.         An additional boolean parameter ADD specifies whether FUNC will be
  3952.         called additionally to the other bound function or whether it will
  3953.         replace the previous function. See bind for the return value.'''
  3954.         return self._bind((self._w, 'tag', 'bind', tagName), sequence, func, add)
  3955.  
  3956.     
  3957.     def tag_cget(self, tagName, option):
  3958.         '''Return the value of OPTION for tag TAGNAME.'''
  3959.         if option[:1] != '-':
  3960.             option = '-' + option
  3961.         
  3962.         if option[-1:] == '_':
  3963.             option = option[:-1]
  3964.         
  3965.         return self.tk.call(self._w, 'tag', 'cget', tagName, option)
  3966.  
  3967.     
  3968.     def tag_configure(self, tagName, cnf = None, **kw):
  3969.         '''Configure a tag TAGNAME.'''
  3970.         return self._configure(('tag', 'configure', tagName), cnf, kw)
  3971.  
  3972.     tag_config = tag_configure
  3973.     
  3974.     def tag_delete(self, *tagNames):
  3975.         '''Delete all tags in TAGNAMES.'''
  3976.         self.tk.call((self._w, 'tag', 'delete') + tagNames)
  3977.  
  3978.     
  3979.     def tag_lower(self, tagName, belowThis = None):
  3980.         '''Change the priority of tag TAGNAME such that it is lower
  3981.         than the priority of BELOWTHIS.'''
  3982.         self.tk.call(self._w, 'tag', 'lower', tagName, belowThis)
  3983.  
  3984.     
  3985.     def tag_names(self, index = None):
  3986.         '''Return a list of all tag names.'''
  3987.         return self.tk.splitlist(self.tk.call(self._w, 'tag', 'names', index))
  3988.  
  3989.     
  3990.     def tag_nextrange(self, tagName, index1, index2 = None):
  3991.         '''Return a list of start and end index for the first sequence of
  3992.         characters between INDEX1 and INDEX2 which all have tag TAGNAME.
  3993.         The text is searched forward from INDEX1.'''
  3994.         return self.tk.splitlist(self.tk.call(self._w, 'tag', 'nextrange', tagName, index1, index2))
  3995.  
  3996.     
  3997.     def tag_prevrange(self, tagName, index1, index2 = None):
  3998.         '''Return a list of start and end index for the first sequence of
  3999.         characters between INDEX1 and INDEX2 which all have tag TAGNAME.
  4000.         The text is searched backwards from INDEX1.'''
  4001.         return self.tk.splitlist(self.tk.call(self._w, 'tag', 'prevrange', tagName, index1, index2))
  4002.  
  4003.     
  4004.     def tag_raise(self, tagName, aboveThis = None):
  4005.         '''Change the priority of tag TAGNAME such that it is higher
  4006.         than the priority of ABOVETHIS.'''
  4007.         self.tk.call(self._w, 'tag', 'raise', tagName, aboveThis)
  4008.  
  4009.     
  4010.     def tag_ranges(self, tagName):
  4011.         '''Return a list of ranges of text which have tag TAGNAME.'''
  4012.         return self.tk.splitlist(self.tk.call(self._w, 'tag', 'ranges', tagName))
  4013.  
  4014.     
  4015.     def tag_remove(self, tagName, index1, index2 = None):
  4016.         '''Remove tag TAGNAME from all characters between INDEX1 and INDEX2.'''
  4017.         self.tk.call(self._w, 'tag', 'remove', tagName, index1, index2)
  4018.  
  4019.     
  4020.     def window_cget(self, index, option):
  4021.         '''Return the value of OPTION of an embedded window at INDEX.'''
  4022.         if option[:1] != '-':
  4023.             option = '-' + option
  4024.         
  4025.         if option[-1:] == '_':
  4026.             option = option[:-1]
  4027.         
  4028.         return self.tk.call(self._w, 'window', 'cget', index, option)
  4029.  
  4030.     
  4031.     def window_configure(self, index, cnf = None, **kw):
  4032.         '''Configure an embedded window at INDEX.'''
  4033.         return self._configure(('window', 'configure', index), cnf, kw)
  4034.  
  4035.     window_config = window_configure
  4036.     
  4037.     def window_create(self, index, cnf = { }, **kw):
  4038.         '''Create a window at INDEX.'''
  4039.         self.tk.call((self._w, 'window', 'create', index) + self._options(cnf, kw))
  4040.  
  4041.     
  4042.     def window_names(self):
  4043.         '''Return all names of embedded windows in this widget.'''
  4044.         return self.tk.splitlist(self.tk.call(self._w, 'window', 'names'))
  4045.  
  4046.     
  4047.     def xview(self, *what):
  4048.         '''Query and change horizontal position of the view.'''
  4049.         if not what:
  4050.             return self._getdoubles(self.tk.call(self._w, 'xview'))
  4051.         
  4052.         self.tk.call((self._w, 'xview') + what)
  4053.  
  4054.     
  4055.     def xview_moveto(self, fraction):
  4056.         '''Adjusts the view in the window so that FRACTION of the
  4057.         total width of the canvas is off-screen to the left.'''
  4058.         self.tk.call(self._w, 'xview', 'moveto', fraction)
  4059.  
  4060.     
  4061.     def xview_scroll(self, number, what):
  4062.         '''Shift the x-view according to NUMBER which is measured
  4063.         in "units" or "pages" (WHAT).'''
  4064.         self.tk.call(self._w, 'xview', 'scroll', number, what)
  4065.  
  4066.     
  4067.     def yview(self, *what):
  4068.         '''Query and change vertical position of the view.'''
  4069.         if not what:
  4070.             return self._getdoubles(self.tk.call(self._w, 'yview'))
  4071.         
  4072.         self.tk.call((self._w, 'yview') + what)
  4073.  
  4074.     
  4075.     def yview_moveto(self, fraction):
  4076.         '''Adjusts the view in the window so that FRACTION of the
  4077.         total height of the canvas is off-screen to the top.'''
  4078.         self.tk.call(self._w, 'yview', 'moveto', fraction)
  4079.  
  4080.     
  4081.     def yview_scroll(self, number, what):
  4082.         '''Shift the y-view according to NUMBER which is measured
  4083.         in "units" or "pages" (WHAT).'''
  4084.         self.tk.call(self._w, 'yview', 'scroll', number, what)
  4085.  
  4086.     
  4087.     def yview_pickplace(self, *what):
  4088.         '''Obsolete function, use see.'''
  4089.         self.tk.call((self._w, 'yview', '-pickplace') + what)
  4090.  
  4091.  
  4092.  
  4093. class _setit:
  4094.     '''Internal class. It wraps the command in the widget OptionMenu.'''
  4095.     
  4096.     def __init__(self, var, value, callback = None):
  4097.         self._setit__value = value
  4098.         self._setit__var = var
  4099.         self._setit__callback = callback
  4100.  
  4101.     
  4102.     def __call__(self, *args):
  4103.         self._setit__var.set(self._setit__value)
  4104.         if self._setit__callback:
  4105.             self._setit__callback(self._setit__value, *args)
  4106.         
  4107.  
  4108.  
  4109.  
  4110. class OptionMenu(Menubutton):
  4111.     '''OptionMenu which allows the user to select a value from a menu.'''
  4112.     
  4113.     def __init__(self, master, variable, value, *values, **kwargs):
  4114.         '''Construct an optionmenu widget with the parent MASTER, with
  4115.         the resource textvariable set to VARIABLE, the initially selected
  4116.         value VALUE, the other menu values VALUES and an additional
  4117.         keyword argument command.'''
  4118.         kw = {
  4119.             'borderwidth': 2,
  4120.             'textvariable': variable,
  4121.             'indicatoron': 1,
  4122.             'relief': RAISED,
  4123.             'anchor': 'c',
  4124.             'highlightthickness': 2 }
  4125.         Widget.__init__(self, master, 'menubutton', kw)
  4126.         self.widgetName = 'tk_optionMenu'
  4127.         menu = self._OptionMenu__menu = Menu(self, name = 'menu', tearoff = 0)
  4128.         self.menuname = menu._w
  4129.         callback = kwargs.get('command')
  4130.         if kwargs.has_key('command'):
  4131.             del kwargs['command']
  4132.         
  4133.         if kwargs:
  4134.             raise TclError, 'unknown option -' + kwargs.keys()[0]
  4135.         
  4136.         menu.add_command(label = value, command = _setit(variable, value, callback))
  4137.         for v in values:
  4138.             menu.add_command(label = v, command = _setit(variable, v, callback))
  4139.         
  4140.         self['menu'] = menu
  4141.  
  4142.     
  4143.     def __getitem__(self, name):
  4144.         if name == 'menu':
  4145.             return self._OptionMenu__menu
  4146.         
  4147.         return Widget.__getitem__(self, name)
  4148.  
  4149.     
  4150.     def destroy(self):
  4151.         '''Destroy this widget and the associated menu.'''
  4152.         Menubutton.destroy(self)
  4153.         self._OptionMenu__menu = None
  4154.  
  4155.  
  4156.  
  4157. class Image:
  4158.     '''Base class for images.'''
  4159.     _last_id = 0
  4160.     
  4161.     def __init__(self, imgtype, name = None, cnf = { }, master = None, **kw):
  4162.         self.name = None
  4163.         if not master:
  4164.             master = _default_root
  4165.             if not master:
  4166.                 raise RuntimeError, 'Too early to create image'
  4167.             
  4168.         
  4169.         self.tk = master.tk
  4170.         if not name:
  4171.             Image._last_id += 1
  4172.             name = 'pyimage%r' % (Image._last_id,)
  4173.             if name[0] == '-':
  4174.                 name = '_' + name[1:]
  4175.             
  4176.         
  4177.         if kw and cnf:
  4178.             cnf = _cnfmerge((cnf, kw))
  4179.         elif kw:
  4180.             cnf = kw
  4181.         
  4182.         options = ()
  4183.         for k, v in cnf.items():
  4184.             if callable(v):
  4185.                 v = self._register(v)
  4186.             
  4187.             options = options + ('-' + k, v)
  4188.         
  4189.         self.tk.call(('image', 'create', imgtype, name) + options)
  4190.         self.name = name
  4191.  
  4192.     
  4193.     def __str__(self):
  4194.         return self.name
  4195.  
  4196.     
  4197.     def __del__(self):
  4198.         if self.name:
  4199.             
  4200.             try:
  4201.                 self.tk.call('image', 'delete', self.name)
  4202.             except TclError:
  4203.                 pass
  4204.             except:
  4205.                 None<EXCEPTION MATCH>TclError
  4206.             
  4207.  
  4208.         None<EXCEPTION MATCH>TclError
  4209.  
  4210.     
  4211.     def __setitem__(self, key, value):
  4212.         self.tk.call(self.name, 'configure', '-' + key, value)
  4213.  
  4214.     
  4215.     def __getitem__(self, key):
  4216.         return self.tk.call(self.name, 'configure', '-' + key)
  4217.  
  4218.     
  4219.     def configure(self, **kw):
  4220.         '''Configure the image.'''
  4221.         res = ()
  4222.         for k, v in _cnfmerge(kw).items():
  4223.             if v is not None:
  4224.                 if k[-1] == '_':
  4225.                     k = k[:-1]
  4226.                 
  4227.                 if callable(v):
  4228.                     v = self._register(v)
  4229.                 
  4230.                 res = res + ('-' + k, v)
  4231.                 continue
  4232.         
  4233.         self.tk.call((self.name, 'config') + res)
  4234.  
  4235.     config = configure
  4236.     
  4237.     def height(self):
  4238.         '''Return the height of the image.'''
  4239.         return getint(self.tk.call('image', 'height', self.name))
  4240.  
  4241.     
  4242.     def type(self):
  4243.         '''Return the type of the imgage, e.g. "photo" or "bitmap".'''
  4244.         return self.tk.call('image', 'type', self.name)
  4245.  
  4246.     
  4247.     def width(self):
  4248.         '''Return the width of the image.'''
  4249.         return getint(self.tk.call('image', 'width', self.name))
  4250.  
  4251.  
  4252.  
  4253. class PhotoImage(Image):
  4254.     '''Widget which can display colored images in GIF, PPM/PGM format.'''
  4255.     
  4256.     def __init__(self, name = None, cnf = { }, master = None, **kw):
  4257.         '''Create an image with NAME.
  4258.  
  4259.         Valid resource names: data, format, file, gamma, height, palette,
  4260.         width.'''
  4261.         Image.__init__(self, 'photo', name, cnf, master, **kw)
  4262.  
  4263.     
  4264.     def blank(self):
  4265.         '''Display a transparent image.'''
  4266.         self.tk.call(self.name, 'blank')
  4267.  
  4268.     
  4269.     def cget(self, option):
  4270.         '''Return the value of OPTION.'''
  4271.         return self.tk.call(self.name, 'cget', '-' + option)
  4272.  
  4273.     
  4274.     def __getitem__(self, key):
  4275.         return self.tk.call(self.name, 'cget', '-' + key)
  4276.  
  4277.     
  4278.     def copy(self):
  4279.         '''Return a new PhotoImage with the same image as this widget.'''
  4280.         destImage = PhotoImage()
  4281.         self.tk.call(destImage, 'copy', self.name)
  4282.         return destImage
  4283.  
  4284.     
  4285.     def zoom(self, x, y = ''):
  4286.         '''Return a new PhotoImage with the same image as this widget
  4287.         but zoom it with X and Y.'''
  4288.         destImage = PhotoImage()
  4289.         if y == '':
  4290.             y = x
  4291.         
  4292.         self.tk.call(destImage, 'copy', self.name, '-zoom', x, y)
  4293.         return destImage
  4294.  
  4295.     
  4296.     def subsample(self, x, y = ''):
  4297.         '''Return a new PhotoImage based on the same image as this widget
  4298.         but use only every Xth or Yth pixel.'''
  4299.         destImage = PhotoImage()
  4300.         if y == '':
  4301.             y = x
  4302.         
  4303.         self.tk.call(destImage, 'copy', self.name, '-subsample', x, y)
  4304.         return destImage
  4305.  
  4306.     
  4307.     def get(self, x, y):
  4308.         '''Return the color (red, green, blue) of the pixel at X,Y.'''
  4309.         return self.tk.call(self.name, 'get', x, y)
  4310.  
  4311.     
  4312.     def put(self, data, to = None):
  4313.         '''Put row formated colors to image starting from
  4314.         position TO, e.g. image.put("{red green} {blue yellow}", to=(4,6))'''
  4315.         args = (self.name, 'put', data)
  4316.         if to:
  4317.             if to[0] == '-to':
  4318.                 to = to[1:]
  4319.             
  4320.             args = args + ('-to',) + tuple(to)
  4321.         
  4322.         self.tk.call(args)
  4323.  
  4324.     
  4325.     def write(self, filename, format = None, from_coords = None):
  4326.         '''Write image to file FILENAME in FORMAT starting from
  4327.         position FROM_COORDS.'''
  4328.         args = (self.name, 'write', filename)
  4329.         if format:
  4330.             args = args + ('-format', format)
  4331.         
  4332.         if from_coords:
  4333.             args = args + ('-from',) + tuple(from_coords)
  4334.         
  4335.         self.tk.call(args)
  4336.  
  4337.  
  4338.  
  4339. class BitmapImage(Image):
  4340.     '''Widget which can display a bitmap.'''
  4341.     
  4342.     def __init__(self, name = None, cnf = { }, master = None, **kw):
  4343.         '''Create a bitmap with NAME.
  4344.  
  4345.         Valid resource names: background, data, file, foreground, maskdata, maskfile.'''
  4346.         Image.__init__(self, 'bitmap', name, cnf, master, **kw)
  4347.  
  4348.  
  4349.  
  4350. def image_names():
  4351.     return _default_root.tk.call('image', 'names')
  4352.  
  4353.  
  4354. def image_types():
  4355.     return _default_root.tk.call('image', 'types')
  4356.  
  4357.  
  4358. class Spinbox(Widget):
  4359.     '''spinbox widget.'''
  4360.     
  4361.     def __init__(self, master = None, cnf = { }, **kw):
  4362.         '''Construct a spinbox widget with the parent MASTER.
  4363.  
  4364.         STANDARD OPTIONS
  4365.  
  4366.             activebackground, background, borderwidth,
  4367.             cursor, exportselection, font, foreground,
  4368.             highlightbackground, highlightcolor,
  4369.             highlightthickness, insertbackground,
  4370.             insertborderwidth, insertofftime,
  4371.             insertontime, insertwidth, justify, relief,
  4372.             repeatdelay, repeatinterval,
  4373.             selectbackground, selectborderwidth
  4374.             selectforeground, takefocus, textvariable
  4375.             xscrollcommand.
  4376.  
  4377.         WIDGET-SPECIFIC OPTIONS
  4378.  
  4379.             buttonbackground, buttoncursor,
  4380.             buttondownrelief, buttonuprelief,
  4381.             command, disabledbackground,
  4382.             disabledforeground, format, from,
  4383.             invalidcommand, increment,
  4384.             readonlybackground, state, to,
  4385.             validate, validatecommand values,
  4386.             width, wrap,
  4387.         '''
  4388.         Widget.__init__(self, master, 'spinbox', cnf, kw)
  4389.  
  4390.     
  4391.     def bbox(self, index):
  4392.         '''Return a tuple of X1,Y1,X2,Y2 coordinates for a
  4393.         rectangle which encloses the character given by index.
  4394.  
  4395.         The first two elements of the list give the x and y
  4396.         coordinates of the upper-left corner of the screen
  4397.         area covered by the character (in pixels relative
  4398.         to the widget) and the last two elements give the
  4399.         width and height of the character, in pixels. The
  4400.         bounding box may refer to a region outside the
  4401.         visible area of the window.
  4402.         '''
  4403.         return self.tk.call(self._w, 'bbox', index)
  4404.  
  4405.     
  4406.     def delete(self, first, last = None):
  4407.         """Delete one or more elements of the spinbox.
  4408.  
  4409.         First is the index of the first character to delete,
  4410.         and last is the index of the character just after
  4411.         the last one to delete. If last isn't specified it
  4412.         defaults to first+1, i.e. a single character is
  4413.         deleted.  This command returns an empty string.
  4414.         """
  4415.         return self.tk.call(self._w, 'delete', first, last)
  4416.  
  4417.     
  4418.     def get(self):
  4419.         """Returns the spinbox's string"""
  4420.         return self.tk.call(self._w, 'get')
  4421.  
  4422.     
  4423.     def icursor(self, index):
  4424.         '''Alter the position of the insertion cursor.
  4425.  
  4426.         The insertion cursor will be displayed just before
  4427.         the character given by index. Returns an empty string
  4428.         '''
  4429.         return self.tk.call(self._w, 'icursor', index)
  4430.  
  4431.     
  4432.     def identify(self, x, y):
  4433.         '''Returns the name of the widget at position x, y
  4434.  
  4435.         Return value is one of: none, buttondown, buttonup, entry
  4436.         '''
  4437.         return self.tk.call(self._w, 'identify', x, y)
  4438.  
  4439.     
  4440.     def index(self, index):
  4441.         '''Returns the numerical index corresponding to index
  4442.         '''
  4443.         return self.tk.call(self._w, 'index', index)
  4444.  
  4445.     
  4446.     def insert(self, index, s):
  4447.         '''Insert string s at index
  4448.  
  4449.          Returns an empty string.
  4450.         '''
  4451.         return self.tk.call(self._w, 'insert', index, s)
  4452.  
  4453.     
  4454.     def invoke(self, element):
  4455.         '''Causes the specified element to be invoked
  4456.  
  4457.         The element could be buttondown or buttonup
  4458.         triggering the action associated with it.
  4459.         '''
  4460.         return self.tk.call(self._w, 'invoke', element)
  4461.  
  4462.     
  4463.     def scan(self, *args):
  4464.         '''Internal function.'''
  4465.         if not self._getints(self.tk.call((self._w, 'scan') + args)):
  4466.             pass
  4467.         return ()
  4468.  
  4469.     
  4470.     def scan_mark(self, x):
  4471.         '''Records x and the current view in the spinbox window;
  4472.  
  4473.         used in conjunction with later scan dragto commands.
  4474.         Typically this command is associated with a mouse button
  4475.         press in the widget. It returns an empty string.
  4476.         '''
  4477.         return self.scan('mark', x)
  4478.  
  4479.     
  4480.     def scan_dragto(self, x):
  4481.         '''Compute the difference between the given x argument
  4482.         and the x argument to the last scan mark command
  4483.  
  4484.         It then adjusts the view left or right by 10 times the
  4485.         difference in x-coordinates. This command is typically
  4486.         associated with mouse motion events in the widget, to
  4487.         produce the effect of dragging the spinbox at high speed
  4488.         through the window. The return value is an empty string.
  4489.         '''
  4490.         return self.scan('dragto', x)
  4491.  
  4492.     
  4493.     def selection(self, *args):
  4494.         '''Internal function.'''
  4495.         if not self._getints(self.tk.call((self._w, 'selection') + args)):
  4496.             pass
  4497.         return ()
  4498.  
  4499.     
  4500.     def selection_adjust(self, index):
  4501.         """Locate the end of the selection nearest to the character
  4502.         given by index,
  4503.  
  4504.         Then adjust that end of the selection to be at index
  4505.         (i.e including but not going beyond index). The other
  4506.         end of the selection is made the anchor point for future
  4507.         select to commands. If the selection isn't currently in
  4508.         the spinbox, then a new selection is created to include
  4509.         the characters between index and the most recent selection
  4510.         anchor point, inclusive. Returns an empty string.
  4511.         """
  4512.         return self.selection('adjust', index)
  4513.  
  4514.     
  4515.     def selection_clear(self):
  4516.         """Clear the selection
  4517.  
  4518.         If the selection isn't in this widget then the
  4519.         command has no effect. Returns an empty string.
  4520.         """
  4521.         return self.selection('clear')
  4522.  
  4523.     
  4524.     def selection_element(self, element = None):
  4525.         '''Sets or gets the currently selected element.
  4526.  
  4527.         If a spinbutton element is specified, it will be
  4528.         displayed depressed
  4529.         '''
  4530.         return self.selection('element', element)
  4531.  
  4532.  
  4533.  
  4534. class LabelFrame(Widget):
  4535.     '''labelframe widget.'''
  4536.     
  4537.     def __init__(self, master = None, cnf = { }, **kw):
  4538.         '''Construct a labelframe widget with the parent MASTER.
  4539.  
  4540.         STANDARD OPTIONS
  4541.  
  4542.             borderwidth, cursor, font, foreground,
  4543.             highlightbackground, highlightcolor,
  4544.             highlightthickness, padx, pady, relief,
  4545.             takefocus, text
  4546.  
  4547.         WIDGET-SPECIFIC OPTIONS
  4548.  
  4549.             background, class, colormap, container,
  4550.             height, labelanchor, labelwidget,
  4551.             visual, width
  4552.         '''
  4553.         Widget.__init__(self, master, 'labelframe', cnf, kw)
  4554.  
  4555.  
  4556.  
  4557. class PanedWindow(Widget):
  4558.     '''panedwindow widget.'''
  4559.     
  4560.     def __init__(self, master = None, cnf = { }, **kw):
  4561.         '''Construct a panedwindow widget with the parent MASTER.
  4562.  
  4563.         STANDARD OPTIONS
  4564.  
  4565.             background, borderwidth, cursor, height,
  4566.             orient, relief, width
  4567.  
  4568.         WIDGET-SPECIFIC OPTIONS
  4569.  
  4570.             handlepad, handlesize, opaqueresize,
  4571.             sashcursor, sashpad, sashrelief,
  4572.             sashwidth, showhandle,
  4573.         '''
  4574.         Widget.__init__(self, master, 'panedwindow', cnf, kw)
  4575.  
  4576.     
  4577.     def add(self, child, **kw):
  4578.         '''Add a child widget to the panedwindow in a new pane.
  4579.  
  4580.         The child argument is the name of the child widget
  4581.         followed by pairs of arguments that specify how to
  4582.         manage the windows. Options may have any of the values
  4583.         accepted by the configure subcommand.
  4584.         '''
  4585.         self.tk.call((self._w, 'add', child) + self._options(kw))
  4586.  
  4587.     
  4588.     def remove(self, child):
  4589.         '''Remove the pane containing child from the panedwindow
  4590.  
  4591.         All geometry management options for child will be forgotten.
  4592.         '''
  4593.         self.tk.call(self._w, 'forget', child)
  4594.  
  4595.     forget = remove
  4596.     
  4597.     def identify(self, x, y):
  4598.         '''Identify the panedwindow component at point x, y
  4599.  
  4600.         If the point is over a sash or a sash handle, the result
  4601.         is a two element list containing the index of the sash or
  4602.         handle, and a word indicating whether it is over a sash
  4603.         or a handle, such as {0 sash} or {2 handle}. If the point
  4604.         is over any other part of the panedwindow, the result is
  4605.         an empty list.
  4606.         '''
  4607.         return self.tk.call(self._w, 'identify', x, y)
  4608.  
  4609.     
  4610.     def proxy(self, *args):
  4611.         '''Internal function.'''
  4612.         if not self._getints(self.tk.call((self._w, 'proxy') + args)):
  4613.             pass
  4614.         return ()
  4615.  
  4616.     
  4617.     def proxy_coord(self):
  4618.         '''Return the x and y pair of the most recent proxy location
  4619.         '''
  4620.         return self.proxy('coord')
  4621.  
  4622.     
  4623.     def proxy_forget(self):
  4624.         '''Remove the proxy from the display.
  4625.         '''
  4626.         return self.proxy('forget')
  4627.  
  4628.     
  4629.     def proxy_place(self, x, y):
  4630.         '''Place the proxy at the given x and y coordinates.
  4631.         '''
  4632.         return self.proxy('place', x, y)
  4633.  
  4634.     
  4635.     def sash(self, *args):
  4636.         '''Internal function.'''
  4637.         if not self._getints(self.tk.call((self._w, 'sash') + args)):
  4638.             pass
  4639.         return ()
  4640.  
  4641.     
  4642.     def sash_coord(self, index):
  4643.         '''Return the current x and y pair for the sash given by index.
  4644.  
  4645.         Index must be an integer between 0 and 1 less than the
  4646.         number of panes in the panedwindow. The coordinates given are
  4647.         those of the top left corner of the region containing the sash.
  4648.         pathName sash dragto index x y This command computes the
  4649.         difference between the given coordinates and the coordinates
  4650.         given to the last sash coord command for the given sash. It then
  4651.         moves that sash the computed difference. The return value is the
  4652.         empty string.
  4653.         '''
  4654.         return self.sash('coord', index)
  4655.  
  4656.     
  4657.     def sash_mark(self, index):
  4658.         '''Records x and y for the sash given by index;
  4659.  
  4660.         Used in conjunction with later dragto commands to move the sash.
  4661.         '''
  4662.         return self.sash('mark', index)
  4663.  
  4664.     
  4665.     def sash_place(self, index, x, y):
  4666.         '''Place the sash given by index at the given coordinates
  4667.         '''
  4668.         return self.sash('place', index, x, y)
  4669.  
  4670.     
  4671.     def panecget(self, child, option):
  4672.         '''Query a management option for window.
  4673.  
  4674.         Option may be any value allowed by the paneconfigure subcommand
  4675.         '''
  4676.         return self.tk.call((self._w, 'panecget') + (child, '-' + option))
  4677.  
  4678.     
  4679.     def paneconfigure(self, tagOrId, cnf = None, **kw):
  4680.         '''Query or modify the management options for window.
  4681.  
  4682.         If no option is specified, returns a list describing all
  4683.         of the available options for pathName.  If option is
  4684.         specified with no value, then the command returns a list
  4685.         describing the one named option (this list will be identical
  4686.         to the corresponding sublist of the value returned if no
  4687.         option is specified). If one or more option-value pairs are
  4688.         specified, then the command modifies the given widget
  4689.         option(s) to have the given value(s); in this case the
  4690.         command returns an empty string. The following options
  4691.         are supported:
  4692.  
  4693.         after window
  4694.             Insert the window after the window specified. window
  4695.             should be the name of a window already managed by pathName.
  4696.         before window
  4697.             Insert the window before the window specified. window
  4698.             should be the name of a window already managed by pathName.
  4699.         height size
  4700.             Specify a height for the window. The height will be the
  4701.             outer dimension of the window including its border, if
  4702.             any. If size is an empty string, or if -height is not
  4703.             specified, then the height requested internally by the
  4704.             window will be used initially; the height may later be
  4705.             adjusted by the movement of sashes in the panedwindow.
  4706.             Size may be any value accepted by Tk_GetPixels.
  4707.         minsize n
  4708.             Specifies that the size of the window cannot be made
  4709.             less than n. This constraint only affects the size of
  4710.             the widget in the paned dimension -- the x dimension
  4711.             for horizontal panedwindows, the y dimension for
  4712.             vertical panedwindows. May be any value accepted by
  4713.             Tk_GetPixels.
  4714.         padx n
  4715.             Specifies a non-negative value indicating how much
  4716.             extra space to leave on each side of the window in
  4717.             the X-direction. The value may have any of the forms
  4718.             accepted by Tk_GetPixels.
  4719.         pady n
  4720.             Specifies a non-negative value indicating how much
  4721.             extra space to leave on each side of the window in
  4722.             the Y-direction. The value may have any of the forms
  4723.             accepted by Tk_GetPixels.
  4724.         sticky style
  4725.             If a window\'s pane is larger than the requested
  4726.             dimensions of the window, this option may be used
  4727.             to position (or stretch) the window within its pane.
  4728.             Style is a string that contains zero or more of the
  4729.             characters n, s, e or w. The string can optionally
  4730.             contains spaces or commas, but they are ignored. Each
  4731.             letter refers to a side (north, south, east, or west)
  4732.             that the window will "stick" to. If both n and s
  4733.             (or e and w) are specified, the window will be
  4734.             stretched to fill the entire height (or width) of
  4735.             its cavity.
  4736.         width size
  4737.             Specify a width for the window. The width will be
  4738.             the outer dimension of the window including its
  4739.             border, if any. If size is an empty string, or
  4740.             if -width is not specified, then the width requested
  4741.             internally by the window will be used initially; the
  4742.             width may later be adjusted by the movement of sashes
  4743.             in the panedwindow. Size may be any value accepted by
  4744.             Tk_GetPixels.
  4745.  
  4746.         '''
  4747.         if cnf is None and not kw:
  4748.             cnf = { }
  4749.             for x in self.tk.split(self.tk.call(self._w, 'paneconfigure', tagOrId)):
  4750.                 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
  4751.             
  4752.             return cnf
  4753.         
  4754.         if type(cnf) == StringType and not kw:
  4755.             x = self.tk.split(self.tk.call(self._w, 'paneconfigure', tagOrId, '-' + cnf))
  4756.             return (x[0][1:],) + x[1:]
  4757.         
  4758.         self.tk.call((self._w, 'paneconfigure', tagOrId) + self._options(cnf, kw))
  4759.  
  4760.     paneconfig = paneconfigure
  4761.     
  4762.     def panes(self):
  4763.         '''Returns an ordered list of the child panes.'''
  4764.         return self.tk.call(self._w, 'panes')
  4765.  
  4766.  
  4767.  
  4768. class Studbutton(Button):
  4769.     
  4770.     def __init__(self, master = None, cnf = { }, **kw):
  4771.         Widget.__init__(self, master, 'studbutton', cnf, kw)
  4772.         self.bind('<Any-Enter>', self.tkButtonEnter)
  4773.         self.bind('<Any-Leave>', self.tkButtonLeave)
  4774.         self.bind('<1>', self.tkButtonDown)
  4775.         self.bind('<ButtonRelease-1>', self.tkButtonUp)
  4776.  
  4777.  
  4778.  
  4779. class Tributton(Button):
  4780.     
  4781.     def __init__(self, master = None, cnf = { }, **kw):
  4782.         Widget.__init__(self, master, 'tributton', cnf, kw)
  4783.         self.bind('<Any-Enter>', self.tkButtonEnter)
  4784.         self.bind('<Any-Leave>', self.tkButtonLeave)
  4785.         self.bind('<1>', self.tkButtonDown)
  4786.         self.bind('<ButtonRelease-1>', self.tkButtonUp)
  4787.         self['fg'] = self['bg']
  4788.         self['activebackground'] = self['bg']
  4789.  
  4790.  
  4791.  
  4792. def _test():
  4793.     root = Tk()
  4794.     text = 'This is Tcl/Tk version %s' % TclVersion
  4795.     if TclVersion >= 8.1:
  4796.         
  4797.         try:
  4798.             text = text + unicode('\nThis should be a cedilla: \xe7', 'iso-8859-1')
  4799.         except NameError:
  4800.             pass
  4801.         except:
  4802.             None<EXCEPTION MATCH>NameError
  4803.         
  4804.  
  4805.     None<EXCEPTION MATCH>NameError
  4806.     label = Label(root, text = text)
  4807.     label.pack()
  4808.     test = Button(root, text = 'Click me!', command = (lambda root = root: root.test.configure(text = '[%s]' % root.test['text'])))
  4809.     test.pack()
  4810.     root.test = test
  4811.     quit = Button(root, text = 'QUIT', command = root.destroy)
  4812.     quit.pack()
  4813.     root.iconify()
  4814.     root.update()
  4815.     root.deiconify()
  4816.     root.mainloop()
  4817.  
  4818. if __name__ == '__main__':
  4819.     _test()
  4820.  
  4821.