Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorroot <root@ghunt-desktop.(none)>2010-07-01 02:46:06 (GMT)
committer root <root@ghunt-desktop.(none)>2010-07-01 02:46:06 (GMT)
commitfb89ae22b057916217d26aa63d052544d1b5204c (patch)
tree6a0034e5b17b075179f265861a1e41059730040e /examples
parent2201eeafa41382e5b1c19b5acbc8dee74c904a4b (diff)
added HelpTemplate, fixes to write activity.info
Diffstat (limited to 'examples')
-rw-r--r--examples/HelpTemplate.activity/MANIFEST10
-rw-r--r--examples/HelpTemplate.activity/activity/HelpTemplate.svg117
-rw-r--r--examples/HelpTemplate.activity/activity/activity.info6
-rw-r--r--examples/HelpTemplate.activity/activity/activity.save6
-rw-r--r--examples/HelpTemplate.activity/dist/HelpTemplate-1.xobin0 -> 33949 bytes
-rw-r--r--examples/HelpTemplate.activity/help/HelpApi.htm33
-rw-r--r--examples/HelpTemplate.activity/help/__init__.py0
-rw-r--r--examples/HelpTemplate.activity/help/help.py236
-rwxr-xr-xexamples/HelpTemplate.activity/helptemplate.py79
-rwxr-xr-xexamples/HelpTemplate.activity/setup.py22
10 files changed, 509 insertions, 0 deletions
diff --git a/examples/HelpTemplate.activity/MANIFEST b/examples/HelpTemplate.activity/MANIFEST
new file mode 100644
index 0000000..69c82cf
--- /dev/null
+++ b/examples/HelpTemplate.activity/MANIFEST
@@ -0,0 +1,10 @@
+pydebug.py
+setup.py
+helptemplate.pyo
+help_pd.py
+helptemplate.py
+activity/activity.save
+activity/activity.info
+activity/HelpTemplateHTs.svg
+help/__init__.py
+help/help_pd.py
diff --git a/examples/HelpTemplate.activity/activity/HelpTemplate.svg b/examples/HelpTemplate.activity/activity/HelpTemplate.svg
new file mode 100644
index 0000000..3be9ac0
--- /dev/null
+++ b/examples/HelpTemplate.activity/activity/HelpTemplate.svg
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [
+ <!ENTITY stroke_color "#666666">
+ <!ENTITY fill_color "#ffffff">
+]>
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="55"
+ height="55"
+ id="svg4502"
+ sodipodi:version="0.32"
+ inkscape:version="0.46"
+ version="1.0"
+ sodipodi:docbase="/Users/eben/Desktop"
+ sodipodi:docname="star.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape"
+ style="display:inline">
+ <defs
+ id="defs4504">
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 27.5 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="55 : 27.5 : 1"
+ inkscape:persp3d-origin="27.5 : 18.333333 : 1"
+ id="perspective2408" />
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ gridtolerance="10000"
+ guidetolerance="10"
+ objecttolerance="10"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="7.919596"
+ inkscape:cx="29.322982"
+ inkscape:cy="20.358239"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer4"
+ width="55px"
+ height="55px"
+ inkscape:window-width="701"
+ inkscape:window-height="722"
+ inkscape:window-x="285"
+ inkscape:window-y="68"
+ showgrid="false">
+ <inkscape:grid
+ id="GridFromPre046Settings"
+ type="xygrid"
+ originx="0px"
+ originy="0px"
+ spacingx="15px"
+ spacingy="15px"
+ color="#0000ff"
+ empcolor="#0000ff"
+ opacity="0.2"
+ empopacity="0.4"
+ empspacing="5" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata4507">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:groupmode="layer"
+ id="layer4"
+ inkscape:label="icon"
+ style="display:inline">
+ <text
+ xml:space="preserve"
+ style="font-size:19.38258234px;font-style:normal;font-weight:bold;fill:&fill_color;;fill-opacity:1;stroke:&stroke_color;;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Bold;font-stretch:normal;font-variant:normal;text-anchor:start;text-align:start;writing-mode:lr;line-height:125%"
+ x="12.776501"
+ y="30.940331"
+ id="text2432"
+ transform="matrix(0.9107558,8.8314569e-3,-9.9819452e-3,1.0978923,0,0)"
+ inkscape:transform-center-x="6.6723495"
+ inkscape:transform-center-y="11.705454"
+ sodipodi:linespacing="125%"><tspan
+ sodipodi:role="line"
+ id="tspan2434"
+ x="12.776501"
+ y="30.940331">HT</tspan></text>
+ <path
+ sodipodi:type="star"
+ style="opacity:0.49568966;fill:&fill_color;;fill-opacity:1;stroke:&stroke_color;;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3777"
+ sodipodi:sides="5"
+ sodipodi:cx="2.0203052"
+ sodipodi:cy="1.4619155"
+ sodipodi:r1="29.278091"
+ sodipodi:r2="14.639046"
+ sodipodi:arg1="0.59517951"
+ sodipodi:arg2="1.223498"
+ inkscape:flatsided="false"
+ inkscape:rounded="0"
+ inkscape:randomized="0"
+ d="M 26.263966,17.876894 L 7.0028314,15.226947 L -6.0995641,29.591515 L -9.5313324,10.454208 L -27.241711,2.4319852 L -10.101526,-6.7455734 L -7.9447463,-26.068148 L 6.0802392,-12.602884 L 25.123581,-16.522669 L 16.651313,0.97688005 L 26.263966,17.876894 z"
+ transform="matrix(0.9442497,0.3292302,-0.3292302,0.9442497,26.564173,27.280746)" />
+ </g>
+</svg>
diff --git a/examples/HelpTemplate.activity/activity/activity.info b/examples/HelpTemplate.activity/activity/activity.info
new file mode 100644
index 0000000..b78a370
--- /dev/null
+++ b/examples/HelpTemplate.activity/activity/activity.info
@@ -0,0 +1,6 @@
+[Activity]
+name = HelpTemplate
+bundle_id = org.laptop.HelpTemplate
+activity_version = 1
+icon = HelpTemplate
+class = helptemplate.HelpTemplate
diff --git a/examples/HelpTemplate.activity/activity/activity.save b/examples/HelpTemplate.activity/activity/activity.save
new file mode 100644
index 0000000..b78a370
--- /dev/null
+++ b/examples/HelpTemplate.activity/activity/activity.save
@@ -0,0 +1,6 @@
+[Activity]
+name = HelpTemplate
+bundle_id = org.laptop.HelpTemplate
+activity_version = 1
+icon = HelpTemplate
+class = helptemplate.HelpTemplate
diff --git a/examples/HelpTemplate.activity/dist/HelpTemplate-1.xo b/examples/HelpTemplate.activity/dist/HelpTemplate-1.xo
new file mode 100644
index 0000000..99545b0
--- /dev/null
+++ b/examples/HelpTemplate.activity/dist/HelpTemplate-1.xo
Binary files differ
diff --git a/examples/HelpTemplate.activity/help/HelpApi.htm b/examples/HelpTemplate.activity/help/HelpApi.htm
new file mode 100644
index 0000000..a1888d4
--- /dev/null
+++ b/examples/HelpTemplate.activity/help/HelpApi.htm
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<title>Untitled Document</title>
+</head>
+
+<body>
+<h1>Why this Template? </h1>
+<p>The installed base which is most of the 1.5 Million XO's has the following code on line 156 of webview.py for adjusting the visibility of html:
+<pre> def set_visibility(self, visibility):
+ logging.debug(&quot;nsIEmbeddingSiteWindow.set_visibility: %r&quot; % visibility)
+ if visibility:
+ self.web_view.show()
+ self.web_view.get_toplevel().show()
+ else:
+ self.web_view.get_toplevel().hide()
+
+
+This makes it difficult to use the webview widget in applications that want to display html based Help because
+when you want to hide the help page, you simultaneously end up hiding the rest of your application.
+ (F11 code has corrected this shortcoming).
+
+
+This HelpTemplate creates a new and separate window, so that the hide toplevel doesn't hide the rest of
+your application. In order to use this strategy, you will need to create the same number of tabs on the
+help page so that the user doesn't percieve that he is actually on a separate window.
+
+
+Admittedly, it's a little kludgey, but it will let your help pages be visible on old sugar builds.</pre>
+</p>
+</body>
+</html>
diff --git a/examples/HelpTemplate.activity/help/__init__.py b/examples/HelpTemplate.activity/help/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/examples/HelpTemplate.activity/help/__init__.py
diff --git a/examples/HelpTemplate.activity/help/help.py b/examples/HelpTemplate.activity/help/help.py
new file mode 100644
index 0000000..39940d3
--- /dev/null
+++ b/examples/HelpTemplate.activity/help/help.py
@@ -0,0 +1,236 @@
+# Copyright (C) 2006, Red Hat, Inc.
+#
+# 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
+
+import os, sys
+from gettext import gettext as _
+from subprocess import Popen, PIPE
+import shutil
+
+import gtk
+import gobject
+import wnck
+#from time import time
+from sugar import util
+
+from sugar.activity import activity
+from sugar.graphics.window import Window
+from sugar.graphics.toolbox import Toolbox
+from sugar.activity.activityhandle import ActivityHandle
+from sugar import wm, env
+#from IPython.Debugger import Tracer
+from pdb import *
+from sugar.graphics.toolbutton import ToolButton
+
+import hulahop
+#hulahop.startup(os.path.join(activity.get_activity_root(), 'data/gecko'))
+
+"""#from hulahop.webview import WebView
+from browser import Browser
+import xpcom
+from xpcom.components import interfaces
+"""
+gobject.threads_init()
+
+HOME = os.path.join(activity.get_bundle_path(), _('help/HelpApi.htm'))
+#HOME = "http://website.com/something.html"
+HELP_PANE = 1
+
+# Initialize logging.
+import logging
+_logger = logging.getLogger()
+
+class Help(Window):
+ def __init__(self, parent):
+ self.parent_obj = parent
+ hulahop.startup(os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'],'data','gecko'))
+ #from hulahop.webview import WebView
+ from browser import Browser
+ import xpcom
+ from xpcom.components import interfaces
+ self.help_id = None
+ self.handle = ActivityHandle()
+ self.handle.activity_id = util.unique_id()
+ Window.__init__(self)
+ self.connect('realize',self.realize_cb)
+
+ #self.props.max_participants = 1
+
+ self._web_view = Browser()
+
+ #Mimic the other tabs (hide the fact that this is another window)
+ self.toolbox = Toolbox()
+ self.toolbox.connect('current_toolbar_changed',self.goto_cb)
+ self.set_toolbox(self.toolbox)
+ self.toolbox.show()
+
+ activitybar = gtk.Toolbar()
+ self.toolbox.add_toolbar(_('Activity'), activitybar)
+ activitybar.show_all()
+
+ self.help_toolbar = Toolbar(self._web_view)
+ self.help_toolbar.show()
+ self.toolbox.add_toolbar(_('Help'), self.help_toolbar)
+ self.toolbox._notebook.set_current_page(HELP_PANE)
+
+ self.set_canvas(self._web_view)
+ self._web_view.show()
+
+ self.toolbox.set_current_toolbar(HELP_PANE)
+
+ self._web_view.load_uri(HOME)
+
+ def get_help_toolbar(self):
+ return self.help_toolbar
+
+ def realize_help(self):
+
+ #trial and error suggest the following parent activation is necesssary to return reliably to parent window
+ if version > 0.839:
+ self.pywin = self.get_wnck_window_from_activity_id(str(self.parent_obj.handle.activity_id))
+ if self.pywin:
+ self.pywin.activate(gtk.get_current_event_time())
+ _logger.debug('pywin.activate called')
+ self.show_all()
+ self.toolbox._notebook.set_current_page(HELP_PANE)
+ return self
+
+ def realize_cb(self, window):
+ self.help_id = util.unique_id()
+ wm.set_activity_id(window.window, self.help_id)
+ self.help_window = window
+
+ def activate_help(self):
+ _logger.debug('activate_help called')
+ self.help_window.show()
+ if version < 0.838: return
+ window = self.get_wnck_window_from_activity_id(self.help_id)
+ self.toolbox._notebook.set_current_page(HELP_PANE)
+ if window:
+ window.activate(gtk.get_current_event_time())
+ else:
+ _logger.debug('failed to get window')
+
+ def goto_cb(self, page, tab):
+ _logger.debug('current_toolbar_changed event called goto_cb. tab: %s'%tab)
+ if tab == HELP_PANE: return
+ if not self.help_id: return
+ self.parent_obj.set_toolbar(tab)
+ self.help_window.hide()
+ if version < 0.838: return
+ self.pywin = self.get_wnck_window_from_activity_id(str(self.parent_obj.handle.activity_id))
+ if self.pywin:
+ self.pywin.activate(gtk.get_current_event_time())
+
+ def get_wnck_window_from_activity_id(self, activity_id):
+ """Use shell model to look up the wmck window associated with activity_id
+ --the home_model code changed between .82 and .84 sugar
+ --so do the lookup differently depending on sugar version
+ """
+ _logger.debug('get_wnck_window_from_activity_id. id:%s'%activity_id)
+ _logger.debug('sugar version %s'%version)
+ if version and version >= 0.839:
+ home_model = shell.get_model()
+ activity = home_model.get_activity_by_id(activity_id)
+ else:
+ instance = view.Shell.get_instance()
+ home_model = instance.get_model().get_home()
+ activity = home_model._get_activity_by_id(activity_id)
+ if activity:
+ return activity.get_window()
+ else:
+ _logger.debug('wnck_window was none')
+ return None
+
+class Toolbar(gtk.Toolbar):
+ def __init__(self, web_view):
+ gobject.GObject.__init__(self)
+
+ self._web_view = web_view
+
+ self._back = ToolButton('go-previous-paired')
+ self._back.set_tooltip(_('Back'))
+ self._back.props.sensitive = False
+ self._back.connect('clicked', self._go_back_cb)
+ self.insert(self._back, -1)
+ self._back.show()
+
+ self._forward = ToolButton('go-next-paired')
+ self._forward.set_tooltip(_('Forward'))
+ self._forward.props.sensitive = False
+ self._forward.connect('clicked', self._go_forward_cb)
+ self.insert(self._forward, -1)
+ self._forward.show()
+
+ home = ToolButton('zoom-home')
+ home.set_tooltip(_('Home'))
+ home.connect('clicked', self._go_home_cb)
+ self.insert(home, -1)
+ home.show()
+
+ progress_listener = self._web_view.progress
+ progress_listener.connect('location-changed',
+ self._location_changed_cb)
+ progress_listener.connect('loading-stop', self._loading_stop_cb)
+
+ def _location_changed_cb(self, progress_listener, uri):
+ self.update_navigation_buttons()
+
+ def _loading_stop_cb(self, progress_listener):
+ self.update_navigation_buttons()
+
+ def update_navigation_buttons(self):
+ can_go_back = self._web_view.web_navigation.canGoBack
+ self._back.props.sensitive = can_go_back
+
+ can_go_forward = self._web_view.web_navigation.canGoForward
+ self._forward.props.sensitive = can_go_forward
+
+ def _go_back_cb(self, button):
+ self._web_view.web_navigation.goBack()
+
+ def _go_forward_cb(self, button):
+ self._web_view.web_navigation.goForward()
+
+ def _go_home_cb(self, button):
+ self._web_view.load_uri(HOME)
+
+def command_line(cmd):
+ _logger.debug('command_line cmd:%s'%cmd)
+ p1 = Popen(cmd,stdout=PIPE, shell=True)
+ output = p1.communicate()
+ if p1.returncode != 0:
+ return None
+ return output[0]
+
+def sugar_version():
+ cmd = '/bin/rpm -q sugar'
+ reply = command_line(cmd)
+ if reply and reply.find('sugar') > -1:
+ version = reply.split('-')[1]
+ version_chunks = version.split('.')
+ major_minor = version_chunks[0] + '.' + version_chunks[1]
+ return float(major_minor)
+ return None
+
+version = 0.0
+version = sugar_version()
+if version and version >= 0.839:
+ from jarabe.model import shell
+else:
+ if not '/usr/share/sugar/shell/' in sys.path:
+ sys.path.append('/usr/share/sugar/shell/')
+ import view.Shell
+
diff --git a/examples/HelpTemplate.activity/helptemplate.py b/examples/HelpTemplate.activity/helptemplate.py
new file mode 100755
index 0000000..635278f
--- /dev/null
+++ b/examples/HelpTemplate.activity/helptemplate.py
@@ -0,0 +1,79 @@
+# 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
+
+import os
+from gettext import gettext as _
+
+import gtk
+import gobject
+import logging
+_logger = logging.getLogger()
+
+from sugar.activity import activity
+from sugar.graphics.toolbutton import ToolButton
+from help.help import Help
+
+HOME = os.path.join(activity.get_bundle_path(), 'help/XO_Introduction.html')
+#HOME = "http://website.com/something.html"
+HELP_TAB = 1
+
+class HelpTemplate(activity.Activity):
+ def __init__(self, handle):
+ activity.Activity.__init__(self, handle)
+
+ #following are essential for interface to Help
+ self.help_x11 = None
+ self.handle = handle
+ self.help = Help(self)
+
+ self.toolbox = activity.ActivityToolbox(self)
+ self.toolbox.connect_after('current_toolbar_changed',self._toolbar_changed_cb)
+ self.toolbox.show()
+
+ toolbar = gtk.Toolbar()
+ self.toolbox.add_toolbar(_('Help'), toolbar)
+ toolbar.show()
+
+ label = gtk.Button('Help Template')
+ label.show()
+ self.set_canvas(label)
+
+ self.set_toolbox(self.toolbox)
+ self.toolbox.set_current_toolbar(0)
+
+ def _toolbar_changed_cb(self,widget,tab_no):
+ if tab_no == HELP_TAB:
+ self.help_selected()
+
+ def set_toolbar(self,tab):
+ self.toolbox.set_current_toolbar(tab)
+
+ ################ Help routines
+ def help_selected(self):
+ """
+ if help is not created in a gtk.mainwindow then create it
+ else just switch to that viewport
+ """
+ if not self.help_x11:
+ screen = gtk.gdk.screen_get_default()
+ self.pdb_window = screen.get_root_window()
+ _logger.debug('xid for pydebug:%s'%self.pdb_window.xid)
+ #self.window_instance = self.window.window
+ self.help_x11 = self.help.realize_help()
+ #self.x11_window = self.get_x11()os.geteuid()
+ else:
+ self.help.activate_help()
+ #self.help.reshow()
+ #self.help.toolbox.set_current_page(self.panes['HELP']
+
diff --git a/examples/HelpTemplate.activity/setup.py b/examples/HelpTemplate.activity/setup.py
new file mode 100755
index 0000000..fae74b8
--- /dev/null
+++ b/examples/HelpTemplate.activity/setup.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2006, Red Hat, Inc.
+#
+# 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
+
+from sugar.activity import bundlebuilder
+
+bundlebuilder.start()
+