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