Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tawindow.py
diff options
context:
space:
mode:
authorWalter Bender <walter@walter-laptop.(none)>2010-01-29 21:48:22 (GMT)
committer Walter Bender <walter@walter-laptop.(none)>2010-01-29 21:48:22 (GMT)
commit4f49bb9b466afa833be37bceecadb8f7b843d62e (patch)
treee9de718553808cd105e270b11dcedf2c61cfefa9 /tawindow.py
parent25d53af106b1fe6c619a3241af5c406ae72c50d8 (diff)
better input processing for number blocks
Diffstat (limited to 'tawindow.py')
-rw-r--r--tawindow.py41
1 files changed, 14 insertions, 27 deletions
diff --git a/tawindow.py b/tawindow.py
index b9b5b56..7ab79e0 100644
--- a/tawindow.py
+++ b/tawindow.py
@@ -653,10 +653,12 @@ class TurtleArtWindow():
newnum = '-'
elif oldnum[0] != '-':
newnum = '-' + oldnum
+ else:
+ newnum = oldnum
elif keyname == 'period' and '.' not in oldnum:
newnum = oldnum + '.'
elif keyname == 'BackSpace':
- if len(oldnum) > 1:
+ if len(oldnum) > 0:
newnum = oldnum[:len(oldnum)-1]
else:
newnum = ''
@@ -665,10 +667,19 @@ class TurtleArtWindow():
newnum = keyname
else:
newnum = oldnum + keyname
+ elif keyname == 'Return':
+ self._unselect_block()
+ return
else:
newnum = oldnum
- self.selected_blk.spr.set_label("%s%s" % \
- (str(numcheck(newnum,oldnum)), CURSOR))
+ if newnum == '.':
+ newnum = '0.'
+ if len(newnum) > 0 and newnum != '-':
+ try:
+ float(newnum)
+ except ValueError,e:
+ newnum = oldnum
+ self.selected_blk.spr.set_label(newnum + CURSOR)
"""
Make sure alphanumeric input is properly parsed.
@@ -1275,28 +1286,4 @@ class TurtleArtWindow():
self.selected_blk.spr.set_label(s)
self.selected_blk.values[0] = s
-#
-# Utilities used for checking variable validity
-#
-
-def numcheck(new, old):
- n = new.replace(CURSOR,'')
- if n is '':
- return "0"
- if n in ['-', '.', '-.']:
- return n
- if n == '.':
- return '0.'
- try:
- float(n);
- return n
- except ValueError,e:
- return old.replace(CURSOR,'')
-
-def strcheck(new, old):
- try:
- str(new)
- return new.replace(CURSOR,'')
- except ValueError,e:
- return old.replace(CURSOR,'')