mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	Tue Jul 5 13:22:45 1994 (lumholt@login.dkuug.dk)
* Setup.in: moreButtons Tk extension support (again). * mklibapp: $1 is now the path to the Tk extension source directory. The default is /usr/local/src/tcl. * kill.py: Don't use the exec Tcl command. * Tkinter.py (Misc.bind_all): Bug fix; extra graves. (Misc.tk_strictMotif): Return the value. (mainloop, getint, getdouble, getboolean): New functions. (_cnfmerge): Flatten cnfs. Wed Jun 29 22:01:17 1994 Steen Lumholt (lumholt@login.dkuug.dk) * Tkinter.py: (Tk.destroy): master is always None; so don't del. Found by Tommy Burnette, solution from Guido van Rossum. (Misc.selection_get): Missing return. Found by Richard Neitzel. (Misc._options, Widget.config, Canvas._create): If cnf is a tuple or list then merge the contents. Suggested by Matthew Conway.
This commit is contained in:
		
							parent
							
								
									cd3c0425e1
								
							
						
					
					
						commit
						2dcf529b55
					
				
					 2 changed files with 112 additions and 62 deletions
				
			
		| 
						 | 
					@ -1,29 +1,51 @@
 | 
				
			||||||
# Tkinter.py -- Tk/Tcl widget wrappers
 | 
					# Tkinter.py -- Tk/Tcl widget wrappers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import tkinter
 | 
					import tkinter
 | 
				
			||||||
from tkinter import TclError
 | 
					from tkinter import TclError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class _Dummy:
 | 
					class _Dummy:
 | 
				
			||||||
	def meth(self):	return
 | 
						def meth(self):	return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _isfunctype(func):
 | 
					def _func():
 | 
				
			||||||
	return type(func) in CallableTypes
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FunctionType = type(_isfunctype)
 | 
					FunctionType = type(_func)
 | 
				
			||||||
ClassType = type(_Dummy)
 | 
					ClassType = type(_Dummy)
 | 
				
			||||||
MethodType = type(_Dummy.meth)
 | 
					MethodType = type(_Dummy.meth)
 | 
				
			||||||
StringType = type('')
 | 
					StringType = type('')
 | 
				
			||||||
TupleType = type(())
 | 
					TupleType = type(())
 | 
				
			||||||
ListType = type([])
 | 
					ListType = type([])
 | 
				
			||||||
 | 
					DictionaryType = type({})
 | 
				
			||||||
 | 
					NoneType = type(None)
 | 
				
			||||||
CallableTypes = (FunctionType, MethodType)
 | 
					CallableTypes = (FunctionType, MethodType)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def _flatten(tuple):
 | 
				
			||||||
 | 
						res = ()
 | 
				
			||||||
 | 
						for item in tuple:
 | 
				
			||||||
 | 
							if type(item) in (TupleType, ListType):
 | 
				
			||||||
 | 
								res = res + _flatten(item)
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
 | 
								res = res + (item,)
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def _cnfmerge(cnfs):
 | 
				
			||||||
 | 
						if type(cnfs) in (NoneType, DictionaryType, StringType):
 | 
				
			||||||
 | 
							return cnfs
 | 
				
			||||||
 | 
						else:
 | 
				
			||||||
 | 
							cnf = {}
 | 
				
			||||||
 | 
							for c in _flatten(cnfs):
 | 
				
			||||||
 | 
								for k, v in c.items():
 | 
				
			||||||
 | 
									cnf[k] = v
 | 
				
			||||||
 | 
							return cnf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Event:
 | 
				
			||||||
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_default_root = None
 | 
					_default_root = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _tkerror(err):
 | 
					def _tkerror(err):
 | 
				
			||||||
	pass
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Event:
 | 
					 | 
				
			||||||
	pass
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
_varnum = 0
 | 
					_varnum = 0
 | 
				
			||||||
class Variable:
 | 
					class Variable:
 | 
				
			||||||
	def __init__(self, master=None):
 | 
						def __init__(self, master=None):
 | 
				
			||||||
| 
						 | 
					@ -71,15 +93,27 @@ class BooleanVar(Variable):
 | 
				
			||||||
	def get(self):
 | 
						def get(self):
 | 
				
			||||||
		return self._tk.getboolean(self._tk.getvar(self._name))
 | 
							return self._tk.getboolean(self._tk.getvar(self._name))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def mainloop():
 | 
				
			||||||
 | 
						_default_root.tk.mainloop()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def getint(s):
 | 
				
			||||||
 | 
						return _default_root.tk.getint(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def getdouble(s):
 | 
				
			||||||
 | 
						return _default_root.tk.getdouble(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def getboolean(s):
 | 
				
			||||||
 | 
						return _default_root.tk.getboolean(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Misc:
 | 
					class Misc:
 | 
				
			||||||
	def tk_strictMotif(self, boolean=None):
 | 
						def tk_strictMotif(self, boolean=None):
 | 
				
			||||||
		self.tk.getboolean(self.tk.call(
 | 
							return self.tk.getboolean(self.tk.call(
 | 
				
			||||||
			'set', 'tk_strictMotif', boolean))
 | 
								'set', 'tk_strictMotif', boolean))
 | 
				
			||||||
	def tk_menuBar(self, *args):
 | 
						def tk_menuBar(self, *args):
 | 
				
			||||||
		apply(self.tk.call, ('tk_menuBar', self._w) + args)
 | 
							apply(self.tk.call, ('tk_menuBar', self._w) + args)
 | 
				
			||||||
	def waitvar(self, name='PY_VAR'):
 | 
						def wait_variable(self, name='PY_VAR'):
 | 
				
			||||||
		self.tk.call('tkwait', 'variable', name)
 | 
							self.tk.call('tkwait', 'variable', name)
 | 
				
			||||||
	wait_variable = waitvar
 | 
						waitvar = wait_variable # XXX b/w compat
 | 
				
			||||||
	def wait_window(self, window=None):
 | 
						def wait_window(self, window=None):
 | 
				
			||||||
		if window == None:
 | 
							if window == None:
 | 
				
			||||||
			window = self
 | 
								window = self
 | 
				
			||||||
| 
						 | 
					@ -88,7 +122,6 @@ class Misc:
 | 
				
			||||||
		if window == None:
 | 
							if window == None:
 | 
				
			||||||
			window = self
 | 
								window = self
 | 
				
			||||||
		self.tk.call('tkwait', 'visibility', window._w)
 | 
							self.tk.call('tkwait', 'visibility', window._w)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	def setvar(self, name='PY_VAR', value='1'):
 | 
						def setvar(self, name='PY_VAR', value='1'):
 | 
				
			||||||
		self.tk.setvar(name, value)
 | 
							self.tk.setvar(name, value)
 | 
				
			||||||
	def getvar(self, name='PY_VAR'):
 | 
						def getvar(self, name='PY_VAR'):
 | 
				
			||||||
| 
						 | 
					@ -298,7 +331,6 @@ class Misc:
 | 
				
			||||||
		self.tk.mainloop()
 | 
							self.tk.mainloop()
 | 
				
			||||||
	def quit(self):
 | 
						def quit(self):
 | 
				
			||||||
		self.tk.quit()
 | 
							self.tk.quit()
 | 
				
			||||||
	# Utilities
 | 
					 | 
				
			||||||
	def _getints(self, string):
 | 
						def _getints(self, string):
 | 
				
			||||||
		if not string: return None
 | 
							if not string: return None
 | 
				
			||||||
		res = ()
 | 
							res = ()
 | 
				
			||||||
| 
						 | 
					@ -308,11 +340,11 @@ class Misc:
 | 
				
			||||||
	def _getboolean(self, string):
 | 
						def _getboolean(self, string):
 | 
				
			||||||
		if string:
 | 
							if string:
 | 
				
			||||||
			return self.tk.getboolean(string)
 | 
								return self.tk.getboolean(string)
 | 
				
			||||||
		# else return None
 | 
					 | 
				
			||||||
	def _options(self, cnf):
 | 
						def _options(self, cnf):
 | 
				
			||||||
 | 
							cnf = _cnfmerge(cnf)
 | 
				
			||||||
		res = ()
 | 
							res = ()
 | 
				
			||||||
		for k, v in cnf.items():
 | 
							for k, v in cnf.items():
 | 
				
			||||||
			if _isfunctype(v):
 | 
								if type(v) in CallableTypes:
 | 
				
			||||||
				v = self._register(v)
 | 
									v = self._register(v)
 | 
				
			||||||
			res = res + ('-'+k, v)
 | 
								res = res + ('-'+k, v)
 | 
				
			||||||
		return res
 | 
							return res
 | 
				
			||||||
| 
						 | 
					@ -469,7 +501,7 @@ class Wm:
 | 
				
			||||||
	def positionfrom(self, who=None):
 | 
						def positionfrom(self, who=None):
 | 
				
			||||||
		return self.tk.call('wm', 'positionfrom', self._w, who)
 | 
							return self.tk.call('wm', 'positionfrom', self._w, who)
 | 
				
			||||||
	def protocol(self, name=None, func=None):
 | 
						def protocol(self, name=None, func=None):
 | 
				
			||||||
		if _isfunctype(func):
 | 
							if type(func) in CallableTypes:
 | 
				
			||||||
			command = self._register(func)
 | 
								command = self._register(func)
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			command = func
 | 
								command = func
 | 
				
			||||||
| 
						 | 
					@ -572,11 +604,13 @@ class Widget(Misc, Pack, Place):
 | 
				
			||||||
			self.master.children[self._name].destroy()
 | 
								self.master.children[self._name].destroy()
 | 
				
			||||||
		self.master.children[self._name] = self
 | 
							self.master.children[self._name] = self
 | 
				
			||||||
	def __init__(self, master, widgetName, cnf={}, extra=()):
 | 
						def __init__(self, master, widgetName, cnf={}, extra=()):
 | 
				
			||||||
 | 
							cnf = _cnfmerge(cnf)
 | 
				
			||||||
		Widget._setup(self, master, cnf)
 | 
							Widget._setup(self, master, cnf)
 | 
				
			||||||
		self.widgetName = widgetName
 | 
							self.widgetName = widgetName
 | 
				
			||||||
		apply(self.tk.call, (widgetName, self._w) + extra)
 | 
							apply(self.tk.call, (widgetName, self._w) + extra)
 | 
				
			||||||
		Widget.config(self, cnf)
 | 
							Widget.config(self, cnf)
 | 
				
			||||||
	def config(self, cnf=None):
 | 
						def config(self, cnf=None):
 | 
				
			||||||
 | 
					+ 		cnf = _cnfmerge(cnf)
 | 
				
			||||||
		if cnf is None:
 | 
							if cnf is None:
 | 
				
			||||||
			cnf = {}
 | 
								cnf = {}
 | 
				
			||||||
			for x in self.tk.split(
 | 
								for x in self.tk.split(
 | 
				
			||||||
| 
						 | 
					@ -606,7 +640,6 @@ class Widget(Misc, Pack, Place):
 | 
				
			||||||
		return self._w
 | 
							return self._w
 | 
				
			||||||
	def destroy(self):
 | 
						def destroy(self):
 | 
				
			||||||
		for c in self.children.values(): c.destroy()
 | 
							for c in self.children.values(): c.destroy()
 | 
				
			||||||
		del self.master.children[self._name]
 | 
					 | 
				
			||||||
		self.tk.call('destroy', self._w)
 | 
							self.tk.call('destroy', self._w)
 | 
				
			||||||
	def _do(self, name, args=()):
 | 
						def _do(self, name, args=()):
 | 
				
			||||||
		return apply(self.tk.call, (self._w, name) + args) 
 | 
							return apply(self.tk.call, (self._w, name) + args) 
 | 
				
			||||||
| 
						 | 
					@ -696,14 +729,14 @@ class Canvas(Widget):
 | 
				
			||||||
	def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
 | 
						def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
 | 
				
			||||||
		args = _flatten(args)
 | 
							args = _flatten(args)
 | 
				
			||||||
		cnf = args[-1]
 | 
							cnf = args[-1]
 | 
				
			||||||
		if type(cnf) == type({}):
 | 
							if type(cnf) in (DictionaryType, TupleType):
 | 
				
			||||||
			args = args[:-1]
 | 
								args = args[:-1]
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			cnf = {}
 | 
								cnf = {}
 | 
				
			||||||
		v = (self._w, 'create', itemType) + args
 | 
							return self.tk.getint(apply(
 | 
				
			||||||
		for k in cnf.keys():
 | 
								self.tk.call,
 | 
				
			||||||
			v = v + ('-' + k, cnf[k])
 | 
								(self._w, 'create', itemType) 
 | 
				
			||||||
		return self.tk.getint(apply(self.tk.call, v))
 | 
								+ args + self._options(cnf)))
 | 
				
			||||||
	def create_arc(self, *args):
 | 
						def create_arc(self, *args):
 | 
				
			||||||
		return Canvas._create(self, 'arc', args)
 | 
							return Canvas._create(self, 'arc', args)
 | 
				
			||||||
	def create_bitmap(self, *args):
 | 
						def create_bitmap(self, *args):
 | 
				
			||||||
| 
						 | 
					@ -796,15 +829,6 @@ class Canvas(Widget):
 | 
				
			||||||
	def yview(self, index):
 | 
						def yview(self, index):
 | 
				
			||||||
		self.tk.call(self._w, 'yview', index)
 | 
							self.tk.call(self._w, 'yview', index)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _flatten(tuple):
 | 
					 | 
				
			||||||
	res = ()
 | 
					 | 
				
			||||||
	for item in tuple:
 | 
					 | 
				
			||||||
		if type(item) in (TupleType, ListType):
 | 
					 | 
				
			||||||
			res = res + _flatten(item)
 | 
					 | 
				
			||||||
		else:
 | 
					 | 
				
			||||||
			res = res + (item,)
 | 
					 | 
				
			||||||
	return res
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Checkbutton(Widget):
 | 
					class Checkbutton(Widget):
 | 
				
			||||||
	def __init__(self, master=None, cnf={}):
 | 
						def __init__(self, master=None, cnf={}):
 | 
				
			||||||
		Widget.__init__(self, master, 'checkbutton', cnf)
 | 
							Widget.__init__(self, master, 'checkbutton', cnf)
 | 
				
			||||||
| 
						 | 
					@ -856,6 +880,7 @@ class Entry(Widget):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Frame(Widget):
 | 
					class Frame(Widget):
 | 
				
			||||||
	def __init__(self, master=None, cnf={}):
 | 
						def __init__(self, master=None, cnf={}):
 | 
				
			||||||
 | 
							cnf = _cnfmerge(cnf)
 | 
				
			||||||
		extra = ()
 | 
							extra = ()
 | 
				
			||||||
		if cnf.has_key('class'):
 | 
							if cnf.has_key('class'):
 | 
				
			||||||
			extra = ('-class', cnf['class'])
 | 
								extra = ('-class', cnf['class'])
 | 
				
			||||||
| 
						 | 
					@ -1050,7 +1075,7 @@ class Text(Widget):
 | 
				
			||||||
		apply(self.tk.call, 
 | 
							apply(self.tk.call, 
 | 
				
			||||||
		      (self._w, 'tag', 'configure', tagName) 
 | 
							      (self._w, 'tag', 'configure', tagName) 
 | 
				
			||||||
		      + self._options(cnf))
 | 
							      + self._options(cnf))
 | 
				
			||||||
	def tag_delete(self, tagNames):
 | 
						def tag_delete(self, *tagNames):
 | 
				
			||||||
		apply(self.tk.call, (self._w, 'tag', 'delete') 
 | 
							apply(self.tk.call, (self._w, 'tag', 'delete') 
 | 
				
			||||||
		      + tagNames)
 | 
							      + tagNames)
 | 
				
			||||||
	def tag_lower(self, tagName, belowThis=None):
 | 
						def tag_lower(self, tagName, belowThis=None):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,29 +1,51 @@
 | 
				
			||||||
# Tkinter.py -- Tk/Tcl widget wrappers
 | 
					# Tkinter.py -- Tk/Tcl widget wrappers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import tkinter
 | 
					import tkinter
 | 
				
			||||||
from tkinter import TclError
 | 
					from tkinter import TclError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class _Dummy:
 | 
					class _Dummy:
 | 
				
			||||||
	def meth(self):	return
 | 
						def meth(self):	return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _isfunctype(func):
 | 
					def _func():
 | 
				
			||||||
	return type(func) in CallableTypes
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FunctionType = type(_isfunctype)
 | 
					FunctionType = type(_func)
 | 
				
			||||||
ClassType = type(_Dummy)
 | 
					ClassType = type(_Dummy)
 | 
				
			||||||
MethodType = type(_Dummy.meth)
 | 
					MethodType = type(_Dummy.meth)
 | 
				
			||||||
StringType = type('')
 | 
					StringType = type('')
 | 
				
			||||||
TupleType = type(())
 | 
					TupleType = type(())
 | 
				
			||||||
ListType = type([])
 | 
					ListType = type([])
 | 
				
			||||||
 | 
					DictionaryType = type({})
 | 
				
			||||||
 | 
					NoneType = type(None)
 | 
				
			||||||
CallableTypes = (FunctionType, MethodType)
 | 
					CallableTypes = (FunctionType, MethodType)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def _flatten(tuple):
 | 
				
			||||||
 | 
						res = ()
 | 
				
			||||||
 | 
						for item in tuple:
 | 
				
			||||||
 | 
							if type(item) in (TupleType, ListType):
 | 
				
			||||||
 | 
								res = res + _flatten(item)
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
 | 
								res = res + (item,)
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def _cnfmerge(cnfs):
 | 
				
			||||||
 | 
						if type(cnfs) in (NoneType, DictionaryType, StringType):
 | 
				
			||||||
 | 
							return cnfs
 | 
				
			||||||
 | 
						else:
 | 
				
			||||||
 | 
							cnf = {}
 | 
				
			||||||
 | 
							for c in _flatten(cnfs):
 | 
				
			||||||
 | 
								for k, v in c.items():
 | 
				
			||||||
 | 
									cnf[k] = v
 | 
				
			||||||
 | 
							return cnf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Event:
 | 
				
			||||||
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_default_root = None
 | 
					_default_root = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _tkerror(err):
 | 
					def _tkerror(err):
 | 
				
			||||||
	pass
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Event:
 | 
					 | 
				
			||||||
	pass
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
_varnum = 0
 | 
					_varnum = 0
 | 
				
			||||||
class Variable:
 | 
					class Variable:
 | 
				
			||||||
	def __init__(self, master=None):
 | 
						def __init__(self, master=None):
 | 
				
			||||||
| 
						 | 
					@ -71,15 +93,27 @@ class BooleanVar(Variable):
 | 
				
			||||||
	def get(self):
 | 
						def get(self):
 | 
				
			||||||
		return self._tk.getboolean(self._tk.getvar(self._name))
 | 
							return self._tk.getboolean(self._tk.getvar(self._name))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def mainloop():
 | 
				
			||||||
 | 
						_default_root.tk.mainloop()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def getint(s):
 | 
				
			||||||
 | 
						return _default_root.tk.getint(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def getdouble(s):
 | 
				
			||||||
 | 
						return _default_root.tk.getdouble(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def getboolean(s):
 | 
				
			||||||
 | 
						return _default_root.tk.getboolean(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Misc:
 | 
					class Misc:
 | 
				
			||||||
	def tk_strictMotif(self, boolean=None):
 | 
						def tk_strictMotif(self, boolean=None):
 | 
				
			||||||
		self.tk.getboolean(self.tk.call(
 | 
							return self.tk.getboolean(self.tk.call(
 | 
				
			||||||
			'set', 'tk_strictMotif', boolean))
 | 
								'set', 'tk_strictMotif', boolean))
 | 
				
			||||||
	def tk_menuBar(self, *args):
 | 
						def tk_menuBar(self, *args):
 | 
				
			||||||
		apply(self.tk.call, ('tk_menuBar', self._w) + args)
 | 
							apply(self.tk.call, ('tk_menuBar', self._w) + args)
 | 
				
			||||||
	def waitvar(self, name='PY_VAR'):
 | 
						def wait_variable(self, name='PY_VAR'):
 | 
				
			||||||
		self.tk.call('tkwait', 'variable', name)
 | 
							self.tk.call('tkwait', 'variable', name)
 | 
				
			||||||
	wait_variable = waitvar
 | 
						waitvar = wait_variable # XXX b/w compat
 | 
				
			||||||
	def wait_window(self, window=None):
 | 
						def wait_window(self, window=None):
 | 
				
			||||||
		if window == None:
 | 
							if window == None:
 | 
				
			||||||
			window = self
 | 
								window = self
 | 
				
			||||||
| 
						 | 
					@ -88,7 +122,6 @@ class Misc:
 | 
				
			||||||
		if window == None:
 | 
							if window == None:
 | 
				
			||||||
			window = self
 | 
								window = self
 | 
				
			||||||
		self.tk.call('tkwait', 'visibility', window._w)
 | 
							self.tk.call('tkwait', 'visibility', window._w)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	def setvar(self, name='PY_VAR', value='1'):
 | 
						def setvar(self, name='PY_VAR', value='1'):
 | 
				
			||||||
		self.tk.setvar(name, value)
 | 
							self.tk.setvar(name, value)
 | 
				
			||||||
	def getvar(self, name='PY_VAR'):
 | 
						def getvar(self, name='PY_VAR'):
 | 
				
			||||||
| 
						 | 
					@ -298,7 +331,6 @@ class Misc:
 | 
				
			||||||
		self.tk.mainloop()
 | 
							self.tk.mainloop()
 | 
				
			||||||
	def quit(self):
 | 
						def quit(self):
 | 
				
			||||||
		self.tk.quit()
 | 
							self.tk.quit()
 | 
				
			||||||
	# Utilities
 | 
					 | 
				
			||||||
	def _getints(self, string):
 | 
						def _getints(self, string):
 | 
				
			||||||
		if not string: return None
 | 
							if not string: return None
 | 
				
			||||||
		res = ()
 | 
							res = ()
 | 
				
			||||||
| 
						 | 
					@ -308,11 +340,11 @@ class Misc:
 | 
				
			||||||
	def _getboolean(self, string):
 | 
						def _getboolean(self, string):
 | 
				
			||||||
		if string:
 | 
							if string:
 | 
				
			||||||
			return self.tk.getboolean(string)
 | 
								return self.tk.getboolean(string)
 | 
				
			||||||
		# else return None
 | 
					 | 
				
			||||||
	def _options(self, cnf):
 | 
						def _options(self, cnf):
 | 
				
			||||||
 | 
							cnf = _cnfmerge(cnf)
 | 
				
			||||||
		res = ()
 | 
							res = ()
 | 
				
			||||||
		for k, v in cnf.items():
 | 
							for k, v in cnf.items():
 | 
				
			||||||
			if _isfunctype(v):
 | 
								if type(v) in CallableTypes:
 | 
				
			||||||
				v = self._register(v)
 | 
									v = self._register(v)
 | 
				
			||||||
			res = res + ('-'+k, v)
 | 
								res = res + ('-'+k, v)
 | 
				
			||||||
		return res
 | 
							return res
 | 
				
			||||||
| 
						 | 
					@ -469,7 +501,7 @@ class Wm:
 | 
				
			||||||
	def positionfrom(self, who=None):
 | 
						def positionfrom(self, who=None):
 | 
				
			||||||
		return self.tk.call('wm', 'positionfrom', self._w, who)
 | 
							return self.tk.call('wm', 'positionfrom', self._w, who)
 | 
				
			||||||
	def protocol(self, name=None, func=None):
 | 
						def protocol(self, name=None, func=None):
 | 
				
			||||||
		if _isfunctype(func):
 | 
							if type(func) in CallableTypes:
 | 
				
			||||||
			command = self._register(func)
 | 
								command = self._register(func)
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			command = func
 | 
								command = func
 | 
				
			||||||
| 
						 | 
					@ -572,11 +604,13 @@ class Widget(Misc, Pack, Place):
 | 
				
			||||||
			self.master.children[self._name].destroy()
 | 
								self.master.children[self._name].destroy()
 | 
				
			||||||
		self.master.children[self._name] = self
 | 
							self.master.children[self._name] = self
 | 
				
			||||||
	def __init__(self, master, widgetName, cnf={}, extra=()):
 | 
						def __init__(self, master, widgetName, cnf={}, extra=()):
 | 
				
			||||||
 | 
							cnf = _cnfmerge(cnf)
 | 
				
			||||||
		Widget._setup(self, master, cnf)
 | 
							Widget._setup(self, master, cnf)
 | 
				
			||||||
		self.widgetName = widgetName
 | 
							self.widgetName = widgetName
 | 
				
			||||||
		apply(self.tk.call, (widgetName, self._w) + extra)
 | 
							apply(self.tk.call, (widgetName, self._w) + extra)
 | 
				
			||||||
		Widget.config(self, cnf)
 | 
							Widget.config(self, cnf)
 | 
				
			||||||
	def config(self, cnf=None):
 | 
						def config(self, cnf=None):
 | 
				
			||||||
 | 
					+ 		cnf = _cnfmerge(cnf)
 | 
				
			||||||
		if cnf is None:
 | 
							if cnf is None:
 | 
				
			||||||
			cnf = {}
 | 
								cnf = {}
 | 
				
			||||||
			for x in self.tk.split(
 | 
								for x in self.tk.split(
 | 
				
			||||||
| 
						 | 
					@ -606,7 +640,6 @@ class Widget(Misc, Pack, Place):
 | 
				
			||||||
		return self._w
 | 
							return self._w
 | 
				
			||||||
	def destroy(self):
 | 
						def destroy(self):
 | 
				
			||||||
		for c in self.children.values(): c.destroy()
 | 
							for c in self.children.values(): c.destroy()
 | 
				
			||||||
		del self.master.children[self._name]
 | 
					 | 
				
			||||||
		self.tk.call('destroy', self._w)
 | 
							self.tk.call('destroy', self._w)
 | 
				
			||||||
	def _do(self, name, args=()):
 | 
						def _do(self, name, args=()):
 | 
				
			||||||
		return apply(self.tk.call, (self._w, name) + args) 
 | 
							return apply(self.tk.call, (self._w, name) + args) 
 | 
				
			||||||
| 
						 | 
					@ -696,14 +729,14 @@ class Canvas(Widget):
 | 
				
			||||||
	def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
 | 
						def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
 | 
				
			||||||
		args = _flatten(args)
 | 
							args = _flatten(args)
 | 
				
			||||||
		cnf = args[-1]
 | 
							cnf = args[-1]
 | 
				
			||||||
		if type(cnf) == type({}):
 | 
							if type(cnf) in (DictionaryType, TupleType):
 | 
				
			||||||
			args = args[:-1]
 | 
								args = args[:-1]
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			cnf = {}
 | 
								cnf = {}
 | 
				
			||||||
		v = (self._w, 'create', itemType) + args
 | 
							return self.tk.getint(apply(
 | 
				
			||||||
		for k in cnf.keys():
 | 
								self.tk.call,
 | 
				
			||||||
			v = v + ('-' + k, cnf[k])
 | 
								(self._w, 'create', itemType) 
 | 
				
			||||||
		return self.tk.getint(apply(self.tk.call, v))
 | 
								+ args + self._options(cnf)))
 | 
				
			||||||
	def create_arc(self, *args):
 | 
						def create_arc(self, *args):
 | 
				
			||||||
		return Canvas._create(self, 'arc', args)
 | 
							return Canvas._create(self, 'arc', args)
 | 
				
			||||||
	def create_bitmap(self, *args):
 | 
						def create_bitmap(self, *args):
 | 
				
			||||||
| 
						 | 
					@ -796,15 +829,6 @@ class Canvas(Widget):
 | 
				
			||||||
	def yview(self, index):
 | 
						def yview(self, index):
 | 
				
			||||||
		self.tk.call(self._w, 'yview', index)
 | 
							self.tk.call(self._w, 'yview', index)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _flatten(tuple):
 | 
					 | 
				
			||||||
	res = ()
 | 
					 | 
				
			||||||
	for item in tuple:
 | 
					 | 
				
			||||||
		if type(item) in (TupleType, ListType):
 | 
					 | 
				
			||||||
			res = res + _flatten(item)
 | 
					 | 
				
			||||||
		else:
 | 
					 | 
				
			||||||
			res = res + (item,)
 | 
					 | 
				
			||||||
	return res
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Checkbutton(Widget):
 | 
					class Checkbutton(Widget):
 | 
				
			||||||
	def __init__(self, master=None, cnf={}):
 | 
						def __init__(self, master=None, cnf={}):
 | 
				
			||||||
		Widget.__init__(self, master, 'checkbutton', cnf)
 | 
							Widget.__init__(self, master, 'checkbutton', cnf)
 | 
				
			||||||
| 
						 | 
					@ -856,6 +880,7 @@ class Entry(Widget):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Frame(Widget):
 | 
					class Frame(Widget):
 | 
				
			||||||
	def __init__(self, master=None, cnf={}):
 | 
						def __init__(self, master=None, cnf={}):
 | 
				
			||||||
 | 
							cnf = _cnfmerge(cnf)
 | 
				
			||||||
		extra = ()
 | 
							extra = ()
 | 
				
			||||||
		if cnf.has_key('class'):
 | 
							if cnf.has_key('class'):
 | 
				
			||||||
			extra = ('-class', cnf['class'])
 | 
								extra = ('-class', cnf['class'])
 | 
				
			||||||
| 
						 | 
					@ -1050,7 +1075,7 @@ class Text(Widget):
 | 
				
			||||||
		apply(self.tk.call, 
 | 
							apply(self.tk.call, 
 | 
				
			||||||
		      (self._w, 'tag', 'configure', tagName) 
 | 
							      (self._w, 'tag', 'configure', tagName) 
 | 
				
			||||||
		      + self._options(cnf))
 | 
							      + self._options(cnf))
 | 
				
			||||||
	def tag_delete(self, tagNames):
 | 
						def tag_delete(self, *tagNames):
 | 
				
			||||||
		apply(self.tk.call, (self._w, 'tag', 'delete') 
 | 
							apply(self.tk.call, (self._w, 'tag', 'delete') 
 | 
				
			||||||
		      + tagNames)
 | 
							      + tagNames)
 | 
				
			||||||
	def tag_lower(self, tagName, belowThis=None):
 | 
						def tag_lower(self, tagName, belowThis=None):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue