diff options
author | Marion Zepf <marion.zepf@gmail.com> | 2013-10-27 02:06:05 (GMT) |
---|---|---|
committer | Walter Bender <walter@sugarlabs.org> | 2013-10-27 02:06:05 (GMT) |
commit | 629722d8859d1e8db47417673cb78963d41ce435 (patch) | |
tree | d188a0c26c724bc151c3449eb7a5613777f2ed40 /TurtleArt/tautils.py | |
parent | 8ac55749fbe9672ea3f403c93713b403efac46af (diff) |
python export
Diffstat (limited to 'TurtleArt/tautils.py')
-rw-r--r-- | TurtleArt/tautils.py | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py index b0aa368..634ee01 100644 --- a/TurtleArt/tautils.py +++ b/TurtleArt/tautils.py @@ -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] @@ -808,6 +806,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 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 ''' |