Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2013-01-18 13:35:22 (GMT)
committer Walter Bender <walter.bender@gmail.com>2013-01-18 13:35:22 (GMT)
commit0bc8c883d287b64df35d6553ab43e7d11f7160d4 (patch)
treeb3ab1a18eff8245f3b4b6efc939c613e1c560cd8 /TurtleArt
parent9bc0ae7bf490bef64edf9e2c54ff813c204bda2e (diff)
convert color names to numbers when using numeric operators
Diffstat (limited to 'TurtleArt')
-rw-r--r--TurtleArt/tabasics.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py
index 776dc3b..42eb1e1 100644
--- a/TurtleArt/tabasics.py
+++ b/TurtleArt/tabasics.py
@@ -67,7 +67,14 @@ from gettext import gettext as _
from tapalette import make_palette, define_logo_function
from talogo import primitive_dictionary, logoerror
from tautils import convert, chr_to_ord, round_int, strtype
-from taconstants import BLACK, WHITE, CONSTANTS, XO30
+from taconstants import COLORDICT, CONSTANTS, XO30
+
+
+def _color_to_num(c):
+ if COLORDICT[c][0] is None:
+ return(COLORDICT[c][1])
+ else:
+ return(COLORDICT[c][0])
def _num_type(x):
@@ -447,8 +454,8 @@ pensize\rend\r')
self._make_constant(palette, 'blue', _('blue'), CONSTANTS['blue'])
self._make_constant(palette, 'purple', _('purple'),
CONSTANTS['purple'])
- self._make_constant(palette, 'white', _('white'), WHITE)
- self._make_constant(palette, 'black', _('black'), BLACK)
+ self._make_constant(palette, 'white', _('white'), CONSTANTS['white'])
+ self._make_constant(palette, 'black', _('black'), CONSTANTS['black'])
# deprecated blocks
palette.add_block('settextcolor',
@@ -1241,6 +1248,10 @@ variable'))
def _prim_plus(self, x, y):
""" Add numbers, concat strings """
+ if x in COLORDICT:
+ x = _color_to_num(x)
+ if y in COLORDICT:
+ y = _color_to_num(y)
if _num_type(x) and _num_type(y):
return(x + y)
elif type(x) == list and type(y) == list:
@@ -1341,6 +1352,7 @@ variable'))
def _string_to_num(self, x):
""" Try to comvert a string to a number """
+ print x
if type(x) is float:
return(x)
if type(x) is int:
@@ -1349,6 +1361,8 @@ variable'))
return(int(x))
if type(x) is list:
raise logoerror("#syntaxerror")
+ if x in COLORDICT:
+ return _color_to_num(x)
xx = convert(x.replace(self.tw.decimal_point, '.'), float)
if type(xx) is float:
return xx