Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
diff options
context:
space:
mode:
authorC. Scott Ananian <cscott@laptop.org>2007-12-18 20:09:54 (GMT)
committer C. Scott Ananian <cscott@laptop.org>2007-12-18 20:09:54 (GMT)
commit259bd3d0e475eb1996e6aca2a726ee9f6ad63846 (patch)
tree2a6e2a6147e2439024a6439a6045ef4c904f9912 /activity.py
parent622d1fb0d3136c5f2f6c061d75c34c1344703d84 (diff)
Make the 'view source' key work in Pippy and generated activities.
Also register Pippy as a handler for text/x-python.
Diffstat (limited to 'activity.py')
-rw-r--r--activity.py51
1 files changed, 45 insertions, 6 deletions
diff --git a/activity.py b/activity.py
index 67da456..6f6c9d1 100644
--- a/activity.py
+++ b/activity.py
@@ -1,17 +1,56 @@
from sugar.activity import activity
-import os, sys
-import gtk, pango, vte
+class ViewSourceActivity(activity.Activity):
+ """Activity subclass which handles the 'view source' key."""
+ def __init__(self, handle):
+ super(ViewSourceActivity, self).__init__(handle)
+ self.__source_object_id = None # XXX: persist this across invocations?
+ self.connect('key-press-event', self._key_press_cb)
+ def _key_press_cb(self, widget, event):
+ import gtk
+ if gtk.gdk.keyval_name(event.keyval) == 'XF86Start':
+ self.view_source()
+ return True
+ return False
+ def view_source(self):
+ """Implement the 'view source' key by saving pippy_app.py to the
+ datastore, and then telling the Journal to view it."""
+ if self.__source_object_id is None:
+ from sugar import profile
+ from sugar.datastore import datastore
+ from sugar.activity.activity import get_bundle_name, get_bundle_path
+ from gettext import gettext as _
+ import os.path
+ jobject = datastore.create()
+ metadata = {
+ 'title': _('%s Source') % get_bundle_name(),
+ 'title_set_by_user': '1',
+ 'suggested_filename': 'pippy_app.py',
+ 'icon-color': profile.get_color().to_string(),
+ 'mime_type': 'text/x-python',
+ }
+ for k,v in metadata.items():
+ jobject.metadata[k] = v # dict.update method is missing =(
+ jobject.file_path = os.path.join(get_bundle_path(), 'pippy_app.py')
+ datastore.write(jobject)
+ self.__source_object_id = jobject.object_id
+ jobject.destroy()
+ self.journal_show_object(self.__source_object_id)
+ def journal_show_object(self, object_id):
+ """Invoke parent class' journal_show_object if it exists."""
+ s = super(ViewSourceActivity, self)
+ if hasattr(s, 'journal_show_object'):
+ s.journal_show_object(object_id)
+
-class VteActivity(activity.Activity):
+class VteActivity(ViewSourceActivity):
def __init__(self, handle):
- activity.Activity.__init__(self, handle)
+ import gtk, pango, vte
+ super(VteActivity, self).__init__(handle)
toolbox = activity.ActivityToolbox(self)
self.set_toolbox(toolbox)
toolbox.show()
- # XXX: NEED SHOW SOURCE BUTTON / KEYBINDING
-
# creates vte widget
self._vte = vte.Terminal()
self._vte.set_size(30,5)