Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArtActivity.py
diff options
context:
space:
mode:
authorDaniel Francis <francis@sugarlabs.org>2013-12-03 18:17:42 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-12-03 18:17:42 (GMT)
commit3eb32aa6c17543f59d4d90d7194f8278a4954bef (patch)
tree8619be9f8ab5d88afda7dfcf1f361a058f815d0d /TurtleArtActivity.py
parentcd9c77a8866e25b587f5a625c6646a5f7d2e740a (diff)
Add load-plugin support to GNOME version
Diffstat (limited to 'TurtleArtActivity.py')
-rw-r--r--TurtleArtActivity.py115
1 files changed, 8 insertions, 107 deletions
diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py
index f15650e..f3cb17f 100644
--- a/TurtleArtActivity.py
+++ b/TurtleArtActivity.py
@@ -63,6 +63,8 @@ except ImportError:
from gettext import gettext as _
+from TurtleArt.taplugin import (load_a_plugin, cancel_plugin_install,
+ complete_plugin_install)
from TurtleArt.tapalette import (palette_names, help_strings, help_palettes,
help_windows, default_values)
from TurtleArt.taconstants import (BLOCK_SCALE, XO1, XO15, XO175, XO4,
@@ -95,6 +97,8 @@ class TurtleArtActivity(activity.Activity):
self.tw = None
self.init_complete = False
+ self.bundle_path = activity.get_bundle_path()
+
self.error_list = []
self.palette_buttons = []
@@ -1337,109 +1341,6 @@ class TurtleArtActivity(activity.Activity):
self.metadata['error_list'] = data_to_string(errors)
_logger.debug('Wrote to file: %s' % (file_path))
- def _load_a_plugin(self, tmp_dir):
- ''' Load a plugin from the Journal and initialize it '''
- plugin_path = os.path.join(tmp_dir, 'plugin.info')
- _logger.debug(plugin_path)
- file_info = ConfigParser.ConfigParser()
- if len(file_info.read(plugin_path)) == 0:
- _logger.debug('Required file plugin.info could not be found.')
- self.tw.showlabel('status',
- label=_('Plugin could not be installed.'))
- elif not file_info.has_option('Plugin', 'name'):
- _logger.debug('Required open name not found in \
-Plugin section of plugin.info file.')
- self.tw.showlabel(
- 'status', label=_('Plugin could not be installed.'))
- else:
- plugin_name = file_info.get('Plugin', 'name')
- _logger.debug('Plugin name: %s' % (plugin_name))
- tmp_path = os.path.join(tmp_dir, plugin_name)
- plugin_path = os.path.join(activity.get_bundle_path(), 'plugins')
- if os.path.exists(os.path.join(plugin_path, plugin_name)):
- self._reload_plugin_alert(tmp_dir, tmp_path, plugin_path,
- plugin_name, file_info)
- else:
- self._complete_plugin_install(tmp_dir, tmp_path, plugin_path,
- plugin_name, file_info)
-
- def _complete_plugin_install(self, tmp_dir, tmp_path, plugin_path,
- plugin_name, file_info):
- ''' We complete the installation directly or from ConfirmationAlert '''
- status = subprocess.call(['cp', '-r', tmp_path, plugin_path + '/'])
- if status == 0:
- # Save the plugin.info file in the plugin directory
- subprocess.call(['cp', os.path.join(tmp_dir, 'plugin.info'),
- os.path.join(plugin_path, plugin_name) + '/'])
- _logger.debug('Plugin installed successfully.')
- if self.has_toolbarbox:
- palette_name_list = []
- if file_info.has_option('Plugin', 'palette'):
- palette_name_list = file_info.get(
- 'Plugin', 'palette').split(',')
- create_palette = []
- for palette_name in palette_name_list:
- if not palette_name.strip() in palette_names:
- create_palette.append(True)
- else:
- create_palette.append(False)
- _logger.debug('Initializing plugin...')
- self.tw.init_plugin(plugin_name)
- self.tw.turtleart_plugins[-1].setup()
- self.tw.load_media_shapes()
- for i, palette_name in enumerate(palette_name_list):
- if create_palette[i]:
- _logger.debug('Creating plugin palette %s (%d)' %
- (palette_name.strip(), i))
- j = len(self.palette_buttons)
- self.palette_buttons.append(
- self._radio_button_factory(
- palette_name.strip() + 'off',
- self._palette_toolbar,
- self.do_palette_buttons_cb,
- j - 1,
- help_strings[palette_name.strip()],
- self.palette_buttons[0]))
- self._overflow_buttons.append(
- self._add_button(
- palette_name.strip() + 'off',
- None,
- self.do_palette_buttons_cb,
- None,
- arg=j - 1))
- self._overflow_box.pack_start(
- self._overflow_buttons[j - 1])
- self.tw.palettes.insert(j - 1, [])
- self.tw.palette_sprs.insert(j - 1, [None, None])
- else:
- _logger.debug('Palette already exists... \
-skipping insert')
- # We need to change the index associated with the
- # Trash Palette Button.
- j = len(palette_names)
- pidx = palette_names.index(palette_name.strip())
- self.palette_buttons[pidx].connect(
- 'clicked', self.do_palette_buttons_cb, j - 1)
- self._overflow_buttons[pidx].connect(
- 'clicked', self.do_palette_buttons_cb, j - 1)
- _logger.debug('reinitializing palette toolbar')
- self._setup_palette_toolbar()
- else:
- self.tw.showlabel('status',
- label=_('Please restart Turtle Art \
-in order to use the plugin.'))
- else:
- self.tw.showlabel(
- 'status', label=_('Plugin could not be installed.'))
- status = subprocess.call(['rm', '-r', tmp_path])
- if status != 0:
- _logger.debug('Problems cleaning up tmp_path.')
- shutil.rmtree(tmp_dir)
-
- def _cancel_plugin_install(self, tmp_dir):
- ''' If we cancel, just cleanup '''
- shutil.rmtree(tmp_dir)
-
def _reload_plugin_alert(self, tmp_dir, tmp_path, plugin_path, plugin_name,
file_info):
''' We warn the user if the plugin was previously loaded '''
@@ -1453,12 +1354,12 @@ in order to use the plugin.'))
if response_id is gtk.RESPONSE_OK:
_logger.debug('continue to install')
self.remove_alert(alert)
- self._complete_plugin_install(tmp_dir, tmp_path, plugin_path,
- plugin_name, file_info)
+ complete_plugin_install(self, tmp_dir, tmp_path, plugin_path,
+ plugin_name, file_info)
elif response_id is gtk.RESPONSE_CANCEL:
_logger.debug('cancel install')
self.remove_alert(alert)
- self._cancel_plugin_install(tmp_dir)
+ cancel_plugin_install(self, tmp_dir)
alert.connect('response', _reload_plugin_alert_response_cb, self,
tmp_dir, tmp_path, plugin_path, plugin_name, file_info)
@@ -1501,7 +1402,7 @@ in order to use the plugin.'))
gobject.idle_add(self._project_loader, turtle_code)
else:
_logger.debug('load a plugin from %s' % (tmp_dir))
- self._load_a_plugin(tmp_dir)
+ load_a_plugin(self, tmp_dir)
self.restore_cursor()
except:
_logger.debug('Could not extract files from %s.' %