mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
* 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.
This commit is contained in:
parent
fea128ecf3
commit
08a403821d
2 changed files with 54 additions and 28 deletions
|
@ -6,13 +6,15 @@ class _Dummy:
|
||||||
def meth(self): return
|
def meth(self): return
|
||||||
|
|
||||||
def _isfunctype(func):
|
def _isfunctype(func):
|
||||||
return type(func) in (type(_Dummy.meth), type(_isfunctype))
|
return type(func) in CallableTypes
|
||||||
|
|
||||||
FunctionType = type(_isfunctype)
|
FunctionType = type(_isfunctype)
|
||||||
ClassType = type(_Dummy)
|
ClassType = type(_Dummy)
|
||||||
MethodType = type(_Dummy.meth)
|
MethodType = type(_Dummy.meth)
|
||||||
|
StringType = type('')
|
||||||
TupleType = type(())
|
TupleType = type(())
|
||||||
ListType = type([])
|
ListType = type([])
|
||||||
|
CallableTypes = (FunctionType, MethodType)
|
||||||
|
|
||||||
def _tkerror(err):
|
def _tkerror(err):
|
||||||
pass
|
pass
|
||||||
|
@ -54,8 +56,16 @@ class Misc:
|
||||||
if not func:
|
if not func:
|
||||||
self.tk.call('after', ms)
|
self.tk.call('after', ms)
|
||||||
else:
|
else:
|
||||||
name = self._register(func)
|
# XXX Disgusting hack to clean up after calling func
|
||||||
apply(self.tk.call, ('after', ms, name) + args)
|
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
|
# XXX grab current w/o window argument
|
||||||
def grab_current(self):
|
def grab_current(self):
|
||||||
name = self.tk.call('grab', 'current', self._w)
|
name = self.tk.call('grab', 'current', self._w)
|
||||||
|
@ -591,12 +601,13 @@ class Canvas(Widget):
|
||||||
def coords(self, *args):
|
def coords(self, *args):
|
||||||
return self._do('coords', args)
|
return self._do('coords', args)
|
||||||
def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
|
def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
|
||||||
|
args = _flatten(args)
|
||||||
cnf = args[-1]
|
cnf = args[-1]
|
||||||
if type(cnf) == type({}):
|
if type(cnf) == type({}):
|
||||||
args = args[:-1]
|
args = args[:-1]
|
||||||
else:
|
else:
|
||||||
cnf = {}
|
cnf = {}
|
||||||
v = (self._w, 'create', itemType) + _flatten(args)
|
v = (self._w, 'create', itemType) + args
|
||||||
for k in cnf.keys():
|
for k in cnf.keys():
|
||||||
v = v + ('-' + k, cnf[k])
|
v = v + ('-' + k, cnf[k])
|
||||||
return self.tk.getint(apply(self.tk.call, v))
|
return self.tk.getint(apply(self.tk.call, v))
|
||||||
|
@ -623,7 +634,7 @@ class Canvas(Widget):
|
||||||
def dtag(self, *args):
|
def dtag(self, *args):
|
||||||
self._do('dtag', args)
|
self._do('dtag', args)
|
||||||
def find(self, *args):
|
def find(self, *args):
|
||||||
return self.tk.splitlist(self._do('find', args))
|
return self._getints(self._do('find', args))
|
||||||
def focus(self, *args):
|
def focus(self, *args):
|
||||||
return self._do('focus', args)
|
return self._do('focus', args)
|
||||||
def gettags(self, *args):
|
def gettags(self, *args):
|
||||||
|
@ -634,7 +645,13 @@ class Canvas(Widget):
|
||||||
return self.tk.getint(self._do('index', args))
|
return self.tk.getint(self._do('index', args))
|
||||||
def insert(self, *args):
|
def insert(self, *args):
|
||||||
self._do('insert', 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))
|
self._do('itemconfigure', (tagOrId,) + self._options(cnf))
|
||||||
def lower(self, *args):
|
def lower(self, *args):
|
||||||
self._do('lower', args)
|
self._do('lower', args)
|
||||||
|
@ -652,21 +669,17 @@ class Canvas(Widget):
|
||||||
def scan_dragto(self, x, y):
|
def scan_dragto(self, x, y):
|
||||||
self.tk.call(self._w, 'scan', 'dragto', x, y)
|
self.tk.call(self._w, 'scan', 'dragto', x, y)
|
||||||
def select_adjust(self, tagOrId, index):
|
def select_adjust(self, tagOrId, index):
|
||||||
self.tk.call(
|
self.tk.call(self._w, 'select', 'adjust', tagOrId, index)
|
||||||
self._w, 'select', 'adjust', tagOrId, index)
|
|
||||||
def select_clear(self):
|
def select_clear(self):
|
||||||
self.tk.call(self._w, 'select', 'clear')
|
self.tk.call(self._w, 'select', 'clear')
|
||||||
def select_from(self, tagOrId, index):
|
def select_from(self, tagOrId, index):
|
||||||
self.tk.call(
|
self.tk.call(self._w, 'select', 'from', tagOrId, index)
|
||||||
self._w, 'select', 'from', tagOrId, index)
|
|
||||||
def select_item(self):
|
def select_item(self):
|
||||||
self.tk.call(self._w, 'select', 'item')
|
self.tk.call(self._w, 'select', 'item')
|
||||||
def select_to(self, tagOrId, index):
|
def select_to(self, tagOrId, index):
|
||||||
self.tk.call(
|
self.tk.call(self._w, 'select', 'to', tagOrId, index)
|
||||||
self._w, 'select', 'to', tagOrId, index)
|
|
||||||
def type(self, tagOrId):
|
def type(self, tagOrId):
|
||||||
return self.tk.splitlist(self.tk.call(
|
return self.tk.call(self._w, 'type', tagOrId) or None
|
||||||
self._w, 'type', tagOrId))
|
|
||||||
def xview(self, index):
|
def xview(self, index):
|
||||||
self.tk.call(self._w, 'xview', index)
|
self.tk.call(self._w, 'xview', index)
|
||||||
def yview(self, index):
|
def yview(self, index):
|
||||||
|
|
|
@ -6,13 +6,15 @@ class _Dummy:
|
||||||
def meth(self): return
|
def meth(self): return
|
||||||
|
|
||||||
def _isfunctype(func):
|
def _isfunctype(func):
|
||||||
return type(func) in (type(_Dummy.meth), type(_isfunctype))
|
return type(func) in CallableTypes
|
||||||
|
|
||||||
FunctionType = type(_isfunctype)
|
FunctionType = type(_isfunctype)
|
||||||
ClassType = type(_Dummy)
|
ClassType = type(_Dummy)
|
||||||
MethodType = type(_Dummy.meth)
|
MethodType = type(_Dummy.meth)
|
||||||
|
StringType = type('')
|
||||||
TupleType = type(())
|
TupleType = type(())
|
||||||
ListType = type([])
|
ListType = type([])
|
||||||
|
CallableTypes = (FunctionType, MethodType)
|
||||||
|
|
||||||
def _tkerror(err):
|
def _tkerror(err):
|
||||||
pass
|
pass
|
||||||
|
@ -54,8 +56,16 @@ class Misc:
|
||||||
if not func:
|
if not func:
|
||||||
self.tk.call('after', ms)
|
self.tk.call('after', ms)
|
||||||
else:
|
else:
|
||||||
name = self._register(func)
|
# XXX Disgusting hack to clean up after calling func
|
||||||
apply(self.tk.call, ('after', ms, name) + args)
|
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
|
# XXX grab current w/o window argument
|
||||||
def grab_current(self):
|
def grab_current(self):
|
||||||
name = self.tk.call('grab', 'current', self._w)
|
name = self.tk.call('grab', 'current', self._w)
|
||||||
|
@ -591,12 +601,13 @@ class Canvas(Widget):
|
||||||
def coords(self, *args):
|
def coords(self, *args):
|
||||||
return self._do('coords', args)
|
return self._do('coords', args)
|
||||||
def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
|
def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
|
||||||
|
args = _flatten(args)
|
||||||
cnf = args[-1]
|
cnf = args[-1]
|
||||||
if type(cnf) == type({}):
|
if type(cnf) == type({}):
|
||||||
args = args[:-1]
|
args = args[:-1]
|
||||||
else:
|
else:
|
||||||
cnf = {}
|
cnf = {}
|
||||||
v = (self._w, 'create', itemType) + _flatten(args)
|
v = (self._w, 'create', itemType) + args
|
||||||
for k in cnf.keys():
|
for k in cnf.keys():
|
||||||
v = v + ('-' + k, cnf[k])
|
v = v + ('-' + k, cnf[k])
|
||||||
return self.tk.getint(apply(self.tk.call, v))
|
return self.tk.getint(apply(self.tk.call, v))
|
||||||
|
@ -623,7 +634,7 @@ class Canvas(Widget):
|
||||||
def dtag(self, *args):
|
def dtag(self, *args):
|
||||||
self._do('dtag', args)
|
self._do('dtag', args)
|
||||||
def find(self, *args):
|
def find(self, *args):
|
||||||
return self.tk.splitlist(self._do('find', args))
|
return self._getints(self._do('find', args))
|
||||||
def focus(self, *args):
|
def focus(self, *args):
|
||||||
return self._do('focus', args)
|
return self._do('focus', args)
|
||||||
def gettags(self, *args):
|
def gettags(self, *args):
|
||||||
|
@ -634,7 +645,13 @@ class Canvas(Widget):
|
||||||
return self.tk.getint(self._do('index', args))
|
return self.tk.getint(self._do('index', args))
|
||||||
def insert(self, *args):
|
def insert(self, *args):
|
||||||
self._do('insert', 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))
|
self._do('itemconfigure', (tagOrId,) + self._options(cnf))
|
||||||
def lower(self, *args):
|
def lower(self, *args):
|
||||||
self._do('lower', args)
|
self._do('lower', args)
|
||||||
|
@ -652,21 +669,17 @@ class Canvas(Widget):
|
||||||
def scan_dragto(self, x, y):
|
def scan_dragto(self, x, y):
|
||||||
self.tk.call(self._w, 'scan', 'dragto', x, y)
|
self.tk.call(self._w, 'scan', 'dragto', x, y)
|
||||||
def select_adjust(self, tagOrId, index):
|
def select_adjust(self, tagOrId, index):
|
||||||
self.tk.call(
|
self.tk.call(self._w, 'select', 'adjust', tagOrId, index)
|
||||||
self._w, 'select', 'adjust', tagOrId, index)
|
|
||||||
def select_clear(self):
|
def select_clear(self):
|
||||||
self.tk.call(self._w, 'select', 'clear')
|
self.tk.call(self._w, 'select', 'clear')
|
||||||
def select_from(self, tagOrId, index):
|
def select_from(self, tagOrId, index):
|
||||||
self.tk.call(
|
self.tk.call(self._w, 'select', 'from', tagOrId, index)
|
||||||
self._w, 'select', 'from', tagOrId, index)
|
|
||||||
def select_item(self):
|
def select_item(self):
|
||||||
self.tk.call(self._w, 'select', 'item')
|
self.tk.call(self._w, 'select', 'item')
|
||||||
def select_to(self, tagOrId, index):
|
def select_to(self, tagOrId, index):
|
||||||
self.tk.call(
|
self.tk.call(self._w, 'select', 'to', tagOrId, index)
|
||||||
self._w, 'select', 'to', tagOrId, index)
|
|
||||||
def type(self, tagOrId):
|
def type(self, tagOrId):
|
||||||
return self.tk.splitlist(self.tk.call(
|
return self.tk.call(self._w, 'type', tagOrId) or None
|
||||||
self._w, 'type', tagOrId))
|
|
||||||
def xview(self, index):
|
def xview(self, index):
|
||||||
self.tk.call(self._w, 'xview', index)
|
self.tk.call(self._w, 'xview', index)
|
||||||
def yview(self, index):
|
def yview(self, index):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue