Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ElementsActivity.py
diff options
context:
space:
mode:
Diffstat (limited to 'ElementsActivity.py')
-rw-r--r--ElementsActivity.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/ElementsActivity.py b/ElementsActivity.py
new file mode 100644
index 0000000..62bee1d
--- /dev/null
+++ b/ElementsActivity.py
@@ -0,0 +1,46 @@
+from sugar.activity import activity
+from sugar import env
+import os
+import gtk
+import gobject
+import hulahop
+hulahop.startup(os.path.join(env.get_profile_path(), 'gecko'))
+from XOCom import XOCom
+
+class ElementsActivity (activity.Activity):
+ def __init__(self, handle):
+ activity.Activity.__init__(self, handle)
+ self.set_title('Elements')
+
+ # The XOCom object helps us communicate with the browser
+ # This uses web/index.html as the default page to load
+ self.xocom = XOCom("file://"+os.path.join(os.path.dirname(os.path.abspath(__file__)),"web/allelements.xml"))
+
+ toolbox = activity.ActivityToolbox(self)
+ self.set_toolbox(toolbox)
+ toolbox.show()
+
+ self.set_canvas( self.xocom.create_webview() )
+
+ #self.read_file(os.path.join(os.path.dirname(os.path.abspath(__file__)),"datos.txt"))
+
+
+ def write_file(self, filename):
+ filename = os.path.join(os.path.dirname(os.path.abspath(__file__)),"web/datos.js")
+ content = self.xocom.send_to_browser('write')
+
+ if content:
+ fh = open(filename, 'w')
+ fh.write(content)
+ fh.close()
+
+ def read_file(self, filename):
+ fh = open(filename, 'r')
+ content = fh.read()
+ def send_delayed_read():
+ self.xocom.send_to_browser('read', content)
+ return False
+ # 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(5000, send_delayed_read)