Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
diff options
context:
space:
mode:
Diffstat (limited to 'activity.py')
-rw-r--r--activity.py135
1 files changed, 135 insertions, 0 deletions
diff --git a/activity.py b/activity.py
new file mode 100644
index 0000000..09fbba8
--- /dev/null
+++ b/activity.py
@@ -0,0 +1,135 @@
+# -*- coding: utf-8 -*-
+# Copyright 2011 Manuel QuiƱones
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""
+TiddlyWiki Activity: A reusable non-linear personal web notebook.
+
+This activity displays a TiddlyWiki, which is a wiki in a single html,
+via WebKit.
+
+"""
+
+import os
+import gtk
+import webkit
+import logging
+
+from sugar.activity import activity
+from sugar.graphics.toolbarbox import ToolbarBox
+from sugar.graphics.toolbarbox import ToolbarButton
+from sugar.activity.widgets import ActivityToolbarButton
+from sugar.activity.widgets import StopButton
+from sugar.activity.widgets import EditToolbar
+
+from toolbars import ViewToolbar
+
+_TIDDLYWIKI_PATH = os.path.join(activity.get_bundle_path(),
+ "data/empty.html")
+
+
+class TiddlyWikiActivity(activity.Activity):
+ """TiddlyWikiActivity class as specified in activity.info"""
+
+ def __init__(self, handle):
+ """Set up the TiddlyWiki activity."""
+ activity.Activity.__init__(self, handle)
+
+ self._web_view = None
+
+ # we do not have collaboration features, make the share option
+ # insensitive:
+ self.max_participants = 1
+
+ # add the toolbar:
+ toolbar_box = self._make_toolbar()
+ self.set_toolbar_box(toolbar_box)
+ toolbar_box.show()
+
+ # add the webkit view in the canvas:
+ canvas_widget = self.make_webkit_view()
+ self.set_canvas(canvas_widget)
+ canvas_widget.show()
+
+ def _make_toolbar(self):
+ logging.info("Creating toolbars")
+ toolbar_box = ToolbarBox()
+
+ # activity toolbar:
+ activity_button = ActivityToolbarButton(self)
+ toolbar_box.toolbar.insert(activity_button, -1)
+ activity_button.show()
+
+ # edit toolbar:
+ edit_toolbar = EditToolbar()
+ edit_toolbar.undo.connect('clicked', self._edit_undo_cb)
+ edit_toolbar.redo.connect('clicked', self._edit_redo_cb)
+ edit_toolbar.copy.connect('clicked', self._edit_copy_cb)
+ edit_toolbar.paste.connect('clicked', self._edit_paste_cb)
+ edit_toolbar_button = ToolbarButton(page=edit_toolbar,
+ icon_name='toolbar-edit')
+ toolbar_box.toolbar.insert(edit_toolbar_button, -1)
+ edit_toolbar_button.show()
+
+ # view toolbar:
+ view_toolbar = ViewToolbar()
+ view_toolbar.set_view(self)
+ view_toolbar_button = ToolbarButton(page=view_toolbar,
+ icon_name='toolbar-view')
+ toolbar_box.toolbar.insert(view_toolbar_button, -1)
+ view_toolbar_button.show()
+
+ # fill with blank space:
+ separator = gtk.SeparatorToolItem()
+ separator.props.draw = False
+ separator.set_expand(True)
+ toolbar_box.toolbar.insert(separator, -1)
+ separator.show()
+
+ # stop button:
+ stop_button = StopButton(self)
+ toolbar_box.toolbar.insert(stop_button, -1)
+ stop_button.show()
+
+ return toolbar_box
+
+ def make_webkit_view(self):
+ logging.info("Creating webkit view")
+ web_view = webkit.WebView()
+ web_view.load_uri('file://' + _TIDDLYWIKI_PATH)
+ self._web_view = web_view
+ web_view.show()
+ scrolledwindow = gtk.ScrolledWindow()
+ scrolledwindow.add(web_view)
+ return scrolledwindow
+
+ def _edit_undo_cb(self, button):
+ self._web_view.undo()
+
+ def _edit_redo_cb(self, button):
+ self._web_view.redo()
+
+ def _edit_copy_cb(self, button):
+ self._web_view.copy_clipboard()
+
+ def _edit_paste_cb(self, button):
+ self._web_view.paste_clipboard()
+
+ def zoom_in(self):
+ self._web_view.zoom_in()
+
+ def zoom_out(self):
+ self._web_view.zoom_out()