[Sugar-devel] How to start the Browse activity from my own activity?
Behavior Vehikel
b.vehikel at googlemail.com
Mon Feb 1 14:58:59 EST 2010
How to start the Browse activity from my own activity?
My Kandid activity can dump internal states as a HTML files. For
example this information is written to
~/.sugar/default/net.sourceforge.kandid/tmp/_znuaxz_169/index.html
Now I am searching for a possibility to launch the Brows activity
displaying this HTML file.
First I tried using the webbrowser.open() method from Python. But no
effect when running under SoaS release 2 (Bluberry) Sugar 0.86.3
def on_explain_activate(self, *args):
ka_debug.info('on_explain_activate [%s]' % args[0].get_name())
protozoon = self.model.protozoans[name_to_index(args[0].get_name())]
folder = os.path.join(self._activity_root, 'tmp')
file_path = 'file://' + self.explain('html', protozoon, 'index', folder)
#Start up a new instance of the Web activity.
result = webbrowser.open(file_path)
ka_debug.info('webbrowser.open: [%s] %s' % (file_path, str(result)))
My second try and error version is using the
activityfactory.create_with_uri() method.
But it will produce an exception when running with SoaS Bluberry.
def on_explain_activate(self, *args):
ka_debug.info('on_explain_activate [%s]' % args[0].get_name())
protozoon = self.model.protozoans[name_to_index(args[0].get_name())]
folder = os.path.join(self._activity_root, 'tmp')
file_path = 'file://' + self.explain('html', protozoon, 'index', folder)
#Start up a new instance of the Web activity.
ka_debug.info('webbrowser.open: [%s]' % (file_path))
activityfactory.create_with_uri('org.laptop.WebActivity', file_path)
1265051065.540251 DEBUG Kandid: on_explain_activate [exportpng_menuitem_2]
1265051069.314681 DEBUG Kandid: webbrowser.open:
[file:///home/liveuser/.sugar/default/net.sourceforge.kandid/tmp/_xjwwqo_43/index.html]
Traceback (most recent call last):
File "/home/liveuser/Activities/Kandid.activity/ka_controller.py",
line 340, in on_explain_activate
activityfactory.create_with_uri('org.laptop.WebActivity', file_path)
File "/usr/lib/python2.6/site-packages/sugar/activity/activityfactory.py",
line 332, in create_with_uri
return ActivityCreationHandler(bundle, activity_handle)
File "/usr/lib/python2.6/site-packages/sugar/activity/activityfactory.py",
line 206, in __init__
self._service_name = bundle.get_bundle_id()
AttributeError: 'str' object has no attribute 'get_bundle_id'
1265051112.422281 DEBUG Kandid: write_file
[/home/liveuser/.sugar/default/net.sourceforge.kandid/instance/1265051112]
How can I start a browser to display a HTML page? Please add more
information to http://wiki.sugarlabs.org/go/Development_Team/Almanac/sugar.activity.activityfactory
Thanks, Thomas
More information about the Sugar-devel
mailing list