diff options
author | Walter Bender <walter@sugarlabs.org> | 2013-11-13 22:42:18 (GMT) |
---|---|---|
committer | Walter Bender <walter@sugarlabs.org> | 2013-11-13 22:42:18 (GMT) |
commit | 6acdbc3db543f2692ee336a99722f5ab0b46c77e (patch) | |
tree | 97b84e77c63bddeb49bcb804e25e2457008f6a8d /TurtleArt/tautils.py | |
parent | 3865e3c912f70fd7fcef2d20831a0231d30d96f1 (diff) |
convert to new primitive type
Diffstat (limited to 'TurtleArt/tautils.py')
-rw-r--r-- | TurtleArt/tautils.py | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py index b0aa368..ff30b19 100644 --- a/TurtleArt/tautils.py +++ b/TurtleArt/tautils.py @@ -51,7 +51,7 @@ except (ImportError, AttributeError): from StringIO import StringIO from taconstants import (HIT_HIDE, HIT_SHOW, XO1, XO15, XO175, XO4, UNKNOWN, - MAGICNUMBER, SUFFIX) + MAGICNUMBER, SUFFIX, ARG_MUST_BE_NUMBER) import logging _logger = logging.getLogger('turtleart-activity') @@ -107,7 +107,7 @@ def chr_to_ord(x): ''' Try to comvert a string to an ord ''' if strtype(x) and len(x) == 1: try: - return ord(x[0]), True + return ord(x), True except ValueError: return x, False return x, False @@ -115,9 +115,7 @@ def chr_to_ord(x): def strtype(x): ''' Is x a string type? ''' - if isinstance(x, (str, unicode)): - return True - return False + return isinstance(x, basestring) def increment_name(name): @@ -311,7 +309,7 @@ def get_save_name(filefilter, load_save_folder, save_file_name): gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) - if filefilter in ['.png', '.svg', '.lg']: + if filefilter in ['.png', '.svg', '.lg', '.py']: suffix = filefilter else: suffix = SUFFIX[1] @@ -679,14 +677,11 @@ def arithmetic_check(blk1, blk2, dock1, dock2): return False if dock1 == 2 and zero_arg(blk2.values[0]): return False - elif blk1.name \ - in ['product2', 'minus2', 'random', 'remainder2', 'string'] and \ - blk2.name \ - in ['product2', 'minus2', 'random', 'remainder2', 'string']: + elif blk1.name in ARG_MUST_BE_NUMBER and blk2.name in ARG_MUST_BE_NUMBER: if blk1.name == 'string': if not numeric_arg(blk1.values[0]): return False - elif blk1.name == 'string': + elif blk2.name == 'string': if not numeric_arg(blk2.values[0]): return False elif blk1.name in ['greater2', 'less2'] and blk2.name == 'string': @@ -808,6 +803,30 @@ def find_blk_below(blk, namelist): return None +def get_stack_name(blk): + ''' Return the name of the action stack that the given block belongs to. + If the top block of this stack is not a stack-defining block, return + None. ''' + top_block = find_top_block(blk) + if top_block.name == 'start': + return 'start' + elif top_block.name == 'hat1': + return 'stack1' + elif top_block.name == 'hat2': + return 'stack2' + elif top_block.name == 'hat': + try: + return str(top_block.connections[1].values[0]) + except (AttributeError, TypeError, IndexError): + # AttributeError: t_b has no attribute 'connections' or t_b.c[1] + # has no attribute 'value' + # TypeError: t_b.c or t_b.c[1].v is not a subscriptable sequence + # IndexError: t_b.c or t_b.c[1].v is too short + return None + else: + return None + + def get_hardware(): ''' Determine whether we are using XO 1.0, 1.5, ... or 'unknown' hardware ''' |