blob: 99f9fff8401b536d7df2f342a61909107d165434 [file] [log] [blame]
Guido van Rossumd77d6992007-07-16 23:10:57 +00001# -*-mode: python; fill-column: 75; tab-width: 8 -*-
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00002#
3# $Id$
4#
Martin v. Löwisb7b32602001-11-02 23:48:20 +00005# Tix.py -- Tix widget wrappers.
6#
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00007# For Tix, see http://tix.sourceforge.net
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00008#
Moshe Zadka22710822001-03-21 17:24:49 +00009# - Sudhir Shenoy (sshenoy@gol.com), Dec. 1995.
Martin v. Löwisb7b32602001-11-02 23:48:20 +000010# based on an idea of Jean-Marc Lugrin (lugrin@ms.com)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000011#
12# NOTE: In order to minimize changes to Tkinter.py, some of the code here
Moshe Zadka22710822001-03-21 17:24:49 +000013# (TixWidget.__init__) has been taken from Tkinter (Widget.__init__)
14# and will break if there are major changes in Tkinter.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000015#
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
Moshe Zadka22710822001-03-21 17:24:49 +000020# w.ok['text'] = 'Who Cares'
21# or w.ok['bg'] = w['bg']
22# or even w.ok.invoke()
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000023# etc.
24#
25# Compare the demo tixwidgets.py to the original Tcl program and you will
26# appreciate the advantages.
27#
28
Georg Brandl14fc4272008-05-17 18:39:55 +000029from tkinter import *
30from tkinter import _flatten, _cnfmerge, _default_root
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000031
32# WARNING - TkVersion is a limited precision floating point number
33if TkVersion < 3.999:
Collin Winterce36ad82007-08-30 01:19:48 +000034 raise ImportError("This version of Tix.py requires Tk 4.0 or higher")
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000035
36import _tkinter # If this fails your Python may not be configured for Tk
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000037
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 Polobcd03df2009-08-18 15:35:57 +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
Fred Drake723293c2001-12-13 04:53:07 +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
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000072# 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 Brandl14fc4272008-05-17 18:39:55 +000075import tkinter, os
Martin v. Löwisb7b32602001-11-02 23:48:20 +000076
77# Could probably add this to Tkinter.Misc
78class tixCommand:
Fred Drake723293c2001-12-13 04:53:07 +000079 """The tix commands provide access to miscellaneous elements
Martin v. Löwisb7b32602001-11-02 23:48:20 +000080 of Tix's internal state and the Tix application context.
Fred Drake723293c2001-12-13 04:53:07 +000081 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.
Martin v. Löwisb7b32602001-11-02 23:48:20 +000084
85 This is a mixin class, assumed to be mixed to Tkinter.Tk
86 that supports the self.tk.call method.
87 """
Fred Drake723293c2001-12-13 04:53:07 +000088
Martin v. Löwisb7b32602001-11-02 23:48:20 +000089 def tix_addbitmapdir(self, directory):
Fred Drake723293c2001-12-13 04:53:07 +000090 """Tix maintains a list of directories under which
Martin v. Löwisb7b32602001-11-02 23:48:20 +000091 the tix_getimage and tix_getbitmap commands will
Fred Drake723293c2001-12-13 04:53:07 +000092 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
Martin v. Löwisb7b32602001-11-02 23:48:20 +000095 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):
Fred Drake723293c2001-12-13 04:53:07 +0000109 """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.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000118 """
Fred Drake723293c2001-12-13 04:53:07 +0000119 # 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))
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000133
134 def tix_filedialog(self, dlgclass=None):
Fred Drake723293c2001-12-13 04:53:07 +0000135 """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.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000142 """
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):
Fred Drake723293c2001-12-13 04:53:07 +0000149 """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.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000156 """
157 return self.tk.call('tix', 'getbitmap', name)
158
159 def tix_getimage(self, name):
Fred Drake723293c2001-12-13 04:53:07 +0000160 """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
Ezio Melotti42da6632011-03-15 05:18:48 +0200166 tix_ getimage, you can avoid hard coding the pathnames of the
Fred Drake723293c2001-12-13 04:53:07 +0000167 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.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000170 """
171 return self.tk.call('tix', 'getimage', name)
172
173 def tix_option_get(self, name):
Ezio Melotti13925002011-03-16 11:05:33 +0200174 """Gets the options maintained by the Tix
Fred Drake723293c2001-12-13 04:53:07 +0000175 scheme mechanism. Available options include:
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000176
177 active_bg active_fg bg
178 bold_font dark1_bg dark1_fg
179 dark2_bg dark2_fg disabled_fg
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000180 fg fixed_font font
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000181 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):
Fred Drake723293c2001-12-13 04:53:07 +0000191 """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.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000196
Fred Drake723293c2001-12-13 04:53:07 +0000197 The optional parameter newScmPrio can be given to reset the
198 priority level of the Tk options set by the Tix schemes.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000199
Fred Drake723293c2001-12-13 04:53:07 +0000200 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.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000204 """
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 Brandl14fc4272008-05-17 18:39:55 +0000210class Tk(tkinter.Tk, tixCommand):
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000211 """Toplevel widget of Tix which represents mostly the main window
212 of an application. It has an associated Tcl interpreter."""
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000213 def __init__(self, screenName=None, baseName=None, className='Tix'):
Georg Brandl14fc4272008-05-17 18:39:55 +0000214 tkinter.Tk.__init__(self, screenName, baseName, className)
Moshe Zadka22710822001-03-21 17:24:49 +0000215 tixlib = os.environ.get('TIX_LIBRARY')
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000216 self.tk.eval('global auto_path; lappend auto_path [file dir [info nameof]]')
Moshe Zadka22710822001-03-21 17:24:49 +0000217 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)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000220 # Load Tix - this should work dynamically or statically
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +0000221 # If it's static, tcl/tix8.1/pkgIndex.tcl should have
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000222 # 'load {} Tix'
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +0000223 # If it's dynamic under Unix, tcl/tix8.1/pkgIndex.tcl should have
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000224 # 'load libtix8.1.8.3.so Tix'
Moshe Zadka22710822001-03-21 17:24:49 +0000225 self.tk.eval('package require Tix')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000226
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +0000227 def destroy(self):
228 # For safety, remove an delete_window binding before destroy
229 self.protocol("WM_DELETE_WINDOW", "")
Georg Brandl14fc4272008-05-17 18:39:55 +0000230 tkinter.Tk.destroy(self)
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000231
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000232# 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):
Raymond Hettingerff41c482003-04-06 09:01:11 +0000240 self.tk.call('tixForm', self._w, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000241
242 form = config
243
244 def __setitem__(self, key, value):
Guido van Rossum49fa2bd2001-08-13 14:12:35 +0000245 Form.form(self, {key: value})
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000246
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
Martin v. Löwis46874282002-12-06 10:33:45 +0000261 return self.tk.call('tixForm', 'grid', self._w, xsize, ysize)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000262
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):
Alexander Belopolsky022f0492010-11-22 19:40:51 +0000271 return [self._nametowidget(x) for x in
272 self.tk.splitlist(
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000273 self.tk.call(
Alexander Belopolsky022f0492010-11-22 19:40:51 +0000274 'tixForm', 'slaves', self._w))]
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000275
276
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000277
Georg Brandl14fc4272008-05-17 18:39:55 +0000278tkinter.Widget.__bases__ = tkinter.Widget.__bases__ + (Form,)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000279
Georg Brandl14fc4272008-05-17 18:39:55 +0000280class TixWidget(tkinter.Widget):
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000281 """A TixWidget class is used to package all (or most) Tix widgets.
282
283 Widget initialization is extended in two ways:
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000284 1) It is possible to give a list of options which must be part of
Moshe Zadka22710822001-03-21 17:24:49 +0000285 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__
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000290
291 Both options are for use by subclasses only.
292 """
293 def __init__ (self, master=None, widgetName=None,
Moshe Zadka22710822001-03-21 17:24:49 +0000294 static_options=None, cnf={}, kw={}):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000295 # Merge keywords and dictionary arguments
296 if kw:
Moshe Zadka22710822001-03-21 17:24:49 +0000297 cnf = _cnfmerge((cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000298 else:
299 cnf = _cnfmerge(cnf)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000300
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000301 # Move static options into extra. static_options must be
302 # a list of keywords (or None).
303 extra=()
Neal Norwitzf539bde2002-11-14 02:43:40 +0000304
305 # 'options' is always a static option
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000306 if static_options:
Neal Norwitzf539bde2002-11-14 02:43:40 +0000307 static_options.append('options')
308 else:
309 static_options = ['options']
Raymond Hettingerff41c482003-04-06 09:01:11 +0000310
Hirokazu Yamamoto21027e62009-01-10 12:15:23 +0000311 for k,v in list(cnf.items()):
Neal Norwitzf539bde2002-11-14 02:43:40 +0000312 if k in static_options:
313 extra = extra + ('-' + k, v)
314 del cnf[k]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000315
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000316 self.widgetName = widgetName
317 Widget._setup(self, master, cnf)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000318
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000319 # 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:
Raymond Hettingerff41c482003-04-06 09:01:11 +0000322 self.tk.call(widgetName, self._w, *extra)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000323
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000324 # Non-static options - to be done via a 'config' command
325 if cnf:
326 Widget.config(self, cnf)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000327
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000328 # 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 = {}
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000332
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):
Guido van Rossume014a132006-08-19 16:53:45 +0000339 if name in self.subwidget_list:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000340 return self.subwidget_list[name]
Collin Winterce36ad82007-08-30 01:19:48 +0000341 raise AttributeError(name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000342
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000343 def set_silent(self, value):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000344 """Set a variable without calling its action routine"""
345 self.tk.call('tixSetSilent', self._w, value)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000346
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000347 def subwidget(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000348 """Return the named subwidget (which must have been created by
349 the sub-class)."""
350 n = self._subwidget_name(name)
351 if not n:
Collin Winterce36ad82007-08-30 01:19:48 +0000352 raise TclError("Subwidget " + name + " not child of " + self._name)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000353 # Remove header of name and leading dot
354 n = n[len(self._w)+1:]
355 return self._nametowidget(n)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000356
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000357 def subwidgets_all(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000358 """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
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000371
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000372 def _subwidget_name(self,name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000373 """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
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000378
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000379 def _subwidget_names(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000380 """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
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000386
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000387 def config_all(self, option, value):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000388 """Set configuration options for all subwidgets (and self)."""
389 if option == '':
390 return
391 elif not isinstance(option, StringType):
Walter Dörwald70a6b492004-02-12 17:35:32 +0000392 option = repr(option)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000393 if not isinstance(value, StringType):
Walter Dörwald70a6b492004-02-12 17:35:32 +0000394 value = repr(value)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000395 names = self._subwidget_names()
396 for name in names:
397 self.tk.call(name, 'configure', '-' + option, value)
Neal Norwitz731a9862002-12-10 02:18:49 +0000398 # These are missing from Tkinter
399 def image_create(self, imgtype, cnf={}, master=None, **kw):
400 if not master:
Georg Brandl14fc4272008-05-17 18:39:55 +0000401 master = tkinter._default_root
Neal Norwitz731a9862002-12-10 02:18:49 +0000402 if not master:
Collin Winterce36ad82007-08-30 01:19:48 +0000403 raise RuntimeError('Too early to create image')
Neal Norwitz731a9862002-12-10 02:18:49 +0000404 if kw and cnf: cnf = _cnfmerge((cnf, kw))
405 elif kw: cnf = kw
406 options = ()
407 for k, v in cnf.items():
Florent Xicluna5d1155c2011-10-28 14:45:05 +0200408 if callable(v):
Neal Norwitz731a9862002-12-10 02:18:49 +0000409 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
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000418
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,
Moshe Zadka22710822001-03-21 17:24:49 +0000430 destroy_physically=1, check_intermediate=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000431 if check_intermediate:
432 path = master._subwidget_name(name)
433 try:
434 path = path[len(master._w)+1:]
Neal Norwitzebb41902002-05-31 20:51:31 +0000435 plist = path.split('.')
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000436 except:
437 plist = []
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000438
Thomas Wouters89f507f2006-12-13 04:49:30 +0000439 if not check_intermediate:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000440 # 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):
Neal Norwitzebb41902002-05-31 20:51:31 +0000446 n = '.'.join(plist[:i+1])
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000447 try:
448 w = master._nametowidget(n)
449 parent = w
450 except KeyError:
451 # Create the intermediate widget
452 parent = TixSubWidget(parent, plist[i],
Neal Norwitzf539bde2002-11-14 02:43:40 +0000453 destroy_physically=0,
454 check_intermediate=0)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000455 # The Tk widget name is in plist, not in name
456 if plist:
457 name = plist[-1]
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000458 TixWidget.__init__(self, parent, None, None, {'name' : name})
459 self.destroy_physically = destroy_physically
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000460
461 def destroy(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000462 # 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
Hirokazu Yamamoto21027e62009-01-10 12:15:23 +0000466 for c in list(self.children.values()): c.destroy()
Guido van Rossume014a132006-08-19 16:53:45 +0000467 if self._name in self.master.children:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000468 del self.master.children[self._name]
Guido van Rossume014a132006-08-19 16:53:45 +0000469 if self._name in self.master.subwidget_list:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000470 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)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000474
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:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000480 dict[x[0][1:]] = (x[0][1:],) + x[1:]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000481 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
Thomas Wouters73e5a5b2006-06-08 15:35:45 +0000489 def __init__(self, itemtype, cnf={}, **kw):
Moshe Zadka22710822001-03-21 17:24:49 +0000490 master = _default_root # global from Tkinter
Guido van Rossume014a132006-08-19 16:53:45 +0000491 if not master and 'refwindow' in cnf: master=cnf['refwindow']
492 elif not master and 'refwindow' in kw: master= kw['refwindow']
Collin Winterce36ad82007-08-30 01:19:48 +0000493 elif not master: raise RuntimeError("Too early to create display style: no root window")
Moshe Zadka22710822001-03-21 17:24:49 +0000494 self.tk = master.tk
Raymond Hettingerff41c482003-04-06 09:01:11 +0000495 self.stylename = self.tk.call('tixDisplayStyle', itemtype,
496 *self._options(cnf,kw) )
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000497
498 def __str__(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000499 return self.stylename
500
Thomas Wouters73e5a5b2006-06-08 15:35:45 +0000501 def _options(self, cnf, kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000502 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
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000511 def delete(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000512 self.tk.call(self.stylename, 'delete')
513
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000514 def __setitem__(self,key,value):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000515 self.tk.call(self.stylename, 'configure', '-%s'%key, value)
516
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000517 def config(self, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000518 return _lst2dict(
519 self.tk.split(
Raymond Hettingerff41c482003-04-06 09:01:11 +0000520 self.tk.call(
521 self.stylename, 'configure', *self._options(cnf,kw))))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000522
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000523 def __getitem__(self,key):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000524 return self.tk.call(self.stylename, 'cget', '-%s'%key)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000525
526
527######################################################
528### The Tix Widget classes - in alphabetical order ###
529######################################################
530
531class Balloon(TixWidget):
532 """Balloon help widget.
533
Moshe Zadka22710822001-03-21 17:24:49 +0000534 Subwidget Class
535 --------- -----
Fred Drake723293c2001-12-13 04:53:07 +0000536 label Label
537 message Message"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000538
Martin v. Löwis46874282002-12-06 10:33:45 +0000539 # FIXME: It should inherit -superclass tixShell
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000540 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis652e1912001-11-25 14:50:56 +0000541 # static seem to be -installcolormap -initwait -statusbar -cursor
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000542 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)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000549
550 def bind_widget(self, widget, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000551 """Bind balloon widget to another.
552 One balloon widget may be bound to several widgets at the same time"""
Raymond Hettingerff41c482003-04-06 09:01:11 +0000553 self.tk.call(self._w, 'bind', widget._w, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000554
555 def unbind_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000556 self.tk.call(self._w, 'unbind', widget._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000557
558class ButtonBox(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000559 """ButtonBox - A container for pushbuttons.
560 Subwidgets are the buttons added with the add method.
561 """
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000562 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000563 TixWidget.__init__(self, master, 'tixButtonBox',
564 ['orientation', 'options'], cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000565
566 def add(self, name, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000567 """Add a button with given name to box."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000568
Raymond Hettingerff41c482003-04-06 09:01:11 +0000569 btn = self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000570 self.subwidget_list[name] = _dummyButton(self, name)
571 return btn
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000572
573 def invoke(self, name):
Guido van Rossume014a132006-08-19 16:53:45 +0000574 if name in self.subwidget_list:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000575 self.tk.call(self._w, 'invoke', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000576
577class ComboBox(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000578 """ComboBox - an Entry field with a dropdown menu. The user can select a
Ezio Melotti13925002011-03-16 11:05:33 +0200579 choice by either typing in the entry subwidget or selecting from the
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000580 listbox subwidget.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000581
Moshe Zadka22710822001-03-21 17:24:49 +0000582 Subwidget Class
583 --------- -----
584 entry Entry
585 arrow Button
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000586 slistbox ScrolledListBox
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000587 tick Button
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000588 cross Button : present if created with the fancy option"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000589
Martin v. Löwis46874282002-12-06 10:33:45 +0000590 # FIXME: It should inherit -superclass tixLabelWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000591 def __init__ (self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000592 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
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000606
Neal Norwitz731a9862002-12-10 02:18:49 +0000607 # align
Raymond Hettingerff41c482003-04-06 09:01:11 +0000608
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000609 def add_history(self, str):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000610 self.tk.call(self._w, 'addhistory', str)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000611
612 def append_history(self, str):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000613 self.tk.call(self._w, 'appendhistory', str)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000614
615 def insert(self, index, str):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000616 self.tk.call(self._w, 'insert', index, str)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000617
618 def pick(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000619 self.tk.call(self._w, 'pick', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000620
621class Control(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000622 """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.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000626
Moshe Zadka22710822001-03-21 17:24:49 +0000627 Subwidget Class
628 --------- -----
629 incr Button
630 decr Button
631 entry Entry
632 label Label"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000633
Martin v. Löwis46874282002-12-06 10:33:45 +0000634 # FIXME: It should inherit -superclass tixLabelWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000635 def __init__ (self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000636 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')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000641
642 def decrement(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000643 self.tk.call(self._w, 'decr')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000644
645 def increment(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000646 self.tk.call(self._w, 'incr')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000647
648 def invoke(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000649 self.tk.call(self._w, 'invoke')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000650
651 def update(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000652 self.tk.call(self._w, 'update')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000653
654class DirList(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000655 """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.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000658
Moshe Zadka22710822001-03-21 17:24:49 +0000659 Subwidget Class
660 --------- -----
661 hlist HList
662 hsb Scrollbar
663 vsb Scrollbar"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000664
Martin v. Löwis46874282002-12-06 10:33:45 +0000665 # FIXME: It should inherit -superclass tixScrolledHList
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000666 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000667 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')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000671
672 def chdir(self, dir):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000673 self.tk.call(self._w, 'chdir', dir)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000674
675class DirTree(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000676 """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.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000680
Moshe Zadka22710822001-03-21 17:24:49 +0000681 Subwidget Class
682 --------- -----
Neal Norwitzf539bde2002-11-14 02:43:40 +0000683 hlist HList
684 hsb Scrollbar
685 vsb Scrollbar"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000686
Martin v. Löwis46874282002-12-06 10:33:45 +0000687 # FIXME: It should inherit -superclass tixScrolledHList
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000688 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000689 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')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000693
694 def chdir(self, dir):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000695 self.tk.call(self._w, 'chdir', dir)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000696
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000697class 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.
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000703
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000704 Subwidget Class
705 --------- -----
706 selection ComboBox
Neal Norwitzf539bde2002-11-14 02:43:40 +0000707 filter ComboBox
708 dirlist ScrolledListBox
709 filelist ScrolledListBox"""
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000710
711 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000712 TixWidget.__init__(self, master, 'tixDirSelectBox', ['options'], cnf, kw)
713 self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
714 self.subwidget_list['dircbx'] = _dummyFileComboBox(self, 'dircbx')
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000715
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000716class ExFileSelectBox(TixWidget):
717 """ExFileSelectBox - MS Windows style file select box.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000718 It provides an convenient method for the user to select files.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000719
Moshe Zadka22710822001-03-21 17:24:49 +0000720 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"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000730
731 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000732 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')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000741
742 def filter(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000743 self.tk.call(self._w, 'filter')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000744
745 def invoke(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000746 self.tk.call(self._w, 'invoke')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000747
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000748
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
Martin v. Löwis46874282002-12-06 10:33:45 +0000759 # FIXME: It should inherit -superclass tixDialogShell
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000760 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000761 TixWidget.__init__(self, master, 'tixDirSelectDialog',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000762 ['options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000763 self.subwidget_list['dirbox'] = _dummyDirSelectBox(self, 'dirbox')
764 # cancel and ok buttons are missing
765
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000766 def popup(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000767 self.tk.call(self._w, 'popup')
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000768
769 def popdown(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000770 self.tk.call(self._w, 'popdown')
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000771
772
773# Should inherit from a Dialog class
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000774class ExFileSelectDialog(TixWidget):
775 """ExFileSelectDialog - MS Windows style file select dialog.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000776 It provides an convenient method for the user to select files.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000777
Moshe Zadka22710822001-03-21 17:24:49 +0000778 Subwidgets Class
779 ---------- -----
780 fsbox ExFileSelectBox"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000781
Martin v. Löwis46874282002-12-06 10:33:45 +0000782 # FIXME: It should inherit -superclass tixDialogShell
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000783 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000784 TixWidget.__init__(self, master, 'tixExFileSelectDialog',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000785 ['options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000786 self.subwidget_list['fsbox'] = _dummyExFileSelectBox(self, 'fsbox')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000787
788 def popup(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000789 self.tk.call(self._w, 'popup')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000790
791 def popdown(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000792 self.tk.call(self._w, 'popdown')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000793
794class FileSelectBox(TixWidget):
795 """ExFileSelectBox - Motif style file select box.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000796 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.
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000800
Moshe Zadka22710822001-03-21 17:24:49 +0000801 Subwidget Class
802 --------- -----
803 selection ComboBox
Neal Norwitzf539bde2002-11-14 02:43:40 +0000804 filter ComboBox
805 dirlist ScrolledListBox
806 filelist ScrolledListBox"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000807
808 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000809 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')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000814
Moshe Zadka22710822001-03-21 17:24:49 +0000815 def apply_filter(self): # name of subwidget is same as command
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000816 self.tk.call(self._w, 'filter')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000817
818 def invoke(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000819 self.tk.call(self._w, 'invoke')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000820
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000821# Should inherit from a Dialog class
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000822class FileSelectDialog(TixWidget):
823 """FileSelectDialog - Motif style file select dialog.
824
Moshe Zadka22710822001-03-21 17:24:49 +0000825 Subwidgets Class
826 ---------- -----
827 btns StdButtonBox
828 fsbox FileSelectBox"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000829
Martin v. Löwis46874282002-12-06 10:33:45 +0000830 # FIXME: It should inherit -superclass tixStdDialogShell
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000831 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000832 TixWidget.__init__(self, master, 'tixFileSelectDialog',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000833 ['options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000834 self.subwidget_list['btns'] = _dummyStdButtonBox(self, 'btns')
835 self.subwidget_list['fsbox'] = _dummyFileSelectBox(self, 'fsbox')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000836
837 def popup(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000838 self.tk.call(self._w, 'popup')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000839
840 def popdown(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000841 self.tk.call(self._w, 'popdown')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000842
843class FileEntry(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000844 """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.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000848
Moshe Zadka22710822001-03-21 17:24:49 +0000849 Subwidgets Class
850 ---------- -----
851 button Button
852 entry Entry"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000853
Martin v. Löwis46874282002-12-06 10:33:45 +0000854 # FIXME: It should inherit -superclass tixLabelWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000855 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000856 TixWidget.__init__(self, master, 'tixFileEntry',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000857 ['dialogtype', 'options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000858 self.subwidget_list['button'] = _dummyButton(self, 'button')
859 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000860
861 def invoke(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000862 self.tk.call(self._w, 'invoke')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000863
864 def file_dialog(self):
Martin v. Löwis46874282002-12-06 10:33:45 +0000865 # FIXME: return python object
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000866 pass
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000867
Guilherme Polo1fff0082009-08-14 15:05:30 +0000868class HList(TixWidget, XView, YView):
Martin v. Löwisb7b32602001-11-02 23:48:20 +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
Ezio Melotti13925002011-03-16 11:05:33 +0200872 according to their places in the hierarchy.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000873
874 Subwidgets - None"""
875
876 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000877 TixWidget.__init__(self, master, 'tixHList',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000878 ['columns', 'options'], cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000879
880 def add(self, entry, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +0000881 return self.tk.call(self._w, 'add', entry, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000882
883 def add_child(self, parent=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000884 if not parent:
885 parent = ''
Raymond Hettingerff41c482003-04-06 09:01:11 +0000886 return self.tk.call(
887 self._w, 'addchild', parent, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000888
889 def anchor_set(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000890 self.tk.call(self._w, 'anchor', 'set', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000891
892 def anchor_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000893 self.tk.call(self._w, 'anchor', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000894
895 def column_width(self, col=0, width=None, chars=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000896 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,
Neal Norwitzf539bde2002-11-14 02:43:40 +0000900 '-char', chars)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000901
902 def delete_all(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000903 self.tk.call(self._w, 'delete', 'all')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000904
905 def delete_entry(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000906 self.tk.call(self._w, 'delete', 'entry', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000907
908 def delete_offsprings(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000909 self.tk.call(self._w, 'delete', 'offsprings', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000910
911 def delete_siblings(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000912 self.tk.call(self._w, 'delete', 'siblings', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000913
914 def dragsite_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000915 self.tk.call(self._w, 'dragsite', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000916
917 def dragsite_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000918 self.tk.call(self._w, 'dragsite', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000919
920 def dropsite_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000921 self.tk.call(self._w, 'dropsite', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000922
923 def dropsite_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000924 self.tk.call(self._w, 'dropsite', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000925
926 def header_create(self, col, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +0000927 self.tk.call(self._w, 'header', 'create', col, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000928
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000929 def header_configure(self, col, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000930 if cnf is None:
931 return _lst2dict(
Neal Norwitzf539bde2002-11-14 02:43:40 +0000932 self.tk.split(
933 self.tk.call(self._w, 'header', 'configure', col)))
Raymond Hettingerff41c482003-04-06 09:01:11 +0000934 self.tk.call(self._w, 'header', 'configure', col,
935 *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000936
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000937 def header_cget(self, col, opt):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000938 return self.tk.call(self._w, 'header', 'cget', col, opt)
939
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000940 def header_exists(self, col):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000941 return self.tk.call(self._w, 'header', 'exists', col)
942
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000943 def header_delete(self, col):
Moshe Zadka22710822001-03-21 17:24:49 +0000944 self.tk.call(self._w, 'header', 'delete', col)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000945
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000946 def header_size(self, col):
Moshe Zadka22710822001-03-21 17:24:49 +0000947 return self.tk.call(self._w, 'header', 'size', col)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000948
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000949 def hide_entry(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000950 self.tk.call(self._w, 'hide', 'entry', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000951
952 def indicator_create(self, entry, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +0000953 self.tk.call(
954 self._w, 'indicator', 'create', entry, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000955
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000956 def indicator_configure(self, entry, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000957 if cnf is None:
958 return _lst2dict(
Neal Norwitzf539bde2002-11-14 02:43:40 +0000959 self.tk.split(
960 self.tk.call(self._w, 'indicator', 'configure', entry)))
Raymond Hettingerff41c482003-04-06 09:01:11 +0000961 self.tk.call(
962 self._w, 'indicator', 'configure', entry, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000963
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000964 def indicator_cget(self, entry, opt):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000965 return self.tk.call(self._w, 'indicator', 'cget', entry, opt)
966
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000967 def indicator_exists(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000968 return self.tk.call (self._w, 'indicator', 'exists', entry)
969
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000970 def indicator_delete(self, entry):
Moshe Zadka22710822001-03-21 17:24:49 +0000971 self.tk.call(self._w, 'indicator', 'delete', entry)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000972
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000973 def indicator_size(self, entry):
Moshe Zadka22710822001-03-21 17:24:49 +0000974 return self.tk.call(self._w, 'indicator', 'size', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000975
976 def info_anchor(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000977 return self.tk.call(self._w, 'info', 'anchor')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000978
Guilherme Polobcd03df2009-08-18 15:35:57 +0000979 def info_bbox(self, entry):
980 return self._getints(
981 self.tk.call(self._w, 'info', 'bbox', entry)) or None
982
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000983 def info_children(self, entry=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000984 c = self.tk.call(self._w, 'info', 'children', entry)
985 return self.tk.splitlist(c)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000986
987 def info_data(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000988 return self.tk.call(self._w, 'info', 'data', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000989
Guilherme Polobcd03df2009-08-18 15:35:57 +0000990 def info_dragsite(self):
991 return self.tk.call(self._w, 'info', 'dragsite')
992
993 def info_dropsite(self):
994 return self.tk.call(self._w, 'info', 'dropsite')
995
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000996 def info_exists(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000997 return self.tk.call(self._w, 'info', 'exists', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000998
999 def info_hidden(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001000 return self.tk.call(self._w, 'info', 'hidden', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001001
1002 def info_next(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001003 return self.tk.call(self._w, 'info', 'next', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001004
1005 def info_parent(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001006 return self.tk.call(self._w, 'info', 'parent', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001007
1008 def info_prev(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001009 return self.tk.call(self._w, 'info', 'prev', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001010
1011 def info_selection(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001012 c = self.tk.call(self._w, 'info', 'selection')
1013 return self.tk.splitlist(c)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001014
Martin v. Löwis3e048482001-10-09 11:50:55 +00001015 def item_cget(self, entry, col, opt):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001016 return self.tk.call(self._w, 'item', 'cget', entry, col, opt)
1017
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001018 def item_configure(self, entry, col, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001019 if cnf is None:
1020 return _lst2dict(
Neal Norwitzf539bde2002-11-14 02:43:40 +00001021 self.tk.split(
1022 self.tk.call(self._w, 'item', 'configure', entry, col)))
Raymond Hettingerff41c482003-04-06 09:01:11 +00001023 self.tk.call(self._w, 'item', 'configure', entry, col,
1024 *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001025
1026 def item_create(self, entry, col, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001027 self.tk.call(
1028 self._w, 'item', 'create', entry, col, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001029
1030 def item_exists(self, entry, col):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001031 return self.tk.call(self._w, 'item', 'exists', entry, col)
1032
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001033 def item_delete(self, entry, col):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001034 self.tk.call(self._w, 'item', 'delete', entry, col)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001035
Martin v. Löwis433fa692004-03-21 15:26:44 +00001036 def entrycget(self, entry, opt):
1037 return self.tk.call(self._w, 'entrycget', entry, opt)
1038
1039 def entryconfigure(self, entry, cnf={}, **kw):
1040 if cnf is None:
1041 return _lst2dict(
1042 self.tk.split(
1043 self.tk.call(self._w, 'entryconfigure', entry)))
1044 self.tk.call(self._w, 'entryconfigure', entry,
1045 *self._options(cnf, kw))
1046
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001047 def nearest(self, y):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001048 return self.tk.call(self._w, 'nearest', y)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001049
1050 def see(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001051 self.tk.call(self._w, 'see', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001052
1053 def selection_clear(self, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001054 self.tk.call(self._w, 'selection', 'clear', *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001055
1056 def selection_includes(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001057 return self.tk.call(self._w, 'selection', 'includes', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001058
1059 def selection_set(self, first, last=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001060 self.tk.call(self._w, 'selection', 'set', first, last)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001061
1062 def show_entry(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001063 return self.tk.call(self._w, 'show', 'entry', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001064
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001065class InputOnly(TixWidget):
Martin v. Löwis46874282002-12-06 10:33:45 +00001066 """InputOnly - Invisible widget. Unix only.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001067
1068 Subwidgets - None"""
1069
1070 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001071 TixWidget.__init__(self, master, 'tixInputOnly', None, cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001072
1073class LabelEntry(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001074 """LabelEntry - Entry field with label. Packages an entry widget
1075 and a label into one mega widget. It can beused be used to simplify
1076 the creation of ``entry-form'' type of interface.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001077
Moshe Zadka22710822001-03-21 17:24:49 +00001078 Subwidgets Class
1079 ---------- -----
1080 label Label
1081 entry Entry"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001082
1083 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001084 TixWidget.__init__(self, master, 'tixLabelEntry',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001085 ['labelside','options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001086 self.subwidget_list['label'] = _dummyLabel(self, 'label')
1087 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001088
1089class LabelFrame(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001090 """LabelFrame - Labelled Frame container. Packages a frame widget
1091 and a label into one mega widget. To create widgets inside a
1092 LabelFrame widget, one creates the new widgets relative to the
1093 frame subwidget and manage them inside the frame subwidget.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001094
Moshe Zadka22710822001-03-21 17:24:49 +00001095 Subwidgets Class
1096 ---------- -----
1097 label Label
1098 frame Frame"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001099
1100 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001101 TixWidget.__init__(self, master, 'tixLabelFrame',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001102 ['labelside','options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001103 self.subwidget_list['label'] = _dummyLabel(self, 'label')
1104 self.subwidget_list['frame'] = _dummyFrame(self, 'frame')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001105
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001106
1107class ListNoteBook(TixWidget):
1108 """A ListNoteBook widget is very similar to the TixNoteBook widget:
1109 it can be used to display many windows in a limited space using a
1110 notebook metaphor. The notebook is divided into a stack of pages
1111 (windows). At one time only one of these pages can be shown.
1112 The user can navigate through these pages by
1113 choosing the name of the desired page in the hlist subwidget."""
1114
1115 def __init__(self, master, cnf={}, **kw):
Neal Norwitzf539bde2002-11-14 02:43:40 +00001116 TixWidget.__init__(self, master, 'tixListNoteBook', ['options'], cnf, kw)
1117 # Is this necessary? It's not an exposed subwidget in Tix.
1118 self.subwidget_list['pane'] = _dummyPanedWindow(self, 'pane',
1119 destroy_physically=0)
1120 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1121 self.subwidget_list['shlist'] = _dummyScrolledHList(self, 'shlist')
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001122
1123 def add(self, name, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001124 self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001125 self.subwidget_list[name] = TixSubWidget(self, name)
1126 return self.subwidget_list[name]
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001127
Martin v. Löwis01824bf2002-09-19 08:12:55 +00001128 def page(self, name):
Tim Peters182b5ac2004-07-18 06:16:08 +00001129 return self.subwidget(name)
Martin v. Löwis01824bf2002-09-19 08:12:55 +00001130
1131 def pages(self):
Tim Peters182b5ac2004-07-18 06:16:08 +00001132 # Can't call subwidgets_all directly because we don't want .nbframe
1133 names = self.tk.split(self.tk.call(self._w, 'pages'))
1134 ret = []
1135 for x in names:
1136 ret.append(self.subwidget(x))
1137 return ret
Martin v. Löwis01824bf2002-09-19 08:12:55 +00001138
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001139 def raise_page(self, name): # raise is a python keyword
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001140 self.tk.call(self._w, 'raise', name)
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001141
1142class Meter(TixWidget):
1143 """The Meter widget can be used to show the progress of a background
1144 job which may take a long time to execute.
1145 """
1146
1147 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001148 TixWidget.__init__(self, master, 'tixMeter',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001149 ['options'], cnf, kw)
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001150
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001151class NoteBook(TixWidget):
1152 """NoteBook - Multi-page container widget (tabbed notebook metaphor).
1153
Moshe Zadka22710822001-03-21 17:24:49 +00001154 Subwidgets Class
1155 ---------- -----
1156 nbframe NoteBookFrame
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001157 <pages> page widgets added dynamically with the add method"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001158
1159 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001160 TixWidget.__init__(self,master,'tixNoteBook', ['options'], cnf, kw)
1161 self.subwidget_list['nbframe'] = TixSubWidget(self, 'nbframe',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001162 destroy_physically=0)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001163
1164 def add(self, name, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001165 self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001166 self.subwidget_list[name] = TixSubWidget(self, name)
1167 return self.subwidget_list[name]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001168
1169 def delete(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001170 self.tk.call(self._w, 'delete', name)
1171 self.subwidget_list[name].destroy()
1172 del self.subwidget_list[name]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001173
1174 def page(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001175 return self.subwidget(name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001176
1177 def pages(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001178 # Can't call subwidgets_all directly because we don't want .nbframe
1179 names = self.tk.split(self.tk.call(self._w, 'pages'))
1180 ret = []
1181 for x in names:
1182 ret.append(self.subwidget(x))
1183 return ret
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001184
Moshe Zadka22710822001-03-21 17:24:49 +00001185 def raise_page(self, name): # raise is a python keyword
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001186 self.tk.call(self._w, 'raise', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001187
1188 def raised(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001189 return self.tk.call(self._w, 'raised')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001190
1191class NoteBookFrame(TixWidget):
Martin v. Löwis46874282002-12-06 10:33:45 +00001192 # FIXME: This is dangerous to expose to be called on its own.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001193 pass
1194
1195class OptionMenu(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001196 """OptionMenu - creates a menu button of options.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001197
Moshe Zadka22710822001-03-21 17:24:49 +00001198 Subwidget Class
1199 --------- -----
Neal Norwitzf539bde2002-11-14 02:43:40 +00001200 menubutton Menubutton
1201 menu Menu"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001202
1203 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001204 TixWidget.__init__(self, master, 'tixOptionMenu', ['options'], cnf, kw)
1205 self.subwidget_list['menubutton'] = _dummyMenubutton(self, 'menubutton')
1206 self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001207
1208 def add_command(self, name, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001209 self.tk.call(self._w, 'add', 'command', name, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001210
1211 def add_separator(self, name, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001212 self.tk.call(self._w, 'add', 'separator', name, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001213
1214 def delete(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001215 self.tk.call(self._w, 'delete', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001216
1217 def disable(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001218 self.tk.call(self._w, 'disable', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001219
1220 def enable(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001221 self.tk.call(self._w, 'enable', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001222
1223class PanedWindow(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001224 """PanedWindow - Multi-pane container widget
1225 allows the user to interactively manipulate the sizes of several
1226 panes. The panes can be arranged either vertically or horizontally.The
1227 user changes the sizes of the panes by dragging the resize handle
1228 between two panes.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001229
Moshe Zadka22710822001-03-21 17:24:49 +00001230 Subwidgets Class
1231 ---------- -----
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001232 <panes> g/p widgets added dynamically with the add method."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001233
1234 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001235 TixWidget.__init__(self, master, 'tixPanedWindow', ['orientation', 'options'], cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001236
Neal Norwitzf539bde2002-11-14 02:43:40 +00001237 # add delete forget panecget paneconfigure panes setsize
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001238 def add(self, name, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001239 self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001240 self.subwidget_list[name] = TixSubWidget(self, name,
Neal Norwitzf539bde2002-11-14 02:43:40 +00001241 check_intermediate=0)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001242 return self.subwidget_list[name]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001243
Neal Norwitzf539bde2002-11-14 02:43:40 +00001244 def delete(self, name):
1245 self.tk.call(self._w, 'delete', name)
1246 self.subwidget_list[name].destroy()
1247 del self.subwidget_list[name]
1248
1249 def forget(self, name):
1250 self.tk.call(self._w, 'forget', name)
1251
1252 def panecget(self, entry, opt):
1253 return self.tk.call(self._w, 'panecget', entry, opt)
1254
1255 def paneconfigure(self, entry, cnf={}, **kw):
1256 if cnf is None:
1257 return _lst2dict(
1258 self.tk.split(
1259 self.tk.call(self._w, 'paneconfigure', entry)))
Raymond Hettingerff41c482003-04-06 09:01:11 +00001260 self.tk.call(self._w, 'paneconfigure', entry, *self._options(cnf, kw))
Neal Norwitzf539bde2002-11-14 02:43:40 +00001261
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001262 def panes(self):
Guilherme Polobcd03df2009-08-18 15:35:57 +00001263 names = self.tk.splitlist(self.tk.call(self._w, 'panes'))
1264 return [self.subwidget(x) for x in names]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001265
1266class PopupMenu(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001267 """PopupMenu widget can be used as a replacement of the tk_popup command.
1268 The advantage of the Tix PopupMenu widget is it requires less application
1269 code to manipulate.
1270
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001271
Moshe Zadka22710822001-03-21 17:24:49 +00001272 Subwidgets Class
1273 ---------- -----
1274 menubutton Menubutton
1275 menu Menu"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001276
Martin v. Löwis46874282002-12-06 10:33:45 +00001277 # FIXME: It should inherit -superclass tixShell
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001278 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001279 TixWidget.__init__(self, master, 'tixPopupMenu', ['options'], cnf, kw)
1280 self.subwidget_list['menubutton'] = _dummyMenubutton(self, 'menubutton')
1281 self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001282
1283 def bind_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001284 self.tk.call(self._w, 'bind', widget._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001285
1286 def unbind_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001287 self.tk.call(self._w, 'unbind', widget._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001288
1289 def post_widget(self, widget, x, y):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001290 self.tk.call(self._w, 'post', widget._w, x, y)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001291
1292class ResizeHandle(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001293 """Internal widget to draw resize handles on Scrolled widgets."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001294 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001295 # There seems to be a Tix bug rejecting the configure method
1296 # Let's try making the flags -static
1297 flags = ['options', 'command', 'cursorfg', 'cursorbg',
1298 'handlesize', 'hintcolor', 'hintwidth',
1299 'x', 'y']
1300 # In fact, x y height width are configurable
1301 TixWidget.__init__(self, master, 'tixResizeHandle',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001302 flags, cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001303
1304 def attach_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001305 self.tk.call(self._w, 'attachwidget', widget._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001306
Martin v. Löwis652e1912001-11-25 14:50:56 +00001307 def detach_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001308 self.tk.call(self._w, 'detachwidget', widget._w)
Martin v. Löwis652e1912001-11-25 14:50:56 +00001309
1310 def hide(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001311 self.tk.call(self._w, 'hide', widget._w)
Martin v. Löwis652e1912001-11-25 14:50:56 +00001312
1313 def show(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001314 self.tk.call(self._w, 'show', widget._w)
Martin v. Löwis652e1912001-11-25 14:50:56 +00001315
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001316class ScrolledHList(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001317 """ScrolledHList - HList with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001318
Martin v. Löwis46874282002-12-06 10:33:45 +00001319 # FIXME: It should inherit -superclass tixScrolledWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001320 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001321 TixWidget.__init__(self, master, 'tixScrolledHList', ['options'],
Neal Norwitzf539bde2002-11-14 02:43:40 +00001322 cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001323 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1324 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1325 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001326
1327class ScrolledListBox(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001328 """ScrolledListBox - Listbox with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001329
Martin v. Löwis46874282002-12-06 10:33:45 +00001330 # FIXME: It should inherit -superclass tixScrolledWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001331 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001332 TixWidget.__init__(self, master, 'tixScrolledListBox', ['options'], cnf, kw)
1333 self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox')
1334 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1335 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001336
1337class ScrolledText(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001338 """ScrolledText - Text with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001339
Martin v. Löwis46874282002-12-06 10:33:45 +00001340 # FIXME: It should inherit -superclass tixScrolledWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001341 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001342 TixWidget.__init__(self, master, 'tixScrolledText', ['options'], cnf, kw)
1343 self.subwidget_list['text'] = _dummyText(self, 'text')
1344 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1345 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001346
1347class ScrolledTList(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001348 """ScrolledTList - TList with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001349
Martin v. Löwis46874282002-12-06 10:33:45 +00001350 # FIXME: It should inherit -superclass tixScrolledWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001351 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001352 TixWidget.__init__(self, master, 'tixScrolledTList', ['options'],
Neal Norwitzf539bde2002-11-14 02:43:40 +00001353 cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001354 self.subwidget_list['tlist'] = _dummyTList(self, 'tlist')
1355 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1356 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001357
1358class ScrolledWindow(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001359 """ScrolledWindow - Window with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001360
Martin v. Löwis46874282002-12-06 10:33:45 +00001361 # FIXME: It should inherit -superclass tixScrolledWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001362 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001363 TixWidget.__init__(self, master, 'tixScrolledWindow', ['options'], cnf, kw)
1364 self.subwidget_list['window'] = _dummyFrame(self, 'window')
1365 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1366 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001367
1368class Select(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001369 """Select - Container of button subwidgets. It can be used to provide
1370 radio-box or check-box style of selection options for the user.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001371
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001372 Subwidgets are buttons added dynamically using the add method."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001373
Martin v. Löwis46874282002-12-06 10:33:45 +00001374 # FIXME: It should inherit -superclass tixLabelWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001375 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001376 TixWidget.__init__(self, master, 'tixSelect',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001377 ['allowzero', 'radio', 'orientation', 'labelside',
1378 'options'],
1379 cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001380 self.subwidget_list['label'] = _dummyLabel(self, 'label')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001381
1382 def add(self, name, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001383 self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001384 self.subwidget_list[name] = _dummyButton(self, name)
1385 return self.subwidget_list[name]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001386
1387 def invoke(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001388 self.tk.call(self._w, 'invoke', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001389
Neal Norwitzf539bde2002-11-14 02:43:40 +00001390class Shell(TixWidget):
1391 """Toplevel window.
1392
1393 Subwidgets - None"""
1394
1395 def __init__ (self,master=None,cnf={}, **kw):
1396 TixWidget.__init__(self, master, 'tixShell', ['options', 'title'], cnf, kw)
1397
1398class DialogShell(TixWidget):
1399 """Toplevel window, with popup popdown and center methods.
1400 It tells the window manager that it is a dialog window and should be
1401 treated specially. The exact treatment depends on the treatment of
1402 the window manager.
1403
1404 Subwidgets - None"""
1405
Martin v. Löwis46874282002-12-06 10:33:45 +00001406 # FIXME: It should inherit from Shell
Neal Norwitzf539bde2002-11-14 02:43:40 +00001407 def __init__ (self,master=None,cnf={}, **kw):
1408 TixWidget.__init__(self, master,
1409 'tixDialogShell',
1410 ['options', 'title', 'mapped',
1411 'minheight', 'minwidth',
1412 'parent', 'transient'], cnf, kw)
1413
1414 def popdown(self):
1415 self.tk.call(self._w, 'popdown')
1416
1417 def popup(self):
1418 self.tk.call(self._w, 'popup')
1419
1420 def center(self):
1421 self.tk.call(self._w, 'center')
1422
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001423class StdButtonBox(TixWidget):
1424 """StdButtonBox - Standard Button Box (OK, Apply, Cancel and Help) """
1425
1426 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001427 TixWidget.__init__(self, master, 'tixStdButtonBox',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001428 ['orientation', 'options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001429 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1430 self.subwidget_list['apply'] = _dummyButton(self, 'apply')
1431 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1432 self.subwidget_list['help'] = _dummyButton(self, 'help')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001433
1434 def invoke(self, name):
Guido van Rossume014a132006-08-19 16:53:45 +00001435 if name in self.subwidget_list:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001436 self.tk.call(self._w, 'invoke', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001437
Guilherme Polo1fff0082009-08-14 15:05:30 +00001438class TList(TixWidget, XView, YView):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001439 """TList - Hierarchy display widget which can be
1440 used to display data in a tabular format. The list entries of a TList
1441 widget are similar to the entries in the Tk listbox widget. The main
1442 differences are (1) the TList widget can display the list entries in a
1443 two dimensional format and (2) you can use graphical images as well as
1444 multiple colors and fonts for the list entries.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001445
1446 Subwidgets - None"""
1447
1448 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001449 TixWidget.__init__(self, master, 'tixTList', ['options'], cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001450
1451 def active_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001452 self.tk.call(self._w, 'active', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001453
1454 def active_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001455 self.tk.call(self._w, 'active', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001456
1457 def anchor_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001458 self.tk.call(self._w, 'anchor', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001459
1460 def anchor_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001461 self.tk.call(self._w, 'anchor', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001462
1463 def delete(self, from_, to=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001464 self.tk.call(self._w, 'delete', from_, to)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001465
1466 def dragsite_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001467 self.tk.call(self._w, 'dragsite', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001468
1469 def dragsite_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001470 self.tk.call(self._w, 'dragsite', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001471
1472 def dropsite_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001473 self.tk.call(self._w, 'dropsite', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001474
1475 def dropsite_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001476 self.tk.call(self._w, 'dropsite', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001477
1478 def insert(self, index, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001479 self.tk.call(self._w, 'insert', index, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001480
1481 def info_active(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001482 return self.tk.call(self._w, 'info', 'active')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001483
1484 def info_anchor(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001485 return self.tk.call(self._w, 'info', 'anchor')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001486
1487 def info_down(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001488 return self.tk.call(self._w, 'info', 'down', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001489
1490 def info_left(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001491 return self.tk.call(self._w, 'info', 'left', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001492
1493 def info_right(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001494 return self.tk.call(self._w, 'info', 'right', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001495
1496 def info_selection(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001497 c = self.tk.call(self._w, 'info', 'selection')
1498 return self.tk.splitlist(c)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001499
1500 def info_size(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001501 return self.tk.call(self._w, 'info', 'size')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001502
1503 def info_up(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001504 return self.tk.call(self._w, 'info', 'up', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001505
1506 def nearest(self, x, y):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001507 return self.tk.call(self._w, 'nearest', x, y)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001508
1509 def see(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001510 self.tk.call(self._w, 'see', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001511
1512 def selection_clear(self, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001513 self.tk.call(self._w, 'selection', 'clear', *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001514
1515 def selection_includes(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001516 return self.tk.call(self._w, 'selection', 'includes', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001517
1518 def selection_set(self, first, last=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001519 self.tk.call(self._w, 'selection', 'set', first, last)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001520
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001521class Tree(TixWidget):
Ezio Melotti13925002011-03-16 11:05:33 +02001522 """Tree - The tixTree widget can be used to display hierarchical
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001523 data in a tree form. The user can adjust
1524 the view of the tree by opening or closing parts of the tree."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001525
Martin v. Löwis46874282002-12-06 10:33:45 +00001526 # FIXME: It should inherit -superclass tixScrolledWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001527 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001528 TixWidget.__init__(self, master, 'tixTree',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001529 ['options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001530 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1531 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1532 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001533
1534 def autosetmode(self):
Martin v. Löwis46874282002-12-06 10:33:45 +00001535 '''This command calls the setmode method for all the entries in this
1536 Tree widget: if an entry has no child entries, its mode is set to
1537 none. Otherwise, if the entry has any hidden child entries, its mode is
1538 set to open; otherwise its mode is set to close.'''
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001539 self.tk.call(self._w, 'autosetmode')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001540
1541 def close(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001542 '''Close the entry given by entryPath if its mode is close.'''
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001543 self.tk.call(self._w, 'close', entrypath)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001544
1545 def getmode(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001546 '''Returns the current mode of the entry given by entryPath.'''
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001547 return self.tk.call(self._w, 'getmode', entrypath)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001548
1549 def open(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001550 '''Open the entry given by entryPath if its mode is open.'''
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001551 self.tk.call(self._w, 'open', entrypath)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001552
1553 def setmode(self, entrypath, mode='none'):
Martin v. Löwis46874282002-12-06 10:33:45 +00001554 '''This command is used to indicate whether the entry given by
1555 entryPath has children entries and whether the children are visible. mode
1556 must be one of open, close or none. If mode is set to open, a (+)
Ezio Melottie130a522011-10-19 10:58:56 +03001557 indicator is drawn next the entry. If mode is set to close, a (-)
1558 indicator is drawn next the entry. If mode is set to none, no
Martin v. Löwis46874282002-12-06 10:33:45 +00001559 indicators will be drawn for this entry. The default mode is none. The
1560 open mode indicates the entry has hidden children and this entry can be
1561 opened by the user. The close mode indicates that all the children of the
1562 entry are now visible and the entry can be closed by the user.'''
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001563 self.tk.call(self._w, 'setmode', entrypath, mode)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001564
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001565
1566# Could try subclassing Tree for CheckList - would need another arg to init
1567class CheckList(TixWidget):
1568 """The CheckList widget
1569 displays a list of items to be selected by the user. CheckList acts
1570 similarly to the Tk checkbutton or radiobutton widgets, except it is
1571 capable of handling many more items than checkbuttons or radiobuttons.
1572 """
Martin v. Löwis46874282002-12-06 10:33:45 +00001573 # FIXME: It should inherit -superclass tixTree
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001574 def __init__(self, master=None, cnf={}, **kw):
1575 TixWidget.__init__(self, master, 'tixCheckList',
Guilherme Polobcd03df2009-08-18 15:35:57 +00001576 ['options', 'radio'], cnf, kw)
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001577 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1578 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1579 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001580
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001581 def autosetmode(self):
Martin v. Löwis46874282002-12-06 10:33:45 +00001582 '''This command calls the setmode method for all the entries in this
1583 Tree widget: if an entry has no child entries, its mode is set to
1584 none. Otherwise, if the entry has any hidden child entries, its mode is
1585 set to open; otherwise its mode is set to close.'''
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001586 self.tk.call(self._w, 'autosetmode')
1587
1588 def close(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001589 '''Close the entry given by entryPath if its mode is close.'''
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001590 self.tk.call(self._w, 'close', entrypath)
1591
1592 def getmode(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001593 '''Returns the current mode of the entry given by entryPath.'''
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001594 return self.tk.call(self._w, 'getmode', entrypath)
1595
1596 def open(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001597 '''Open the entry given by entryPath if its mode is open.'''
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001598 self.tk.call(self._w, 'open', entrypath)
1599
1600 def getselection(self, mode='on'):
Martin v. Löwis46874282002-12-06 10:33:45 +00001601 '''Returns a list of items whose status matches status. If status is
1602 not specified, the list of items in the "on" status will be returned.
1603 Mode can be on, off, default'''
1604 c = self.tk.split(self.tk.call(self._w, 'getselection', mode))
1605 return self.tk.splitlist(c)
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001606
1607 def getstatus(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001608 '''Returns the current status of entryPath.'''
1609 return self.tk.call(self._w, 'getstatus', entrypath)
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001610
1611 def setstatus(self, entrypath, mode='on'):
Martin v. Löwis46874282002-12-06 10:33:45 +00001612 '''Sets the status of entryPath to be status. A bitmap will be
1613 displayed next to the entry its status is on, off or default.'''
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001614 self.tk.call(self._w, 'setstatus', entrypath, mode)
1615
1616
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001617###########################################################################
1618### The subclassing below is used to instantiate the subwidgets in each ###
1619### mega widget. This allows us to access their methods directly. ###
1620###########################################################################
1621
1622class _dummyButton(Button, TixSubWidget):
1623 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001624 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001625
1626class _dummyCheckbutton(Checkbutton, TixSubWidget):
1627 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001628 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001629
1630class _dummyEntry(Entry, TixSubWidget):
1631 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001632 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001633
1634class _dummyFrame(Frame, TixSubWidget):
1635 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001636 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001637
1638class _dummyLabel(Label, TixSubWidget):
1639 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001640 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001641
1642class _dummyListbox(Listbox, TixSubWidget):
1643 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001644 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001645
1646class _dummyMenu(Menu, TixSubWidget):
1647 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001648 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001649
1650class _dummyMenubutton(Menubutton, TixSubWidget):
1651 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001652 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001653
1654class _dummyScrollbar(Scrollbar, TixSubWidget):
1655 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001656 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001657
1658class _dummyText(Text, TixSubWidget):
1659 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001660 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001661
1662class _dummyScrolledListBox(ScrolledListBox, TixSubWidget):
1663 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001664 TixSubWidget.__init__(self, master, name, destroy_physically)
1665 self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox')
1666 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1667 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001668
1669class _dummyHList(HList, TixSubWidget):
1670 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001671 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001672
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001673class _dummyScrolledHList(ScrolledHList, TixSubWidget):
1674 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001675 TixSubWidget.__init__(self, master, name, destroy_physically)
1676 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1677 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1678 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001679
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001680class _dummyTList(TList, TixSubWidget):
1681 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001682 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001683
1684class _dummyComboBox(ComboBox, TixSubWidget):
1685 def __init__(self, master, name, destroy_physically=1):
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001686 TixSubWidget.__init__(self, master, name, ['fancy',destroy_physically])
1687 self.subwidget_list['label'] = _dummyLabel(self, 'label')
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001688 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
1689 self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001690
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001691 self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001692 'slistbox')
1693 try:
1694 self.subwidget_list['tick'] = _dummyButton(self, 'tick')
1695 #cross Button : present if created with the fancy option
1696 self.subwidget_list['cross'] = _dummyButton(self, 'cross')
1697 except TypeError:
1698 # unavailable when -fancy not specified
1699 pass
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001700
1701class _dummyDirList(DirList, TixSubWidget):
1702 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001703 TixSubWidget.__init__(self, master, name, destroy_physically)
1704 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1705 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1706 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001707
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001708class _dummyDirSelectBox(DirSelectBox, TixSubWidget):
1709 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001710 TixSubWidget.__init__(self, master, name, destroy_physically)
1711 self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
1712 self.subwidget_list['dircbx'] = _dummyFileComboBox(self, 'dircbx')
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001713
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001714class _dummyExFileSelectBox(ExFileSelectBox, TixSubWidget):
1715 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001716 TixSubWidget.__init__(self, master, name, destroy_physically)
1717 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1718 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1719 self.subwidget_list['hidden'] = _dummyCheckbutton(self, 'hidden')
1720 self.subwidget_list['types'] = _dummyComboBox(self, 'types')
1721 self.subwidget_list['dir'] = _dummyComboBox(self, 'dir')
1722 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
1723 self.subwidget_list['file'] = _dummyComboBox(self, 'file')
1724 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001725
1726class _dummyFileSelectBox(FileSelectBox, TixSubWidget):
1727 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001728 TixSubWidget.__init__(self, master, name, destroy_physically)
1729 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
1730 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
1731 self.subwidget_list['filter'] = _dummyComboBox(self, 'filter')
1732 self.subwidget_list['selection'] = _dummyComboBox(self, 'selection')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001733
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001734class _dummyFileComboBox(ComboBox, TixSubWidget):
1735 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001736 TixSubWidget.__init__(self, master, name, destroy_physically)
1737 self.subwidget_list['dircbx'] = _dummyComboBox(self, 'dircbx')
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001738
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001739class _dummyStdButtonBox(StdButtonBox, TixSubWidget):
1740 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001741 TixSubWidget.__init__(self, master, name, destroy_physically)
1742 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1743 self.subwidget_list['apply'] = _dummyButton(self, 'apply')
1744 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1745 self.subwidget_list['help'] = _dummyButton(self, 'help')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001746
1747class _dummyNoteBookFrame(NoteBookFrame, TixSubWidget):
1748 def __init__(self, master, name, destroy_physically=0):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001749 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001750
Martin v. Löwis01824bf2002-09-19 08:12:55 +00001751class _dummyPanedWindow(PanedWindow, TixSubWidget):
1752 def __init__(self, master, name, destroy_physically=1):
Tim Peters182b5ac2004-07-18 06:16:08 +00001753 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwis01824bf2002-09-19 08:12:55 +00001754
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001755########################
1756### Utility Routines ###
1757########################
1758
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001759#mike Should tixDestroy be exposed as a wrapper? - but not for widgets.
1760
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001761def OptionName(widget):
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001762 '''Returns the qualified path name for the widget. Normally used to set
1763 default options for subwidgets. See tixwidgets.py'''
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001764 return widget.tk.call('tixOptionName', widget._w)
1765
1766# Called with a dictionary argument of the form
1767# {'*.c':'C source files', '*.txt':'Text Files', '*':'All files'}
1768# returns a string which can be used to configure the fsbox file types
1769# in an ExFileSelectBox. i.e.,
1770# '{{*} {* - All files}} {{*.c} {*.c - C source files}} {{*.txt} {*.txt - Text Files}}'
1771def FileTypeList(dict):
1772 s = ''
1773 for type in dict.keys():
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001774 s = s + '{{' + type + '} {' + type + ' - ' + dict[type] + '}} '
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001775 return s
1776
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001777# Still to be done:
Martin v. Löwis46874282002-12-06 10:33:45 +00001778# tixIconView
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001779class CObjView(TixWidget):
1780 """This file implements the Canvas Object View widget. This is a base
1781 class of IconView. It implements automatic placement/adjustment of the
1782 scrollbars according to the canvas objects inside the canvas subwidget.
1783 The scrollbars are adjusted so that the canvas is just large enough
1784 to see all the objects.
1785 """
Martin v. Löwis46874282002-12-06 10:33:45 +00001786 # FIXME: It should inherit -superclass tixScrolledWidget
1787 pass
1788
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001789
Guilherme Polo1fff0082009-08-14 15:05:30 +00001790class Grid(TixWidget, XView, YView):
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001791 '''The Tix Grid command creates a new window and makes it into a
1792 tixGrid widget. Additional options, may be specified on the command
1793 line or in the option database to configure aspects such as its cursor
1794 and relief.
1795
1796 A Grid widget displays its contents in a two dimensional grid of cells.
1797 Each cell may contain one Tix display item, which may be in text,
1798 graphics or other formats. See the DisplayStyle class for more information
1799 about Tix display items. Individual cells, or groups of cells, can be
1800 formatted with a wide range of attributes, such as its color, relief and
1801 border.
1802
1803 Subwidgets - None'''
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001804 # valid specific resources as of Tk 8.4
1805 # editdonecmd, editnotifycmd, floatingcols, floatingrows, formatcmd,
1806 # highlightbackground, highlightcolor, leftmargin, itemtype, selectmode,
1807 # selectunit, topmargin,
1808 def __init__(self, master=None, cnf={}, **kw):
1809 static= []
1810 self.cnf= cnf
1811 TixWidget.__init__(self, master, 'tixGrid', static, cnf, kw)
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001812
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001813 # valid options as of Tk 8.4
Guilherme Polobcd03df2009-08-18 15:35:57 +00001814 # anchor, bdtype, cget, configure, delete, dragsite, dropsite, entrycget,
1815 # edit, entryconfigure, format, geometryinfo, info, index, move, nearest,
1816 # selection, set, size, unset, xview, yview
1817 def anchor_clear(self):
1818 """Removes the selection anchor."""
1819 self.tk.call(self, 'anchor', 'clear')
1820
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001821 def anchor_get(self):
1822 "Get the (x,y) coordinate of the current anchor cell"
1823 return self._getints(self.tk.call(self, 'anchor', 'get'))
1824
Guilherme Polobcd03df2009-08-18 15:35:57 +00001825 def anchor_set(self, x, y):
1826 """Set the selection anchor to the cell at (x, y)."""
1827 self.tk.call(self, 'anchor', 'set', x, y)
1828
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001829 def delete_row(self, from_, to=None):
1830 """Delete rows between from_ and to inclusive.
1831 If to is not provided, delete only row at from_"""
1832 if to is None:
1833 self.tk.call(self, 'delete', 'row', from_)
1834 else:
1835 self.tk.call(self, 'delete', 'row', from_, to)
Guilherme Polobcd03df2009-08-18 15:35:57 +00001836
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001837 def delete_column(self, from_, to=None):
1838 """Delete columns between from_ and to inclusive.
1839 If to is not provided, delete only column at from_"""
1840 if to is None:
1841 self.tk.call(self, 'delete', 'column', from_)
1842 else:
1843 self.tk.call(self, 'delete', 'column', from_, to)
Guilherme Polobcd03df2009-08-18 15:35:57 +00001844
1845 def edit_apply(self):
1846 """If any cell is being edited, de-highlight the cell and applies
1847 the changes."""
1848 self.tk.call(self, 'edit', 'apply')
1849
1850 def edit_set(self, x, y):
1851 """Highlights the cell at (x, y) for editing, if the -editnotify
1852 command returns True for this cell."""
1853 self.tk.call(self, 'edit', 'set', x, y)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001854
1855 def entrycget(self, x, y, option):
1856 "Get the option value for cell at (x,y)"
Guilherme Polobcd03df2009-08-18 15:35:57 +00001857 if option and option[0] != '-':
1858 option = '-' + option
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001859 return self.tk.call(self, 'entrycget', x, y, option)
1860
Guilherme Polobcd03df2009-08-18 15:35:57 +00001861 def entryconfigure(self, x, y, cnf=None, **kw):
1862 return self._configure(('entryconfigure', x, y), cnf, kw)
1863
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001864 # def format
1865 # def index
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001866
1867 def info_exists(self, x, y):
1868 "Return True if display item exists at (x,y)"
Guilherme Polobcd03df2009-08-18 15:35:57 +00001869 return self._getboolean(self.tk.call(self, 'info', 'exists', x, y))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001870
1871 def info_bbox(self, x, y):
1872 # This seems to always return '', at least for 'text' displayitems
1873 return self.tk.call(self, 'info', 'bbox', x, y)
1874
Guilherme Polobcd03df2009-08-18 15:35:57 +00001875 def move_column(self, from_, to, offset):
Ezio Melottie130a522011-10-19 10:58:56 +03001876 """Moves the range of columns from position FROM through TO by
Guilherme Polobcd03df2009-08-18 15:35:57 +00001877 the distance indicated by OFFSET. For example, move_column(2, 4, 1)
1878 moves the columns 2,3,4 to columns 3,4,5."""
1879 self.tk.call(self, 'move', 'column', from_, to, offset)
1880
1881 def move_row(self, from_, to, offset):
Ezio Melottie130a522011-10-19 10:58:56 +03001882 """Moves the range of rows from position FROM through TO by
Guilherme Polobcd03df2009-08-18 15:35:57 +00001883 the distance indicated by OFFSET.
1884 For example, move_row(2, 4, 1) moves the rows 2,3,4 to rows 3,4,5."""
1885 self.tk.call(self, 'move', 'row', from_, to, offset)
1886
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001887 def nearest(self, x, y):
1888 "Return coordinate of cell nearest pixel coordinate (x,y)"
1889 return self._getints(self.tk.call(self, 'nearest', x, y))
1890
1891 # def selection adjust
1892 # def selection clear
1893 # def selection includes
1894 # def selection set
1895 # def selection toggle
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001896
1897 def set(self, x, y, itemtype=None, **kw):
1898 args= self._options(self.cnf, kw)
1899 if itemtype is not None:
1900 args= ('-itemtype', itemtype) + args
1901 self.tk.call(self, 'set', x, y, *args)
1902
Guilherme Polobcd03df2009-08-18 15:35:57 +00001903 def size_column(self, index, **kw):
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001904 """Queries or sets the size of the column given by
1905 INDEX. INDEX may be any non-negative
1906 integer that gives the position of a given column.
Guilherme Polobcd03df2009-08-18 15:35:57 +00001907 INDEX can also be the string "default"; in this case, this command
1908 queries or sets the default size of all columns.
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001909 When no option-value pair is given, this command returns a tuple
1910 containing the current size setting of the given column. When
1911 option-value pairs are given, the corresponding options of the
Guilherme Polobcd03df2009-08-18 15:35:57 +00001912 size setting of the given column are changed. Options may be one
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001913 of the follwing:
Guilherme Polobcd03df2009-08-18 15:35:57 +00001914 pad0 pixels
1915 Specifies the paddings to the left of a column.
1916 pad1 pixels
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001917 Specifies the paddings to the right of a column.
Guilherme Polobcd03df2009-08-18 15:35:57 +00001918 size val
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001919 Specifies the width of a column. Val may be:
1920 "auto" -- the width of the column is set to the
1921 width of the widest cell in the column;
1922 a valid Tk screen distance unit;
1923 or a real number following by the word chars
Guilherme Polobcd03df2009-08-18 15:35:57 +00001924 (e.g. 3.4chars) that sets the width of the column to the
1925 given number of characters."""
1926 return self.tk.split(self.tk.call(self._w, 'size', 'column', index,
1927 *self._options({}, kw)))
1928
1929 def size_row(self, index, **kw):
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001930 """Queries or sets the size of the row given by
1931 INDEX. INDEX may be any non-negative
1932 integer that gives the position of a given row .
Guilherme Polobcd03df2009-08-18 15:35:57 +00001933 INDEX can also be the string "default"; in this case, this command
1934 queries or sets the default size of all rows.
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001935 When no option-value pair is given, this command returns a list con-
1936 taining the current size setting of the given row . When option-value
Guilherme Polobcd03df2009-08-18 15:35:57 +00001937 pairs are given, the corresponding options of the size setting of the
1938 given row are changed. Options may be one of the follwing:
1939 pad0 pixels
1940 Specifies the paddings to the top of a row.
1941 pad1 pixels
Ezio Melottie130a522011-10-19 10:58:56 +03001942 Specifies the paddings to the bottom of a row.
Guilherme Polobcd03df2009-08-18 15:35:57 +00001943 size val
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001944 Specifies the height of a row. Val may be:
1945 "auto" -- the height of the row is set to the
1946 height of the highest cell in the row;
1947 a valid Tk screen distance unit;
1948 or a real number following by the word chars
Guilherme Polobcd03df2009-08-18 15:35:57 +00001949 (e.g. 3.4chars) that sets the height of the row to the
1950 given number of characters."""
1951 return self.tk.split(self.tk.call(
1952 self, 'size', 'row', index, *self._options({}, kw)))
1953
1954 def unset(self, x, y):
1955 """Clears the cell at (x, y) by removing its display item."""
1956 self.tk.call(self._w, 'unset', x, y)
1957
Raymond Hettingerff41c482003-04-06 09:01:11 +00001958
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001959class ScrolledGrid(Grid):
Martin v. Löwis46874282002-12-06 10:33:45 +00001960 '''Scrolled Grid widgets'''
1961
1962 # FIXME: It should inherit -superclass tixScrolledWidget
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001963 def __init__(self, master=None, cnf={}, **kw):
1964 static= []
1965 self.cnf= cnf
1966 TixWidget.__init__(self, master, 'tixScrolledGrid', static, cnf, kw)