Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius
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 /tutorius
parent660a5bd1e0a24d83fc963a83097b540bc2f28eaa (diff)
code review related fixes
Diffstat (limited to 'tutorius')
-rw-r--r--tutorius/creator.py62
-rw-r--r--tutorius/properties.py8
-rw-r--r--tutorius/ui/creator.glade209
-rw-r--r--tutorius/viewer.py31
4 files changed, 64 insertions, 246 deletions
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/ui/creator.glade b/tutorius/ui/creator.glade
deleted file mode 100644
index 1c9669d..0000000
--- a/tutorius/ui/creator.glade
+++ /dev/null
@@ -1,209 +0,0 @@
-<?xml version="1.0"?>
-<glade-interface>
- <!-- interface-requires gtk+ 2.16 -->
- <!-- interface-naming-policy project-wide -->
- <widget class="GtkWindow" id="mainwindow">
- <property name="width_request">300</property>
- <property name="height_request">500</property>
- <property name="title" translatable="yes">Toolbox</property>
- <property name="resizable">False</property>
- <property name="window_position">center-on-parent</property>
- <property name="default_width">200</property>
- <property name="default_height">500</property>
- <property name="destroy_with_parent">True</property>
- <property name="skip_taskbar_hint">True</property>
- <property name="skip_pager_hint">True</property>
- <property name="focus_on_map">False</property>
- <property name="deletable">False</property>
- <signal name="destroy" handler="on_mainwindow_destroy"/>
- <child>
- <widget class="GtkVBox" id="vbox1">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">5</property>
- <child>
- <widget class="GtkHButtonBox" id="hbuttonbox1">
- <property name="visible">True</property>
- <property name="spacing">5</property>
- <property name="layout_style">start</property>
- <child>
- <widget class="GtkButton" id="button2">
- <property name="label">gtk-save</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
- <signal name="clicked" handler="on_save_clicked"/>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <widget class="GtkButton" id="button4">
- <property name="label">gtk-quit</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
- <signal name="clicked" handler="on_quit_clicked"/>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <widget class="GtkScrolledWindow" id="scrolledwindow1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">never</property>
- <property name="vscrollbar_policy">automatic</property>
- <property name="shadow_type">in</property>
- <child>
- <widget class="GtkViewport" id="viewport1">
- <property name="visible">True</property>
- <property name="resize_mode">queue</property>
- <child>
- <widget class="GtkVBox" id="vbox2">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <child>
- <widget class="GtkExpander" id="expander1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="expanded">True</property>
- <child>
- <widget class="GtkIconView" id="iconview1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="columns">2</property>
- <property name="row_spacing">0</property>
- <property name="column_spacing">0</property>
- <property name="item_padding">0</property>
- <signal name="item_activated" handler="on_action_activate"/>
- </widget>
- </child>
- <child>
- <widget class="GtkLabel" id="label3">
- <property name="visible">True</property>
- <property name="label" translatable="yes">actions</property>
- </widget>
- <packing>
- <property name="type">label_item</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <widget class="GtkExpander" id="expander2">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="expanded">True</property>
- <child>
- <widget class="GtkIconView" id="iconview2">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="columns">2</property>
- <property name="row_spacing">0</property>
- <property name="column_spacing">0</property>
- <property name="item_padding">0</property>
- <signal name="item_activated" handler="on_event_activate"/>
- </widget>
- </child>
- <child>
- <widget class="GtkLabel" id="label2">
- <property name="visible">True</property>
- <property name="label" translatable="yes">events</property>
- </widget>
- <packing>
- <property name="type">label_item</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
- </child>
- </widget>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <widget class="GtkVBox" id="propbox">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">10</property>
- <child>
- <placeholder/>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="padding">5</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <widget class="GtkHButtonBox" id="hbuttonbox2">
- <property name="visible">True</property>
- <property name="spacing">5</property>
- <property name="layout_style">start</property>
- <child>
- <widget class="GtkButton" id="button1">
- <property name="label">gtk-media-record</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <widget class="GtkButton" id="button3">
- <property name="label">gtk-media-stop</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">3</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
-</glade-interface>
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)