Tix.py 75 KB

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