Skip to content

Commit

Permalink
Make web/index.html the default uri, and remove any extra scraps of code
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Closs committed Apr 26, 2008
1 parent 03a4281 commit a591f47
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
Binary file modified OnePageWikiActivity-1.xo
Binary file not shown.
22 changes: 8 additions & 14 deletions 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)
Expand All @@ -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)

9 changes: 6 additions & 3 deletions 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
Expand Down Expand Up @@ -58,4 +62,3 @@ def send_to_browser(self, command, parameter=None):
result = result.QueryInterface(components.interfaces.nsISupportsString)
return result.toString()
return None

0 comments on commit a591f47

Please sign in to comment.