From c80ccaf443dc6f1ea9dd59f45e60e8d7fa525fa1 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Tue, 08 Oct 2013 20:44:17 +0000 Subject: resync with 191 changes --- (limited to 'TurtleArt') diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py index beccd2a..3d1eb10 100644 --- a/TurtleArt/tabasics.py +++ b/TurtleArt/tabasics.py @@ -70,7 +70,7 @@ 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 tautils import (convert, chr_to_ord, round_int, strtype, debug_output) from taconstants import (COLORDICT, CONSTANTS) @@ -119,6 +119,8 @@ class Palettes(): def _turtle_palette(self): ''' The basic Turtle Art turtle palette ''' + debug_output('creating %s palette' % _('turtle'), + self.tw.running_sugar) palette = make_palette('turtle', colors=["#00FF00", "#00A000"], help_string=_('Palette of turtle commands')) @@ -276,10 +278,11 @@ turtle (can be used in place of a number block)'), 0, lambda self: self.tw.turtles.get_active_turtle().get_heading()) + # This block is used for holding the remote turtle name palette.add_block('turtle-label', hidden=True, style='blank-style', - label=['turtle']) + label=['remote turtle name']) # Deprecated palette.add_block('setxy', @@ -303,6 +306,8 @@ setxy :x :y\npendown\nend\n') def _pen_palette(self): ''' The basic Turtle Art pen palette ''' + debug_output('creating %s palette' % _('pen'), + self.tw.running_sugar) palette = make_palette('pen', colors=["#00FFFF", "#00A0A0"], help_string=_('Palette of pen commands')) @@ -503,6 +508,8 @@ pensize\nend\n') def _color_palette(self): ''' The basic Turtle Art color palette ''' + debug_output('creating %s palette' % _('colors'), + self.tw.running_sugar) palette = make_palette('colors', colors=["#00FFFF", "#00A0A0"], help_string=_('Palette of pen colors')) @@ -596,6 +603,8 @@ tasetshade :shade \n') def _numbers_palette(self): ''' The basic Turtle Art numbers palette ''' + debug_output('creating %s palette' % _('numbers'), + self.tw.running_sugar) palette = make_palette('numbers', colors=["#FF00FF", "#A000A0"], help_string=_('Palette of numeric operators')) @@ -779,6 +788,8 @@ operators')) def _flow_palette(self): ''' The basic Turtle Art flow palette ''' + debug_output('creating %s palette' % _('flow'), + self.tw.running_sugar) palette = make_palette('flow', colors=["#FFC000", "#A08000"], help_string=_('Palette of flow operators')) @@ -879,6 +890,8 @@ boolean operators from Numbers palette')) def _blocks_palette(self): ''' The basic Turtle Art blocks palette ''' + debug_output('creating %s palette' % _('blocks'), + self.tw.running_sugar) palette = make_palette('blocks', colors=["#FFFF00", "#A0A000"], help_string=_('Palette of variable blocks')) @@ -1040,6 +1053,8 @@ variable')) def _trash_palette(self): ''' The basic Turtle Art turtle palette ''' + debug_output('creating %s palette' % _('trash'), + self.tw.running_sugar) palette = make_palette('trash', colors=["#FFFF00", "#A0A000"], help_string=_('trash')) diff --git a/TurtleArt/tagplay.py b/TurtleArt/tagplay.py index 2fc6919..9e9f821 100644 --- a/TurtleArt/tagplay.py +++ b/TurtleArt/tagplay.py @@ -235,9 +235,8 @@ class GstPlayer(gobject.GObject): elif t == gst.MESSAGE_STATE_CHANGED: old, new, pen = message.parse_state_changed() if old == gst.STATE_READY and new == gst.STATE_PAUSED: - if hasattr(self.player.props, 'stream_info_value_array'): - self.emit('stream-info', - self.player.props.stream_info_value_array) + self.emit('stream-info', + self.player.props.stream_info_value_array) # else: # logging.debug(message.type) diff --git a/TurtleArt/tapalette.py b/TurtleArt/tapalette.py index 3c38722..6fd347a 100644 --- a/TurtleArt/tapalette.py +++ b/TurtleArt/tapalette.py @@ -22,6 +22,7 @@ help_palettes = {} help_windows = {} palette_names = [] +palette_i18n_names = [] palette_init_on_start = [] palette_blocks = [] block_colors = [] @@ -128,12 +129,14 @@ class Palette(): def add_palette(self, position=None, init_on_start=False): if self._name is None: - debug_output('You must specify a name for your palette') + print 'You must specify a name for your palette' return # Insert new palette just before the trash if 'trash' in palette_names: i = palette_names.index('trash') + elif _('trash') in palette_i18n_names: + i = palette_i18n_names.index(_('trash')) else: i = len(palette_names) @@ -142,6 +145,7 @@ class Palette(): if self._name not in palette_names: palette_names.insert(i, self._name) + palette_i18n_names.insert(i, _(self._name)) palette_blocks.insert(i, []) block_colors.insert(i, self._colors) if init_on_start: @@ -236,6 +240,8 @@ def palette_name_to_index(palette_name): ''' Find the index associated with palette_name. ''' if palette_name in palette_names: return palette_names.index(palette_name) + elif palette_name in palette_i18n_names: + return palette_i18n_names.index(palette_name) else: return None @@ -267,7 +273,7 @@ class Block(): def add_block(self, position=None): if self._name is None: - debug_output('You must specify a name for your block') + print 'You must specify a name for your block' return # FIXME: Does the block already exist? A block can live on @@ -276,7 +282,7 @@ class Block(): # all lists except palettes before regeneration. if self._style is None: - debug_output('You must specify a style for your block') + print 'You must specify a style for your block' return else: block_styles[self._style].append(self._name) @@ -293,8 +299,8 @@ class Block(): if self._palette is not None: i = palette_names.index(self._palette) if self._name in palette_blocks[i]: - debug_output('%s already in palette %s, skipping...' % - (self._name, self._palette)) + print '%s already in palette %s, skipping...' % \ + (self._name, self._palette) else: if position is not None and isinstance(position, int) and \ position < len(palette_blocks[i]): @@ -302,8 +308,7 @@ class Block(): else: palette_blocks[i].append(self._name) if position is not None: - debug_output('Ignoring position (%s)' % - (str(position))) + print 'Ignoring position (%s)' % (str(position)) if self._help is not None: help_strings[self._name] = self._help @@ -357,7 +362,7 @@ class Block(): def set_palette(self, palette): if not palette in palette_names: - debug_output('Could not find palette %s' % (palette)) + print 'Could not find palette %s' % (palette) else: self._palette = palette @@ -381,7 +386,7 @@ class Block(): def set_style(self, style): if style not in block_styles: - debug_output('Unknown style: %s' % (style)) + print 'Unknown style: %s' % (style) else: self._style = style diff --git a/TurtleArt/taturtle.py b/TurtleArt/taturtle.py index 5e24ce7..b87d0a6 100644 --- a/TurtleArt/taturtle.py +++ b/TurtleArt/taturtle.py @@ -34,6 +34,7 @@ from tacanvas import wrap100, COLOR_TABLE from sprites import Sprite from tautils import (debug_output, data_to_string, round_int, get_path, image_to_base64) +from TurtleArt.talogo import logoerror SHAPES = 36 DEGTOR = pi / 180. @@ -151,6 +152,27 @@ class Turtles: self._active_turtle.hide() self.set_turtle(self._default_turtle_name) + def get_turtle_x(self, turtle_name): + if turtle_name not in self.dict: + debug_output('%s not found in turtle dictionary' % (turtle_name), + self.turtle_window.running_sugar) + raise logoerror("#syntaxerror") + return self.dict[turtle_name].get_x() + + def get_turtle_y(self, turtle_name): + if turtle_name not in self.dict: + debug_output('%s not found in turtle dictionary' % (turtle_name), + self.turtle_window.running_sugar) + raise logoerror("#syntaxerror") + return self.dict[turtle_name].get_y() + + def get_turtle_heading(self, turtle_name): + if turtle_name not in self.dict: + debug_output('%s not found in turtle dictionary' % (turtle_name), + self.turtle_window.running_sugar) + raise logoerror("#syntaxerror") + return self.dict[turtle_name].get_heading() + def set_turtle(self, turtle_name, colors=None): ''' Select the current turtle and associated pen status ''' if turtle_name not in self.dict: diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index af611a3..2bd720e 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -382,6 +382,7 @@ class TurtleArtWindow(): except Exception as e: debug_output('Failed to load %s: %s' % (plugin_class, str(e)), self.running_sugar) + def _add_plugin_icon_dir(self, dirname): ''' If there is an icon subdir, add it to the search path. ''' @@ -404,38 +405,73 @@ class TurtleArtWindow(): def _setup_plugins(self): ''' Initial setup -- called just once. ''' for plugin in self.turtleart_plugins: - plugin.setup() + try: + plugin.setup() + except Exception as e: + debug_output('Plugin %s failed during setup: %s' % + (plugin, str(e)), self.running_sugar) + # If setup fails, remove the plugin from the list + self.turtleart_plugins.remove(plugin) def _start_plugins(self): ''' Start is called everytime we execute blocks. ''' for plugin in self.turtleart_plugins: - plugin.start() + if hasattr(plugin, 'start'): + try: + plugin.start() + except Exception as e: + debug_output('Plugin %s failed during start: %s' % + (plugin, str(e)), self.running_sugar) def stop_plugins(self): ''' Stop is called whenever we stop execution. ''' for plugin in self.turtleart_plugins: - plugin.stop() + if hasattr(plugin, 'stop'): + try: + plugin.stop() + except Exception as e: + debug_output('Plugin %s failed during stop: %s' % + (plugin, str(e)), self.running_sugar) def clear_plugins(self): ''' Clear is called from the clean block and erase button. ''' for plugin in self.turtleart_plugins: if hasattr(plugin, 'clear'): - plugin.clear() + try: + plugin.clear() + except Exception as e: + debug_output('Plugin %s failed during clear: %s' % + (plugin, str(e)), self.running_sugar) def background_plugins(self): ''' Background is called when we are pushed to the background. ''' for plugin in self.turtleart_plugins: - plugin.goto_background() + if hasattr(plugin, 'goto_background'): + try: + plugin.goto_background() + except Exception as e: + debug_output('Plugin %s failed during background: %s' % + (plugin, str(e)), self.running_sugar) def foreground_plugins(self): ''' Foreground is called when we are return from the background. ''' for plugin in self.turtleart_plugins: - plugin.return_to_foreground() + if hasattr(plugin, 'return_to_foreground'): + try: + plugin.return_to_foreground() + except Exception as e: + debug_output('Plugin %s failed during foreground: %s' % + (plugin, str(e)), self.running_sugar) def quit_plugins(self): ''' Quit is called upon program exit. ''' for plugin in self.turtleart_plugins: - plugin.quit() + if hasattr(plugin, 'quit'): + try: + plugin.quit() + except Exception as e: + debug_output('Plugin %s failed during quit: %s' % + (plugin, str(e)), self.running_sugar) def _setup_events(self): ''' Register the events we listen to. ''' @@ -1002,7 +1038,8 @@ class TurtleArtWindow(): self.running_sugar) else: blk.spr.hide() - if 'trash' in palette_names and n == palette_names.index('trash'): + if 'trash' in palette_names and \ + n == palette_names.index('trash'): for blk in self.trash_stack: # Deprecated for gblk in find_group(blk): @@ -1545,9 +1582,9 @@ before making changes to your program')) self._restore_from_trash(find_top_block(blk)) elif blk.type == 'proto': if self.deleting_blocks: - if 'myblocks' in palette_names and \ + if 'my blocks' in palette_names and \ self.selected_palette == \ - palette_names.index('myblocks'): + palette_names.index('my blocks'): self._delete_stack_alert(blk) self.parent.get_window().set_cursor( gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)) @@ -1569,8 +1606,9 @@ before making changes to your program')) self._put_in_trash(b1) else: self._put_in_trash(find_top_block(b)) - self.show_toolbar_palette(palette_names.index('trash'), - regenerate=True) + if 'trash' in palette_names: + self.show_toolbar_palette( + palette_names.index('trash'), regenerate=True) elif blk.name in MACROS: self.new_macro(blk.name, x + 20, y + 20) else: @@ -1752,7 +1790,7 @@ before making changes to your program')) error_output('Could not remove macro %s: %s' % (macro_path, e)) return - i = palette_names.index('myblocks') + i = palette_names.index('my blocks') palette_blocks[i].remove(blk.name) for pblk in self.palettes[i]: if pblk.name == blk.name: @@ -2117,8 +2155,9 @@ before making changes to your program')) blk.type = 'deleted' blk.spr.hide() self.trash_stack = [] - self.show_toolbar_palette(palette_names.index('trash'), - regenerate=True) + if 'trash' in palette_names: + self.show_toolbar_palette(palette_names.index('trash'), + regenerate=True) def _in_the_trash(self, x, y): ''' Is x, y over a palette? ''' -- cgit v0.9.1