mirror of
https://github.com/python/cpython
synced 2024-09-16 01:31:10 +00:00
Get rid of nearly all clals to self._do -- turns out self.tk.call can
be used just as well, so this saves one Python call in many cases!
This commit is contained in:
parent
29892d848c
commit
0bd5433cf8
|
@ -1076,6 +1076,7 @@ def destroy(self):
|
|||
self.tk.call('destroy', self._w)
|
||||
Misc.destroy(self)
|
||||
def _do(self, name, args=()):
|
||||
# XXX Obsolete -- better use self.tk.call directly!
|
||||
return self.tk.call((self._w, name) + args)
|
||||
|
||||
class Widget(BaseWidget, Pack, Place, Grid):
|
||||
|
@ -1142,7 +1143,7 @@ class Canvas(Widget):
|
|||
def __init__(self, master=None, cnf={}, **kw):
|
||||
Widget.__init__(self, master, 'canvas', cnf, kw)
|
||||
def addtag(self, *args):
|
||||
self._do('addtag', args)
|
||||
self.tk.call((self._w, 'addtag') + args)
|
||||
def addtag_above(self, newtag, tagOrId):
|
||||
self.addtag(newtag, 'above', tagOrId)
|
||||
def addtag_all(self, newtag):
|
||||
|
@ -1158,7 +1159,8 @@ def addtag_overlapping(self, newtag, x1, y1, x2, y2):
|
|||
def addtag_withtag(self, newtag, tagOrId):
|
||||
self.addtag(newtag, 'withtag', tagOrId)
|
||||
def bbox(self, *args):
|
||||
return self._getints(self._do('bbox', args)) or None
|
||||
return self._getints(
|
||||
self.tk.call((self._w, 'bbox') + args)) or None
|
||||
def tag_unbind(self, tagOrId, sequence, funcid=None):
|
||||
self.tk.call(self._w, 'bind', tagOrId, sequence, '')
|
||||
if funcid:
|
||||
|
@ -1175,7 +1177,8 @@ def canvasy(self, screeny, gridspacing=None):
|
|||
def coords(self, *args):
|
||||
# XXX Should use _flatten on args
|
||||
return map(getdouble,
|
||||
self.tk.splitlist(self._do('coords', args)))
|
||||
self.tk.splitlist(
|
||||
self.tk.call((self._w, 'coords') + args)))
|
||||
def _create(self, itemType, args, kw): # Args: (val, val, ..., cnf={})
|
||||
args = _flatten(args)
|
||||
cnf = args[-1]
|
||||
|
@ -1206,13 +1209,14 @@ def create_text(self, *args, **kw):
|
|||
def create_window(self, *args, **kw):
|
||||
return self._create('window', args, kw)
|
||||
def dchars(self, *args):
|
||||
self._do('dchars', args)
|
||||
self.tk.call((self._w, 'dchars') + args)
|
||||
def delete(self, *args):
|
||||
self._do('delete', args)
|
||||
self.tk.call((self._w, 'delete') + args)
|
||||
def dtag(self, *args):
|
||||
self._do('dtag', args)
|
||||
self.tk.call((self._w, 'dtag') + args)
|
||||
def find(self, *args):
|
||||
return self._getints(self._do('find', args)) or ()
|
||||
return self._getints(
|
||||
self.tk.call((self._w, 'find') + args)) or ()
|
||||
def find_above(self, tagOrId):
|
||||
return self.find('above', tagOrId)
|
||||
def find_all(self):
|
||||
|
@ -1228,42 +1232,46 @@ def find_overlapping(self, x1, y1, x2, y2):
|
|||
def find_withtag(self, tagOrId):
|
||||
return self.find('withtag', tagOrId)
|
||||
def focus(self, *args):
|
||||
return self._do('focus', args)
|
||||
return self.tk.call((self._w, 'focus') + args)
|
||||
def gettags(self, *args):
|
||||
return self.tk.splitlist(self._do('gettags', args))
|
||||
return self.tk.splitlist(
|
||||
self.tk.call((self._w, 'gettags') + args))
|
||||
def icursor(self, *args):
|
||||
self._do('icursor', args)
|
||||
self.tk.call((self._w, 'icursor') + args)
|
||||
def index(self, *args):
|
||||
return getint(self._do('index', args))
|
||||
return getint(self.tk.call((self._w, 'index') + args))
|
||||
def insert(self, *args):
|
||||
self._do('insert', args)
|
||||
self.tk.call((self._w, 'insert') + args)
|
||||
def itemcget(self, tagOrId, option):
|
||||
return self._do('itemcget', (tagOrId, '-'+option))
|
||||
return self.tk.call(
|
||||
(self._w, 'itemcget') + (tagOrId, '-'+option))
|
||||
def itemconfigure(self, tagOrId, cnf=None, **kw):
|
||||
if cnf is None and not kw:
|
||||
cnf = {}
|
||||
for x in self.tk.split(
|
||||
self._do('itemconfigure', (tagOrId,))):
|
||||
self.tk.call(self._w,
|
||||
'itemconfigure', tagOrId)):
|
||||
cnf[x[0][1:]] = (x[0][1:],) + x[1:]
|
||||
return cnf
|
||||
if type(cnf) == StringType and not kw:
|
||||
x = self.tk.split(self._do('itemconfigure',
|
||||
(tagOrId, '-'+cnf,)))
|
||||
x = self.tk.split(self.tk.call(
|
||||
self._w, 'itemconfigure', tagOrId, '-'+cnf))
|
||||
return (x[0][1:],) + x[1:]
|
||||
self._do('itemconfigure', (tagOrId,)
|
||||
+ self._options(cnf, kw))
|
||||
self.tk.call((self._w, 'itemconfigure', tagOrId) +
|
||||
self._options(cnf, kw))
|
||||
itemconfig = itemconfigure
|
||||
def lower(self, *args):
|
||||
self._do('lower', args)
|
||||
self.tk.call((self._w, 'lower') + args)
|
||||
def move(self, *args):
|
||||
self._do('move', args)
|
||||
self.tk.call((self._w, 'move') + args)
|
||||
def postscript(self, cnf={}, **kw):
|
||||
return self._do('postscript', self._options(cnf, kw))
|
||||
return self.tk.call((self._w, 'postscript') +
|
||||
self._options(cnf, kw))
|
||||
def tkraise(self, *args):
|
||||
self._do('raise', args)
|
||||
self.tk.call((self._w, 'raise') + args)
|
||||
lift = tkraise
|
||||
def scale(self, *args):
|
||||
self._do('scale', args)
|
||||
self.tk.call((self._w, 'scale') + args)
|
||||
def scan_mark(self, x, y):
|
||||
self.tk.call(self._w, 'scan', 'mark', x, y)
|
||||
def scan_dragto(self, x, y):
|
||||
|
@ -1283,11 +1291,11 @@ def type(self, tagOrId):
|
|||
def xview(self, *args):
|
||||
if not args:
|
||||
return self._getdoubles(self.tk.call(self._w, 'xview'))
|
||||
self.tk.call((self._w, 'xview')+args)
|
||||
self.tk.call((self._w, 'xview') + args)
|
||||
def yview(self, *args):
|
||||
if not args:
|
||||
return self._getdoubles(self.tk.call(self._w, 'yview'))
|
||||
self.tk.call((self._w, 'yview')+args)
|
||||
self.tk.call((self._w, 'yview') + args)
|
||||
|
||||
class Checkbutton(Widget):
|
||||
def __init__(self, master=None, cnf={}, **kw):
|
||||
|
@ -1369,7 +1377,8 @@ def __init__(self, master=None, cnf={}, **kw):
|
|||
def activate(self, index):
|
||||
self.tk.call(self._w, 'activate', index)
|
||||
def bbox(self, *args):
|
||||
return self._getints(self._do('bbox', args)) or None
|
||||
return self._getints(
|
||||
self.tk.call((self._w, 'bbox') + args)) or None
|
||||
def curselection(self):
|
||||
# XXX Ought to apply self._getints()...
|
||||
return self.tk.splitlist(self.tk.call(
|
||||
|
@ -1416,11 +1425,11 @@ def size(self):
|
|||
def xview(self, *what):
|
||||
if not what:
|
||||
return self._getdoubles(self.tk.call(self._w, 'xview'))
|
||||
self.tk.call((self._w, 'xview')+what)
|
||||
self.tk.call((self._w, 'xview') + what)
|
||||
def yview(self, *what):
|
||||
if not what:
|
||||
return self._getdoubles(self.tk.call(self._w, 'yview'))
|
||||
self.tk.call((self._w, 'yview')+what)
|
||||
self.tk.call((self._w, 'yview') + what)
|
||||
|
||||
class Menu(Widget):
|
||||
def __init__(self, master=None, cnf={}, **kw):
|
||||
|
@ -1452,8 +1461,8 @@ def tk_popup(self, x, y, entry=""):
|
|||
def activate(self, index):
|
||||
self.tk.call(self._w, 'activate', index)
|
||||
def add(self, itemType, cnf={}, **kw):
|
||||
self.tk.call((self._w, 'add', itemType)
|
||||
+ self._options(cnf, kw))
|
||||
self.tk.call((self._w, 'add', itemType) +
|
||||
self._options(cnf, kw))
|
||||
def add_cascade(self, cnf={}, **kw):
|
||||
self.add('cascade', cnf or kw)
|
||||
def add_checkbutton(self, cnf={}, **kw):
|
||||
|
@ -1465,8 +1474,8 @@ def add_radiobutton(self, cnf={}, **kw):
|
|||
def add_separator(self, cnf={}, **kw):
|
||||
self.add('separator', cnf or kw)
|
||||
def insert(self, index, itemType, cnf={}, **kw):
|
||||
self.tk.call((self._w, 'insert', index, itemType)
|
||||
+ self._options(cnf, kw))
|
||||
self.tk.call((self._w, 'insert', index, itemType) +
|
||||
self._options(cnf, kw))
|
||||
def insert_cascade(self, index, cnf={}, **kw):
|
||||
self.insert(index, 'cascade', cnf or kw)
|
||||
def insert_checkbutton(self, index, cnf={}, **kw):
|
||||
|
@ -1558,13 +1567,14 @@ def identify(self, x, y):
|
|||
def get(self):
|
||||
return self._getdoubles(self.tk.call(self._w, 'get'))
|
||||
def set(self, *args):
|
||||
self.tk.call((self._w, 'set')+args)
|
||||
self.tk.call((self._w, 'set') + args)
|
||||
|
||||
class Text(Widget):
|
||||
def __init__(self, master=None, cnf={}, **kw):
|
||||
Widget.__init__(self, master, 'text', cnf, kw)
|
||||
def bbox(self, *args):
|
||||
return self._getints(self._do('bbox', args)) or None
|
||||
return self._getints(
|
||||
self.tk.call((self._w, 'bbox') + args)) or None
|
||||
def tk_textSelectTo(self, index):
|
||||
self.tk.call('tk_textSelectTo', self._w, index)
|
||||
def tk_textBackspace(self):
|
||||
|
@ -1588,7 +1598,7 @@ def get(self, index1, index2=None):
|
|||
def index(self, index):
|
||||
return self.tk.call(self._w, 'index', index)
|
||||
def insert(self, index, chars, *args):
|
||||
self.tk.call((self._w, 'insert', index, chars)+args)
|
||||
self.tk.call((self._w, 'insert', index, chars) + args)
|
||||
def mark_gravity(self, markName, direction=None):
|
||||
return self.tk.call(
|
||||
(self._w, 'mark', 'gravity', markName, direction))
|
||||
|
@ -1693,13 +1703,13 @@ def window_names(self):
|
|||
def xview(self, *what):
|
||||
if not what:
|
||||
return self._getdoubles(self.tk.call(self._w, 'xview'))
|
||||
self.tk.call((self._w, 'xview')+what)
|
||||
self.tk.call((self._w, 'xview') + what)
|
||||
def yview(self, *what):
|
||||
if not what:
|
||||
return self._getdoubles(self.tk.call(self._w, 'yview'))
|
||||
self.tk.call((self._w, 'yview')+what)
|
||||
self.tk.call((self._w, 'yview') + what)
|
||||
def yview_pickplace(self, *what):
|
||||
self.tk.call((self._w, 'yview', '-pickplace')+what)
|
||||
self.tk.call((self._w, 'yview', '-pickplace') + what)
|
||||
|
||||
class _setit:
|
||||
def __init__(self, var, value):
|
||||
|
|
Loading…
Reference in a new issue