summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1994-06-21 11:44:21 (GMT)
committerGuido van Rossum <guido@python.org>1994-06-21 11:44:21 (GMT)
commit08a403821d8fa803bc7f3e05050499ff22c4cd3d (patch)
treef4dc4a2c60b375cc5538462490d0fb590b8fa459
parentfea128ecf387fbe4644ea0aa8dce0a908b30ceee (diff)
downloadcpython-08a403821d8fa803bc7f3e05050499ff22c4cd3d.zip
cpython-08a403821d8fa803bc7f3e05050499ff22c4cd3d.tar.gz
cpython-08a403821d8fa803bc7f3e05050499ff22c4cd3d.tar.bz2
* Tkinter.py: some tidying up.
(Misc.after): arrange to call deletecommand after it is called. (Canvas.itemconfig): generalized to support all forms. (Canvas.find): returns a list of integers instead of strings. * Tkinter.py (Canvas._create): call _flatten earlier.
-rw-r--r--Lib/lib-tk/Tkinter.py41
-rwxr-xr-xLib/tkinter/Tkinter.py41
2 files changed, 54 insertions, 28 deletions
diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py
index 8b5d94f..70e70cd 100644
--- a/Lib/lib-tk/Tkinter.py
+++ b/Lib/lib-tk/Tkinter.py
@@ -6,13 +6,15 @@ class _Dummy:
def meth(self): return
def _isfunctype(func):
- return type(func) in (type(_Dummy.meth), type(_isfunctype))
+ return type(func) in CallableTypes
FunctionType = type(_isfunctype)
ClassType = type(_Dummy)
MethodType = type(_Dummy.meth)
+StringType = type('')
TupleType = type(())
ListType = type([])
+CallableTypes = (FunctionType, MethodType)
def _tkerror(err):
pass
@@ -54,8 +56,16 @@ class Misc:
if not func:
self.tk.call('after', ms)
else:
- name = self._register(func)
- apply(self.tk.call, ('after', ms, name) + args)
+ # XXX Disgusting hack to clean up after calling func
+ tmp = []
+ def callit(func=func, args=args, tk=self.tk, tmp=tmp):
+ try:
+ apply(func, args)
+ finally:
+ tk.deletecommand(tmp[0])
+ name = self._register(callit)
+ tmp.append(name)
+ self.tk.call('after', ms, name)
# XXX grab current w/o window argument
def grab_current(self):
name = self.tk.call('grab', 'current', self._w)
@@ -591,12 +601,13 @@ class Canvas(Widget):
def coords(self, *args):
return self._do('coords', args)
def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
+ args = _flatten(args)
cnf = args[-1]
if type(cnf) == type({}):
args = args[:-1]
else:
cnf = {}
- v = (self._w, 'create', itemType) + _flatten(args)
+ v = (self._w, 'create', itemType) + args
for k in cnf.keys():
v = v + ('-' + k, cnf[k])
return self.tk.getint(apply(self.tk.call, v))
@@ -623,7 +634,7 @@ class Canvas(Widget):
def dtag(self, *args):
self._do('dtag', args)
def find(self, *args):
- return self.tk.splitlist(self._do('find', args))
+ return self._getints(self._do('find', args))
def focus(self, *args):
return self._do('focus', args)
def gettags(self, *args):
@@ -634,7 +645,13 @@ class Canvas(Widget):
return self.tk.getint(self._do('index', args))
def insert(self, *args):
self._do('insert', args)
- def itemconfig(self, tagOrId, cnf={}):
+ def itemconfig(self, tagOrId, cnf=None):
+ if cnf is None:
+ return self.tk.split(self._do('itemconfigure',
+ (tagOrId)))
+ if type(cnf) == StringType:
+ return self.tk.split(self._do('itemconfigure',
+ (tagOrId, '-'+cnf,)))
self._do('itemconfigure', (tagOrId,) + self._options(cnf))
def lower(self, *args):
self._do('lower', args)
@@ -652,21 +669,17 @@ class Canvas(Widget):
def scan_dragto(self, x, y):
self.tk.call(self._w, 'scan', 'dragto', x, y)
def select_adjust(self, tagOrId, index):
- self.tk.call(
- self._w, 'select', 'adjust', tagOrId, index)
+ self.tk.call(self._w, 'select', 'adjust', tagOrId, index)
def select_clear(self):
self.tk.call(self._w, 'select', 'clear')
def select_from(self, tagOrId, index):
- self.tk.call(
- self._w, 'select', 'from', tagOrId, index)
+ self.tk.call(self._w, 'select', 'from', tagOrId, index)
def select_item(self):
self.tk.call(self._w, 'select', 'item')
def select_to(self, tagOrId, index):
- self.tk.call(
- self._w, 'select', 'to', tagOrId, index)
+ self.tk.call(self._w, 'select', 'to', tagOrId, index)
def type(self, tagOrId):
- return self.tk.splitlist(self.tk.call(
- self._w, 'type', tagOrId))
+ return self.tk.call(self._w, 'type', tagOrId) or None
def xview(self, index):
self.tk.call(self._w, 'xview', index)
def yview(self, index):
diff --git a/Lib/tkinter/Tkinter.py b/Lib/tkinter/Tkinter.py
index 8b5d94f..70e70cd 100755
--- a/Lib/tkinter/Tkinter.py
+++ b/Lib/tkinter/Tkinter.py
@@ -6,13 +6,15 @@ class _Dummy:
def meth(self): return
def _isfunctype(func):
- return type(func) in (type(_Dummy.meth), type(_isfunctype))
+ return type(func) in CallableTypes
FunctionType = type(_isfunctype)
ClassType = type(_Dummy)
MethodType = type(_Dummy.meth)
+StringType = type('')
TupleType = type(())
ListType = type([])
+CallableTypes = (FunctionType, MethodType)
def _tkerror(err):
pass
@@ -54,8 +56,16 @@ class Misc:
if not func:
self.tk.call('after', ms)
else:
- name = self._register(func)
- apply(self.tk.call, ('after', ms, name) + args)
+ # XXX Disgusting hack to clean up after calling func
+ tmp = []
+ def callit(func=func, args=args, tk=self.tk, tmp=tmp):
+ try:
+ apply(func, args)
+ finally:
+ tk.deletecommand(tmp[0])
+ name = self._register(callit)
+ tmp.append(name)
+ self.tk.call('after', ms, name)
# XXX grab current w/o window argument
def grab_current(self):
name = self.tk.call('grab', 'current', self._w)
@@ -591,12 +601,13 @@ class Canvas(Widget):
def coords(self, *args):
return self._do('coords', args)
def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
+ args = _flatten(args)
cnf = args[-1]
if type(cnf) == type({}):
args = args[:-1]
else:
cnf = {}
- v = (self._w, 'create', itemType) + _flatten(args)
+ v = (self._w, 'create', itemType) + args
for k in cnf.keys():
v = v + ('-' + k, cnf[k])
return self.tk.getint(apply(self.tk.call, v))
@@ -623,7 +634,7 @@ class Canvas(Widget):
def dtag(self, *args):
self._do('dtag', args)
def find(self, *args):
- return self.tk.splitlist(self._do('find', args))
+ return self._getints(self._do('find', args))
def focus(self, *args):
return self._do('focus', args)
def gettags(self, *args):
@@ -634,7 +645,13 @@ class Canvas(Widget):
return self.tk.getint(self._do('index', args))
def insert(self, *args):
self._do('insert', args)
- def itemconfig(self, tagOrId, cnf={}):
+ def itemconfig(self, tagOrId, cnf=None):
+ if cnf is None:
+ return self.tk.split(self._do('itemconfigure',
+ (tagOrId)))
+ if type(cnf) == StringType:
+ return self.tk.split(self._do('itemconfigure',
+ (tagOrId, '-'+cnf,)))
self._do('itemconfigure', (tagOrId,) + self._options(cnf))
def lower(self, *args):
self._do('lower', args)
@@ -652,21 +669,17 @@ class Canvas(Widget):
def scan_dragto(self, x, y):
self.tk.call(self._w, 'scan', 'dragto', x, y)
def select_adjust(self, tagOrId, index):
- self.tk.call(
- self._w, 'select', 'adjust', tagOrId, index)
+ self.tk.call(self._w, 'select', 'adjust', tagOrId, index)
def select_clear(self):
self.tk.call(self._w, 'select', 'clear')
def select_from(self, tagOrId, index):
- self.tk.call(
- self._w, 'select', 'from', tagOrId, index)
+ self.tk.call(self._w, 'select', 'from', tagOrId, index)
def select_item(self):
self.tk.call(self._w, 'select', 'item')
def select_to(self, tagOrId, index):
- self.tk.call(
- self._w, 'select', 'to', tagOrId, index)
+ self.tk.call(self._w, 'select', 'to', tagOrId, index)
def type(self, tagOrId):
- return self.tk.splitlist(self.tk.call(
- self._w, 'type', tagOrId))
+ return self.tk.call(self._w, 'type', tagOrId) or None
def xview(self, index):
self.tk.call(self._w, 'xview', index)
def yview(self, index):