From 636ea828404401df256b234f254bad32c70aba66 Mon Sep 17 00:00:00 2001 From: Simon Poirier Date: Tue, 27 Oct 2009 19:25:12 +0000 Subject: code review related fixes --- (limited to 'tutorius/creator.py') diff --git a/tutorius/creator.py b/tutorius/creator.py index b322b69..4f4cacc 100644 --- a/tutorius/creator.py +++ b/tutorius/creator.py @@ -30,10 +30,9 @@ import os from sugar.graphics import icon import copy -from sugar.tutorius import overlayer, gtkutils, actions, bundler, properties, addon -from sugar.tutorius import filters, __path__ +from sugar.tutorius import overlayer, gtkutils, actions, vault, properties, addon +from sugar.tutorius import filters from sugar.tutorius.services import ObjectStore -from sugar.tutorius.linear_creator import LinearCreator from sugar.tutorius.core import Tutorial, FiniteStateMachine, State from sugar.tutorius import viewer @@ -247,7 +246,7 @@ class Creator(object): def _add_action_cb(self, widget, path): """Callback for the action creation toolbar tool""" - action_type = self._propedit._actions_icons[path][2] + action_type = self._propedit.actions_list[path][ToolBox.ICON_NAME] action = addon.create(action_type) action.enter_editmode() self._state.add_action(action) @@ -258,7 +257,7 @@ class Creator(object): def _add_event_cb(self, widget, path): """Callback for the event creation toolbar tool""" - event_type = self._propedit._events_icons[path][2] + event_type = self._propedit.events_list[path][ToolBox.ICON_NAME] event = addon.create(event_type) addonname = type(event).__name__ meta = addon.get_addon_meta(addonname) @@ -267,7 +266,7 @@ class Creator(object): if isinstance(prop, properties.TUAMProperty): selector = WidgetSelector(self._activity) setattr(event, propname, selector.select()) - elif isinstance(prop, properties.TGtkSignal): + elif isinstance(prop, properties.TEventType): try: dlg = SignalInputDialog(self._activity, text="Mandatory property", @@ -297,7 +296,8 @@ class Creator(object): # blocks are shifted, full redraw is necessary self._overview.win.queue_draw() else: - # append empty event only if edit not inserting between events + # append empty state only if edit inserting at end of linearized + # tutorial. self._update_next_state(self._state, event, str(self._state_counter)) next_state = str(self._state_counter) new_state = State(name=str(self._state_counter)) @@ -364,7 +364,7 @@ class Creator(object): # prepare tutorial for serialization self.tuto = Tutorial(tutorialName, self._tutorial) - bundle = bundler.TutorialBundler(self._guid) + bundle = vault.TutorialBundler(self._guid) self._guid = bundle.Guid bundle.write_metadata_file(self.tuto) bundle.write_fsm(self._tutorial) @@ -380,10 +380,16 @@ class Creator(object): launch = staticmethod(launch) class ToolBox(object): + ICON_LABEL = 0 + ICON_IMAGE = 1 + ICON_NAME = 2 + ICON_TIP = 3 def __init__(self, parent): super(ToolBox, self).__init__() self.__parent = parent - glade_file = os.path.join(__path__[0], 'ui', 'creator.glade') + sugar_prefix = os.getenv("SUGAR_PREFIX",default="/usr") + glade_file = os.path.join(sugar_prefix, 'share', 'tutorius', + 'ui', 'creator.glade') self.tree = gtk.glade.XML(glade_file) self.window = self.tree.get_widget('mainwindow') self._propbox = self.tree.get_widget('propbox') @@ -391,10 +397,10 @@ class ToolBox(object): self.window.set_transient_for(parent) self._action = None - self._actions_icons = gtk.ListStore(str, gtk.gdk.Pixbuf, str, str) - self._actions_icons.set_sort_column_id(0, gtk.SORT_ASCENDING) - self._events_icons = gtk.ListStore(str, gtk.gdk.Pixbuf, str, str) - self._events_icons.set_sort_column_id(0, gtk.SORT_ASCENDING) + self.actions_list = gtk.ListStore(str, gtk.gdk.Pixbuf, str, str) + self.actions_list.set_sort_column_id(self.ICON_LABEL, gtk.SORT_ASCENDING) + self.events_list = gtk.ListStore(str, gtk.gdk.Pixbuf, str, str) + self.events_list.set_sort_column_id(self.ICON_LABEL, gtk.SORT_ASCENDING) for toolname in addon.list_addons(): meta = addon.get_addon_meta(toolname) @@ -404,20 +410,20 @@ class ToolBox(object): label = format_multiline(meta['display_name']) if meta['type'] == addon.TYPE_ACTION: - self._actions_icons.append((label, img, toolname, meta['display_name'])) + self.actions_list.append((label, img, toolname, meta['display_name'])) else: - self._events_icons.append((label, img, toolname, meta['display_name'])) - - iconview1 = self.tree.get_widget('iconview1') - iconview1.set_model(self._actions_icons) - iconview1.set_text_column(0) - iconview1.set_pixbuf_column(1) - iconview1.set_tooltip_column(3) - iconview2 = self.tree.get_widget('iconview2') - iconview2.set_model(self._events_icons) - iconview2.set_text_column(0) - iconview2.set_pixbuf_column(1) - iconview2.set_tooltip_column(3) + self.events_list.append((label, img, toolname, meta['display_name'])) + + iconview_action = self.tree.get_widget('iconview1') + iconview_action.set_model(self.actions_list) + iconview_action.set_text_column(self.ICON_LABEL) + iconview_action.set_pixbuf_column(self.ICON_IMAGE) + iconview_action.set_tooltip_column(self.ICON_TIP) + iconview_event = self.tree.get_widget('iconview2') + iconview_event.set_model(self.events_list) + iconview_event.set_text_column(self.ICON_LABEL) + iconview_event.set_pixbuf_column(self.ICON_IMAGE) + iconview_event.set_tooltip_column(self.ICON_TIP) self.window.show() @@ -677,6 +683,10 @@ class TextInputDialog(gtk.MessageDialog): def _dialog_done_cb(self, entry, response): self.response(response) +# The purpose of this function is to reformat text, as current IconView +# implentation does not insert carriage returns on long lines. +# To preserve layout, this call reformat text to fit in small space under an +# icon. def format_multiline(text, length=10, lines=3, line_separator='\n'): """ Reformat a text to fit in a small space. -- cgit v0.9.1