logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

tix.py (77040B)


  1. # Tix.py -- Tix widget wrappers.
  2. #
  3. # For Tix, see http://tix.sourceforge.net
  4. #
  5. # - Sudhir Shenoy (sshenoy@gol.com), Dec. 1995.
  6. # based on an idea of Jean-Marc Lugrin (lugrin@ms.com)
  7. #
  8. # NOTE: In order to minimize changes to Tkinter.py, some of the code here
  9. # (TixWidget.__init__) has been taken from Tkinter (Widget.__init__)
  10. # and will break if there are major changes in Tkinter.
  11. #
  12. # The Tix widgets are represented by a class hierarchy in python with proper
  13. # inheritance of base classes.
  14. #
  15. # As a result after creating a 'w = StdButtonBox', I can write
  16. # w.ok['text'] = 'Who Cares'
  17. # or w.ok['bg'] = w['bg']
  18. # or even w.ok.invoke()
  19. # etc.
  20. #
  21. # Compare the demo tixwidgets.py to the original Tcl program and you will
  22. # appreciate the advantages.
  23. #
  24. # NOTE: This module is deprecated since Python 3.6.
  25. import os
  26. import warnings
  27. import tkinter
  28. from tkinter import *
  29. from tkinter import _cnfmerge
  30. warnings.warn(
  31. 'The Tix Tk extension is unmaintained, and the tkinter.tix wrapper module'
  32. ' is deprecated in favor of tkinter.ttk',
  33. DeprecationWarning,
  34. stacklevel=2,
  35. )
  36. # Some more constants (for consistency with Tkinter)
  37. WINDOW = 'window'
  38. TEXT = 'text'
  39. STATUS = 'status'
  40. IMMEDIATE = 'immediate'
  41. IMAGE = 'image'
  42. IMAGETEXT = 'imagetext'
  43. BALLOON = 'balloon'
  44. AUTO = 'auto'
  45. ACROSSTOP = 'acrosstop'
  46. # A few useful constants for the Grid widget
  47. ASCII = 'ascii'
  48. CELL = 'cell'
  49. COLUMN = 'column'
  50. DECREASING = 'decreasing'
  51. INCREASING = 'increasing'
  52. INTEGER = 'integer'
  53. MAIN = 'main'
  54. MAX = 'max'
  55. REAL = 'real'
  56. ROW = 'row'
  57. S_REGION = 's-region'
  58. X_REGION = 'x-region'
  59. Y_REGION = 'y-region'
  60. # Some constants used by Tkinter dooneevent()
  61. TCL_DONT_WAIT = 1 << 1
  62. TCL_WINDOW_EVENTS = 1 << 2
  63. TCL_FILE_EVENTS = 1 << 3
  64. TCL_TIMER_EVENTS = 1 << 4
  65. TCL_IDLE_EVENTS = 1 << 5
  66. TCL_ALL_EVENTS = 0
  67. # BEWARE - this is implemented by copying some code from the Widget class
  68. # in Tkinter (to override Widget initialization) and is therefore
  69. # liable to break.
  70. # Could probably add this to Tkinter.Misc
  71. class tixCommand:
  72. """The tix commands provide access to miscellaneous elements
  73. of Tix's internal state and the Tix application context.
  74. Most of the information manipulated by these commands pertains
  75. to the application as a whole, or to a screen or
  76. display, rather than to a particular window.
  77. This is a mixin class, assumed to be mixed to Tkinter.Tk
  78. that supports the self.tk.call method.
  79. """
  80. def tix_addbitmapdir(self, directory):
  81. """Tix maintains a list of directories under which
  82. the tix_getimage and tix_getbitmap commands will
  83. search for image files. The standard bitmap directory
  84. is $TIX_LIBRARY/bitmaps. The addbitmapdir command
  85. adds directory into this list. By using this
  86. command, the image files of an applications can
  87. also be located using the tix_getimage or tix_getbitmap
  88. command.
  89. """
  90. return self.tk.call('tix', 'addbitmapdir', directory)
  91. def tix_cget(self, option):
  92. """Returns the current value of the configuration
  93. option given by option. Option may be any of the
  94. options described in the CONFIGURATION OPTIONS section.
  95. """
  96. return self.tk.call('tix', 'cget', option)
  97. def tix_configure(self, cnf=None, **kw):
  98. """Query or modify the configuration options of the Tix application
  99. context. If no option is specified, returns a dictionary all of the
  100. available options. If option is specified with no value, then the
  101. command returns a list describing the one named option (this list
  102. will be identical to the corresponding sublist of the value
  103. returned if no option is specified). If one or more option-value
  104. pairs are specified, then the command modifies the given option(s)
  105. to have the given value(s); in this case the command returns an
  106. empty string. Option may be any of the configuration options.
  107. """
  108. # Copied from Tkinter.py
  109. if kw:
  110. cnf = _cnfmerge((cnf, kw))
  111. elif cnf:
  112. cnf = _cnfmerge(cnf)
  113. if cnf is None:
  114. return self._getconfigure('tix', 'configure')
  115. if isinstance(cnf, str):
  116. return self._getconfigure1('tix', 'configure', '-'+cnf)
  117. return self.tk.call(('tix', 'configure') + self._options(cnf))
  118. def tix_filedialog(self, dlgclass=None):
  119. """Returns the file selection dialog that may be shared among
  120. different calls from this application. This command will create a
  121. file selection dialog widget when it is called the first time. This
  122. dialog will be returned by all subsequent calls to tix_filedialog.
  123. An optional dlgclass parameter can be passed to specified what type
  124. of file selection dialog widget is desired. Possible options are
  125. tix FileSelectDialog or tixExFileSelectDialog.
  126. """
  127. if dlgclass is not None:
  128. return self.tk.call('tix', 'filedialog', dlgclass)
  129. else:
  130. return self.tk.call('tix', 'filedialog')
  131. def tix_getbitmap(self, name):
  132. """Locates a bitmap file of the name name.xpm or name in one of the
  133. bitmap directories (see the tix_addbitmapdir command above). By
  134. using tix_getbitmap, you can avoid hard coding the pathnames of the
  135. bitmap files in your application. When successful, it returns the
  136. complete pathname of the bitmap file, prefixed with the character
  137. '@'. The returned value can be used to configure the -bitmap
  138. option of the TK and Tix widgets.
  139. """
  140. return self.tk.call('tix', 'getbitmap', name)
  141. def tix_getimage(self, name):
  142. """Locates an image file of the name name.xpm, name.xbm or name.ppm
  143. in one of the bitmap directories (see the addbitmapdir command
  144. above). If more than one file with the same name (but different
  145. extensions) exist, then the image type is chosen according to the
  146. depth of the X display: xbm images are chosen on monochrome
  147. displays and color images are chosen on color displays. By using
  148. tix_ getimage, you can avoid hard coding the pathnames of the
  149. image files in your application. When successful, this command
  150. returns the name of the newly created image, which can be used to
  151. configure the -image option of the Tk and Tix widgets.
  152. """
  153. return self.tk.call('tix', 'getimage', name)
  154. def tix_option_get(self, name):
  155. """Gets the options maintained by the Tix
  156. scheme mechanism. Available options include:
  157. active_bg active_fg bg
  158. bold_font dark1_bg dark1_fg
  159. dark2_bg dark2_fg disabled_fg
  160. fg fixed_font font
  161. inactive_bg inactive_fg input1_bg
  162. input2_bg italic_font light1_bg
  163. light1_fg light2_bg light2_fg
  164. menu_font output1_bg output2_bg
  165. select_bg select_fg selector
  166. """
  167. # could use self.tk.globalgetvar('tixOption', name)
  168. return self.tk.call('tix', 'option', 'get', name)
  169. def tix_resetoptions(self, newScheme, newFontSet, newScmPrio=None):
  170. """Resets the scheme and fontset of the Tix application to
  171. newScheme and newFontSet, respectively. This affects only those
  172. widgets created after this call. Therefore, it is best to call the
  173. resetoptions command before the creation of any widgets in a Tix
  174. application.
  175. The optional parameter newScmPrio can be given to reset the
  176. priority level of the Tk options set by the Tix schemes.
  177. Because of the way Tk handles the X option database, after Tix has
  178. been has imported and inited, it is not possible to reset the color
  179. schemes and font sets using the tix config command. Instead, the
  180. tix_resetoptions command must be used.
  181. """
  182. if newScmPrio is not None:
  183. return self.tk.call('tix', 'resetoptions', newScheme, newFontSet, newScmPrio)
  184. else:
  185. return self.tk.call('tix', 'resetoptions', newScheme, newFontSet)
  186. class Tk(tkinter.Tk, tixCommand):
  187. """Toplevel widget of Tix which represents mostly the main window
  188. of an application. It has an associated Tcl interpreter."""
  189. def __init__(self, screenName=None, baseName=None, className='Tix'):
  190. tkinter.Tk.__init__(self, screenName, baseName, className)
  191. tixlib = os.environ.get('TIX_LIBRARY')
  192. self.tk.eval('global auto_path; lappend auto_path [file dir [info nameof]]')
  193. if tixlib is not None:
  194. self.tk.eval('global auto_path; lappend auto_path {%s}' % tixlib)
  195. self.tk.eval('global tcl_pkgPath; lappend tcl_pkgPath {%s}' % tixlib)
  196. # Load Tix - this should work dynamically or statically
  197. # If it's static, tcl/tix8.1/pkgIndex.tcl should have
  198. # 'load {} Tix'
  199. # If it's dynamic under Unix, tcl/tix8.1/pkgIndex.tcl should have
  200. # 'load libtix8.1.8.3.so Tix'
  201. self.tk.eval('package require Tix')
  202. def destroy(self):
  203. # For safety, remove the delete_window binding before destroy
  204. self.protocol("WM_DELETE_WINDOW", "")
  205. tkinter.Tk.destroy(self)
  206. # The Tix 'tixForm' geometry manager
  207. class Form:
  208. """The Tix Form geometry manager
  209. Widgets can be arranged by specifying attachments to other widgets.
  210. See Tix documentation for complete details"""
  211. def config(self, cnf={}, **kw):
  212. self.tk.call('tixForm', self._w, *self._options(cnf, kw))
  213. form = config
  214. def __setitem__(self, key, value):
  215. Form.form(self, {key: value})
  216. def check(self):
  217. return self.tk.call('tixForm', 'check', self._w)
  218. def forget(self):
  219. self.tk.call('tixForm', 'forget', self._w)
  220. def grid(self, xsize=0, ysize=0):
  221. if (not xsize) and (not ysize):
  222. x = self.tk.call('tixForm', 'grid', self._w)
  223. y = self.tk.splitlist(x)
  224. z = ()
  225. for x in y:
  226. z = z + (self.tk.getint(x),)
  227. return z
  228. return self.tk.call('tixForm', 'grid', self._w, xsize, ysize)
  229. def info(self, option=None):
  230. if not option:
  231. return self.tk.call('tixForm', 'info', self._w)
  232. if option[0] != '-':
  233. option = '-' + option
  234. return self.tk.call('tixForm', 'info', self._w, option)
  235. def slaves(self):
  236. return [self._nametowidget(x) for x in
  237. self.tk.splitlist(
  238. self.tk.call(
  239. 'tixForm', 'slaves', self._w))]
  240. tkinter.Widget.__bases__ = tkinter.Widget.__bases__ + (Form,)
  241. class TixWidget(tkinter.Widget):
  242. """A TixWidget class is used to package all (or most) Tix widgets.
  243. Widget initialization is extended in two ways:
  244. 1) It is possible to give a list of options which must be part of
  245. the creation command (so called Tix 'static' options). These cannot be
  246. given as a 'config' command later.
  247. 2) It is possible to give the name of an existing TK widget. These are
  248. child widgets created automatically by a Tix mega-widget. The Tk call
  249. to create these widgets is therefore bypassed in TixWidget.__init__
  250. Both options are for use by subclasses only.
  251. """
  252. def __init__ (self, master=None, widgetName=None,
  253. static_options=None, cnf={}, kw={}):
  254. # Merge keywords and dictionary arguments
  255. if kw:
  256. cnf = _cnfmerge((cnf, kw))
  257. else:
  258. cnf = _cnfmerge(cnf)
  259. # Move static options into extra. static_options must be
  260. # a list of keywords (or None).
  261. extra=()
  262. # 'options' is always a static option
  263. if static_options:
  264. static_options.append('options')
  265. else:
  266. static_options = ['options']
  267. for k,v in list(cnf.items()):
  268. if k in static_options:
  269. extra = extra + ('-' + k, v)
  270. del cnf[k]
  271. self.widgetName = widgetName
  272. Widget._setup(self, master, cnf)
  273. # If widgetName is None, this is a dummy creation call where the
  274. # corresponding Tk widget has already been created by Tix
  275. if widgetName:
  276. self.tk.call(widgetName, self._w, *extra)
  277. # Non-static options - to be done via a 'config' command
  278. if cnf:
  279. Widget.config(self, cnf)
  280. # Dictionary to hold subwidget names for easier access. We can't
  281. # use the children list because the public Tix names may not be the
  282. # same as the pathname component
  283. self.subwidget_list = {}
  284. # We set up an attribute access function so that it is possible to
  285. # do w.ok['text'] = 'Hello' rather than w.subwidget('ok')['text'] = 'Hello'
  286. # when w is a StdButtonBox.
  287. # We can even do w.ok.invoke() because w.ok is subclassed from the
  288. # Button class if you go through the proper constructors
  289. def __getattr__(self, name):
  290. if name in self.subwidget_list:
  291. return self.subwidget_list[name]
  292. raise AttributeError(name)
  293. def set_silent(self, value):
  294. """Set a variable without calling its action routine"""
  295. self.tk.call('tixSetSilent', self._w, value)
  296. def subwidget(self, name):
  297. """Return the named subwidget (which must have been created by
  298. the sub-class)."""
  299. n = self._subwidget_name(name)
  300. if not n:
  301. raise TclError("Subwidget " + name + " not child of " + self._name)
  302. # Remove header of name and leading dot
  303. n = n[len(self._w)+1:]
  304. return self._nametowidget(n)
  305. def subwidgets_all(self):
  306. """Return all subwidgets."""
  307. names = self._subwidget_names()
  308. if not names:
  309. return []
  310. retlist = []
  311. for name in names:
  312. name = name[len(self._w)+1:]
  313. try:
  314. retlist.append(self._nametowidget(name))
  315. except:
  316. # some of the widgets are unknown e.g. border in LabelFrame
  317. pass
  318. return retlist
  319. def _subwidget_name(self,name):
  320. """Get a subwidget name (returns a String, not a Widget !)"""
  321. try:
  322. return self.tk.call(self._w, 'subwidget', name)
  323. except TclError:
  324. return None
  325. def _subwidget_names(self):
  326. """Return the name of all subwidgets."""
  327. try:
  328. x = self.tk.call(self._w, 'subwidgets', '-all')
  329. return self.tk.splitlist(x)
  330. except TclError:
  331. return None
  332. def config_all(self, option, value):
  333. """Set configuration options for all subwidgets (and self)."""
  334. if option == '':
  335. return
  336. elif not isinstance(option, str):
  337. option = repr(option)
  338. if not isinstance(value, str):
  339. value = repr(value)
  340. names = self._subwidget_names()
  341. for name in names:
  342. self.tk.call(name, 'configure', '-' + option, value)
  343. # These are missing from Tkinter
  344. def image_create(self, imgtype, cnf={}, master=None, **kw):
  345. if master is None:
  346. master = self
  347. if kw and cnf: cnf = _cnfmerge((cnf, kw))
  348. elif kw: cnf = kw
  349. options = ()
  350. for k, v in cnf.items():
  351. if callable(v):
  352. v = self._register(v)
  353. options = options + ('-'+k, v)
  354. return master.tk.call(('image', 'create', imgtype,) + options)
  355. def image_delete(self, imgname):
  356. try:
  357. self.tk.call('image', 'delete', imgname)
  358. except TclError:
  359. # May happen if the root was destroyed
  360. pass
  361. # Subwidgets are child widgets created automatically by mega-widgets.
  362. # In python, we have to create these subwidgets manually to mirror their
  363. # existence in Tk/Tix.
  364. class TixSubWidget(TixWidget):
  365. """Subwidget class.
  366. This is used to mirror child widgets automatically created
  367. by Tix/Tk as part of a mega-widget in Python (which is not informed
  368. of this)"""
  369. def __init__(self, master, name,
  370. destroy_physically=1, check_intermediate=1):
  371. if check_intermediate:
  372. path = master._subwidget_name(name)
  373. try:
  374. path = path[len(master._w)+1:]
  375. plist = path.split('.')
  376. except:
  377. plist = []
  378. if not check_intermediate:
  379. # immediate descendant
  380. TixWidget.__init__(self, master, None, None, {'name' : name})
  381. else:
  382. # Ensure that the intermediate widgets exist
  383. parent = master
  384. for i in range(len(plist) - 1):
  385. n = '.'.join(plist[:i+1])
  386. try:
  387. w = master._nametowidget(n)
  388. parent = w
  389. except KeyError:
  390. # Create the intermediate widget
  391. parent = TixSubWidget(parent, plist[i],
  392. destroy_physically=0,
  393. check_intermediate=0)
  394. # The Tk widget name is in plist, not in name
  395. if plist:
  396. name = plist[-1]
  397. TixWidget.__init__(self, parent, None, None, {'name' : name})
  398. self.destroy_physically = destroy_physically
  399. def destroy(self):
  400. # For some widgets e.g., a NoteBook, when we call destructors,
  401. # we must be careful not to destroy the frame widget since this
  402. # also destroys the parent NoteBook thus leading to an exception
  403. # in Tkinter when it finally calls Tcl to destroy the NoteBook
  404. for c in list(self.children.values()): c.destroy()
  405. if self._name in self.master.children:
  406. del self.master.children[self._name]
  407. if self._name in self.master.subwidget_list:
  408. del self.master.subwidget_list[self._name]
  409. if self.destroy_physically:
  410. # This is bypassed only for a few widgets
  411. self.tk.call('destroy', self._w)
  412. # Useful class to create a display style - later shared by many items.
  413. # Contributed by Steffen Kremser
  414. class DisplayStyle:
  415. """DisplayStyle - handle configuration options shared by
  416. (multiple) Display Items"""
  417. def __init__(self, itemtype, cnf={}, *, master=None, **kw):
  418. if master is None:
  419. if 'refwindow' in kw:
  420. master = kw['refwindow']
  421. elif 'refwindow' in cnf:
  422. master = cnf['refwindow']
  423. else:
  424. master = tkinter._get_default_root('create display style')
  425. self.tk = master.tk
  426. self.stylename = self.tk.call('tixDisplayStyle', itemtype,
  427. *self._options(cnf,kw) )
  428. def __str__(self):
  429. return self.stylename
  430. def _options(self, cnf, kw):
  431. if kw and cnf:
  432. cnf = _cnfmerge((cnf, kw))
  433. elif kw:
  434. cnf = kw
  435. opts = ()
  436. for k, v in cnf.items():
  437. opts = opts + ('-'+k, v)
  438. return opts
  439. def delete(self):
  440. self.tk.call(self.stylename, 'delete')
  441. def __setitem__(self,key,value):
  442. self.tk.call(self.stylename, 'configure', '-%s'%key, value)
  443. def config(self, cnf={}, **kw):
  444. return self._getconfigure(
  445. self.stylename, 'configure', *self._options(cnf,kw))
  446. def __getitem__(self,key):
  447. return self.tk.call(self.stylename, 'cget', '-%s'%key)
  448. ######################################################
  449. ### The Tix Widget classes - in alphabetical order ###
  450. ######################################################
  451. class Balloon(TixWidget):
  452. """Balloon help widget.
  453. Subwidget Class
  454. --------- -----
  455. label Label
  456. message Message"""
  457. # FIXME: It should inherit -superclass tixShell
  458. def __init__(self, master=None, cnf={}, **kw):
  459. # static seem to be -installcolormap -initwait -statusbar -cursor
  460. static = ['options', 'installcolormap', 'initwait', 'statusbar',
  461. 'cursor']
  462. TixWidget.__init__(self, master, 'tixBalloon', static, cnf, kw)
  463. self.subwidget_list['label'] = _dummyLabel(self, 'label',
  464. destroy_physically=0)
  465. self.subwidget_list['message'] = _dummyLabel(self, 'message',
  466. destroy_physically=0)
  467. def bind_widget(self, widget, cnf={}, **kw):
  468. """Bind balloon widget to another.
  469. One balloon widget may be bound to several widgets at the same time"""
  470. self.tk.call(self._w, 'bind', widget._w, *self._options(cnf, kw))
  471. def unbind_widget(self, widget):
  472. self.tk.call(self._w, 'unbind', widget._w)
  473. class ButtonBox(TixWidget):
  474. """ButtonBox - A container for pushbuttons.
  475. Subwidgets are the buttons added with the add method.
  476. """
  477. def __init__(self, master=None, cnf={}, **kw):
  478. TixWidget.__init__(self, master, 'tixButtonBox',
  479. ['orientation', 'options'], cnf, kw)
  480. def add(self, name, cnf={}, **kw):
  481. """Add a button with given name to box."""
  482. btn = self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
  483. self.subwidget_list[name] = _dummyButton(self, name)
  484. return btn
  485. def invoke(self, name):
  486. if name in self.subwidget_list:
  487. self.tk.call(self._w, 'invoke', name)
  488. class ComboBox(TixWidget):
  489. """ComboBox - an Entry field with a dropdown menu. The user can select a
  490. choice by either typing in the entry subwidget or selecting from the
  491. listbox subwidget.
  492. Subwidget Class
  493. --------- -----
  494. entry Entry
  495. arrow Button
  496. slistbox ScrolledListBox
  497. tick Button
  498. cross Button : present if created with the fancy option"""
  499. # FIXME: It should inherit -superclass tixLabelWidget
  500. def __init__ (self, master=None, cnf={}, **kw):
  501. TixWidget.__init__(self, master, 'tixComboBox',
  502. ['editable', 'dropdown', 'fancy', 'options'],
  503. cnf, kw)
  504. self.subwidget_list['label'] = _dummyLabel(self, 'label')
  505. self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
  506. self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
  507. self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
  508. 'slistbox')
  509. try:
  510. self.subwidget_list['tick'] = _dummyButton(self, 'tick')
  511. self.subwidget_list['cross'] = _dummyButton(self, 'cross')
  512. except TypeError:
  513. # unavailable when -fancy not specified
  514. pass
  515. # align
  516. def add_history(self, str):
  517. self.tk.call(self._w, 'addhistory', str)
  518. def append_history(self, str):
  519. self.tk.call(self._w, 'appendhistory', str)
  520. def insert(self, index, str):
  521. self.tk.call(self._w, 'insert', index, str)
  522. def pick(self, index):
  523. self.tk.call(self._w, 'pick', index)
  524. class Control(TixWidget):
  525. """Control - An entry field with value change arrows. The user can
  526. adjust the value by pressing the two arrow buttons or by entering
  527. the value directly into the entry. The new value will be checked
  528. against the user-defined upper and lower limits.
  529. Subwidget Class
  530. --------- -----
  531. incr Button
  532. decr Button
  533. entry Entry
  534. label Label"""
  535. # FIXME: It should inherit -superclass tixLabelWidget
  536. def __init__ (self, master=None, cnf={}, **kw):
  537. TixWidget.__init__(self, master, 'tixControl', ['options'], cnf, kw)
  538. self.subwidget_list['incr'] = _dummyButton(self, 'incr')
  539. self.subwidget_list['decr'] = _dummyButton(self, 'decr')
  540. self.subwidget_list['label'] = _dummyLabel(self, 'label')
  541. self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
  542. def decrement(self):
  543. self.tk.call(self._w, 'decr')
  544. def increment(self):
  545. self.tk.call(self._w, 'incr')
  546. def invoke(self):
  547. self.tk.call(self._w, 'invoke')
  548. def update(self):
  549. self.tk.call(self._w, 'update')
  550. class DirList(TixWidget):
  551. """DirList - displays a list view of a directory, its previous
  552. directories and its sub-directories. The user can choose one of
  553. the directories displayed in the list or change to another directory.
  554. Subwidget Class
  555. --------- -----
  556. hlist HList
  557. hsb Scrollbar
  558. vsb Scrollbar"""
  559. # FIXME: It should inherit -superclass tixScrolledHList
  560. def __init__(self, master, cnf={}, **kw):
  561. TixWidget.__init__(self, master, 'tixDirList', ['options'], cnf, kw)
  562. self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
  563. self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
  564. self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
  565. def chdir(self, dir):
  566. self.tk.call(self._w, 'chdir', dir)
  567. class DirTree(TixWidget):
  568. """DirTree - Directory Listing in a hierarchical view.
  569. Displays a tree view of a directory, its previous directories and its
  570. sub-directories. The user can choose one of the directories displayed
  571. in the list or change to another directory.
  572. Subwidget Class
  573. --------- -----
  574. hlist HList
  575. hsb Scrollbar
  576. vsb Scrollbar"""
  577. # FIXME: It should inherit -superclass tixScrolledHList
  578. def __init__(self, master, cnf={}, **kw):
  579. TixWidget.__init__(self, master, 'tixDirTree', ['options'], cnf, kw)
  580. self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
  581. self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
  582. self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
  583. def chdir(self, dir):
  584. self.tk.call(self._w, 'chdir', dir)
  585. class DirSelectBox(TixWidget):
  586. """DirSelectBox - Motif style file select box.
  587. It is generally used for
  588. the user to choose a file. FileSelectBox stores the files mostly
  589. recently selected into a ComboBox widget so that they can be quickly
  590. selected again.
  591. Subwidget Class
  592. --------- -----
  593. selection ComboBox
  594. filter ComboBox
  595. dirlist ScrolledListBox
  596. filelist ScrolledListBox"""
  597. def __init__(self, master, cnf={}, **kw):
  598. TixWidget.__init__(self, master, 'tixDirSelectBox', ['options'], cnf, kw)
  599. self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
  600. self.subwidget_list['dircbx'] = _dummyFileComboBox(self, 'dircbx')
  601. class ExFileSelectBox(TixWidget):
  602. """ExFileSelectBox - MS Windows style file select box.
  603. It provides a convenient method for the user to select files.
  604. Subwidget Class
  605. --------- -----
  606. cancel Button
  607. ok Button
  608. hidden Checkbutton
  609. types ComboBox
  610. dir ComboBox
  611. file ComboBox
  612. dirlist ScrolledListBox
  613. filelist ScrolledListBox"""
  614. def __init__(self, master, cnf={}, **kw):
  615. TixWidget.__init__(self, master, 'tixExFileSelectBox', ['options'], cnf, kw)
  616. self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
  617. self.subwidget_list['ok'] = _dummyButton(self, 'ok')
  618. self.subwidget_list['hidden'] = _dummyCheckbutton(self, 'hidden')
  619. self.subwidget_list['types'] = _dummyComboBox(self, 'types')
  620. self.subwidget_list['dir'] = _dummyComboBox(self, 'dir')
  621. self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
  622. self.subwidget_list['file'] = _dummyComboBox(self, 'file')
  623. self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
  624. def filter(self):
  625. self.tk.call(self._w, 'filter')
  626. def invoke(self):
  627. self.tk.call(self._w, 'invoke')
  628. # Should inherit from a Dialog class
  629. class DirSelectDialog(TixWidget):
  630. """The DirSelectDialog widget presents the directories in the file
  631. system in a dialog window. The user can use this dialog window to
  632. navigate through the file system to select the desired directory.
  633. Subwidgets Class
  634. ---------- -----
  635. dirbox DirSelectDialog"""
  636. # FIXME: It should inherit -superclass tixDialogShell
  637. def __init__(self, master, cnf={}, **kw):
  638. TixWidget.__init__(self, master, 'tixDirSelectDialog',
  639. ['options'], cnf, kw)
  640. self.subwidget_list['dirbox'] = _dummyDirSelectBox(self, 'dirbox')
  641. # cancel and ok buttons are missing
  642. def popup(self):
  643. self.tk.call(self._w, 'popup')
  644. def popdown(self):
  645. self.tk.call(self._w, 'popdown')
  646. # Should inherit from a Dialog class
  647. class ExFileSelectDialog(TixWidget):
  648. """ExFileSelectDialog - MS Windows style file select dialog.
  649. It provides a convenient method for the user to select files.
  650. Subwidgets Class
  651. ---------- -----
  652. fsbox ExFileSelectBox"""
  653. # FIXME: It should inherit -superclass tixDialogShell
  654. def __init__(self, master, cnf={}, **kw):
  655. TixWidget.__init__(self, master, 'tixExFileSelectDialog',
  656. ['options'], cnf, kw)
  657. self.subwidget_list['fsbox'] = _dummyExFileSelectBox(self, 'fsbox')
  658. def popup(self):
  659. self.tk.call(self._w, 'popup')
  660. def popdown(self):
  661. self.tk.call(self._w, 'popdown')
  662. class FileSelectBox(TixWidget):
  663. """ExFileSelectBox - Motif style file select box.
  664. It is generally used for
  665. the user to choose a file. FileSelectBox stores the files mostly
  666. recently selected into a ComboBox widget so that they can be quickly
  667. selected again.
  668. Subwidget Class
  669. --------- -----
  670. selection ComboBox
  671. filter ComboBox
  672. dirlist ScrolledListBox
  673. filelist ScrolledListBox"""
  674. def __init__(self, master, cnf={}, **kw):
  675. TixWidget.__init__(self, master, 'tixFileSelectBox', ['options'], cnf, kw)
  676. self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
  677. self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
  678. self.subwidget_list['filter'] = _dummyComboBox(self, 'filter')
  679. self.subwidget_list['selection'] = _dummyComboBox(self, 'selection')
  680. def apply_filter(self): # name of subwidget is same as command
  681. self.tk.call(self._w, 'filter')
  682. def invoke(self):
  683. self.tk.call(self._w, 'invoke')
  684. # Should inherit from a Dialog class
  685. class FileSelectDialog(TixWidget):
  686. """FileSelectDialog - Motif style file select dialog.
  687. Subwidgets Class
  688. ---------- -----
  689. btns StdButtonBox
  690. fsbox FileSelectBox"""
  691. # FIXME: It should inherit -superclass tixStdDialogShell
  692. def __init__(self, master, cnf={}, **kw):
  693. TixWidget.__init__(self, master, 'tixFileSelectDialog',
  694. ['options'], cnf, kw)
  695. self.subwidget_list['btns'] = _dummyStdButtonBox(self, 'btns')
  696. self.subwidget_list['fsbox'] = _dummyFileSelectBox(self, 'fsbox')
  697. def popup(self):
  698. self.tk.call(self._w, 'popup')
  699. def popdown(self):
  700. self.tk.call(self._w, 'popdown')
  701. class FileEntry(TixWidget):
  702. """FileEntry - Entry field with button that invokes a FileSelectDialog.
  703. The user can type in the filename manually. Alternatively, the user can
  704. press the button widget that sits next to the entry, which will bring
  705. up a file selection dialog.
  706. Subwidgets Class
  707. ---------- -----
  708. button Button
  709. entry Entry"""
  710. # FIXME: It should inherit -superclass tixLabelWidget
  711. def __init__(self, master, cnf={}, **kw):
  712. TixWidget.__init__(self, master, 'tixFileEntry',
  713. ['dialogtype', 'options'], cnf, kw)
  714. self.subwidget_list['button'] = _dummyButton(self, 'button')
  715. self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
  716. def invoke(self):
  717. self.tk.call(self._w, 'invoke')
  718. def file_dialog(self):
  719. # FIXME: return python object
  720. pass
  721. class HList(TixWidget, XView, YView):
  722. """HList - Hierarchy display widget can be used to display any data
  723. that have a hierarchical structure, for example, file system directory
  724. trees. The list entries are indented and connected by branch lines
  725. according to their places in the hierarchy.
  726. Subwidgets - None"""
  727. def __init__ (self,master=None,cnf={}, **kw):
  728. TixWidget.__init__(self, master, 'tixHList',
  729. ['columns', 'options'], cnf, kw)
  730. def add(self, entry, cnf={}, **kw):
  731. return self.tk.call(self._w, 'add', entry, *self._options(cnf, kw))
  732. def add_child(self, parent=None, cnf={}, **kw):
  733. if parent is None:
  734. parent = ''
  735. return self.tk.call(
  736. self._w, 'addchild', parent, *self._options(cnf, kw))
  737. def anchor_set(self, entry):
  738. self.tk.call(self._w, 'anchor', 'set', entry)
  739. def anchor_clear(self):
  740. self.tk.call(self._w, 'anchor', 'clear')
  741. def column_width(self, col=0, width=None, chars=None):
  742. if not chars:
  743. return self.tk.call(self._w, 'column', 'width', col, width)
  744. else:
  745. return self.tk.call(self._w, 'column', 'width', col,
  746. '-char', chars)
  747. def delete_all(self):
  748. self.tk.call(self._w, 'delete', 'all')
  749. def delete_entry(self, entry):
  750. self.tk.call(self._w, 'delete', 'entry', entry)
  751. def delete_offsprings(self, entry):
  752. self.tk.call(self._w, 'delete', 'offsprings', entry)
  753. def delete_siblings(self, entry):
  754. self.tk.call(self._w, 'delete', 'siblings', entry)
  755. def dragsite_set(self, index):
  756. self.tk.call(self._w, 'dragsite', 'set', index)
  757. def dragsite_clear(self):
  758. self.tk.call(self._w, 'dragsite', 'clear')
  759. def dropsite_set(self, index):
  760. self.tk.call(self._w, 'dropsite', 'set', index)
  761. def dropsite_clear(self):
  762. self.tk.call(self._w, 'dropsite', 'clear')
  763. def header_create(self, col, cnf={}, **kw):
  764. self.tk.call(self._w, 'header', 'create', col, *self._options(cnf, kw))
  765. def header_configure(self, col, cnf={}, **kw):
  766. if cnf is None:
  767. return self._getconfigure(self._w, 'header', 'configure', col)
  768. self.tk.call(self._w, 'header', 'configure', col,
  769. *self._options(cnf, kw))
  770. def header_cget(self, col, opt):
  771. return self.tk.call(self._w, 'header', 'cget', col, opt)
  772. def header_exists(self, col):
  773. # A workaround to Tix library bug (issue #25464).
  774. # The documented command is "exists", but only erroneous "exist" is
  775. # accepted.
  776. return self.tk.getboolean(self.tk.call(self._w, 'header', 'exist', col))
  777. header_exist = header_exists
  778. def header_delete(self, col):
  779. self.tk.call(self._w, 'header', 'delete', col)
  780. def header_size(self, col):
  781. return self.tk.call(self._w, 'header', 'size', col)
  782. def hide_entry(self, entry):
  783. self.tk.call(self._w, 'hide', 'entry', entry)
  784. def indicator_create(self, entry, cnf={}, **kw):
  785. self.tk.call(
  786. self._w, 'indicator', 'create', entry, *self._options(cnf, kw))
  787. def indicator_configure(self, entry, cnf={}, **kw):
  788. if cnf is None:
  789. return self._getconfigure(
  790. self._w, 'indicator', 'configure', entry)
  791. self.tk.call(
  792. self._w, 'indicator', 'configure', entry, *self._options(cnf, kw))
  793. def indicator_cget(self, entry, opt):
  794. return self.tk.call(self._w, 'indicator', 'cget', entry, opt)
  795. def indicator_exists(self, entry):
  796. return self.tk.call (self._w, 'indicator', 'exists', entry)
  797. def indicator_delete(self, entry):
  798. self.tk.call(self._w, 'indicator', 'delete', entry)
  799. def indicator_size(self, entry):
  800. return self.tk.call(self._w, 'indicator', 'size', entry)
  801. def info_anchor(self):
  802. return self.tk.call(self._w, 'info', 'anchor')
  803. def info_bbox(self, entry):
  804. return self._getints(
  805. self.tk.call(self._w, 'info', 'bbox', entry)) or None
  806. def info_children(self, entry=None):
  807. c = self.tk.call(self._w, 'info', 'children', entry)
  808. return self.tk.splitlist(c)
  809. def info_data(self, entry):
  810. return self.tk.call(self._w, 'info', 'data', entry)
  811. def info_dragsite(self):
  812. return self.tk.call(self._w, 'info', 'dragsite')
  813. def info_dropsite(self):
  814. return self.tk.call(self._w, 'info', 'dropsite')
  815. def info_exists(self, entry):
  816. return self.tk.call(self._w, 'info', 'exists', entry)
  817. def info_hidden(self, entry):
  818. return self.tk.call(self._w, 'info', 'hidden', entry)
  819. def info_next(self, entry):
  820. return self.tk.call(self._w, 'info', 'next', entry)
  821. def info_parent(self, entry):
  822. return self.tk.call(self._w, 'info', 'parent', entry)
  823. def info_prev(self, entry):
  824. return self.tk.call(self._w, 'info', 'prev', entry)
  825. def info_selection(self):
  826. c = self.tk.call(self._w, 'info', 'selection')
  827. return self.tk.splitlist(c)
  828. def item_cget(self, entry, col, opt):
  829. return self.tk.call(self._w, 'item', 'cget', entry, col, opt)
  830. def item_configure(self, entry, col, cnf={}, **kw):
  831. if cnf is None:
  832. return self._getconfigure(self._w, 'item', 'configure', entry, col)
  833. self.tk.call(self._w, 'item', 'configure', entry, col,
  834. *self._options(cnf, kw))
  835. def item_create(self, entry, col, cnf={}, **kw):
  836. self.tk.call(
  837. self._w, 'item', 'create', entry, col, *self._options(cnf, kw))
  838. def item_exists(self, entry, col):
  839. return self.tk.call(self._w, 'item', 'exists', entry, col)
  840. def item_delete(self, entry, col):
  841. self.tk.call(self._w, 'item', 'delete', entry, col)
  842. def entrycget(self, entry, opt):
  843. return self.tk.call(self._w, 'entrycget', entry, opt)
  844. def entryconfigure(self, entry, cnf={}, **kw):
  845. if cnf is None:
  846. return self._getconfigure(self._w, 'entryconfigure', entry)
  847. self.tk.call(self._w, 'entryconfigure', entry,
  848. *self._options(cnf, kw))
  849. def nearest(self, y):
  850. return self.tk.call(self._w, 'nearest', y)
  851. def see(self, entry):
  852. self.tk.call(self._w, 'see', entry)
  853. def selection_clear(self, cnf={}, **kw):
  854. self.tk.call(self._w, 'selection', 'clear', *self._options(cnf, kw))
  855. def selection_includes(self, entry):
  856. return self.tk.call(self._w, 'selection', 'includes', entry)
  857. def selection_set(self, first, last=None):
  858. self.tk.call(self._w, 'selection', 'set', first, last)
  859. def show_entry(self, entry):
  860. return self.tk.call(self._w, 'show', 'entry', entry)
  861. class InputOnly(TixWidget):
  862. """InputOnly - Invisible widget. Unix only.
  863. Subwidgets - None"""
  864. def __init__ (self,master=None,cnf={}, **kw):
  865. TixWidget.__init__(self, master, 'tixInputOnly', None, cnf, kw)
  866. class LabelEntry(TixWidget):
  867. """LabelEntry - Entry field with label. Packages an entry widget
  868. and a label into one mega widget. It can be used to simplify the creation
  869. of ``entry-form'' type of interface.
  870. Subwidgets Class
  871. ---------- -----
  872. label Label
  873. entry Entry"""
  874. def __init__ (self,master=None,cnf={}, **kw):
  875. TixWidget.__init__(self, master, 'tixLabelEntry',
  876. ['labelside','options'], cnf, kw)
  877. self.subwidget_list['label'] = _dummyLabel(self, 'label')
  878. self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
  879. class LabelFrame(TixWidget):
  880. """LabelFrame - Labelled Frame container. Packages a frame widget
  881. and a label into one mega widget. To create widgets inside a
  882. LabelFrame widget, one creates the new widgets relative to the
  883. frame subwidget and manage them inside the frame subwidget.
  884. Subwidgets Class
  885. ---------- -----
  886. label Label
  887. frame Frame"""
  888. def __init__ (self,master=None,cnf={}, **kw):
  889. TixWidget.__init__(self, master, 'tixLabelFrame',
  890. ['labelside','options'], cnf, kw)
  891. self.subwidget_list['label'] = _dummyLabel(self, 'label')
  892. self.subwidget_list['frame'] = _dummyFrame(self, 'frame')
  893. class ListNoteBook(TixWidget):
  894. """A ListNoteBook widget is very similar to the TixNoteBook widget:
  895. it can be used to display many windows in a limited space using a
  896. notebook metaphor. The notebook is divided into a stack of pages
  897. (windows). At one time only one of these pages can be shown.
  898. The user can navigate through these pages by
  899. choosing the name of the desired page in the hlist subwidget."""
  900. def __init__(self, master, cnf={}, **kw):
  901. TixWidget.__init__(self, master, 'tixListNoteBook', ['options'], cnf, kw)
  902. # Is this necessary? It's not an exposed subwidget in Tix.
  903. self.subwidget_list['pane'] = _dummyPanedWindow(self, 'pane',
  904. destroy_physically=0)
  905. self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
  906. self.subwidget_list['shlist'] = _dummyScrolledHList(self, 'shlist')
  907. def add(self, name, cnf={}, **kw):
  908. self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
  909. self.subwidget_list[name] = TixSubWidget(self, name)
  910. return self.subwidget_list[name]
  911. def page(self, name):
  912. return self.subwidget(name)
  913. def pages(self):
  914. # Can't call subwidgets_all directly because we don't want .nbframe
  915. names = self.tk.splitlist(self.tk.call(self._w, 'pages'))
  916. ret = []
  917. for x in names:
  918. ret.append(self.subwidget(x))
  919. return ret
  920. def raise_page(self, name): # raise is a python keyword
  921. self.tk.call(self._w, 'raise', name)
  922. class Meter(TixWidget):
  923. """The Meter widget can be used to show the progress of a background
  924. job which may take a long time to execute.
  925. """
  926. def __init__(self, master=None, cnf={}, **kw):
  927. TixWidget.__init__(self, master, 'tixMeter',
  928. ['options'], cnf, kw)
  929. class NoteBook(TixWidget):
  930. """NoteBook - Multi-page container widget (tabbed notebook metaphor).
  931. Subwidgets Class
  932. ---------- -----
  933. nbframe NoteBookFrame
  934. <pages> page widgets added dynamically with the add method"""
  935. def __init__ (self,master=None,cnf={}, **kw):
  936. TixWidget.__init__(self,master,'tixNoteBook', ['options'], cnf, kw)
  937. self.subwidget_list['nbframe'] = TixSubWidget(self, 'nbframe',
  938. destroy_physically=0)
  939. def add(self, name, cnf={}, **kw):
  940. self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
  941. self.subwidget_list[name] = TixSubWidget(self, name)
  942. return self.subwidget_list[name]
  943. def delete(self, name):
  944. self.tk.call(self._w, 'delete', name)
  945. self.subwidget_list[name].destroy()
  946. del self.subwidget_list[name]
  947. def page(self, name):
  948. return self.subwidget(name)
  949. def pages(self):
  950. # Can't call subwidgets_all directly because we don't want .nbframe
  951. names = self.tk.splitlist(self.tk.call(self._w, 'pages'))
  952. ret = []
  953. for x in names:
  954. ret.append(self.subwidget(x))
  955. return ret
  956. def raise_page(self, name): # raise is a python keyword
  957. self.tk.call(self._w, 'raise', name)
  958. def raised(self):
  959. return self.tk.call(self._w, 'raised')
  960. class NoteBookFrame(TixWidget):
  961. # FIXME: This is dangerous to expose to be called on its own.
  962. pass
  963. class OptionMenu(TixWidget):
  964. """OptionMenu - creates a menu button of options.
  965. Subwidget Class
  966. --------- -----
  967. menubutton Menubutton
  968. menu Menu"""
  969. def __init__(self, master, cnf={}, **kw):
  970. TixWidget.__init__(self, master, 'tixOptionMenu', ['options'], cnf, kw)
  971. self.subwidget_list['menubutton'] = _dummyMenubutton(self, 'menubutton')
  972. self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
  973. def add_command(self, name, cnf={}, **kw):
  974. self.tk.call(self._w, 'add', 'command', name, *self._options(cnf, kw))
  975. def add_separator(self, name, cnf={}, **kw):
  976. self.tk.call(self._w, 'add', 'separator', name, *self._options(cnf, kw))
  977. def delete(self, name):
  978. self.tk.call(self._w, 'delete', name)
  979. def disable(self, name):
  980. self.tk.call(self._w, 'disable', name)
  981. def enable(self, name):
  982. self.tk.call(self._w, 'enable', name)
  983. class PanedWindow(TixWidget):
  984. """PanedWindow - Multi-pane container widget
  985. allows the user to interactively manipulate the sizes of several
  986. panes. The panes can be arranged either vertically or horizontally.The
  987. user changes the sizes of the panes by dragging the resize handle
  988. between two panes.
  989. Subwidgets Class
  990. ---------- -----
  991. <panes> g/p widgets added dynamically with the add method."""
  992. def __init__(self, master, cnf={}, **kw):
  993. TixWidget.__init__(self, master, 'tixPanedWindow', ['orientation', 'options'], cnf, kw)
  994. # add delete forget panecget paneconfigure panes setsize
  995. def add(self, name, cnf={}, **kw):
  996. self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
  997. self.subwidget_list[name] = TixSubWidget(self, name,
  998. check_intermediate=0)
  999. return self.subwidget_list[name]
  1000. def delete(self, name):
  1001. self.tk.call(self._w, 'delete', name)
  1002. self.subwidget_list[name].destroy()
  1003. del self.subwidget_list[name]
  1004. def forget(self, name):
  1005. self.tk.call(self._w, 'forget', name)
  1006. def panecget(self, entry, opt):
  1007. return self.tk.call(self._w, 'panecget', entry, opt)
  1008. def paneconfigure(self, entry, cnf={}, **kw):
  1009. if cnf is None:
  1010. return self._getconfigure(self._w, 'paneconfigure', entry)
  1011. self.tk.call(self._w, 'paneconfigure', entry, *self._options(cnf, kw))
  1012. def panes(self):
  1013. names = self.tk.splitlist(self.tk.call(self._w, 'panes'))
  1014. return [self.subwidget(x) for x in names]
  1015. class PopupMenu(TixWidget):
  1016. """PopupMenu widget can be used as a replacement of the tk_popup command.
  1017. The advantage of the Tix PopupMenu widget is it requires less application
  1018. code to manipulate.
  1019. Subwidgets Class
  1020. ---------- -----
  1021. menubutton Menubutton
  1022. menu Menu"""
  1023. # FIXME: It should inherit -superclass tixShell
  1024. def __init__(self, master, cnf={}, **kw):
  1025. TixWidget.__init__(self, master, 'tixPopupMenu', ['options'], cnf, kw)
  1026. self.subwidget_list['menubutton'] = _dummyMenubutton(self, 'menubutton')
  1027. self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
  1028. def bind_widget(self, widget):
  1029. self.tk.call(self._w, 'bind', widget._w)
  1030. def unbind_widget(self, widget):
  1031. self.tk.call(self._w, 'unbind', widget._w)
  1032. def post_widget(self, widget, x, y):
  1033. self.tk.call(self._w, 'post', widget._w, x, y)
  1034. class ResizeHandle(TixWidget):
  1035. """Internal widget to draw resize handles on Scrolled widgets."""
  1036. def __init__(self, master, cnf={}, **kw):
  1037. # There seems to be a Tix bug rejecting the configure method
  1038. # Let's try making the flags -static
  1039. flags = ['options', 'command', 'cursorfg', 'cursorbg',
  1040. 'handlesize', 'hintcolor', 'hintwidth',
  1041. 'x', 'y']
  1042. # In fact, x y height width are configurable
  1043. TixWidget.__init__(self, master, 'tixResizeHandle',
  1044. flags, cnf, kw)
  1045. def attach_widget(self, widget):
  1046. self.tk.call(self._w, 'attachwidget', widget._w)
  1047. def detach_widget(self, widget):
  1048. self.tk.call(self._w, 'detachwidget', widget._w)
  1049. def hide(self, widget):
  1050. self.tk.call(self._w, 'hide', widget._w)
  1051. def show(self, widget):
  1052. self.tk.call(self._w, 'show', widget._w)
  1053. class ScrolledHList(TixWidget):
  1054. """ScrolledHList - HList with automatic scrollbars."""
  1055. # FIXME: It should inherit -superclass tixScrolledWidget
  1056. def __init__(self, master, cnf={}, **kw):
  1057. TixWidget.__init__(self, master, 'tixScrolledHList', ['options'],
  1058. cnf, kw)
  1059. self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
  1060. self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
  1061. self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
  1062. class ScrolledListBox(TixWidget):
  1063. """ScrolledListBox - Listbox with automatic scrollbars."""
  1064. # FIXME: It should inherit -superclass tixScrolledWidget
  1065. def __init__(self, master, cnf={}, **kw):
  1066. TixWidget.__init__(self, master, 'tixScrolledListBox', ['options'], cnf, kw)
  1067. self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox')
  1068. self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
  1069. self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
  1070. class ScrolledText(TixWidget):
  1071. """ScrolledText - Text with automatic scrollbars."""
  1072. # FIXME: It should inherit -superclass tixScrolledWidget
  1073. def __init__(self, master, cnf={}, **kw):
  1074. TixWidget.__init__(self, master, 'tixScrolledText', ['options'], cnf, kw)
  1075. self.subwidget_list['text'] = _dummyText(self, 'text')
  1076. self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
  1077. self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
  1078. class ScrolledTList(TixWidget):
  1079. """ScrolledTList - TList with automatic scrollbars."""
  1080. # FIXME: It should inherit -superclass tixScrolledWidget
  1081. def __init__(self, master, cnf={}, **kw):
  1082. TixWidget.__init__(self, master, 'tixScrolledTList', ['options'],
  1083. cnf, kw)
  1084. self.subwidget_list['tlist'] = _dummyTList(self, 'tlist')
  1085. self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
  1086. self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
  1087. class ScrolledWindow(TixWidget):
  1088. """ScrolledWindow - Window with automatic scrollbars."""
  1089. # FIXME: It should inherit -superclass tixScrolledWidget
  1090. def __init__(self, master, cnf={}, **kw):
  1091. TixWidget.__init__(self, master, 'tixScrolledWindow', ['options'], cnf, kw)
  1092. self.subwidget_list['window'] = _dummyFrame(self, 'window')
  1093. self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
  1094. self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
  1095. class Select(TixWidget):
  1096. """Select - Container of button subwidgets. It can be used to provide
  1097. radio-box or check-box style of selection options for the user.
  1098. Subwidgets are buttons added dynamically using the add method."""
  1099. # FIXME: It should inherit -superclass tixLabelWidget
  1100. def __init__(self, master, cnf={}, **kw):
  1101. TixWidget.__init__(self, master, 'tixSelect',
  1102. ['allowzero', 'radio', 'orientation', 'labelside',
  1103. 'options'],
  1104. cnf, kw)
  1105. self.subwidget_list['label'] = _dummyLabel(self, 'label')
  1106. def add(self, name, cnf={}, **kw):
  1107. self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
  1108. self.subwidget_list[name] = _dummyButton(self, name)
  1109. return self.subwidget_list[name]
  1110. def invoke(self, name):
  1111. self.tk.call(self._w, 'invoke', name)
  1112. class Shell(TixWidget):
  1113. """Toplevel window.
  1114. Subwidgets - None"""
  1115. def __init__ (self,master=None,cnf={}, **kw):
  1116. TixWidget.__init__(self, master, 'tixShell', ['options', 'title'], cnf, kw)
  1117. class DialogShell(TixWidget):
  1118. """Toplevel window, with popup popdown and center methods.
  1119. It tells the window manager that it is a dialog window and should be
  1120. treated specially. The exact treatment depends on the treatment of
  1121. the window manager.
  1122. Subwidgets - None"""
  1123. # FIXME: It should inherit from Shell
  1124. def __init__ (self,master=None,cnf={}, **kw):
  1125. TixWidget.__init__(self, master,
  1126. 'tixDialogShell',
  1127. ['options', 'title', 'mapped',
  1128. 'minheight', 'minwidth',
  1129. 'parent', 'transient'], cnf, kw)
  1130. def popdown(self):
  1131. self.tk.call(self._w, 'popdown')
  1132. def popup(self):
  1133. self.tk.call(self._w, 'popup')
  1134. def center(self):
  1135. self.tk.call(self._w, 'center')
  1136. class StdButtonBox(TixWidget):
  1137. """StdButtonBox - Standard Button Box (OK, Apply, Cancel and Help) """
  1138. def __init__(self, master=None, cnf={}, **kw):
  1139. TixWidget.__init__(self, master, 'tixStdButtonBox',
  1140. ['orientation', 'options'], cnf, kw)
  1141. self.subwidget_list['ok'] = _dummyButton(self, 'ok')
  1142. self.subwidget_list['apply'] = _dummyButton(self, 'apply')
  1143. self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
  1144. self.subwidget_list['help'] = _dummyButton(self, 'help')
  1145. def invoke(self, name):
  1146. if name in self.subwidget_list:
  1147. self.tk.call(self._w, 'invoke', name)
  1148. class TList(TixWidget, XView, YView):
  1149. """TList - Hierarchy display widget which can be
  1150. used to display data in a tabular format. The list entries of a TList
  1151. widget are similar to the entries in the Tk listbox widget. The main
  1152. differences are (1) the TList widget can display the list entries in a
  1153. two dimensional format and (2) you can use graphical images as well as
  1154. multiple colors and fonts for the list entries.
  1155. Subwidgets - None"""
  1156. def __init__ (self,master=None,cnf={}, **kw):
  1157. TixWidget.__init__(self, master, 'tixTList', ['options'], cnf, kw)
  1158. def active_set(self, index):
  1159. self.tk.call(self._w, 'active', 'set', index)
  1160. def active_clear(self):
  1161. self.tk.call(self._w, 'active', 'clear')
  1162. def anchor_set(self, index):
  1163. self.tk.call(self._w, 'anchor', 'set', index)
  1164. def anchor_clear(self):
  1165. self.tk.call(self._w, 'anchor', 'clear')
  1166. def delete(self, from_, to=None):
  1167. self.tk.call(self._w, 'delete', from_, to)
  1168. def dragsite_set(self, index):
  1169. self.tk.call(self._w, 'dragsite', 'set', index)
  1170. def dragsite_clear(self):
  1171. self.tk.call(self._w, 'dragsite', 'clear')
  1172. def dropsite_set(self, index):
  1173. self.tk.call(self._w, 'dropsite', 'set', index)
  1174. def dropsite_clear(self):
  1175. self.tk.call(self._w, 'dropsite', 'clear')
  1176. def insert(self, index, cnf={}, **kw):
  1177. self.tk.call(self._w, 'insert', index, *self._options(cnf, kw))
  1178. def info_active(self):
  1179. return self.tk.call(self._w, 'info', 'active')
  1180. def info_anchor(self):
  1181. return self.tk.call(self._w, 'info', 'anchor')
  1182. def info_down(self, index):
  1183. return self.tk.call(self._w, 'info', 'down', index)
  1184. def info_left(self, index):
  1185. return self.tk.call(self._w, 'info', 'left', index)
  1186. def info_right(self, index):
  1187. return self.tk.call(self._w, 'info', 'right', index)
  1188. def info_selection(self):
  1189. c = self.tk.call(self._w, 'info', 'selection')
  1190. return self.tk.splitlist(c)
  1191. def info_size(self):
  1192. return self.tk.call(self._w, 'info', 'size')
  1193. def info_up(self, index):
  1194. return self.tk.call(self._w, 'info', 'up', index)
  1195. def nearest(self, x, y):
  1196. return self.tk.call(self._w, 'nearest', x, y)
  1197. def see(self, index):
  1198. self.tk.call(self._w, 'see', index)
  1199. def selection_clear(self, cnf={}, **kw):
  1200. self.tk.call(self._w, 'selection', 'clear', *self._options(cnf, kw))
  1201. def selection_includes(self, index):
  1202. return self.tk.call(self._w, 'selection', 'includes', index)
  1203. def selection_set(self, first, last=None):
  1204. self.tk.call(self._w, 'selection', 'set', first, last)
  1205. class Tree(TixWidget):
  1206. """Tree - The tixTree widget can be used to display hierarchical
  1207. data in a tree form. The user can adjust
  1208. the view of the tree by opening or closing parts of the tree."""
  1209. # FIXME: It should inherit -superclass tixScrolledWidget
  1210. def __init__(self, master=None, cnf={}, **kw):
  1211. TixWidget.__init__(self, master, 'tixTree',
  1212. ['options'], cnf, kw)
  1213. self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
  1214. self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
  1215. self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
  1216. def autosetmode(self):
  1217. '''This command calls the setmode method for all the entries in this
  1218. Tree widget: if an entry has no child entries, its mode is set to
  1219. none. Otherwise, if the entry has any hidden child entries, its mode is
  1220. set to open; otherwise its mode is set to close.'''
  1221. self.tk.call(self._w, 'autosetmode')
  1222. def close(self, entrypath):
  1223. '''Close the entry given by entryPath if its mode is close.'''
  1224. self.tk.call(self._w, 'close', entrypath)
  1225. def getmode(self, entrypath):
  1226. '''Returns the current mode of the entry given by entryPath.'''
  1227. return self.tk.call(self._w, 'getmode', entrypath)
  1228. def open(self, entrypath):
  1229. '''Open the entry given by entryPath if its mode is open.'''
  1230. self.tk.call(self._w, 'open', entrypath)
  1231. def setmode(self, entrypath, mode='none'):
  1232. '''This command is used to indicate whether the entry given by
  1233. entryPath has children entries and whether the children are visible. mode
  1234. must be one of open, close or none. If mode is set to open, a (+)
  1235. indicator is drawn next the entry. If mode is set to close, a (-)
  1236. indicator is drawn next the entry. If mode is set to none, no
  1237. indicators will be drawn for this entry. The default mode is none. The
  1238. open mode indicates the entry has hidden children and this entry can be
  1239. opened by the user. The close mode indicates that all the children of the
  1240. entry are now visible and the entry can be closed by the user.'''
  1241. self.tk.call(self._w, 'setmode', entrypath, mode)
  1242. # Could try subclassing Tree for CheckList - would need another arg to init
  1243. class CheckList(TixWidget):
  1244. """The CheckList widget
  1245. displays a list of items to be selected by the user. CheckList acts
  1246. similarly to the Tk checkbutton or radiobutton widgets, except it is
  1247. capable of handling many more items than checkbuttons or radiobuttons.
  1248. """
  1249. # FIXME: It should inherit -superclass tixTree
  1250. def __init__(self, master=None, cnf={}, **kw):
  1251. TixWidget.__init__(self, master, 'tixCheckList',
  1252. ['options', 'radio'], cnf, kw)
  1253. self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
  1254. self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
  1255. self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
  1256. def autosetmode(self):
  1257. '''This command calls the setmode method for all the entries in this
  1258. Tree widget: if an entry has no child entries, its mode is set to
  1259. none. Otherwise, if the entry has any hidden child entries, its mode is
  1260. set to open; otherwise its mode is set to close.'''
  1261. self.tk.call(self._w, 'autosetmode')
  1262. def close(self, entrypath):
  1263. '''Close the entry given by entryPath if its mode is close.'''
  1264. self.tk.call(self._w, 'close', entrypath)
  1265. def getmode(self, entrypath):
  1266. '''Returns the current mode of the entry given by entryPath.'''
  1267. return self.tk.call(self._w, 'getmode', entrypath)
  1268. def open(self, entrypath):
  1269. '''Open the entry given by entryPath if its mode is open.'''
  1270. self.tk.call(self._w, 'open', entrypath)
  1271. def getselection(self, mode='on'):
  1272. '''Returns a list of items whose status matches status. If status is
  1273. not specified, the list of items in the "on" status will be returned.
  1274. Mode can be on, off, default'''
  1275. return self.tk.splitlist(self.tk.call(self._w, 'getselection', mode))
  1276. def getstatus(self, entrypath):
  1277. '''Returns the current status of entryPath.'''
  1278. return self.tk.call(self._w, 'getstatus', entrypath)
  1279. def setstatus(self, entrypath, mode='on'):
  1280. '''Sets the status of entryPath to be status. A bitmap will be
  1281. displayed next to the entry its status is on, off or default.'''
  1282. self.tk.call(self._w, 'setstatus', entrypath, mode)
  1283. ###########################################################################
  1284. ### The subclassing below is used to instantiate the subwidgets in each ###
  1285. ### mega widget. This allows us to access their methods directly. ###
  1286. ###########################################################################
  1287. class _dummyButton(Button, TixSubWidget):
  1288. def __init__(self, master, name, destroy_physically=1):
  1289. TixSubWidget.__init__(self, master, name, destroy_physically)
  1290. class _dummyCheckbutton(Checkbutton, TixSubWidget):
  1291. def __init__(self, master, name, destroy_physically=1):
  1292. TixSubWidget.__init__(self, master, name, destroy_physically)
  1293. class _dummyEntry(Entry, TixSubWidget):
  1294. def __init__(self, master, name, destroy_physically=1):
  1295. TixSubWidget.__init__(self, master, name, destroy_physically)
  1296. class _dummyFrame(Frame, TixSubWidget):
  1297. def __init__(self, master, name, destroy_physically=1):
  1298. TixSubWidget.__init__(self, master, name, destroy_physically)
  1299. class _dummyLabel(Label, TixSubWidget):
  1300. def __init__(self, master, name, destroy_physically=1):
  1301. TixSubWidget.__init__(self, master, name, destroy_physically)
  1302. class _dummyListbox(Listbox, TixSubWidget):
  1303. def __init__(self, master, name, destroy_physically=1):
  1304. TixSubWidget.__init__(self, master, name, destroy_physically)
  1305. class _dummyMenu(Menu, TixSubWidget):
  1306. def __init__(self, master, name, destroy_physically=1):
  1307. TixSubWidget.__init__(self, master, name, destroy_physically)
  1308. class _dummyMenubutton(Menubutton, TixSubWidget):
  1309. def __init__(self, master, name, destroy_physically=1):
  1310. TixSubWidget.__init__(self, master, name, destroy_physically)
  1311. class _dummyScrollbar(Scrollbar, TixSubWidget):
  1312. def __init__(self, master, name, destroy_physically=1):
  1313. TixSubWidget.__init__(self, master, name, destroy_physically)
  1314. class _dummyText(Text, TixSubWidget):
  1315. def __init__(self, master, name, destroy_physically=1):
  1316. TixSubWidget.__init__(self, master, name, destroy_physically)
  1317. class _dummyScrolledListBox(ScrolledListBox, TixSubWidget):
  1318. def __init__(self, master, name, destroy_physically=1):
  1319. TixSubWidget.__init__(self, master, name, destroy_physically)
  1320. self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox')
  1321. self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
  1322. self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
  1323. class _dummyHList(HList, TixSubWidget):
  1324. def __init__(self, master, name, destroy_physically=1):
  1325. TixSubWidget.__init__(self, master, name, destroy_physically)
  1326. class _dummyScrolledHList(ScrolledHList, TixSubWidget):
  1327. def __init__(self, master, name, destroy_physically=1):
  1328. TixSubWidget.__init__(self, master, name, destroy_physically)
  1329. self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
  1330. self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
  1331. self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
  1332. class _dummyTList(TList, TixSubWidget):
  1333. def __init__(self, master, name, destroy_physically=1):
  1334. TixSubWidget.__init__(self, master, name, destroy_physically)
  1335. class _dummyComboBox(ComboBox, TixSubWidget):
  1336. def __init__(self, master, name, destroy_physically=1):
  1337. TixSubWidget.__init__(self, master, name, ['fancy',destroy_physically])
  1338. self.subwidget_list['label'] = _dummyLabel(self, 'label')
  1339. self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
  1340. self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
  1341. self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
  1342. 'slistbox')
  1343. try:
  1344. self.subwidget_list['tick'] = _dummyButton(self, 'tick')
  1345. #cross Button : present if created with the fancy option
  1346. self.subwidget_list['cross'] = _dummyButton(self, 'cross')
  1347. except TypeError:
  1348. # unavailable when -fancy not specified
  1349. pass
  1350. class _dummyDirList(DirList, TixSubWidget):
  1351. def __init__(self, master, name, destroy_physically=1):
  1352. TixSubWidget.__init__(self, master, name, destroy_physically)
  1353. self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
  1354. self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
  1355. self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
  1356. class _dummyDirSelectBox(DirSelectBox, TixSubWidget):
  1357. def __init__(self, master, name, destroy_physically=1):
  1358. TixSubWidget.__init__(self, master, name, destroy_physically)
  1359. self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
  1360. self.subwidget_list['dircbx'] = _dummyFileComboBox(self, 'dircbx')
  1361. class _dummyExFileSelectBox(ExFileSelectBox, TixSubWidget):
  1362. def __init__(self, master, name, destroy_physically=1):
  1363. TixSubWidget.__init__(self, master, name, destroy_physically)
  1364. self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
  1365. self.subwidget_list['ok'] = _dummyButton(self, 'ok')
  1366. self.subwidget_list['hidden'] = _dummyCheckbutton(self, 'hidden')
  1367. self.subwidget_list['types'] = _dummyComboBox(self, 'types')
  1368. self.subwidget_list['dir'] = _dummyComboBox(self, 'dir')
  1369. self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
  1370. self.subwidget_list['file'] = _dummyComboBox(self, 'file')
  1371. self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
  1372. class _dummyFileSelectBox(FileSelectBox, TixSubWidget):
  1373. def __init__(self, master, name, destroy_physically=1):
  1374. TixSubWidget.__init__(self, master, name, destroy_physically)
  1375. self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
  1376. self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
  1377. self.subwidget_list['filter'] = _dummyComboBox(self, 'filter')
  1378. self.subwidget_list['selection'] = _dummyComboBox(self, 'selection')
  1379. class _dummyFileComboBox(ComboBox, TixSubWidget):
  1380. def __init__(self, master, name, destroy_physically=1):
  1381. TixSubWidget.__init__(self, master, name, destroy_physically)
  1382. self.subwidget_list['dircbx'] = _dummyComboBox(self, 'dircbx')
  1383. class _dummyStdButtonBox(StdButtonBox, TixSubWidget):
  1384. def __init__(self, master, name, destroy_physically=1):
  1385. TixSubWidget.__init__(self, master, name, destroy_physically)
  1386. self.subwidget_list['ok'] = _dummyButton(self, 'ok')
  1387. self.subwidget_list['apply'] = _dummyButton(self, 'apply')
  1388. self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
  1389. self.subwidget_list['help'] = _dummyButton(self, 'help')
  1390. class _dummyNoteBookFrame(NoteBookFrame, TixSubWidget):
  1391. def __init__(self, master, name, destroy_physically=0):
  1392. TixSubWidget.__init__(self, master, name, destroy_physically)
  1393. class _dummyPanedWindow(PanedWindow, TixSubWidget):
  1394. def __init__(self, master, name, destroy_physically=1):
  1395. TixSubWidget.__init__(self, master, name, destroy_physically)
  1396. ########################
  1397. ### Utility Routines ###
  1398. ########################
  1399. #mike Should tixDestroy be exposed as a wrapper? - but not for widgets.
  1400. def OptionName(widget):
  1401. '''Returns the qualified path name for the widget. Normally used to set
  1402. default options for subwidgets. See tixwidgets.py'''
  1403. return widget.tk.call('tixOptionName', widget._w)
  1404. # Called with a dictionary argument of the form
  1405. # {'*.c':'C source files', '*.txt':'Text Files', '*':'All files'}
  1406. # returns a string which can be used to configure the fsbox file types
  1407. # in an ExFileSelectBox. i.e.,
  1408. # '{{*} {* - All files}} {{*.c} {*.c - C source files}} {{*.txt} {*.txt - Text Files}}'
  1409. def FileTypeList(dict):
  1410. s = ''
  1411. for type in dict.keys():
  1412. s = s + '{{' + type + '} {' + type + ' - ' + dict[type] + '}} '
  1413. return s
  1414. # Still to be done:
  1415. # tixIconView
  1416. class CObjView(TixWidget):
  1417. """This file implements the Canvas Object View widget. This is a base
  1418. class of IconView. It implements automatic placement/adjustment of the
  1419. scrollbars according to the canvas objects inside the canvas subwidget.
  1420. The scrollbars are adjusted so that the canvas is just large enough
  1421. to see all the objects.
  1422. """
  1423. # FIXME: It should inherit -superclass tixScrolledWidget
  1424. pass
  1425. class Grid(TixWidget, XView, YView):
  1426. '''The Tix Grid command creates a new window and makes it into a
  1427. tixGrid widget. Additional options, may be specified on the command
  1428. line or in the option database to configure aspects such as its cursor
  1429. and relief.
  1430. A Grid widget displays its contents in a two dimensional grid of cells.
  1431. Each cell may contain one Tix display item, which may be in text,
  1432. graphics or other formats. See the DisplayStyle class for more information
  1433. about Tix display items. Individual cells, or groups of cells, can be
  1434. formatted with a wide range of attributes, such as its color, relief and
  1435. border.
  1436. Subwidgets - None'''
  1437. # valid specific resources as of Tk 8.4
  1438. # editdonecmd, editnotifycmd, floatingcols, floatingrows, formatcmd,
  1439. # highlightbackground, highlightcolor, leftmargin, itemtype, selectmode,
  1440. # selectunit, topmargin,
  1441. def __init__(self, master=None, cnf={}, **kw):
  1442. static= []
  1443. self.cnf= cnf
  1444. TixWidget.__init__(self, master, 'tixGrid', static, cnf, kw)
  1445. # valid options as of Tk 8.4
  1446. # anchor, bdtype, cget, configure, delete, dragsite, dropsite, entrycget,
  1447. # edit, entryconfigure, format, geometryinfo, info, index, move, nearest,
  1448. # selection, set, size, unset, xview, yview
  1449. def anchor_clear(self):
  1450. """Removes the selection anchor."""
  1451. self.tk.call(self, 'anchor', 'clear')
  1452. def anchor_get(self):
  1453. "Get the (x,y) coordinate of the current anchor cell"
  1454. return self._getints(self.tk.call(self, 'anchor', 'get'))
  1455. def anchor_set(self, x, y):
  1456. """Set the selection anchor to the cell at (x, y)."""
  1457. self.tk.call(self, 'anchor', 'set', x, y)
  1458. def delete_row(self, from_, to=None):
  1459. """Delete rows between from_ and to inclusive.
  1460. If to is not provided, delete only row at from_"""
  1461. if to is None:
  1462. self.tk.call(self, 'delete', 'row', from_)
  1463. else:
  1464. self.tk.call(self, 'delete', 'row', from_, to)
  1465. def delete_column(self, from_, to=None):
  1466. """Delete columns between from_ and to inclusive.
  1467. If to is not provided, delete only column at from_"""
  1468. if to is None:
  1469. self.tk.call(self, 'delete', 'column', from_)
  1470. else:
  1471. self.tk.call(self, 'delete', 'column', from_, to)
  1472. def edit_apply(self):
  1473. """If any cell is being edited, de-highlight the cell and applies
  1474. the changes."""
  1475. self.tk.call(self, 'edit', 'apply')
  1476. def edit_set(self, x, y):
  1477. """Highlights the cell at (x, y) for editing, if the -editnotify
  1478. command returns True for this cell."""
  1479. self.tk.call(self, 'edit', 'set', x, y)
  1480. def entrycget(self, x, y, option):
  1481. "Get the option value for cell at (x,y)"
  1482. if option and option[0] != '-':
  1483. option = '-' + option
  1484. return self.tk.call(self, 'entrycget', x, y, option)
  1485. def entryconfigure(self, x, y, cnf=None, **kw):
  1486. return self._configure(('entryconfigure', x, y), cnf, kw)
  1487. # def format
  1488. # def index
  1489. def info_exists(self, x, y):
  1490. "Return True if display item exists at (x,y)"
  1491. return self._getboolean(self.tk.call(self, 'info', 'exists', x, y))
  1492. def info_bbox(self, x, y):
  1493. # This seems to always return '', at least for 'text' displayitems
  1494. return self.tk.call(self, 'info', 'bbox', x, y)
  1495. def move_column(self, from_, to, offset):
  1496. """Moves the range of columns from position FROM through TO by
  1497. the distance indicated by OFFSET. For example, move_column(2, 4, 1)
  1498. moves the columns 2,3,4 to columns 3,4,5."""
  1499. self.tk.call(self, 'move', 'column', from_, to, offset)
  1500. def move_row(self, from_, to, offset):
  1501. """Moves the range of rows from position FROM through TO by
  1502. the distance indicated by OFFSET.
  1503. For example, move_row(2, 4, 1) moves the rows 2,3,4 to rows 3,4,5."""
  1504. self.tk.call(self, 'move', 'row', from_, to, offset)
  1505. def nearest(self, x, y):
  1506. "Return coordinate of cell nearest pixel coordinate (x,y)"
  1507. return self._getints(self.tk.call(self, 'nearest', x, y))
  1508. # def selection adjust
  1509. # def selection clear
  1510. # def selection includes
  1511. # def selection set
  1512. # def selection toggle
  1513. def set(self, x, y, itemtype=None, **kw):
  1514. args= self._options(self.cnf, kw)
  1515. if itemtype is not None:
  1516. args= ('-itemtype', itemtype) + args
  1517. self.tk.call(self, 'set', x, y, *args)
  1518. def size_column(self, index, **kw):
  1519. """Queries or sets the size of the column given by
  1520. INDEX. INDEX may be any non-negative
  1521. integer that gives the position of a given column.
  1522. INDEX can also be the string "default"; in this case, this command
  1523. queries or sets the default size of all columns.
  1524. When no option-value pair is given, this command returns a tuple
  1525. containing the current size setting of the given column. When
  1526. option-value pairs are given, the corresponding options of the
  1527. size setting of the given column are changed. Options may be one
  1528. of the following:
  1529. pad0 pixels
  1530. Specifies the paddings to the left of a column.
  1531. pad1 pixels
  1532. Specifies the paddings to the right of a column.
  1533. size val
  1534. Specifies the width of a column. Val may be:
  1535. "auto" -- the width of the column is set to the
  1536. width of the widest cell in the column;
  1537. a valid Tk screen distance unit;
  1538. or a real number following by the word chars
  1539. (e.g. 3.4chars) that sets the width of the column to the
  1540. given number of characters."""
  1541. return self.tk.splitlist(self.tk.call(self._w, 'size', 'column', index,
  1542. *self._options({}, kw)))
  1543. def size_row(self, index, **kw):
  1544. """Queries or sets the size of the row given by
  1545. INDEX. INDEX may be any non-negative
  1546. integer that gives the position of a given row .
  1547. INDEX can also be the string "default"; in this case, this command
  1548. queries or sets the default size of all rows.
  1549. When no option-value pair is given, this command returns a list con-
  1550. taining the current size setting of the given row . When option-value
  1551. pairs are given, the corresponding options of the size setting of the
  1552. given row are changed. Options may be one of the following:
  1553. pad0 pixels
  1554. Specifies the paddings to the top of a row.
  1555. pad1 pixels
  1556. Specifies the paddings to the bottom of a row.
  1557. size val
  1558. Specifies the height of a row. Val may be:
  1559. "auto" -- the height of the row is set to the
  1560. height of the highest cell in the row;
  1561. a valid Tk screen distance unit;
  1562. or a real number following by the word chars
  1563. (e.g. 3.4chars) that sets the height of the row to the
  1564. given number of characters."""
  1565. return self.tk.splitlist(self.tk.call(
  1566. self, 'size', 'row', index, *self._options({}, kw)))
  1567. def unset(self, x, y):
  1568. """Clears the cell at (x, y) by removing its display item."""
  1569. self.tk.call(self._w, 'unset', x, y)
  1570. class ScrolledGrid(Grid):
  1571. '''Scrolled Grid widgets'''
  1572. # FIXME: It should inherit -superclass tixScrolledWidget
  1573. def __init__(self, master=None, cnf={}, **kw):
  1574. static= []
  1575. self.cnf= cnf
  1576. TixWidget.__init__(self, master, 'tixScrolledGrid', static, cnf, kw)