blob: 3d38e5db070a7ded63a4623560613d4efdea7976 [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 *
Victor Stinner7fa767e2014-03-20 09:16:38 +010030from tkinter import _cnfmerge, _default_root
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000031
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000032import _tkinter # If this fails your Python may not be configured for Tk
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000033
34# Some more constants (for consistency with Tkinter)
35WINDOW = 'window'
36TEXT = 'text'
37STATUS = 'status'
38IMMEDIATE = 'immediate'
39IMAGE = 'image'
40IMAGETEXT = 'imagetext'
41BALLOON = 'balloon'
42AUTO = 'auto'
43ACROSSTOP = 'acrosstop'
44
Guilherme Polobcd03df2009-08-18 15:35:57 +000045# A few useful constants for the Grid widget
46ASCII = 'ascii'
47CELL = 'cell'
48COLUMN = 'column'
49DECREASING = 'decreasing'
50INCREASING = 'increasing'
51INTEGER = 'integer'
52MAIN = 'main'
53MAX = 'max'
54REAL = 'real'
55ROW = 'row'
56S_REGION = 's-region'
57X_REGION = 'x-region'
58Y_REGION = 'y-region'
59
Fred Drake723293c2001-12-13 04:53:07 +000060# Some constants used by Tkinter dooneevent()
61TCL_DONT_WAIT = 1 << 1
62TCL_WINDOW_EVENTS = 1 << 2
63TCL_FILE_EVENTS = 1 << 3
64TCL_TIMER_EVENTS = 1 << 4
65TCL_IDLE_EVENTS = 1 << 5
66TCL_ALL_EVENTS = 0
67
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000068# BEWARE - this is implemented by copying some code from the Widget class
69# in Tkinter (to override Widget initialization) and is therefore
70# liable to break.
Georg Brandl14fc4272008-05-17 18:39:55 +000071import tkinter, os
Martin v. Löwisb7b32602001-11-02 23:48:20 +000072
73# Could probably add this to Tkinter.Misc
74class tixCommand:
Fred Drake723293c2001-12-13 04:53:07 +000075 """The tix commands provide access to miscellaneous elements
Martin v. Löwisb7b32602001-11-02 23:48:20 +000076 of Tix's internal state and the Tix application context.
Fred Drake723293c2001-12-13 04:53:07 +000077 Most of the information manipulated by these commands pertains
78 to the application as a whole, or to a screen or
79 display, rather than to a particular window.
Martin v. Löwisb7b32602001-11-02 23:48:20 +000080
81 This is a mixin class, assumed to be mixed to Tkinter.Tk
82 that supports the self.tk.call method.
83 """
Fred Drake723293c2001-12-13 04:53:07 +000084
Martin v. Löwisb7b32602001-11-02 23:48:20 +000085 def tix_addbitmapdir(self, directory):
Fred Drake723293c2001-12-13 04:53:07 +000086 """Tix maintains a list of directories under which
Martin v. Löwisb7b32602001-11-02 23:48:20 +000087 the tix_getimage and tix_getbitmap commands will
Fred Drake723293c2001-12-13 04:53:07 +000088 search for image files. The standard bitmap directory
89 is $TIX_LIBRARY/bitmaps. The addbitmapdir command
90 adds directory into this list. By using this
Martin v. Löwisb7b32602001-11-02 23:48:20 +000091 command, the image files of an applications can
92 also be located using the tix_getimage or tix_getbitmap
93 command.
94 """
95 return self.tk.call('tix', 'addbitmapdir', directory)
96
97 def tix_cget(self, option):
98 """Returns the current value of the configuration
99 option given by option. Option may be any of the
100 options described in the CONFIGURATION OPTIONS section.
101 """
102 return self.tk.call('tix', 'cget', option)
103
104 def tix_configure(self, cnf=None, **kw):
Fred Drake723293c2001-12-13 04:53:07 +0000105 """Query or modify the configuration options of the Tix application
106 context. If no option is specified, returns a dictionary all of the
107 available options. If option is specified with no value, then the
108 command returns a list describing the one named option (this list
109 will be identical to the corresponding sublist of the value
110 returned if no option is specified). If one or more option-value
111 pairs are specified, then the command modifies the given option(s)
112 to have the given value(s); in this case the command returns an
113 empty string. Option may be any of the configuration options.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000114 """
Fred Drake723293c2001-12-13 04:53:07 +0000115 # Copied from Tkinter.py
116 if kw:
117 cnf = _cnfmerge((cnf, kw))
118 elif cnf:
119 cnf = _cnfmerge(cnf)
120 if cnf is None:
Serhiy Storchaka848972c2013-12-25 16:35:38 +0200121 return self._getconfigure('tix', 'configure')
Serhiy Storchaka975fce32013-09-16 11:01:31 +0300122 if isinstance(cnf, str):
Serhiy Storchaka848972c2013-12-25 16:35:38 +0200123 return self._getconfigure1('tix', 'configure', '-'+cnf)
Fred Drake723293c2001-12-13 04:53:07 +0000124 return self.tk.call(('tix', 'configure') + self._options(cnf))
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000125
126 def tix_filedialog(self, dlgclass=None):
Fred Drake723293c2001-12-13 04:53:07 +0000127 """Returns the file selection dialog that may be shared among
128 different calls from this application. This command will create a
129 file selection dialog widget when it is called the first time. This
130 dialog will be returned by all subsequent calls to tix_filedialog.
131 An optional dlgclass parameter can be passed to specified what type
132 of file selection dialog widget is desired. Possible options are
133 tix FileSelectDialog or tixExFileSelectDialog.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000134 """
135 if dlgclass is not None:
136 return self.tk.call('tix', 'filedialog', dlgclass)
137 else:
138 return self.tk.call('tix', 'filedialog')
139
140 def tix_getbitmap(self, name):
Fred Drake723293c2001-12-13 04:53:07 +0000141 """Locates a bitmap file of the name name.xpm or name in one of the
142 bitmap directories (see the tix_addbitmapdir command above). By
143 using tix_getbitmap, you can avoid hard coding the pathnames of the
144 bitmap files in your application. When successful, it returns the
145 complete pathname of the bitmap file, prefixed with the character
146 '@'. The returned value can be used to configure the -bitmap
147 option of the TK and Tix widgets.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000148 """
149 return self.tk.call('tix', 'getbitmap', name)
150
151 def tix_getimage(self, name):
Fred Drake723293c2001-12-13 04:53:07 +0000152 """Locates an image file of the name name.xpm, name.xbm or name.ppm
153 in one of the bitmap directories (see the addbitmapdir command
154 above). If more than one file with the same name (but different
155 extensions) exist, then the image type is chosen according to the
156 depth of the X display: xbm images are chosen on monochrome
157 displays and color images are chosen on color displays. By using
Ezio Melotti42da6632011-03-15 05:18:48 +0200158 tix_ getimage, you can avoid hard coding the pathnames of the
Fred Drake723293c2001-12-13 04:53:07 +0000159 image files in your application. When successful, this command
160 returns the name of the newly created image, which can be used to
161 configure the -image option of the Tk and Tix widgets.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000162 """
163 return self.tk.call('tix', 'getimage', name)
164
165 def tix_option_get(self, name):
Ezio Melotti13925002011-03-16 11:05:33 +0200166 """Gets the options maintained by the Tix
Fred Drake723293c2001-12-13 04:53:07 +0000167 scheme mechanism. Available options include:
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000168
169 active_bg active_fg bg
170 bold_font dark1_bg dark1_fg
171 dark2_bg dark2_fg disabled_fg
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000172 fg fixed_font font
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000173 inactive_bg inactive_fg input1_bg
174 input2_bg italic_font light1_bg
175 light1_fg light2_bg light2_fg
176 menu_font output1_bg output2_bg
177 select_bg select_fg selector
178 """
179 # could use self.tk.globalgetvar('tixOption', name)
180 return self.tk.call('tix', 'option', 'get', name)
181
182 def tix_resetoptions(self, newScheme, newFontSet, newScmPrio=None):
Fred Drake723293c2001-12-13 04:53:07 +0000183 """Resets the scheme and fontset of the Tix application to
184 newScheme and newFontSet, respectively. This affects only those
185 widgets created after this call. Therefore, it is best to call the
186 resetoptions command before the creation of any widgets in a Tix
187 application.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000188
Fred Drake723293c2001-12-13 04:53:07 +0000189 The optional parameter newScmPrio can be given to reset the
190 priority level of the Tk options set by the Tix schemes.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000191
Fred Drake723293c2001-12-13 04:53:07 +0000192 Because of the way Tk handles the X option database, after Tix has
193 been has imported and inited, it is not possible to reset the color
194 schemes and font sets using the tix config command. Instead, the
195 tix_resetoptions command must be used.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000196 """
197 if newScmPrio is not None:
198 return self.tk.call('tix', 'resetoptions', newScheme, newFontSet, newScmPrio)
199 else:
200 return self.tk.call('tix', 'resetoptions', newScheme, newFontSet)
201
Georg Brandl14fc4272008-05-17 18:39:55 +0000202class Tk(tkinter.Tk, tixCommand):
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000203 """Toplevel widget of Tix which represents mostly the main window
204 of an application. It has an associated Tcl interpreter."""
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000205 def __init__(self, screenName=None, baseName=None, className='Tix'):
Georg Brandl14fc4272008-05-17 18:39:55 +0000206 tkinter.Tk.__init__(self, screenName, baseName, className)
Moshe Zadka22710822001-03-21 17:24:49 +0000207 tixlib = os.environ.get('TIX_LIBRARY')
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000208 self.tk.eval('global auto_path; lappend auto_path [file dir [info nameof]]')
Moshe Zadka22710822001-03-21 17:24:49 +0000209 if tixlib is not None:
210 self.tk.eval('global auto_path; lappend auto_path {%s}' % tixlib)
211 self.tk.eval('global tcl_pkgPath; lappend tcl_pkgPath {%s}' % tixlib)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000212 # Load Tix - this should work dynamically or statically
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +0000213 # If it's static, tcl/tix8.1/pkgIndex.tcl should have
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000214 # 'load {} Tix'
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +0000215 # If it's dynamic under Unix, tcl/tix8.1/pkgIndex.tcl should have
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000216 # 'load libtix8.1.8.3.so Tix'
Moshe Zadka22710822001-03-21 17:24:49 +0000217 self.tk.eval('package require Tix')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000218
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +0000219 def destroy(self):
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300220 # For safety, remove the delete_window binding before destroy
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +0000221 self.protocol("WM_DELETE_WINDOW", "")
Georg Brandl14fc4272008-05-17 18:39:55 +0000222 tkinter.Tk.destroy(self)
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000223
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000224# The Tix 'tixForm' geometry manager
225class Form:
226 """The Tix Form geometry manager
227
228 Widgets can be arranged by specifying attachments to other widgets.
229 See Tix documentation for complete details"""
230
231 def config(self, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +0000232 self.tk.call('tixForm', self._w, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000233
234 form = config
235
236 def __setitem__(self, key, value):
Guido van Rossum49fa2bd2001-08-13 14:12:35 +0000237 Form.form(self, {key: value})
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000238
239 def check(self):
240 return self.tk.call('tixForm', 'check', self._w)
241
242 def forget(self):
243 self.tk.call('tixForm', 'forget', self._w)
244
245 def grid(self, xsize=0, ysize=0):
246 if (not xsize) and (not ysize):
247 x = self.tk.call('tixForm', 'grid', self._w)
248 y = self.tk.splitlist(x)
249 z = ()
250 for x in y:
251 z = z + (self.tk.getint(x),)
252 return z
Martin v. Löwis46874282002-12-06 10:33:45 +0000253 return self.tk.call('tixForm', 'grid', self._w, xsize, ysize)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000254
255 def info(self, option=None):
256 if not option:
257 return self.tk.call('tixForm', 'info', self._w)
258 if option[0] != '-':
259 option = '-' + option
260 return self.tk.call('tixForm', 'info', self._w, option)
261
262 def slaves(self):
Alexander Belopolsky022f0492010-11-22 19:40:51 +0000263 return [self._nametowidget(x) for x in
264 self.tk.splitlist(
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000265 self.tk.call(
Alexander Belopolsky022f0492010-11-22 19:40:51 +0000266 'tixForm', 'slaves', self._w))]
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000267
268
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000269
Georg Brandl14fc4272008-05-17 18:39:55 +0000270tkinter.Widget.__bases__ = tkinter.Widget.__bases__ + (Form,)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000271
Georg Brandl14fc4272008-05-17 18:39:55 +0000272class TixWidget(tkinter.Widget):
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000273 """A TixWidget class is used to package all (or most) Tix widgets.
274
275 Widget initialization is extended in two ways:
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000276 1) It is possible to give a list of options which must be part of
Moshe Zadka22710822001-03-21 17:24:49 +0000277 the creation command (so called Tix 'static' options). These cannot be
278 given as a 'config' command later.
279 2) It is possible to give the name of an existing TK widget. These are
280 child widgets created automatically by a Tix mega-widget. The Tk call
281 to create these widgets is therefore bypassed in TixWidget.__init__
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000282
283 Both options are for use by subclasses only.
284 """
285 def __init__ (self, master=None, widgetName=None,
Moshe Zadka22710822001-03-21 17:24:49 +0000286 static_options=None, cnf={}, kw={}):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000287 # Merge keywords and dictionary arguments
288 if kw:
Moshe Zadka22710822001-03-21 17:24:49 +0000289 cnf = _cnfmerge((cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000290 else:
291 cnf = _cnfmerge(cnf)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000292
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000293 # Move static options into extra. static_options must be
294 # a list of keywords (or None).
295 extra=()
Neal Norwitzf539bde2002-11-14 02:43:40 +0000296
297 # 'options' is always a static option
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000298 if static_options:
Neal Norwitzf539bde2002-11-14 02:43:40 +0000299 static_options.append('options')
300 else:
301 static_options = ['options']
Raymond Hettingerff41c482003-04-06 09:01:11 +0000302
Hirokazu Yamamoto21027e62009-01-10 12:15:23 +0000303 for k,v in list(cnf.items()):
Neal Norwitzf539bde2002-11-14 02:43:40 +0000304 if k in static_options:
305 extra = extra + ('-' + k, v)
306 del cnf[k]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000307
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000308 self.widgetName = widgetName
309 Widget._setup(self, master, cnf)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000310
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000311 # If widgetName is None, this is a dummy creation call where the
312 # corresponding Tk widget has already been created by Tix
313 if widgetName:
Raymond Hettingerff41c482003-04-06 09:01:11 +0000314 self.tk.call(widgetName, self._w, *extra)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000315
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000316 # Non-static options - to be done via a 'config' command
317 if cnf:
318 Widget.config(self, cnf)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000319
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000320 # Dictionary to hold subwidget names for easier access. We can't
321 # use the children list because the public Tix names may not be the
322 # same as the pathname component
323 self.subwidget_list = {}
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000324
325 # We set up an attribute access function so that it is possible to
326 # do w.ok['text'] = 'Hello' rather than w.subwidget('ok')['text'] = 'Hello'
327 # when w is a StdButtonBox.
328 # We can even do w.ok.invoke() because w.ok is subclassed from the
329 # Button class if you go through the proper constructors
330 def __getattr__(self, name):
Guido van Rossume014a132006-08-19 16:53:45 +0000331 if name in self.subwidget_list:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000332 return self.subwidget_list[name]
Collin Winterce36ad82007-08-30 01:19:48 +0000333 raise AttributeError(name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000334
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000335 def set_silent(self, value):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000336 """Set a variable without calling its action routine"""
337 self.tk.call('tixSetSilent', self._w, value)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000338
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000339 def subwidget(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000340 """Return the named subwidget (which must have been created by
341 the sub-class)."""
342 n = self._subwidget_name(name)
343 if not n:
Collin Winterce36ad82007-08-30 01:19:48 +0000344 raise TclError("Subwidget " + name + " not child of " + self._name)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000345 # Remove header of name and leading dot
346 n = n[len(self._w)+1:]
347 return self._nametowidget(n)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000348
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000349 def subwidgets_all(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000350 """Return all subwidgets."""
351 names = self._subwidget_names()
352 if not names:
353 return []
354 retlist = []
355 for name in names:
356 name = name[len(self._w)+1:]
357 try:
358 retlist.append(self._nametowidget(name))
359 except:
360 # some of the widgets are unknown e.g. border in LabelFrame
361 pass
362 return retlist
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000363
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000364 def _subwidget_name(self,name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000365 """Get a subwidget name (returns a String, not a Widget !)"""
366 try:
367 return self.tk.call(self._w, 'subwidget', name)
368 except TclError:
369 return None
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000370
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000371 def _subwidget_names(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000372 """Return the name of all subwidgets."""
373 try:
374 x = self.tk.call(self._w, 'subwidgets', '-all')
Serhiy Storchaka848972c2013-12-25 16:35:38 +0200375 return self.tk.splitlist(x)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000376 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 config_all(self, option, value):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000380 """Set configuration options for all subwidgets (and self)."""
381 if option == '':
382 return
Serhiy Storchaka975fce32013-09-16 11:01:31 +0300383 elif not isinstance(option, str):
Walter Dörwald70a6b492004-02-12 17:35:32 +0000384 option = repr(option)
Serhiy Storchaka975fce32013-09-16 11:01:31 +0300385 if not isinstance(value, str):
Walter Dörwald70a6b492004-02-12 17:35:32 +0000386 value = repr(value)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000387 names = self._subwidget_names()
388 for name in names:
389 self.tk.call(name, 'configure', '-' + option, value)
Neal Norwitz731a9862002-12-10 02:18:49 +0000390 # These are missing from Tkinter
391 def image_create(self, imgtype, cnf={}, master=None, **kw):
392 if not master:
Georg Brandl14fc4272008-05-17 18:39:55 +0000393 master = tkinter._default_root
Neal Norwitz731a9862002-12-10 02:18:49 +0000394 if not master:
Collin Winterce36ad82007-08-30 01:19:48 +0000395 raise RuntimeError('Too early to create image')
Neal Norwitz731a9862002-12-10 02:18:49 +0000396 if kw and cnf: cnf = _cnfmerge((cnf, kw))
397 elif kw: cnf = kw
398 options = ()
399 for k, v in cnf.items():
Florent Xicluna5d1155c2011-10-28 14:45:05 +0200400 if callable(v):
Neal Norwitz731a9862002-12-10 02:18:49 +0000401 v = self._register(v)
402 options = options + ('-'+k, v)
403 return master.tk.call(('image', 'create', imgtype,) + options)
404 def image_delete(self, imgname):
405 try:
406 self.tk.call('image', 'delete', imgname)
407 except TclError:
408 # May happen if the root was destroyed
409 pass
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000410
411# Subwidgets are child widgets created automatically by mega-widgets.
412# In python, we have to create these subwidgets manually to mirror their
413# existence in Tk/Tix.
414class TixSubWidget(TixWidget):
415 """Subwidget class.
416
417 This is used to mirror child widgets automatically created
418 by Tix/Tk as part of a mega-widget in Python (which is not informed
419 of this)"""
420
421 def __init__(self, master, name,
Moshe Zadka22710822001-03-21 17:24:49 +0000422 destroy_physically=1, check_intermediate=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000423 if check_intermediate:
424 path = master._subwidget_name(name)
425 try:
426 path = path[len(master._w)+1:]
Neal Norwitzebb41902002-05-31 20:51:31 +0000427 plist = path.split('.')
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000428 except:
429 plist = []
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000430
Thomas Wouters89f507f2006-12-13 04:49:30 +0000431 if not check_intermediate:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000432 # immediate descendant
433 TixWidget.__init__(self, master, None, None, {'name' : name})
434 else:
435 # Ensure that the intermediate widgets exist
436 parent = master
437 for i in range(len(plist) - 1):
Neal Norwitzebb41902002-05-31 20:51:31 +0000438 n = '.'.join(plist[:i+1])
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000439 try:
440 w = master._nametowidget(n)
441 parent = w
442 except KeyError:
443 # Create the intermediate widget
444 parent = TixSubWidget(parent, plist[i],
Neal Norwitzf539bde2002-11-14 02:43:40 +0000445 destroy_physically=0,
446 check_intermediate=0)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000447 # The Tk widget name is in plist, not in name
448 if plist:
449 name = plist[-1]
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000450 TixWidget.__init__(self, parent, None, None, {'name' : name})
451 self.destroy_physically = destroy_physically
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000452
453 def destroy(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000454 # For some widgets e.g., a NoteBook, when we call destructors,
455 # we must be careful not to destroy the frame widget since this
456 # also destroys the parent NoteBook thus leading to an exception
457 # in Tkinter when it finally calls Tcl to destroy the NoteBook
Hirokazu Yamamoto21027e62009-01-10 12:15:23 +0000458 for c in list(self.children.values()): c.destroy()
Guido van Rossume014a132006-08-19 16:53:45 +0000459 if self._name in self.master.children:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000460 del self.master.children[self._name]
Guido van Rossume014a132006-08-19 16:53:45 +0000461 if self._name in self.master.subwidget_list:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000462 del self.master.subwidget_list[self._name]
463 if self.destroy_physically:
464 # This is bypassed only for a few widgets
465 self.tk.call('destroy', self._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000466
467
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000468# Useful class to create a display style - later shared by many items.
469# Contributed by Steffen Kremser
470class DisplayStyle:
471 """DisplayStyle - handle configuration options shared by
472 (multiple) Display Items"""
473
Thomas Wouters73e5a5b2006-06-08 15:35:45 +0000474 def __init__(self, itemtype, cnf={}, **kw):
Moshe Zadka22710822001-03-21 17:24:49 +0000475 master = _default_root # global from Tkinter
Guido van Rossume014a132006-08-19 16:53:45 +0000476 if not master and 'refwindow' in cnf: master=cnf['refwindow']
477 elif not master and 'refwindow' in kw: master= kw['refwindow']
Collin Winterce36ad82007-08-30 01:19:48 +0000478 elif not master: raise RuntimeError("Too early to create display style: no root window")
Moshe Zadka22710822001-03-21 17:24:49 +0000479 self.tk = master.tk
Raymond Hettingerff41c482003-04-06 09:01:11 +0000480 self.stylename = self.tk.call('tixDisplayStyle', itemtype,
481 *self._options(cnf,kw) )
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000482
483 def __str__(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000484 return self.stylename
485
Thomas Wouters73e5a5b2006-06-08 15:35:45 +0000486 def _options(self, cnf, kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000487 if kw and cnf:
488 cnf = _cnfmerge((cnf, kw))
489 elif kw:
490 cnf = kw
491 opts = ()
492 for k, v in cnf.items():
493 opts = opts + ('-'+k, v)
494 return opts
495
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000496 def delete(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000497 self.tk.call(self.stylename, 'delete')
498
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000499 def __setitem__(self,key,value):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000500 self.tk.call(self.stylename, 'configure', '-%s'%key, value)
501
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000502 def config(self, cnf={}, **kw):
Serhiy Storchaka848972c2013-12-25 16:35:38 +0200503 return self._getconfigure(
504 self.stylename, 'configure', *self._options(cnf,kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000505
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000506 def __getitem__(self,key):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000507 return self.tk.call(self.stylename, 'cget', '-%s'%key)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000508
509
510######################################################
511### The Tix Widget classes - in alphabetical order ###
512######################################################
513
514class Balloon(TixWidget):
515 """Balloon help widget.
516
Moshe Zadka22710822001-03-21 17:24:49 +0000517 Subwidget Class
518 --------- -----
Fred Drake723293c2001-12-13 04:53:07 +0000519 label Label
520 message Message"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000521
Martin v. Löwis46874282002-12-06 10:33:45 +0000522 # FIXME: It should inherit -superclass tixShell
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000523 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis652e1912001-11-25 14:50:56 +0000524 # static seem to be -installcolormap -initwait -statusbar -cursor
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000525 static = ['options', 'installcolormap', 'initwait', 'statusbar',
526 'cursor']
527 TixWidget.__init__(self, master, 'tixBalloon', static, cnf, kw)
528 self.subwidget_list['label'] = _dummyLabel(self, 'label',
529 destroy_physically=0)
530 self.subwidget_list['message'] = _dummyLabel(self, 'message',
531 destroy_physically=0)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000532
533 def bind_widget(self, widget, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000534 """Bind balloon widget to another.
535 One balloon widget may be bound to several widgets at the same time"""
Raymond Hettingerff41c482003-04-06 09:01:11 +0000536 self.tk.call(self._w, 'bind', widget._w, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000537
538 def unbind_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000539 self.tk.call(self._w, 'unbind', widget._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000540
541class ButtonBox(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000542 """ButtonBox - A container for pushbuttons.
543 Subwidgets are the buttons added with the add method.
544 """
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000545 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000546 TixWidget.__init__(self, master, 'tixButtonBox',
547 ['orientation', 'options'], cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000548
549 def add(self, name, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000550 """Add a button with given name to box."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000551
Raymond Hettingerff41c482003-04-06 09:01:11 +0000552 btn = self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000553 self.subwidget_list[name] = _dummyButton(self, name)
554 return btn
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000555
556 def invoke(self, name):
Guido van Rossume014a132006-08-19 16:53:45 +0000557 if name in self.subwidget_list:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000558 self.tk.call(self._w, 'invoke', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000559
560class ComboBox(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000561 """ComboBox - an Entry field with a dropdown menu. The user can select a
Ezio Melotti13925002011-03-16 11:05:33 +0200562 choice by either typing in the entry subwidget or selecting from the
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000563 listbox subwidget.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000564
Moshe Zadka22710822001-03-21 17:24:49 +0000565 Subwidget Class
566 --------- -----
567 entry Entry
568 arrow Button
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000569 slistbox ScrolledListBox
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000570 tick Button
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000571 cross Button : present if created with the fancy option"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000572
Martin v. Löwis46874282002-12-06 10:33:45 +0000573 # FIXME: It should inherit -superclass tixLabelWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000574 def __init__ (self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000575 TixWidget.__init__(self, master, 'tixComboBox',
576 ['editable', 'dropdown', 'fancy', 'options'],
577 cnf, kw)
578 self.subwidget_list['label'] = _dummyLabel(self, 'label')
579 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
580 self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
581 self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
582 'slistbox')
583 try:
584 self.subwidget_list['tick'] = _dummyButton(self, 'tick')
585 self.subwidget_list['cross'] = _dummyButton(self, 'cross')
586 except TypeError:
587 # unavailable when -fancy not specified
588 pass
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000589
Neal Norwitz731a9862002-12-10 02:18:49 +0000590 # align
Raymond Hettingerff41c482003-04-06 09:01:11 +0000591
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000592 def add_history(self, str):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000593 self.tk.call(self._w, 'addhistory', str)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000594
595 def append_history(self, str):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000596 self.tk.call(self._w, 'appendhistory', str)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000597
598 def insert(self, index, str):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000599 self.tk.call(self._w, 'insert', index, str)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000600
601 def pick(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000602 self.tk.call(self._w, 'pick', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000603
604class Control(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000605 """Control - An entry field with value change arrows. The user can
606 adjust the value by pressing the two arrow buttons or by entering
607 the value directly into the entry. The new value will be checked
608 against the user-defined upper and lower limits.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000609
Moshe Zadka22710822001-03-21 17:24:49 +0000610 Subwidget Class
611 --------- -----
612 incr Button
613 decr Button
614 entry Entry
615 label Label"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000616
Martin v. Löwis46874282002-12-06 10:33:45 +0000617 # FIXME: It should inherit -superclass tixLabelWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000618 def __init__ (self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000619 TixWidget.__init__(self, master, 'tixControl', ['options'], cnf, kw)
620 self.subwidget_list['incr'] = _dummyButton(self, 'incr')
621 self.subwidget_list['decr'] = _dummyButton(self, 'decr')
622 self.subwidget_list['label'] = _dummyLabel(self, 'label')
623 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000624
625 def decrement(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000626 self.tk.call(self._w, 'decr')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000627
628 def increment(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000629 self.tk.call(self._w, 'incr')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000630
631 def invoke(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000632 self.tk.call(self._w, 'invoke')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000633
634 def update(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000635 self.tk.call(self._w, 'update')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000636
637class DirList(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000638 """DirList - displays a list view of a directory, its previous
639 directories and its sub-directories. The user can choose one of
640 the directories displayed in the list or change to another directory.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000641
Moshe Zadka22710822001-03-21 17:24:49 +0000642 Subwidget Class
643 --------- -----
644 hlist HList
645 hsb Scrollbar
646 vsb Scrollbar"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000647
Martin v. Löwis46874282002-12-06 10:33:45 +0000648 # FIXME: It should inherit -superclass tixScrolledHList
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000649 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000650 TixWidget.__init__(self, master, 'tixDirList', ['options'], cnf, kw)
651 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
652 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
653 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000654
655 def chdir(self, dir):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000656 self.tk.call(self._w, 'chdir', dir)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000657
658class DirTree(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000659 """DirTree - Directory Listing in a hierarchical view.
660 Displays a tree view of a directory, its previous directories and its
661 sub-directories. The user can choose one of the directories displayed
662 in the list or change to another directory.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000663
Moshe Zadka22710822001-03-21 17:24:49 +0000664 Subwidget Class
665 --------- -----
Neal Norwitzf539bde2002-11-14 02:43:40 +0000666 hlist HList
667 hsb Scrollbar
668 vsb Scrollbar"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000669
Martin v. Löwis46874282002-12-06 10:33:45 +0000670 # FIXME: It should inherit -superclass tixScrolledHList
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000671 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000672 TixWidget.__init__(self, master, 'tixDirTree', ['options'], cnf, kw)
673 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
674 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
675 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000676
677 def chdir(self, dir):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000678 self.tk.call(self._w, 'chdir', dir)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000679
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000680class DirSelectBox(TixWidget):
681 """DirSelectBox - Motif style file select box.
682 It is generally used for
683 the user to choose a file. FileSelectBox stores the files mostly
684 recently selected into a ComboBox widget so that they can be quickly
685 selected again.
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000686
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000687 Subwidget Class
688 --------- -----
689 selection ComboBox
Neal Norwitzf539bde2002-11-14 02:43:40 +0000690 filter ComboBox
691 dirlist ScrolledListBox
692 filelist ScrolledListBox"""
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000693
694 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000695 TixWidget.__init__(self, master, 'tixDirSelectBox', ['options'], cnf, kw)
696 self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
697 self.subwidget_list['dircbx'] = _dummyFileComboBox(self, 'dircbx')
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000698
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000699class ExFileSelectBox(TixWidget):
700 """ExFileSelectBox - MS Windows style file select box.
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300701 It provides a convenient method for the user to select files.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000702
Moshe Zadka22710822001-03-21 17:24:49 +0000703 Subwidget Class
704 --------- -----
705 cancel Button
706 ok Button
707 hidden Checkbutton
708 types ComboBox
709 dir ComboBox
710 file ComboBox
711 dirlist ScrolledListBox
712 filelist ScrolledListBox"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000713
714 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000715 TixWidget.__init__(self, master, 'tixExFileSelectBox', ['options'], cnf, kw)
716 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
717 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
718 self.subwidget_list['hidden'] = _dummyCheckbutton(self, 'hidden')
719 self.subwidget_list['types'] = _dummyComboBox(self, 'types')
720 self.subwidget_list['dir'] = _dummyComboBox(self, 'dir')
721 self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
722 self.subwidget_list['file'] = _dummyComboBox(self, 'file')
723 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000724
725 def filter(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000726 self.tk.call(self._w, 'filter')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000727
728 def invoke(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000729 self.tk.call(self._w, 'invoke')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000730
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000731
732# Should inherit from a Dialog class
733class DirSelectDialog(TixWidget):
734 """The DirSelectDialog widget presents the directories in the file
735 system in a dialog window. The user can use this dialog window to
736 navigate through the file system to select the desired directory.
737
738 Subwidgets Class
739 ---------- -----
740 dirbox DirSelectDialog"""
741
Martin v. Löwis46874282002-12-06 10:33:45 +0000742 # FIXME: It should inherit -superclass tixDialogShell
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000743 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000744 TixWidget.__init__(self, master, 'tixDirSelectDialog',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000745 ['options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000746 self.subwidget_list['dirbox'] = _dummyDirSelectBox(self, 'dirbox')
747 # cancel and ok buttons are missing
748
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000749 def popup(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000750 self.tk.call(self._w, 'popup')
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000751
752 def popdown(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000753 self.tk.call(self._w, 'popdown')
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000754
755
756# Should inherit from a Dialog class
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000757class ExFileSelectDialog(TixWidget):
758 """ExFileSelectDialog - MS Windows style file select dialog.
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300759 It provides a convenient method for the user to select files.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000760
Moshe Zadka22710822001-03-21 17:24:49 +0000761 Subwidgets Class
762 ---------- -----
763 fsbox ExFileSelectBox"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000764
Martin v. Löwis46874282002-12-06 10:33:45 +0000765 # FIXME: It should inherit -superclass tixDialogShell
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000766 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000767 TixWidget.__init__(self, master, 'tixExFileSelectDialog',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000768 ['options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000769 self.subwidget_list['fsbox'] = _dummyExFileSelectBox(self, 'fsbox')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000770
771 def popup(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000772 self.tk.call(self._w, 'popup')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000773
774 def popdown(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000775 self.tk.call(self._w, 'popdown')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000776
777class FileSelectBox(TixWidget):
778 """ExFileSelectBox - Motif style file select box.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000779 It is generally used for
780 the user to choose a file. FileSelectBox stores the files mostly
781 recently selected into a ComboBox widget so that they can be quickly
782 selected again.
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000783
Moshe Zadka22710822001-03-21 17:24:49 +0000784 Subwidget Class
785 --------- -----
786 selection ComboBox
Neal Norwitzf539bde2002-11-14 02:43:40 +0000787 filter ComboBox
788 dirlist ScrolledListBox
789 filelist ScrolledListBox"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000790
791 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000792 TixWidget.__init__(self, master, 'tixFileSelectBox', ['options'], cnf, kw)
793 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
794 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
795 self.subwidget_list['filter'] = _dummyComboBox(self, 'filter')
796 self.subwidget_list['selection'] = _dummyComboBox(self, 'selection')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000797
Moshe Zadka22710822001-03-21 17:24:49 +0000798 def apply_filter(self): # name of subwidget is same as command
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000799 self.tk.call(self._w, 'filter')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000800
801 def invoke(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000802 self.tk.call(self._w, 'invoke')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000803
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000804# Should inherit from a Dialog class
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000805class FileSelectDialog(TixWidget):
806 """FileSelectDialog - Motif style file select dialog.
807
Moshe Zadka22710822001-03-21 17:24:49 +0000808 Subwidgets Class
809 ---------- -----
810 btns StdButtonBox
811 fsbox FileSelectBox"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000812
Martin v. Löwis46874282002-12-06 10:33:45 +0000813 # FIXME: It should inherit -superclass tixStdDialogShell
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000814 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000815 TixWidget.__init__(self, master, 'tixFileSelectDialog',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000816 ['options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000817 self.subwidget_list['btns'] = _dummyStdButtonBox(self, 'btns')
818 self.subwidget_list['fsbox'] = _dummyFileSelectBox(self, 'fsbox')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000819
820 def popup(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000821 self.tk.call(self._w, 'popup')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000822
823 def popdown(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000824 self.tk.call(self._w, 'popdown')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000825
826class FileEntry(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000827 """FileEntry - Entry field with button that invokes a FileSelectDialog.
828 The user can type in the filename manually. Alternatively, the user can
829 press the button widget that sits next to the entry, which will bring
830 up a file selection dialog.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000831
Moshe Zadka22710822001-03-21 17:24:49 +0000832 Subwidgets Class
833 ---------- -----
834 button Button
835 entry Entry"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000836
Martin v. Löwis46874282002-12-06 10:33:45 +0000837 # FIXME: It should inherit -superclass tixLabelWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000838 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000839 TixWidget.__init__(self, master, 'tixFileEntry',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000840 ['dialogtype', 'options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000841 self.subwidget_list['button'] = _dummyButton(self, 'button')
842 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000843
844 def invoke(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000845 self.tk.call(self._w, 'invoke')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000846
847 def file_dialog(self):
Martin v. Löwis46874282002-12-06 10:33:45 +0000848 # FIXME: return python object
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000849 pass
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000850
Guilherme Polo1fff0082009-08-14 15:05:30 +0000851class HList(TixWidget, XView, YView):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000852 """HList - Hierarchy display widget can be used to display any data
853 that have a hierarchical structure, for example, file system directory
854 trees. The list entries are indented and connected by branch lines
Ezio Melotti13925002011-03-16 11:05:33 +0200855 according to their places in the hierarchy.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000856
857 Subwidgets - None"""
858
859 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000860 TixWidget.__init__(self, master, 'tixHList',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000861 ['columns', 'options'], cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000862
863 def add(self, entry, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +0000864 return self.tk.call(self._w, 'add', entry, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000865
866 def add_child(self, parent=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000867 if not parent:
868 parent = ''
Raymond Hettingerff41c482003-04-06 09:01:11 +0000869 return self.tk.call(
870 self._w, 'addchild', parent, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000871
872 def anchor_set(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000873 self.tk.call(self._w, 'anchor', 'set', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000874
875 def anchor_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000876 self.tk.call(self._w, 'anchor', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000877
878 def column_width(self, col=0, width=None, chars=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000879 if not chars:
880 return self.tk.call(self._w, 'column', 'width', col, width)
881 else:
882 return self.tk.call(self._w, 'column', 'width', col,
Neal Norwitzf539bde2002-11-14 02:43:40 +0000883 '-char', chars)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000884
885 def delete_all(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000886 self.tk.call(self._w, 'delete', 'all')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000887
888 def delete_entry(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000889 self.tk.call(self._w, 'delete', 'entry', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000890
891 def delete_offsprings(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000892 self.tk.call(self._w, 'delete', 'offsprings', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000893
894 def delete_siblings(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000895 self.tk.call(self._w, 'delete', 'siblings', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000896
897 def dragsite_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000898 self.tk.call(self._w, 'dragsite', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000899
900 def dragsite_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000901 self.tk.call(self._w, 'dragsite', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000902
903 def dropsite_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000904 self.tk.call(self._w, 'dropsite', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000905
906 def dropsite_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000907 self.tk.call(self._w, 'dropsite', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000908
909 def header_create(self, col, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +0000910 self.tk.call(self._w, 'header', 'create', col, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000911
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000912 def header_configure(self, col, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000913 if cnf is None:
Serhiy Storchaka848972c2013-12-25 16:35:38 +0200914 return self._getconfigure(self._w, 'header', 'configure', col)
Raymond Hettingerff41c482003-04-06 09:01:11 +0000915 self.tk.call(self._w, 'header', 'configure', col,
916 *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000917
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000918 def header_cget(self, col, opt):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000919 return self.tk.call(self._w, 'header', 'cget', col, opt)
920
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000921 def header_exists(self, col):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000922 return self.tk.call(self._w, 'header', 'exists', col)
923
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000924 def header_delete(self, col):
Moshe Zadka22710822001-03-21 17:24:49 +0000925 self.tk.call(self._w, 'header', 'delete', col)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000926
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000927 def header_size(self, col):
Moshe Zadka22710822001-03-21 17:24:49 +0000928 return self.tk.call(self._w, 'header', 'size', col)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000929
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000930 def hide_entry(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000931 self.tk.call(self._w, 'hide', 'entry', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000932
933 def indicator_create(self, entry, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +0000934 self.tk.call(
935 self._w, 'indicator', 'create', entry, *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 indicator_configure(self, entry, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000938 if cnf is None:
Serhiy Storchaka848972c2013-12-25 16:35:38 +0200939 return self._getconfigure(
940 self._w, 'indicator', 'configure', entry)
Raymond Hettingerff41c482003-04-06 09:01:11 +0000941 self.tk.call(
942 self._w, 'indicator', 'configure', entry, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000943
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000944 def indicator_cget(self, entry, opt):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000945 return self.tk.call(self._w, 'indicator', 'cget', entry, opt)
946
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000947 def indicator_exists(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000948 return self.tk.call (self._w, 'indicator', 'exists', entry)
949
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000950 def indicator_delete(self, entry):
Moshe Zadka22710822001-03-21 17:24:49 +0000951 self.tk.call(self._w, 'indicator', 'delete', entry)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000952
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000953 def indicator_size(self, entry):
Moshe Zadka22710822001-03-21 17:24:49 +0000954 return self.tk.call(self._w, 'indicator', 'size', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000955
956 def info_anchor(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000957 return self.tk.call(self._w, 'info', 'anchor')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000958
Guilherme Polobcd03df2009-08-18 15:35:57 +0000959 def info_bbox(self, entry):
960 return self._getints(
961 self.tk.call(self._w, 'info', 'bbox', entry)) or None
962
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000963 def info_children(self, entry=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000964 c = self.tk.call(self._w, 'info', 'children', entry)
965 return self.tk.splitlist(c)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000966
967 def info_data(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000968 return self.tk.call(self._w, 'info', 'data', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000969
Guilherme Polobcd03df2009-08-18 15:35:57 +0000970 def info_dragsite(self):
971 return self.tk.call(self._w, 'info', 'dragsite')
972
973 def info_dropsite(self):
974 return self.tk.call(self._w, 'info', 'dropsite')
975
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000976 def info_exists(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000977 return self.tk.call(self._w, 'info', 'exists', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000978
979 def info_hidden(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000980 return self.tk.call(self._w, 'info', 'hidden', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000981
982 def info_next(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000983 return self.tk.call(self._w, 'info', 'next', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000984
985 def info_parent(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000986 return self.tk.call(self._w, 'info', 'parent', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000987
988 def info_prev(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000989 return self.tk.call(self._w, 'info', 'prev', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000990
991 def info_selection(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000992 c = self.tk.call(self._w, 'info', 'selection')
993 return self.tk.splitlist(c)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000994
Martin v. Löwis3e048482001-10-09 11:50:55 +0000995 def item_cget(self, entry, col, opt):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000996 return self.tk.call(self._w, 'item', 'cget', entry, col, opt)
997
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000998 def item_configure(self, entry, col, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000999 if cnf is None:
Serhiy Storchaka848972c2013-12-25 16:35:38 +02001000 return self._getconfigure(self._w, 'item', 'configure', entry, col)
Raymond Hettingerff41c482003-04-06 09:01:11 +00001001 self.tk.call(self._w, 'item', 'configure', entry, col,
1002 *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001003
1004 def item_create(self, entry, col, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001005 self.tk.call(
1006 self._w, 'item', 'create', entry, col, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001007
1008 def item_exists(self, entry, col):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001009 return self.tk.call(self._w, 'item', 'exists', entry, col)
1010
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001011 def item_delete(self, entry, col):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001012 self.tk.call(self._w, 'item', 'delete', entry, col)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001013
Martin v. Löwis433fa692004-03-21 15:26:44 +00001014 def entrycget(self, entry, opt):
1015 return self.tk.call(self._w, 'entrycget', entry, opt)
1016
1017 def entryconfigure(self, entry, cnf={}, **kw):
1018 if cnf is None:
Serhiy Storchaka848972c2013-12-25 16:35:38 +02001019 return self._getconfigure(self._w, 'entryconfigure', entry)
Martin v. Löwis433fa692004-03-21 15:26:44 +00001020 self.tk.call(self._w, 'entryconfigure', entry,
1021 *self._options(cnf, kw))
1022
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001023 def nearest(self, y):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001024 return self.tk.call(self._w, 'nearest', y)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001025
1026 def see(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001027 self.tk.call(self._w, 'see', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001028
1029 def selection_clear(self, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001030 self.tk.call(self._w, 'selection', 'clear', *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001031
1032 def selection_includes(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001033 return self.tk.call(self._w, 'selection', 'includes', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001034
1035 def selection_set(self, first, last=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001036 self.tk.call(self._w, 'selection', 'set', first, last)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001037
1038 def show_entry(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001039 return self.tk.call(self._w, 'show', 'entry', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001040
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001041class InputOnly(TixWidget):
Martin v. Löwis46874282002-12-06 10:33:45 +00001042 """InputOnly - Invisible widget. Unix only.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001043
1044 Subwidgets - None"""
1045
1046 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001047 TixWidget.__init__(self, master, 'tixInputOnly', None, cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001048
1049class LabelEntry(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001050 """LabelEntry - Entry field with label. Packages an entry widget
Martin Pantera90a4a92016-05-30 04:04:50 +00001051 and a label into one mega widget. It can be used to simplify the creation
1052 of ``entry-form'' type of interface.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001053
Moshe Zadka22710822001-03-21 17:24:49 +00001054 Subwidgets Class
1055 ---------- -----
1056 label Label
1057 entry Entry"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001058
1059 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001060 TixWidget.__init__(self, master, 'tixLabelEntry',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001061 ['labelside','options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001062 self.subwidget_list['label'] = _dummyLabel(self, 'label')
1063 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001064
1065class LabelFrame(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001066 """LabelFrame - Labelled Frame container. Packages a frame widget
1067 and a label into one mega widget. To create widgets inside a
1068 LabelFrame widget, one creates the new widgets relative to the
1069 frame subwidget and manage them inside the frame subwidget.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001070
Moshe Zadka22710822001-03-21 17:24:49 +00001071 Subwidgets Class
1072 ---------- -----
1073 label Label
1074 frame Frame"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001075
1076 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001077 TixWidget.__init__(self, master, 'tixLabelFrame',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001078 ['labelside','options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001079 self.subwidget_list['label'] = _dummyLabel(self, 'label')
1080 self.subwidget_list['frame'] = _dummyFrame(self, 'frame')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001081
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001082
1083class ListNoteBook(TixWidget):
1084 """A ListNoteBook widget is very similar to the TixNoteBook widget:
1085 it can be used to display many windows in a limited space using a
1086 notebook metaphor. The notebook is divided into a stack of pages
1087 (windows). At one time only one of these pages can be shown.
1088 The user can navigate through these pages by
1089 choosing the name of the desired page in the hlist subwidget."""
1090
1091 def __init__(self, master, cnf={}, **kw):
Neal Norwitzf539bde2002-11-14 02:43:40 +00001092 TixWidget.__init__(self, master, 'tixListNoteBook', ['options'], cnf, kw)
1093 # Is this necessary? It's not an exposed subwidget in Tix.
1094 self.subwidget_list['pane'] = _dummyPanedWindow(self, 'pane',
1095 destroy_physically=0)
1096 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1097 self.subwidget_list['shlist'] = _dummyScrolledHList(self, 'shlist')
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001098
1099 def add(self, name, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001100 self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001101 self.subwidget_list[name] = TixSubWidget(self, name)
1102 return self.subwidget_list[name]
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001103
Martin v. Löwis01824bf2002-09-19 08:12:55 +00001104 def page(self, name):
Tim Peters182b5ac2004-07-18 06:16:08 +00001105 return self.subwidget(name)
Martin v. Löwis01824bf2002-09-19 08:12:55 +00001106
1107 def pages(self):
Tim Peters182b5ac2004-07-18 06:16:08 +00001108 # Can't call subwidgets_all directly because we don't want .nbframe
Serhiy Storchaka6bc87b42016-06-26 00:09:19 +03001109 names = self.tk.splitlist(self.tk.call(self._w, 'pages'))
Tim Peters182b5ac2004-07-18 06:16:08 +00001110 ret = []
1111 for x in names:
1112 ret.append(self.subwidget(x))
1113 return ret
Martin v. Löwis01824bf2002-09-19 08:12:55 +00001114
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001115 def raise_page(self, name): # raise is a python keyword
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001116 self.tk.call(self._w, 'raise', name)
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001117
1118class Meter(TixWidget):
1119 """The Meter widget can be used to show the progress of a background
1120 job which may take a long time to execute.
1121 """
1122
1123 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001124 TixWidget.__init__(self, master, 'tixMeter',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001125 ['options'], cnf, kw)
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001126
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001127class NoteBook(TixWidget):
1128 """NoteBook - Multi-page container widget (tabbed notebook metaphor).
1129
Moshe Zadka22710822001-03-21 17:24:49 +00001130 Subwidgets Class
1131 ---------- -----
1132 nbframe NoteBookFrame
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001133 <pages> page widgets added dynamically with the add method"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001134
1135 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001136 TixWidget.__init__(self,master,'tixNoteBook', ['options'], cnf, kw)
1137 self.subwidget_list['nbframe'] = TixSubWidget(self, 'nbframe',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001138 destroy_physically=0)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001139
1140 def add(self, name, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001141 self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001142 self.subwidget_list[name] = TixSubWidget(self, name)
1143 return self.subwidget_list[name]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001144
1145 def delete(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001146 self.tk.call(self._w, 'delete', name)
1147 self.subwidget_list[name].destroy()
1148 del self.subwidget_list[name]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001149
1150 def page(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001151 return self.subwidget(name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001152
1153 def pages(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001154 # Can't call subwidgets_all directly because we don't want .nbframe
Serhiy Storchaka6bc87b42016-06-26 00:09:19 +03001155 names = self.tk.splitlist(self.tk.call(self._w, 'pages'))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001156 ret = []
1157 for x in names:
1158 ret.append(self.subwidget(x))
1159 return ret
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001160
Moshe Zadka22710822001-03-21 17:24:49 +00001161 def raise_page(self, name): # raise is a python keyword
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001162 self.tk.call(self._w, 'raise', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001163
1164 def raised(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001165 return self.tk.call(self._w, 'raised')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001166
1167class NoteBookFrame(TixWidget):
Martin v. Löwis46874282002-12-06 10:33:45 +00001168 # FIXME: This is dangerous to expose to be called on its own.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001169 pass
1170
1171class OptionMenu(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001172 """OptionMenu - creates a menu button of options.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001173
Moshe Zadka22710822001-03-21 17:24:49 +00001174 Subwidget Class
1175 --------- -----
Neal Norwitzf539bde2002-11-14 02:43:40 +00001176 menubutton Menubutton
1177 menu Menu"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001178
1179 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001180 TixWidget.__init__(self, master, 'tixOptionMenu', ['options'], cnf, kw)
1181 self.subwidget_list['menubutton'] = _dummyMenubutton(self, 'menubutton')
1182 self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001183
1184 def add_command(self, name, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001185 self.tk.call(self._w, 'add', 'command', name, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001186
1187 def add_separator(self, name, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001188 self.tk.call(self._w, 'add', 'separator', name, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001189
1190 def delete(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001191 self.tk.call(self._w, 'delete', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001192
1193 def disable(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001194 self.tk.call(self._w, 'disable', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001195
1196 def enable(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001197 self.tk.call(self._w, 'enable', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001198
1199class PanedWindow(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001200 """PanedWindow - Multi-pane container widget
1201 allows the user to interactively manipulate the sizes of several
1202 panes. The panes can be arranged either vertically or horizontally.The
1203 user changes the sizes of the panes by dragging the resize handle
1204 between two panes.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001205
Moshe Zadka22710822001-03-21 17:24:49 +00001206 Subwidgets Class
1207 ---------- -----
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001208 <panes> g/p widgets added dynamically with the add method."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001209
1210 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001211 TixWidget.__init__(self, master, 'tixPanedWindow', ['orientation', 'options'], cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001212
Neal Norwitzf539bde2002-11-14 02:43:40 +00001213 # add delete forget panecget paneconfigure panes setsize
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001214 def add(self, name, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001215 self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001216 self.subwidget_list[name] = TixSubWidget(self, name,
Neal Norwitzf539bde2002-11-14 02:43:40 +00001217 check_intermediate=0)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001218 return self.subwidget_list[name]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001219
Neal Norwitzf539bde2002-11-14 02:43:40 +00001220 def delete(self, name):
1221 self.tk.call(self._w, 'delete', name)
1222 self.subwidget_list[name].destroy()
1223 del self.subwidget_list[name]
1224
1225 def forget(self, name):
1226 self.tk.call(self._w, 'forget', name)
1227
1228 def panecget(self, entry, opt):
1229 return self.tk.call(self._w, 'panecget', entry, opt)
1230
1231 def paneconfigure(self, entry, cnf={}, **kw):
1232 if cnf is None:
Serhiy Storchaka848972c2013-12-25 16:35:38 +02001233 return self._getconfigure(self._w, 'paneconfigure', entry)
Raymond Hettingerff41c482003-04-06 09:01:11 +00001234 self.tk.call(self._w, 'paneconfigure', entry, *self._options(cnf, kw))
Neal Norwitzf539bde2002-11-14 02:43:40 +00001235
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001236 def panes(self):
Guilherme Polobcd03df2009-08-18 15:35:57 +00001237 names = self.tk.splitlist(self.tk.call(self._w, 'panes'))
1238 return [self.subwidget(x) for x in names]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001239
1240class PopupMenu(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001241 """PopupMenu widget can be used as a replacement of the tk_popup command.
1242 The advantage of the Tix PopupMenu widget is it requires less application
1243 code to manipulate.
1244
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001245
Moshe Zadka22710822001-03-21 17:24:49 +00001246 Subwidgets Class
1247 ---------- -----
1248 menubutton Menubutton
1249 menu Menu"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001250
Martin v. Löwis46874282002-12-06 10:33:45 +00001251 # FIXME: It should inherit -superclass tixShell
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001252 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001253 TixWidget.__init__(self, master, 'tixPopupMenu', ['options'], cnf, kw)
1254 self.subwidget_list['menubutton'] = _dummyMenubutton(self, 'menubutton')
1255 self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001256
1257 def bind_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001258 self.tk.call(self._w, 'bind', widget._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001259
1260 def unbind_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001261 self.tk.call(self._w, 'unbind', widget._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001262
1263 def post_widget(self, widget, x, y):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001264 self.tk.call(self._w, 'post', widget._w, x, y)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001265
1266class ResizeHandle(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001267 """Internal widget to draw resize handles on Scrolled widgets."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001268 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001269 # There seems to be a Tix bug rejecting the configure method
1270 # Let's try making the flags -static
1271 flags = ['options', 'command', 'cursorfg', 'cursorbg',
1272 'handlesize', 'hintcolor', 'hintwidth',
1273 'x', 'y']
1274 # In fact, x y height width are configurable
1275 TixWidget.__init__(self, master, 'tixResizeHandle',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001276 flags, cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001277
1278 def attach_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001279 self.tk.call(self._w, 'attachwidget', widget._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001280
Martin v. Löwis652e1912001-11-25 14:50:56 +00001281 def detach_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001282 self.tk.call(self._w, 'detachwidget', widget._w)
Martin v. Löwis652e1912001-11-25 14:50:56 +00001283
1284 def hide(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001285 self.tk.call(self._w, 'hide', widget._w)
Martin v. Löwis652e1912001-11-25 14:50:56 +00001286
1287 def show(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001288 self.tk.call(self._w, 'show', widget._w)
Martin v. Löwis652e1912001-11-25 14:50:56 +00001289
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001290class ScrolledHList(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001291 """ScrolledHList - HList with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001292
Martin v. Löwis46874282002-12-06 10:33:45 +00001293 # FIXME: It should inherit -superclass tixScrolledWidget
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 TixWidget.__init__(self, master, 'tixScrolledHList', ['options'],
Neal Norwitzf539bde2002-11-14 02:43:40 +00001296 cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001297 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1298 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1299 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001300
1301class ScrolledListBox(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001302 """ScrolledListBox - Listbox with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001303
Martin v. Löwis46874282002-12-06 10:33:45 +00001304 # FIXME: It should inherit -superclass tixScrolledWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001305 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001306 TixWidget.__init__(self, master, 'tixScrolledListBox', ['options'], cnf, kw)
1307 self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox')
1308 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1309 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001310
1311class ScrolledText(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001312 """ScrolledText - Text with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001313
Martin v. Löwis46874282002-12-06 10:33:45 +00001314 # FIXME: It should inherit -superclass tixScrolledWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001315 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001316 TixWidget.__init__(self, master, 'tixScrolledText', ['options'], cnf, kw)
1317 self.subwidget_list['text'] = _dummyText(self, 'text')
1318 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1319 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001320
1321class ScrolledTList(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001322 """ScrolledTList - TList with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001323
Martin v. Löwis46874282002-12-06 10:33:45 +00001324 # FIXME: It should inherit -superclass tixScrolledWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001325 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001326 TixWidget.__init__(self, master, 'tixScrolledTList', ['options'],
Neal Norwitzf539bde2002-11-14 02:43:40 +00001327 cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001328 self.subwidget_list['tlist'] = _dummyTList(self, 'tlist')
1329 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1330 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001331
1332class ScrolledWindow(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001333 """ScrolledWindow - Window with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001334
Martin v. Löwis46874282002-12-06 10:33:45 +00001335 # FIXME: It should inherit -superclass tixScrolledWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001336 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001337 TixWidget.__init__(self, master, 'tixScrolledWindow', ['options'], cnf, kw)
1338 self.subwidget_list['window'] = _dummyFrame(self, 'window')
1339 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1340 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001341
1342class Select(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001343 """Select - Container of button subwidgets. It can be used to provide
1344 radio-box or check-box style of selection options for the user.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001345
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001346 Subwidgets are buttons added dynamically using the add method."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001347
Martin v. Löwis46874282002-12-06 10:33:45 +00001348 # FIXME: It should inherit -superclass tixLabelWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001349 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001350 TixWidget.__init__(self, master, 'tixSelect',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001351 ['allowzero', 'radio', 'orientation', 'labelside',
1352 'options'],
1353 cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001354 self.subwidget_list['label'] = _dummyLabel(self, 'label')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001355
1356 def add(self, name, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001357 self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001358 self.subwidget_list[name] = _dummyButton(self, name)
1359 return self.subwidget_list[name]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001360
1361 def invoke(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001362 self.tk.call(self._w, 'invoke', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001363
Neal Norwitzf539bde2002-11-14 02:43:40 +00001364class Shell(TixWidget):
1365 """Toplevel window.
1366
1367 Subwidgets - None"""
1368
1369 def __init__ (self,master=None,cnf={}, **kw):
1370 TixWidget.__init__(self, master, 'tixShell', ['options', 'title'], cnf, kw)
1371
1372class DialogShell(TixWidget):
1373 """Toplevel window, with popup popdown and center methods.
1374 It tells the window manager that it is a dialog window and should be
1375 treated specially. The exact treatment depends on the treatment of
1376 the window manager.
1377
1378 Subwidgets - None"""
1379
Martin v. Löwis46874282002-12-06 10:33:45 +00001380 # FIXME: It should inherit from Shell
Neal Norwitzf539bde2002-11-14 02:43:40 +00001381 def __init__ (self,master=None,cnf={}, **kw):
1382 TixWidget.__init__(self, master,
1383 'tixDialogShell',
1384 ['options', 'title', 'mapped',
1385 'minheight', 'minwidth',
1386 'parent', 'transient'], cnf, kw)
1387
1388 def popdown(self):
1389 self.tk.call(self._w, 'popdown')
1390
1391 def popup(self):
1392 self.tk.call(self._w, 'popup')
1393
1394 def center(self):
1395 self.tk.call(self._w, 'center')
1396
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001397class StdButtonBox(TixWidget):
1398 """StdButtonBox - Standard Button Box (OK, Apply, Cancel and Help) """
1399
1400 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001401 TixWidget.__init__(self, master, 'tixStdButtonBox',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001402 ['orientation', 'options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001403 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1404 self.subwidget_list['apply'] = _dummyButton(self, 'apply')
1405 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1406 self.subwidget_list['help'] = _dummyButton(self, 'help')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001407
1408 def invoke(self, name):
Guido van Rossume014a132006-08-19 16:53:45 +00001409 if name in self.subwidget_list:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001410 self.tk.call(self._w, 'invoke', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001411
Guilherme Polo1fff0082009-08-14 15:05:30 +00001412class TList(TixWidget, XView, YView):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001413 """TList - Hierarchy display widget which can be
1414 used to display data in a tabular format. The list entries of a TList
1415 widget are similar to the entries in the Tk listbox widget. The main
1416 differences are (1) the TList widget can display the list entries in a
1417 two dimensional format and (2) you can use graphical images as well as
1418 multiple colors and fonts for the list entries.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001419
1420 Subwidgets - None"""
1421
1422 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001423 TixWidget.__init__(self, master, 'tixTList', ['options'], cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001424
1425 def active_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001426 self.tk.call(self._w, 'active', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001427
1428 def active_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001429 self.tk.call(self._w, 'active', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001430
1431 def anchor_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001432 self.tk.call(self._w, 'anchor', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001433
1434 def anchor_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001435 self.tk.call(self._w, 'anchor', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001436
1437 def delete(self, from_, to=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001438 self.tk.call(self._w, 'delete', from_, to)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001439
1440 def dragsite_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001441 self.tk.call(self._w, 'dragsite', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001442
1443 def dragsite_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001444 self.tk.call(self._w, 'dragsite', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001445
1446 def dropsite_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001447 self.tk.call(self._w, 'dropsite', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001448
1449 def dropsite_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001450 self.tk.call(self._w, 'dropsite', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001451
1452 def insert(self, index, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001453 self.tk.call(self._w, 'insert', index, *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001454
1455 def info_active(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001456 return self.tk.call(self._w, 'info', 'active')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001457
1458 def info_anchor(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001459 return self.tk.call(self._w, 'info', 'anchor')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001460
1461 def info_down(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001462 return self.tk.call(self._w, 'info', 'down', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001463
1464 def info_left(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001465 return self.tk.call(self._w, 'info', 'left', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001466
1467 def info_right(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001468 return self.tk.call(self._w, 'info', 'right', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001469
1470 def info_selection(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001471 c = self.tk.call(self._w, 'info', 'selection')
1472 return self.tk.splitlist(c)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001473
1474 def info_size(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001475 return self.tk.call(self._w, 'info', 'size')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001476
1477 def info_up(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001478 return self.tk.call(self._w, 'info', 'up', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001479
1480 def nearest(self, x, y):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001481 return self.tk.call(self._w, 'nearest', x, y)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001482
1483 def see(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001484 self.tk.call(self._w, 'see', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001485
1486 def selection_clear(self, cnf={}, **kw):
Raymond Hettingerff41c482003-04-06 09:01:11 +00001487 self.tk.call(self._w, 'selection', 'clear', *self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001488
1489 def selection_includes(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001490 return self.tk.call(self._w, 'selection', 'includes', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001491
1492 def selection_set(self, first, last=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001493 self.tk.call(self._w, 'selection', 'set', first, last)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001494
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001495class Tree(TixWidget):
Ezio Melotti13925002011-03-16 11:05:33 +02001496 """Tree - The tixTree widget can be used to display hierarchical
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001497 data in a tree form. The user can adjust
1498 the view of the tree by opening or closing parts of the tree."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001499
Martin v. Löwis46874282002-12-06 10:33:45 +00001500 # FIXME: It should inherit -superclass tixScrolledWidget
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001501 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001502 TixWidget.__init__(self, master, 'tixTree',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001503 ['options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001504 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1505 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1506 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001507
1508 def autosetmode(self):
Martin v. Löwis46874282002-12-06 10:33:45 +00001509 '''This command calls the setmode method for all the entries in this
1510 Tree widget: if an entry has no child entries, its mode is set to
1511 none. Otherwise, if the entry has any hidden child entries, its mode is
1512 set to open; otherwise its mode is set to close.'''
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001513 self.tk.call(self._w, 'autosetmode')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001514
1515 def close(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001516 '''Close the entry given by entryPath if its mode is close.'''
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001517 self.tk.call(self._w, 'close', entrypath)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001518
1519 def getmode(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001520 '''Returns the current mode of the entry given by entryPath.'''
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001521 return self.tk.call(self._w, 'getmode', entrypath)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001522
1523 def open(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001524 '''Open the entry given by entryPath if its mode is open.'''
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001525 self.tk.call(self._w, 'open', entrypath)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001526
1527 def setmode(self, entrypath, mode='none'):
Martin v. Löwis46874282002-12-06 10:33:45 +00001528 '''This command is used to indicate whether the entry given by
1529 entryPath has children entries and whether the children are visible. mode
1530 must be one of open, close or none. If mode is set to open, a (+)
Ezio Melottie130a522011-10-19 10:58:56 +03001531 indicator is drawn next the entry. If mode is set to close, a (-)
1532 indicator is drawn next the entry. If mode is set to none, no
Martin v. Löwis46874282002-12-06 10:33:45 +00001533 indicators will be drawn for this entry. The default mode is none. The
1534 open mode indicates the entry has hidden children and this entry can be
1535 opened by the user. The close mode indicates that all the children of the
1536 entry are now visible and the entry can be closed by the user.'''
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001537 self.tk.call(self._w, 'setmode', entrypath, mode)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001538
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001539
1540# Could try subclassing Tree for CheckList - would need another arg to init
1541class CheckList(TixWidget):
1542 """The CheckList widget
1543 displays a list of items to be selected by the user. CheckList acts
1544 similarly to the Tk checkbutton or radiobutton widgets, except it is
1545 capable of handling many more items than checkbuttons or radiobuttons.
1546 """
Martin v. Löwis46874282002-12-06 10:33:45 +00001547 # FIXME: It should inherit -superclass tixTree
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001548 def __init__(self, master=None, cnf={}, **kw):
1549 TixWidget.__init__(self, master, 'tixCheckList',
Guilherme Polobcd03df2009-08-18 15:35:57 +00001550 ['options', 'radio'], cnf, kw)
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001551 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1552 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1553 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001554
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001555 def autosetmode(self):
Martin v. Löwis46874282002-12-06 10:33:45 +00001556 '''This command calls the setmode method for all the entries in this
1557 Tree widget: if an entry has no child entries, its mode is set to
1558 none. Otherwise, if the entry has any hidden child entries, its mode is
1559 set to open; otherwise its mode is set to close.'''
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001560 self.tk.call(self._w, 'autosetmode')
1561
1562 def close(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001563 '''Close the entry given by entryPath if its mode is close.'''
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001564 self.tk.call(self._w, 'close', entrypath)
1565
1566 def getmode(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001567 '''Returns the current mode of the entry given by entryPath.'''
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001568 return self.tk.call(self._w, 'getmode', entrypath)
1569
1570 def open(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001571 '''Open the entry given by entryPath if its mode is open.'''
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001572 self.tk.call(self._w, 'open', entrypath)
1573
1574 def getselection(self, mode='on'):
Martin v. Löwis46874282002-12-06 10:33:45 +00001575 '''Returns a list of items whose status matches status. If status is
1576 not specified, the list of items in the "on" status will be returned.
1577 Mode can be on, off, default'''
Serhiy Storchaka6bc87b42016-06-26 00:09:19 +03001578 return self.tk.splitlist(self.tk.call(self._w, 'getselection', mode))
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001579
1580 def getstatus(self, entrypath):
Martin v. Löwis46874282002-12-06 10:33:45 +00001581 '''Returns the current status of entryPath.'''
1582 return self.tk.call(self._w, 'getstatus', entrypath)
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001583
1584 def setstatus(self, entrypath, mode='on'):
Martin v. Löwis46874282002-12-06 10:33:45 +00001585 '''Sets the status of entryPath to be status. A bitmap will be
1586 displayed next to the entry its status is on, off or default.'''
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001587 self.tk.call(self._w, 'setstatus', entrypath, mode)
1588
1589
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001590###########################################################################
1591### The subclassing below is used to instantiate the subwidgets in each ###
1592### mega widget. This allows us to access their methods directly. ###
1593###########################################################################
1594
1595class _dummyButton(Button, TixSubWidget):
1596 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001597 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001598
1599class _dummyCheckbutton(Checkbutton, TixSubWidget):
1600 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001601 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001602
1603class _dummyEntry(Entry, TixSubWidget):
1604 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001605 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001606
1607class _dummyFrame(Frame, TixSubWidget):
1608 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001609 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001610
1611class _dummyLabel(Label, TixSubWidget):
1612 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001613 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001614
1615class _dummyListbox(Listbox, TixSubWidget):
1616 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001617 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001618
1619class _dummyMenu(Menu, TixSubWidget):
1620 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001621 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001622
1623class _dummyMenubutton(Menubutton, TixSubWidget):
1624 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001625 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001626
1627class _dummyScrollbar(Scrollbar, TixSubWidget):
1628 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001629 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001630
1631class _dummyText(Text, TixSubWidget):
1632 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001633 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001634
1635class _dummyScrolledListBox(ScrolledListBox, TixSubWidget):
1636 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001637 TixSubWidget.__init__(self, master, name, destroy_physically)
1638 self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox')
1639 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1640 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001641
1642class _dummyHList(HList, 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
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001646class _dummyScrolledHList(ScrolledHList, 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)
1649 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1650 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1651 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001652
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001653class _dummyTList(TList, TixSubWidget):
1654 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001655 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001656
1657class _dummyComboBox(ComboBox, TixSubWidget):
1658 def __init__(self, master, name, destroy_physically=1):
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001659 TixSubWidget.__init__(self, master, name, ['fancy',destroy_physically])
1660 self.subwidget_list['label'] = _dummyLabel(self, 'label')
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001661 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
1662 self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001663
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001664 self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001665 'slistbox')
1666 try:
1667 self.subwidget_list['tick'] = _dummyButton(self, 'tick')
1668 #cross Button : present if created with the fancy option
1669 self.subwidget_list['cross'] = _dummyButton(self, 'cross')
1670 except TypeError:
1671 # unavailable when -fancy not specified
1672 pass
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001673
1674class _dummyDirList(DirList, TixSubWidget):
1675 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001676 TixSubWidget.__init__(self, master, name, destroy_physically)
1677 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1678 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1679 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001680
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001681class _dummyDirSelectBox(DirSelectBox, TixSubWidget):
1682 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001683 TixSubWidget.__init__(self, master, name, destroy_physically)
1684 self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
1685 self.subwidget_list['dircbx'] = _dummyFileComboBox(self, 'dircbx')
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001686
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001687class _dummyExFileSelectBox(ExFileSelectBox, TixSubWidget):
1688 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001689 TixSubWidget.__init__(self, master, name, destroy_physically)
1690 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1691 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1692 self.subwidget_list['hidden'] = _dummyCheckbutton(self, 'hidden')
1693 self.subwidget_list['types'] = _dummyComboBox(self, 'types')
1694 self.subwidget_list['dir'] = _dummyComboBox(self, 'dir')
1695 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
1696 self.subwidget_list['file'] = _dummyComboBox(self, 'file')
1697 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001698
1699class _dummyFileSelectBox(FileSelectBox, TixSubWidget):
1700 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001701 TixSubWidget.__init__(self, master, name, destroy_physically)
1702 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
1703 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
1704 self.subwidget_list['filter'] = _dummyComboBox(self, 'filter')
1705 self.subwidget_list['selection'] = _dummyComboBox(self, 'selection')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001706
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001707class _dummyFileComboBox(ComboBox, TixSubWidget):
1708 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001709 TixSubWidget.__init__(self, master, name, destroy_physically)
1710 self.subwidget_list['dircbx'] = _dummyComboBox(self, 'dircbx')
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001711
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001712class _dummyStdButtonBox(StdButtonBox, TixSubWidget):
1713 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001714 TixSubWidget.__init__(self, master, name, destroy_physically)
1715 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1716 self.subwidget_list['apply'] = _dummyButton(self, 'apply')
1717 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1718 self.subwidget_list['help'] = _dummyButton(self, 'help')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001719
1720class _dummyNoteBookFrame(NoteBookFrame, TixSubWidget):
1721 def __init__(self, master, name, destroy_physically=0):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001722 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001723
Martin v. Löwis01824bf2002-09-19 08:12:55 +00001724class _dummyPanedWindow(PanedWindow, TixSubWidget):
1725 def __init__(self, master, name, destroy_physically=1):
Tim Peters182b5ac2004-07-18 06:16:08 +00001726 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwis01824bf2002-09-19 08:12:55 +00001727
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001728########################
1729### Utility Routines ###
1730########################
1731
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001732#mike Should tixDestroy be exposed as a wrapper? - but not for widgets.
1733
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001734def OptionName(widget):
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001735 '''Returns the qualified path name for the widget. Normally used to set
1736 default options for subwidgets. See tixwidgets.py'''
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001737 return widget.tk.call('tixOptionName', widget._w)
1738
1739# Called with a dictionary argument of the form
1740# {'*.c':'C source files', '*.txt':'Text Files', '*':'All files'}
1741# returns a string which can be used to configure the fsbox file types
1742# in an ExFileSelectBox. i.e.,
1743# '{{*} {* - All files}} {{*.c} {*.c - C source files}} {{*.txt} {*.txt - Text Files}}'
1744def FileTypeList(dict):
1745 s = ''
1746 for type in dict.keys():
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001747 s = s + '{{' + type + '} {' + type + ' - ' + dict[type] + '}} '
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001748 return s
1749
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001750# Still to be done:
Martin v. Löwis46874282002-12-06 10:33:45 +00001751# tixIconView
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001752class CObjView(TixWidget):
1753 """This file implements the Canvas Object View widget. This is a base
1754 class of IconView. It implements automatic placement/adjustment of the
1755 scrollbars according to the canvas objects inside the canvas subwidget.
1756 The scrollbars are adjusted so that the canvas is just large enough
1757 to see all the objects.
1758 """
Martin v. Löwis46874282002-12-06 10:33:45 +00001759 # FIXME: It should inherit -superclass tixScrolledWidget
1760 pass
1761
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001762
Guilherme Polo1fff0082009-08-14 15:05:30 +00001763class Grid(TixWidget, XView, YView):
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001764 '''The Tix Grid command creates a new window and makes it into a
1765 tixGrid widget. Additional options, may be specified on the command
1766 line or in the option database to configure aspects such as its cursor
1767 and relief.
1768
1769 A Grid widget displays its contents in a two dimensional grid of cells.
1770 Each cell may contain one Tix display item, which may be in text,
1771 graphics or other formats. See the DisplayStyle class for more information
1772 about Tix display items. Individual cells, or groups of cells, can be
1773 formatted with a wide range of attributes, such as its color, relief and
1774 border.
1775
1776 Subwidgets - None'''
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001777 # valid specific resources as of Tk 8.4
1778 # editdonecmd, editnotifycmd, floatingcols, floatingrows, formatcmd,
1779 # highlightbackground, highlightcolor, leftmargin, itemtype, selectmode,
1780 # selectunit, topmargin,
1781 def __init__(self, master=None, cnf={}, **kw):
1782 static= []
1783 self.cnf= cnf
1784 TixWidget.__init__(self, master, 'tixGrid', static, cnf, kw)
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001785
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001786 # valid options as of Tk 8.4
Guilherme Polobcd03df2009-08-18 15:35:57 +00001787 # anchor, bdtype, cget, configure, delete, dragsite, dropsite, entrycget,
1788 # edit, entryconfigure, format, geometryinfo, info, index, move, nearest,
1789 # selection, set, size, unset, xview, yview
1790 def anchor_clear(self):
1791 """Removes the selection anchor."""
1792 self.tk.call(self, 'anchor', 'clear')
1793
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001794 def anchor_get(self):
1795 "Get the (x,y) coordinate of the current anchor cell"
1796 return self._getints(self.tk.call(self, 'anchor', 'get'))
1797
Guilherme Polobcd03df2009-08-18 15:35:57 +00001798 def anchor_set(self, x, y):
1799 """Set the selection anchor to the cell at (x, y)."""
1800 self.tk.call(self, 'anchor', 'set', x, y)
1801
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001802 def delete_row(self, from_, to=None):
1803 """Delete rows between from_ and to inclusive.
1804 If to is not provided, delete only row at from_"""
1805 if to is None:
1806 self.tk.call(self, 'delete', 'row', from_)
1807 else:
1808 self.tk.call(self, 'delete', 'row', from_, to)
Guilherme Polobcd03df2009-08-18 15:35:57 +00001809
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001810 def delete_column(self, from_, to=None):
1811 """Delete columns between from_ and to inclusive.
1812 If to is not provided, delete only column at from_"""
1813 if to is None:
1814 self.tk.call(self, 'delete', 'column', from_)
1815 else:
1816 self.tk.call(self, 'delete', 'column', from_, to)
Guilherme Polobcd03df2009-08-18 15:35:57 +00001817
1818 def edit_apply(self):
1819 """If any cell is being edited, de-highlight the cell and applies
1820 the changes."""
1821 self.tk.call(self, 'edit', 'apply')
1822
1823 def edit_set(self, x, y):
1824 """Highlights the cell at (x, y) for editing, if the -editnotify
1825 command returns True for this cell."""
1826 self.tk.call(self, 'edit', 'set', x, y)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001827
1828 def entrycget(self, x, y, option):
1829 "Get the option value for cell at (x,y)"
Guilherme Polobcd03df2009-08-18 15:35:57 +00001830 if option and option[0] != '-':
1831 option = '-' + option
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001832 return self.tk.call(self, 'entrycget', x, y, option)
1833
Guilherme Polobcd03df2009-08-18 15:35:57 +00001834 def entryconfigure(self, x, y, cnf=None, **kw):
1835 return self._configure(('entryconfigure', x, y), cnf, kw)
1836
Neal Norwitzd8b5e3f2002-12-30 23:52:01 +00001837 # def format
1838 # def index
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001839
1840 def info_exists(self, x, y):
1841 "Return True if display item exists at (x,y)"
Guilherme Polobcd03df2009-08-18 15:35:57 +00001842 return self._getboolean(self.tk.call(self, 'info', 'exists', x, y))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001843
1844 def info_bbox(self, x, y):
1845 # This seems to always return '', at least for 'text' displayitems
1846 return self.tk.call(self, 'info', 'bbox', x, y)
1847
Guilherme Polobcd03df2009-08-18 15:35:57 +00001848 def move_column(self, from_, to, offset):
Ezio Melottie130a522011-10-19 10:58:56 +03001849 """Moves the range of columns from position FROM through TO by
Guilherme Polobcd03df2009-08-18 15:35:57 +00001850 the distance indicated by OFFSET. For example, move_column(2, 4, 1)
1851 moves the columns 2,3,4 to columns 3,4,5."""
1852 self.tk.call(self, 'move', 'column', from_, to, offset)
1853
1854 def move_row(self, from_, to, offset):
Ezio Melottie130a522011-10-19 10:58:56 +03001855 """Moves the range of rows from position FROM through TO by
Guilherme Polobcd03df2009-08-18 15:35:57 +00001856 the distance indicated by OFFSET.
1857 For example, move_row(2, 4, 1) moves the rows 2,3,4 to rows 3,4,5."""
1858 self.tk.call(self, 'move', 'row', from_, to, offset)
1859
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001860 def nearest(self, x, y):
1861 "Return coordinate of cell nearest pixel coordinate (x,y)"
1862 return self._getints(self.tk.call(self, 'nearest', x, y))
1863
1864 # def selection adjust
1865 # def selection clear
1866 # def selection includes
1867 # def selection set
1868 # def selection toggle
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001869
1870 def set(self, x, y, itemtype=None, **kw):
1871 args= self._options(self.cnf, kw)
1872 if itemtype is not None:
1873 args= ('-itemtype', itemtype) + args
1874 self.tk.call(self, 'set', x, y, *args)
1875
Guilherme Polobcd03df2009-08-18 15:35:57 +00001876 def size_column(self, index, **kw):
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001877 """Queries or sets the size of the column given by
1878 INDEX. INDEX may be any non-negative
1879 integer that gives the position of a given column.
Guilherme Polobcd03df2009-08-18 15:35:57 +00001880 INDEX can also be the string "default"; in this case, this command
1881 queries or sets the default size of all columns.
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001882 When no option-value pair is given, this command returns a tuple
1883 containing the current size setting of the given column. When
1884 option-value pairs are given, the corresponding options of the
Guilherme Polobcd03df2009-08-18 15:35:57 +00001885 size setting of the given column are changed. Options may be one
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001886 of the follwing:
Guilherme Polobcd03df2009-08-18 15:35:57 +00001887 pad0 pixels
1888 Specifies the paddings to the left of a column.
1889 pad1 pixels
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001890 Specifies the paddings to the right of a column.
Guilherme Polobcd03df2009-08-18 15:35:57 +00001891 size val
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001892 Specifies the width of a column. Val may be:
1893 "auto" -- the width of the column is set to the
1894 width of the widest cell in the column;
1895 a valid Tk screen distance unit;
1896 or a real number following by the word chars
Guilherme Polobcd03df2009-08-18 15:35:57 +00001897 (e.g. 3.4chars) that sets the width of the column to the
1898 given number of characters."""
Serhiy Storchaka6bc87b42016-06-26 00:09:19 +03001899 return self.tk.splitlist(self.tk.call(self._w, 'size', 'column', index,
Guilherme Polobcd03df2009-08-18 15:35:57 +00001900 *self._options({}, kw)))
1901
1902 def size_row(self, index, **kw):
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001903 """Queries or sets the size of the row given by
1904 INDEX. INDEX may be any non-negative
1905 integer that gives the position of a given row .
Guilherme Polobcd03df2009-08-18 15:35:57 +00001906 INDEX can also be the string "default"; in this case, this command
1907 queries or sets the default size of all rows.
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001908 When no option-value pair is given, this command returns a list con-
1909 taining the current size setting of the given row . When option-value
Guilherme Polobcd03df2009-08-18 15:35:57 +00001910 pairs are given, the corresponding options of the size setting of the
1911 given row are changed. Options may be one of the follwing:
1912 pad0 pixels
1913 Specifies the paddings to the top of a row.
1914 pad1 pixels
Ezio Melottie130a522011-10-19 10:58:56 +03001915 Specifies the paddings to the bottom of a row.
Guilherme Polobcd03df2009-08-18 15:35:57 +00001916 size val
Terry Jan Reedyc30b7b12013-03-11 17:57:08 -04001917 Specifies the height of a row. Val may be:
1918 "auto" -- the height of the row is set to the
1919 height of the highest cell in the row;
1920 a valid Tk screen distance unit;
1921 or a real number following by the word chars
Guilherme Polobcd03df2009-08-18 15:35:57 +00001922 (e.g. 3.4chars) that sets the height of the row to the
1923 given number of characters."""
Serhiy Storchaka6bc87b42016-06-26 00:09:19 +03001924 return self.tk.splitlist(self.tk.call(
Guilherme Polobcd03df2009-08-18 15:35:57 +00001925 self, 'size', 'row', index, *self._options({}, kw)))
1926
1927 def unset(self, x, y):
1928 """Clears the cell at (x, y) by removing its display item."""
1929 self.tk.call(self._w, 'unset', x, y)
1930
Raymond Hettingerff41c482003-04-06 09:01:11 +00001931
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001932class ScrolledGrid(Grid):
Martin v. Löwis46874282002-12-06 10:33:45 +00001933 '''Scrolled Grid widgets'''
1934
1935 # FIXME: It should inherit -superclass tixScrolledWidget
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001936 def __init__(self, master=None, cnf={}, **kw):
1937 static= []
1938 self.cnf= cnf
1939 TixWidget.__init__(self, master, 'tixScrolledGrid', static, cnf, kw)