Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Poirier <simpoir@gmail.com>2009-10-27 19:25:12 (GMT)
committer Simon Poirier <simpoir@gmail.com>2009-10-27 19:25:12 (GMT)
commit636ea828404401df256b234f254bad32c70aba66 (patch)
tree5db056380d566436378dc450061e76f453bfb35b
parent660a5bd1e0a24d83fc963a83097b540bc2f28eaa (diff)
code review related fixes
-rw-r--r--addons/gtkwidgeteventfilter.py4
-rw-r--r--data/ui/creator.glade (renamed from tutorius/ui/creator.glade)0
-rwxr-xr-xsetup.py5
-rw-r--r--tutorius/creator.py62
-rw-r--r--tutorius/properties.py8
-rw-r--r--tutorius/viewer.py31
6 files changed, 69 insertions, 41 deletions
diff --git a/addons/gtkwidgeteventfilter.py b/addons/gtkwidgeteventfilter.py
index 5811744..8d8ff38 100644
--- a/addons/gtkwidgeteventfilter.py
+++ b/addons/gtkwidgeteventfilter.py
@@ -14,7 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from sugar.tutorius.filters import EventFilter
-from sugar.tutorius.properties import TUAMProperty, TGtkSignal
+from sugar.tutorius.properties import TUAMProperty, TEventType
from sugar.tutorius.gtkutils import find_widget
class GtkWidgetEventFilter(EventFilter):
@@ -22,7 +22,7 @@ class GtkWidgetEventFilter(EventFilter):
Basic Event filter for Gtk widget events
"""
object_id = TUAMProperty()
- event_name = TGtkSignal('clicked')
+ event_name = TEventType('clicked')
def __init__(self, object_id=None, event_name=None):
"""Constructor
diff --git a/tutorius/ui/creator.glade b/data/ui/creator.glade
index 1c9669d..1c9669d 100644
--- a/tutorius/ui/creator.glade
+++ b/data/ui/creator.glade
diff --git a/setup.py b/setup.py
index 23e8532..a994937 100755
--- a/setup.py
+++ b/setup.py
@@ -98,9 +98,10 @@ setup(name='Tutorius',
'sugar.tutorius': 'tutorius',
'sugar.tutorius.addons': 'addons',
},
- package_data={'sugar.tutorius': ['ui/*.glade']},
cmdclass = {'test': TestCommand},
- data_files=[('share/icons/sugar/scalable/actions', glob.glob('data/icons/*.svg')),]
+ data_files=[('share/icons/sugar/scalable/actions', glob.glob('data/icons/*.svg')),
+ ('share/tutorius/ui', glob.glob('data/ui/*.glade')),
+ ]
)
# vim: set et sw=4 sts=4 ts=4:
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.
diff --git a/tutorius/properties.py b/tutorius/properties.py
index 68e6091..b9e6267 100644
--- a/tutorius/properties.py
+++ b/tutorius/properties.py
@@ -331,14 +331,14 @@ class TAddonProperty(TutoriusProperty):
return super(TAddonProperty, self).validate(value)
raise ValueError("Expected TPropContainer instance as TaddonProperty value")
-class TGtkSignal(TutoriusProperty):
+class TEventType(TutoriusProperty):
"""
- Represents a gobject signal for a GTK widget.
+ Represents an GUI signal for a widget.
"""
def __init__(self, value):
- TutoriusProperty.__init__(self)
+ super(TEventType, self).__init__()
self.type = "gtk-signal"
-
+
self.default = self.validate(value)
class TAddonListProperty(TutoriusProperty):
diff --git a/tutorius/viewer.py b/tutorius/viewer.py
index 751e89a..272558e 100644
--- a/tutorius/viewer.py
+++ b/tutorius/viewer.py
@@ -75,13 +75,11 @@ class Viewer(object):
self.win.set_deletable(False)
self.win.move(0, 0)
- #vbox = gtk.VBox()
vbox = gtk.ScrolledWindow()
self.win.add(vbox)
canvas = gtk.DrawingArea()
- #vbox.pack_start(canvas)
- vbox.add_with_viewport(canvas) # temp
+ vbox.add_with_viewport(canvas)
canvas.set_app_paintable(True)
canvas.connect_after("expose-event", self.on_viewer_expose, tutorial._states)
canvas.add_events(gtk.gdk.BUTTON_PRESS_MASK \
@@ -97,9 +95,6 @@ class Viewer(object):
canvas.set_flags(gtk.HAS_FOCUS|gtk.CAN_FOCUS)
canvas.grab_focus()
- #self.scroll = gtk.HScrollbar()
- #vbox.pack_end(self.scroll, False)
-
self.win.show_all()
canvas.set_size_request(2048, 180) # FIXME
@@ -221,6 +216,9 @@ class Viewer(object):
yield False
def _render_snapshot(self, ctx, elem):
+ """
+ Render the "simplified screenshot-like" representation of elements positions.
+ """
ctx.set_source_rgba(1.0, 1.0, 1.0, 0.5)
ctx.rectangle(0, 0, SNAP_WIDTH, SNAP_HEIGHT)
ctx.fill_preserve()
@@ -236,6 +234,10 @@ class Viewer(object):
ctx.stroke()
def _render_app_hints(self, ctx, appname):
+ """
+ Fetches the icon of the app related to current states and renders it on a
+ separator, between states.
+ """
ctx.set_source_rgb(0.0, 0.0, 0.0)
ctx.set_dash((1,1,0,0), 1)
ctx.move_to(0, 0)
@@ -255,6 +257,9 @@ class Viewer(object):
def render_action(self, ctx, width, height, action):
+ """
+ Renders the action block, along with the icon of the action tool.
+ """
ctx.save()
inner_width = width-(BLOCK_CORNERS<<1)
inner_height = height-(BLOCK_CORNERS<<1)
@@ -300,6 +305,9 @@ class Viewer(object):
ctx.restore()
def render_event(self, ctx, width, height, event):
+ """
+ Renders the action block, along with the icon of the action tool.
+ """
ctx.save()
inner_width = width-(BLOCK_CORNERS<<1)
inner_height = height-(BLOCK_CORNERS<<1)
@@ -347,13 +355,22 @@ class Viewer(object):
ctx.restore()
def on_viewer_expose(self, widget, evt, states):
+ """
+ Expose signal handler for the viewer's DrawingArea.
+ This loops through states and renders every action and transition of
+ the "happy path".
+
+ @param widget: the gtk.DrawingArea on which to draw
+ @param evt: the gtk.gdk.Event containing an "expose" event
+ @param states: a tutorius FiniteStateMachine object to paint
+ """
ctx = widget.window.cairo_create()
self.alloc = widget.get_allocation()
ctx.set_source_pixmap(widget.window,
widget.allocation.x,
widget.allocation.y)
- #draw no more than our expose event intersects our child
+ # draw no more than our expose event intersects our child
region = gtk.gdk.region_rectangle(widget.allocation)
r = gtk.gdk.region_rectangle(evt.area)
region.intersect(r)