Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2014-01-24 00:06:43 (GMT)
committer Walter Bender <walter@sugarlabs.org>2014-01-24 00:06:43 (GMT)
commit30ff5e89db6ac91b6bc49d15f4d2e7984fc0bc0a (patch)
tree77e1ded186bd89cc89c5a6b9da3e94a4d7cdc409
parente07c9f11f03e239e56345ea05bd34b31716b52f9 (diff)
fix to color constant block
-rw-r--r--TurtleArt/taconstants.py23
-rw-r--r--TurtleArt/talogo.py2
-rw-r--r--TurtleArt/taturtle.py7
-rw-r--r--TurtleArt/tatype.py3
4 files changed, 31 insertions, 4 deletions
diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py
index a8fc046..0a3cc23 100644
--- a/TurtleArt/taconstants.py
+++ b/TurtleArt/taconstants.py
@@ -151,6 +151,26 @@ REVERSE_KEY_DICT = {
}
+class ColorObj(object):
+ def __init__(self, color):
+ self.color = color
+
+ def __int__(self):
+ if self.color.color is None:
+ return int(self.color.shade)
+ else:
+ return int(self.color.color)
+
+ def __float__(self):
+ return float(int(self))
+
+ def __str__(self):
+ return str(self.color.name)
+
+ def __repr__(self):
+ return str(self.color.name)
+
+
class Color(object):
""" A color used in block programs (e.g., as pen color). """
@@ -176,6 +196,9 @@ class Color(object):
def get_number_string(self):
return str(int(self))
+ def get_number_name(self):
+ return str(self.name)
+
def __str__(self):
return str(self.name)
diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py
index 7307b99..ab7250a 100644
--- a/TurtleArt/talogo.py
+++ b/TurtleArt/talogo.py
@@ -41,7 +41,7 @@ except ImportError:
import traceback
from tablock import (Block, Media, media_blocks_dictionary)
-from taconstants import (TAB_LAYER, DEFAULT_SCALE, ICON_SIZE)
+from taconstants import (TAB_LAYER, DEFAULT_SCALE, ICON_SIZE, Color)
from tajail import (myfunc, myfunc_import)
from tapalette import (block_names, value_blocks)
from tatype import (TATypeError, TYPES_NUMERIC)
diff --git a/TurtleArt/taturtle.py b/TurtleArt/taturtle.py
index c3c7831..9845b07 100644
--- a/TurtleArt/taturtle.py
+++ b/TurtleArt/taturtle.py
@@ -28,7 +28,7 @@ import cairo
from random import uniform
from math import sin, cos, pi, sqrt
from taconstants import (TURTLE_LAYER, DEFAULT_TURTLE_COLORS, DEFAULT_TURTLE,
- Color)
+ CONSTANTS, Color, ColorObj)
from tasprite_factory import SVG, svg_str_to_pixbuf
from tacanvas import wrap100, COLOR_TABLE
from sprites import Sprite
@@ -368,9 +368,12 @@ class Turtle:
def set_color(self, color=None, share=True):
''' Set the pen color for this turtle. '''
+ if isinstance(color, ColorObj):
+ # See comment in tatype.py TYPE_BOX -> TYPE_COLOR
+ color = color.color
if color is None:
color = self._pen_color
- # Special case for color blocks
+ # Special case for color blocks from CONSTANTS
elif isinstance(color, Color):
self.set_shade(color.shade, share)
self.set_gray(color.gray, share)
diff --git a/TurtleArt/tatype.py b/TurtleArt/tatype.py
index 0fcfc3c..709a200 100644
--- a/TurtleArt/tatype.py
+++ b/TurtleArt/tatype.py
@@ -23,7 +23,7 @@
import ast
from tablock import Media
-from taconstants import (Color, CONSTANTS)
+from taconstants import (Color, ColorObj, CONSTANTS)
class Type(object):
@@ -189,6 +189,7 @@ TYPE_CONVERTERS = {
# converting A -> C must yield the same result as converting A -> B -> C.
# TYPE_OBJECT is the supertype of everything.
TYPE_BOX: {
+ TYPE_COLOR: ColorObj, # FIXME: should be Color.name
TYPE_FLOAT: float,
TYPE_INT: int,
TYPE_NUMBER: float,