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/tawindow.py') 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