diff --git a/OnePageWikiActivity-1.xo b/OnePageWikiActivity-1.xo index 896664d..86661b7 100644 Binary files a/OnePageWikiActivity-1.xo and b/OnePageWikiActivity-1.xo differ diff --git a/OnePageWikiActivity.py b/OnePageWikiActivity.py index e636cac..1725188 100644 --- a/OnePageWikiActivity.py +++ b/OnePageWikiActivity.py @@ -1,34 +1,29 @@ from sugar.activity import activity -from sugar.activity.activity import get_bundle_path from sugar import env -import logging -import sys, os +import os import gtk import gobject - import hulahop hulahop.startup(os.path.join(env.get_profile_path(), 'gecko')) - from XOCom import XOCom -# The XOCom object helps us communicate with the browser -uri = 'file://' + get_bundle_path() + '/web/index.html'; -xocom = XOCom(uri) - class OnePageWikiActivity (activity.Activity): def __init__(self, handle): activity.Activity.__init__(self, handle) self.set_title('OnePageWiki') + # The XOCom object helps us communicate with the browser + # This uses web/index.html as the default page to load + self.xocom = XOCom() + toolbox = activity.ActivityToolbox(self) self.set_toolbox(toolbox) toolbox.show() - self.set_canvas( xocom.create_webview() ) + self.set_canvas( self.xocom.create_webview() ) def write_file(self, filename): - content = xocom.send_to_browser('write') - print "write_file(%s): %s"%(filename, content) + content = self.xocom.send_to_browser('write') if content: fh = open(filename, 'w') fh.write(content) @@ -37,9 +32,8 @@ def write_file(self, filename): def read_file(self, filename): fh = open(filename, 'r') content = fh.read() - print "read_file(%s): %s"%(filename, content) # We must delay this to give the browser time to start up # It would be better if this send_to_browser was instead triggered # once the browser had finished loading. - gobject.timeout_add(2000, xocom.send_to_browser, 'read', content) + gobject.timeout_add(2000, self.xocom.send_to_browser, 'read', content) diff --git a/XOCom.py b/XOCom.py index e75a1f2..03f0ff8 100644 --- a/XOCom.py +++ b/XOCom.py @@ -1,11 +1,15 @@ +from sugar.activity.activity import get_bundle_path from hulahop.webview import WebView from xpcom import components class XOCom: # Constructor gives full XPCom access by default # This should be improved for future apps that may not need/want full access - def __init__(self, uri): - self.uri = uri + def __init__(self, uri=None): + if uri: + self.uri = uri + else: + self.uri = 'file://' + get_bundle_path() + '/web/index.html'; self.give_full_xpcom_access() # Give the browser permission to use XPCom interfaces @@ -58,4 +62,3 @@ def send_to_browser(self, command, parameter=None): result = result.QueryInterface(components.interfaces.nsISupportsString) return result.toString() return None -