[Python-checkins] r67274 - sandbox/trunk/tkinter-polo/src/Tkinter.py
guilherme.polo
python-checkins at python.org
Wed Nov 19 00:37:18 CET 2008
Author: guilherme.polo
Date: Wed Nov 19 00:37:18 2008
New Revision: 67274
Log:
Removed most of type() calls
Modified:
sandbox/trunk/tkinter-polo/src/Tkinter.py
Modified: sandbox/trunk/tkinter-polo/src/Tkinter.py
==============================================================================
--- sandbox/trunk/tkinter-polo/src/Tkinter.py (original)
+++ sandbox/trunk/tkinter-polo/src/Tkinter.py Wed Nov 19 00:37:18 2008
@@ -46,14 +46,14 @@
except AttributeError: _tkinter.deletefilehandler = None
-def _flatten(tuple):
+def _flatten(nested):
"""Internal function."""
res = ()
- for item in tuple:
- if type(item) in (TupleType, ListType):
+ for item in nested:
+ if isinstance(item, (tuple, list)):
res = res + _flatten(item)
elif item is not None:
- res = res + (item,)
+ res = res + (item, )
return res
try: _flatten = _tkinter._flatten
@@ -61,9 +61,9 @@
def _cnfmerge(cnfs):
"""Internal function."""
- if type(cnfs) is DictionaryType:
+ if isinstance(cnfs, dict):
return cnfs
- elif type(cnfs) in (NoneType, StringType):
+ elif isinstance(cnfs, (NoneType, str)):
return cnfs
else:
cnf = {}
@@ -873,7 +873,7 @@
data = self.tk.split(
self.tk.call('winfo', 'visualsavailable', self._w,
includeids and 'includeids' or None))
- if type(data) is StringType:
+ if isinstance(data, str):
data = [self.tk.split(data)]
return map(self.__winfo_parseitem, data)
def __winfo_parseitem(self, t):
@@ -941,7 +941,7 @@
self.tk.call('bindtags', self._w, tagList)
def _bind(self, what, sequence, func, add, needcleanup=1):
"""Internal function."""
- if type(func) is StringType:
+ if isinstance(func, str):
self.tk.call(what + (sequence, func))
elif func:
funcid = self._register(func, self._substitute,
@@ -1201,7 +1201,7 @@
self.tk.call(_flatten((self._w, cmd)))):
cnf[x[0][1:]] = (x[0][1:],) + x[1:]
return cnf
- if type(cnf) is StringType:
+ if isinstance(cnf, str):
x = self.tk.split(
self.tk.call(_flatten((self._w, cmd, '-'+cnf))))
return (x[0][1:],) + x[1:]
@@ -1284,7 +1284,7 @@
bbox = grid_bbox
def _grid_configure(self, command, index, cnf, kw):
"""Internal function."""
- if type(cnf) is StringType and not kw:
+ if isinstance(cnf, str) and not kw:
if cnf[-1:] == '_':
cnf = cnf[:-1]
if cnf[:1] != '-':
@@ -1937,7 +1937,7 @@
self._tclCommands = []
classes = []
for k in cnf.keys():
- if type(k) is ClassType:
+ if type(k) is ClassType: # XXX
classes.append((k, cnf[k]))
del cnf[k]
self.tk.call(
@@ -2151,13 +2151,12 @@
"""Internal function."""
args = _flatten(args)
cnf = args[-1]
- if type(cnf) in (DictionaryType, TupleType):
+ if isinstance(cnf, (dict, tuple)):
args = args[:-1]
else:
cnf = {}
return getint(self.tk.call(
- self._w, 'create', itemType,
- *(args + self._options(cnf, kw))))
+ self._w, 'create', itemType, *(args + self._options(cnf, kw))))
def create_arc(self, *args, **kw):
"""Create arc shaped region with coordinates x1,y1,x2,y2."""
return self._create('arc', args, kw)
@@ -2645,8 +2644,7 @@
self.tk.call(self._w, 'activate', index)
def add(self, itemType, cnf={}, **kw):
"""Internal function."""
- 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):
"""Add hierarchical menu item."""
self.add('cascade', cnf or kw)
@@ -3734,7 +3732,7 @@
'paneconfigure', tagOrId)):
cnf[x[0][1:]] = (x[0][1:],) + x[1:]
return cnf
- if type(cnf) == StringType and not kw:
+ if isinstance(cnf, str) and not kw:
x = self.tk.split(self.tk.call(
self._w, 'paneconfigure', tagOrId, '-'+cnf))
return (x[0][1:],) + x[1:]
More information about the Python-checkins
mailing list