Commit 1e9e400b authored by Guido van Rossum's avatar Guido van Rossum

Added getdouble, getboolean.

Removed redundant global statements
getboolean returns None if argument is empty
AtInsert() concatenates optional arguments after 'insert'
parent df09691e
...@@ -30,6 +30,10 @@ class Misc: ...@@ -30,6 +30,10 @@ class Misc:
return self.tk.getvar(name) return self.tk.getvar(name)
def getint(self, s): def getint(self, s):
return self.tk.getint(s) return self.tk.getint(s)
def getdouble(self, s):
return self.tk.getdouble(s)
def getboolean(self, s):
return self.tk.getboolean(s)
def focus(self): def focus(self):
self.tk.call('focus', self._w) self.tk.call('focus', self._w)
def focus_default(self): def focus_default(self):
...@@ -183,19 +187,16 @@ class Misc: ...@@ -183,19 +187,16 @@ class Misc:
def update_idletasks(self): def update_idletasks(self):
self.tk.call('update', 'idletasks') self.tk.call('update', 'idletasks')
def bind(self, sequence, func, add=''): def bind(self, sequence, func, add=''):
global _substitute, _subst_prefix
if add: add = '+' if add: add = '+'
name = self._register(func, _substitute) name = self._register(func, _substitute)
self.tk.call('bind', self._w, sequence, self.tk.call('bind', self._w, sequence,
(add + name,) + _subst_prefix) (add + name,) + _subst_prefix)
def bind_all(self, sequence, func, add=''): def bind_all(self, sequence, func, add=''):
global _substitute, _subst_prefix
if add: add = '+' if add: add = '+'
name = self._register(func, _substitute) name = self._register(func, _substitute)
self.tk.call('bind', 'all' , sequence, self.tk.call('bind', 'all' , sequence,
(add + `name`,) + _subst_prefix) (add + `name`,) + _subst_prefix)
def bind_class(self, className, sequence, func, add=''): def bind_class(self, className, sequence, func, add=''):
global _substitute, _subst_prefix
if add: add = '+' if add: add = '+'
name = self._register(func, _substitute) name = self._register(func, _substitute)
self.tk.call('bind', className , sequence, self.tk.call('bind', className , sequence,
...@@ -216,8 +217,7 @@ class Misc: ...@@ -216,8 +217,7 @@ 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: # else return None
return string
def _options(self, cnf): def _options(self, cnf):
res = () res = ()
for k, v in cnf.items(): for k, v in cnf.items():
...@@ -242,8 +242,6 @@ _subst_prefix = ('%#', '%b', '%f', '%h', '%k', ...@@ -242,8 +242,6 @@ _subst_prefix = ('%#', '%b', '%f', '%h', '%k',
'%A', '%E', '%K', '%N', '%T', '%X', '%Y') '%A', '%E', '%K', '%N', '%T', '%X', '%Y')
def _substitute(*args): def _substitute(*args):
global default_root
global _subst_prefix
tk = default_root.tk tk = default_root.tk
if len(args) != len(_subst_prefix): return args if len(args) != len(_subst_prefix): return args
nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, T, X, Y = args nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, T, X, Y = args
...@@ -503,8 +501,11 @@ class Button(Widget): ...@@ -503,8 +501,11 @@ class Button(Widget):
# Indices: # Indices:
def AtEnd(): def AtEnd():
return 'end' return 'end'
def AtInsert(): def AtInsert(*args):
return 'insert' s = 'insert'
for a in args:
if a: s = s + (' ' + a)
return s
def AtSelFirst(): def AtSelFirst():
return 'sel.first' return 'sel.first'
def AtSelLast(): def AtSelLast():
...@@ -523,7 +524,6 @@ class Canvas(Widget): ...@@ -523,7 +524,6 @@ class Canvas(Widget):
def bbox(self, *args): def bbox(self, *args):
return self._getints(self._do('bbox', args)) return self._getints(self._do('bbox', args))
def bind(self, tagOrId, sequence, func, add=''): def bind(self, tagOrId, sequence, func, add=''):
global _substitute, _subst_prefix
if add: add='+' if add: add='+'
name = self._register(func, _substitute) name = self._register(func, _substitute)
self.tk.call(self._w, 'bind', tagOrId, sequence, self.tk.call(self._w, 'bind', tagOrId, sequence,
...@@ -844,7 +844,6 @@ class Text(Widget): ...@@ -844,7 +844,6 @@ class Text(Widget):
self.tk.call( self.tk.call(
self._w, 'tag', 'add', tagName, index1, index2) self._w, 'tag', 'add', tagName, index1, index2)
def tag_bind(self, tagName, sequence, func, add=''): def tag_bind(self, tagName, sequence, func, add=''):
global _substitute, _subst_prefix
if add: add='+' if add: add='+'
name = self._register(func, _substitute) name = self._register(func, _substitute)
self.tk.call(self._w, 'tag', 'bind', self.tk.call(self._w, 'tag', 'bind',
......
...@@ -30,6 +30,10 @@ class Misc: ...@@ -30,6 +30,10 @@ class Misc:
return self.tk.getvar(name) return self.tk.getvar(name)
def getint(self, s): def getint(self, s):
return self.tk.getint(s) return self.tk.getint(s)
def getdouble(self, s):
return self.tk.getdouble(s)
def getboolean(self, s):
return self.tk.getboolean(s)
def focus(self): def focus(self):
self.tk.call('focus', self._w) self.tk.call('focus', self._w)
def focus_default(self): def focus_default(self):
...@@ -183,19 +187,16 @@ class Misc: ...@@ -183,19 +187,16 @@ class Misc:
def update_idletasks(self): def update_idletasks(self):
self.tk.call('update', 'idletasks') self.tk.call('update', 'idletasks')
def bind(self, sequence, func, add=''): def bind(self, sequence, func, add=''):
global _substitute, _subst_prefix
if add: add = '+' if add: add = '+'
name = self._register(func, _substitute) name = self._register(func, _substitute)
self.tk.call('bind', self._w, sequence, self.tk.call('bind', self._w, sequence,
(add + name,) + _subst_prefix) (add + name,) + _subst_prefix)
def bind_all(self, sequence, func, add=''): def bind_all(self, sequence, func, add=''):
global _substitute, _subst_prefix
if add: add = '+' if add: add = '+'
name = self._register(func, _substitute) name = self._register(func, _substitute)
self.tk.call('bind', 'all' , sequence, self.tk.call('bind', 'all' , sequence,
(add + `name`,) + _subst_prefix) (add + `name`,) + _subst_prefix)
def bind_class(self, className, sequence, func, add=''): def bind_class(self, className, sequence, func, add=''):
global _substitute, _subst_prefix
if add: add = '+' if add: add = '+'
name = self._register(func, _substitute) name = self._register(func, _substitute)
self.tk.call('bind', className , sequence, self.tk.call('bind', className , sequence,
...@@ -216,8 +217,7 @@ class Misc: ...@@ -216,8 +217,7 @@ 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: # else return None
return string
def _options(self, cnf): def _options(self, cnf):
res = () res = ()
for k, v in cnf.items(): for k, v in cnf.items():
...@@ -242,8 +242,6 @@ _subst_prefix = ('%#', '%b', '%f', '%h', '%k', ...@@ -242,8 +242,6 @@ _subst_prefix = ('%#', '%b', '%f', '%h', '%k',
'%A', '%E', '%K', '%N', '%T', '%X', '%Y') '%A', '%E', '%K', '%N', '%T', '%X', '%Y')
def _substitute(*args): def _substitute(*args):
global default_root
global _subst_prefix
tk = default_root.tk tk = default_root.tk
if len(args) != len(_subst_prefix): return args if len(args) != len(_subst_prefix): return args
nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, T, X, Y = args nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, T, X, Y = args
...@@ -503,8 +501,11 @@ class Button(Widget): ...@@ -503,8 +501,11 @@ class Button(Widget):
# Indices: # Indices:
def AtEnd(): def AtEnd():
return 'end' return 'end'
def AtInsert(): def AtInsert(*args):
return 'insert' s = 'insert'
for a in args:
if a: s = s + (' ' + a)
return s
def AtSelFirst(): def AtSelFirst():
return 'sel.first' return 'sel.first'
def AtSelLast(): def AtSelLast():
...@@ -523,7 +524,6 @@ class Canvas(Widget): ...@@ -523,7 +524,6 @@ class Canvas(Widget):
def bbox(self, *args): def bbox(self, *args):
return self._getints(self._do('bbox', args)) return self._getints(self._do('bbox', args))
def bind(self, tagOrId, sequence, func, add=''): def bind(self, tagOrId, sequence, func, add=''):
global _substitute, _subst_prefix
if add: add='+' if add: add='+'
name = self._register(func, _substitute) name = self._register(func, _substitute)
self.tk.call(self._w, 'bind', tagOrId, sequence, self.tk.call(self._w, 'bind', tagOrId, sequence,
...@@ -844,7 +844,6 @@ class Text(Widget): ...@@ -844,7 +844,6 @@ class Text(Widget):
self.tk.call( self.tk.call(
self._w, 'tag', 'add', tagName, index1, index2) self._w, 'tag', 'add', tagName, index1, index2)
def tag_bind(self, tagName, sequence, func, add=''): def tag_bind(self, tagName, sequence, func, add=''):
global _substitute, _subst_prefix
if add: add='+' if add: add='+'
name = self._register(func, _substitute) name = self._register(func, _substitute)
self.tk.call(self._w, 'tag', 'bind', self.tk.call(self._w, 'tag', 'bind',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment