# -*- mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- import Tkinter, Tix # These are missing from older Tix.py # Declare them here in case... class Shell(Tix.TixWidget): """Toplevel window. Subwidgets - None""" def __init__ (self,master=None,cnf={}, **kw): Tix.TixWidget.__init__(self, master, 'tixShell', ['options', 'title'], cnf, kw) class DialogShell(Tix.TixWidget): """Toplevel window, with popup popdown and center methods. It tells the window manager that it is a dialog window and should be treated specially. The exact treatment depends on the treatment of the window manager. Subwidgets - None""" def __init__ (self,master=None,cnf={}, **kw): Tix.TixWidget.__init__(self, master, 'tixDialogShell', ['options', 'title', 'mapped', 'minheight', 'minwidth', 'parent', 'transient'], cnf, kw) def popdown(self): self.tk.call(self._w, 'popdown') def popup(self): self.tk.call(self._w, 'popup') def center(self): self.tk.call(self._w, 'center') # make a mixin class to replace objtix_info class Info: def _gCoerce (self, retval, type): """ObjTix method and slot types are: string symbol lexeme boolean integer float number list arraylist instance widget path""" if type == 'string' or type == 'path': return retval if type == 'symbol' or type == 'lexeme': # Python doesn't have symbols return retval if type == 'boolean': return int(retval) if type == 'list': words = self.tk.splitlist(retval) l = [] for word in words: l.append(word) return l if type == 'integer': return int(retval) if type == 'float': return float(retval) if type == 'number': if '.' in retval: return float(res) return int(retval) if type == 'arraylist': dict = {} words = self.tk.splitlist(retval) for i in range(0, len(words), 2): key = words[i] value = words[i+1] dict[key] = value return dict if type == 'instance' or type == 'widget': # unsure about these - widget might be in an inverse dict return retval # might as well return retval def _methods(self): try: inst = self._w except AttributeError: inst = self._name retval = self.tk.call('objtix_info', 'methods', inst) return self._gCoerce(retval, 'list') def _slots(self): try: inst = self._w except AttributeError: inst = self._name retval = self.tk.call('objtix_info', 'slots', inst) words = self.tk.splitlist(retval) l = [] for word in words: l.append(word[1:]) return l class Misc(Tix.Misc, Info): def __repr__ (self): return "" % (self._w, self._klass) def __str__(self): return self._name def __del__ (self): if not self.__dict__.has_key('tk'): return self.tk.eval('if {[info procs %s] != ""} {rename %s ""}' % (self._name, self._name)) def cget(self, key): """Return the slot value for a KEY according to its type.""" retval = self.tk.call(self._name, 'cget', '-' + key) klass = self.tk.getvar( "%s(className)" % self._name ) type = self.tk.getvar( "%s(%s,type)" % (klass, key) ) return self._gCoerce(retval, type) __getitem__ = cget def __init__(self, master, klass, name='', cnf={}, **kw): if kw: cnf = _cnfmerge((cnf, kw)) if not name: name = klass.lower() + "#" + `id(self)` if kw: cnf = Tkinter._cnfmerge((cnf, kw)) else: cnf = Tkinter._cnfmerge(cnf) options = () for k, v in cnf.items(): options = options + ('-'+k, v) self._klass = klass self._name = self.tk.call((klass, name,) + options) class Widget(Tix.TixWidget, Info): def __repr__ (self): return "" % (self._w, self._klass) def __str__(self): return self._w def __del__ (self): if not self.__dict__.has_key('tk'): return # I'm deeply suspicious of Tkinter's destroy self.tk.eval('catch {destroy %s}' % self._w) def cget(self, key): """Return the resource value for a KEY according to its type.""" retval = self.tk.call(self._w, 'cget', '-' + key) klass = self.tk.getvar( "%s(className)" % self._w ) type = self.tk.getvar( "%s(%s,type)" % (klass, key) ) return self._gCoerce(retval, type) __getitem__ = cget def __init__(self, master, klass, static=[], cnf={}, **kw): if kw: cnf = _cnfmerge((cnf, kw)) self._klass = klass Tix.TixWidget.__init__(self, master, klass, static, cnf)