Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordave <drykod@gmail.com>2009-12-07 06:31:43 (GMT)
committer dave <drykod@gmail.com>2009-12-07 06:31:43 (GMT)
commit8e0656a71f6399060b6377f4fe70a8f92f9fa4d8 (patch)
treea5597d3394cfb605db7f1a02981f5d83b81c95c1
parent8acd9095e8f32ee20a6c4cd105d12a133fa9f346 (diff)
Launch activity if needed from action
-rw-r--r--tutorius/TProbe.py143
1 files changed, 138 insertions, 5 deletions
diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py
index 7f4126e..6dc4e1e 100644
--- a/tutorius/TProbe.py
+++ b/tutorius/TProbe.py
@@ -25,7 +25,10 @@ import cPickle as pickle
from functools import partial
+import gtk
from jarabe.model.shell import get_model
+from jarabe.model import bundleregistry
+from sugar.activity import activityfactory
from sugar.bundle.activitybundle import ActivityBundle
from . import addon
@@ -33,6 +36,7 @@ from . import properties
from .services import ObjectStore
from .dbustools import save_args, ignore, logError
+from .gtkutils import find_widget, raddr_lookup
import copy
"""
@@ -61,11 +65,13 @@ class TProbe(dbus.service.Object):
a DBUS Interface.
"""
- def __init__(self, activity, service_proxy=None):
+ def __init__(self, activity, activity_name, unique_id, service_proxy=None):
"""
Create and register a TProbe for an activity.
@param activity activity reference, must be a gtk container
+ @param activity_name generic name for the activity
+ @param unique_id specific name for this instance
@param service_proxy A Service proxy object to do the registering
"""
# Moving the ObjectStore assignment here, in the meantime
@@ -81,8 +87,8 @@ class TProbe(dbus.service.Object):
ObjectStore().activity = activity
- self._activity_name = activity.get_bundle_id()
- self._unique_id = activity.get_id()
+ self._activity_name = activity_name
+ self._unique_id = unique_id
LOGGER.debug("TProbe :: Creating TProbe for %s (%d)", self._activity_name, os.getpid())
LOGGER.debug("TProbe :: Current gobject context: %s", str(gobject.main_context_default()))
@@ -153,7 +159,7 @@ class TProbe(dbus.service.Object):
action._props.update(loaded_action._props)
if not is_editing:
- action.do(activity=self._activity)
+ action.do(activity=self._activity, probe=self)
else:
action.enter_editmode()
action.set_notification_cb(partial(self.update_action, address))
@@ -233,7 +239,7 @@ class TProbe(dbus.service.Object):
def callback(*args):
self.notify(eventfilter)
- eventfilter.install_handlers(callback, activity=self._activity)
+ eventfilter.install_handlers(callback, activity=self._activity, probe=self)
name = self._generate_event_reference(eventfilter)
self._subscribedEvents[name] = eventfilter
@@ -309,6 +315,107 @@ class TProbe(dbus.service.Object):
return name + str(suffix)
+ # ------------------ Helper functions specific to a component --------------
+ def find_widget(self, base, path, ignore_errors=True):
+ """
+ Finds a widget from a base object. Symmetric with retrieve_path
+
+ @param base the parent widget
+ @param path fqdn-style target object name
+
+ @return widget found
+ """
+ return find_widget(base, path, ignore_errors)
+
+ def retrieve_path(self, widget):
+ """
+ Retrieve the path to access a specific widget.
+ Symmetric with find_widget.
+
+ @param widget the widget to find a path for
+
+ @return path to the widget
+ """
+ return raddr_lookup(widget)
+
+class FrameProbe(TProbe):
+ """
+ Identical to the base probe except that helper functions are redefined
+ to handle the four windows that are part of the Frame.
+ """
+ # ------------------ Helper functions specific to a component --------------
+ def find_widget(self, base, path, ignore_errors=True):
+ """
+ Finds a widget from a base object. Symmetric with retrieve_path
+
+ format for the path for the frame should be:
+
+ frame://<panel>/<path>
+ where panel: top | bottom | left | right
+ path: number[.number]*
+
+ @param base the parent widget
+ @param path fqdn-style target object name
+
+ @return widget found
+ """
+ protocol, p = path.split("://")
+ assert protocol == "frame"
+
+ window, object_id = p.split("/")
+ if window == "top":
+ return find_widget(base._top_panel, object_id, ignore_errors)
+ elif window == "bottom":
+ return find_widget(base._bottom_panel, object_id, ignore_errors)
+ elif window == "left":
+ return find_widget(base._left_panel, object_id, ignore_errors)
+ elif window == "right":
+ return find_widget(base._right_panel, object_id, ignore_errors)
+ else:
+ raise RuntimeWarning("Invalid frame panel: '%s'"%window)
+
+ return find_widget(base, path, ignore_errors)
+
+ def retrieve_path(self, widget):
+ """
+ Retrieve the path to access a specific widget.
+ Symmetric with find_widget.
+
+ format for the path for the frame should be:
+
+ frame://<panel>/<path>
+ where panel: top | bottom | left | right
+ path: number[.number]*
+
+ @param widget the widget to find a path for
+
+ @return path to the widget
+ """
+ name = []
+ child = widget
+ parent = widget.parent
+ while parent:
+ name.append(str(parent.get_children().index(child)))
+ child = parent
+ parent = child.parent
+
+ name.append("0") # root object itself
+ name.reverse()
+
+ window = ""
+ if parent._position == gtk.POS_TOP:
+ window = "top"
+ elif parent._position == gtk.POS_BOTTOM:
+ window = "bottom"
+ elif parent._position == gtk.POS_LEFT:
+ window = "left"
+ elif parent._position == gtk.POS_RIGHT:
+ window = "right"
+ else:
+ raise RuntimeWarning("Invalid root panel in frame: %s"%str(parent))
+
+ return "frame://"+window+"/"+(".".join(name))
+
class ProbeProxy:
"""
ProbeProxy is a Proxy class for connecting to a remote TProbe.
@@ -585,6 +692,28 @@ class ProbeManager(object):
else:
return None
+ def prelaunch_activity(self, activity):
+ bundle = bundleregistry.get_registry().get_bundle(activity)
+ if not bundle:
+ print 'WARNING : Cannot find bundle'
+ else:
+ path = bundle.get_path()
+ activity_bundle = ActivityBundle(path)
+
+ active_activities = get_model()._get_activities_with_window()
+
+ is_active = False
+ for active_activity in active_activities:
+ logging.debug("ACTIVE ACTIVITY = %s" % active_activity.get_bundle_path())
+ if active_activity.get_bundle_path() is path:
+ is_active = True
+ logging.debug("SETTING FOCUS TO ACTIVITY")
+ active_activity.get_window().activate(gtk.get_current_event_time())
+
+ if not is_active:
+ logging.debug("LAUNCHING ACTIVITY")
+ activityfactory.create(activity_bundle)
+
def install(self, action, action_installed_cb, error_cb, is_editing=False, editing_cb=None):
"""
Install an action on the current activity
@@ -603,6 +732,10 @@ class ProbeManager(object):
activity = self.currentActivity
if activity:
+ logging.debug("**** ACTIVITY SOURCE : %s" % activity)
+
+ self.prelaunch_activity(activity)
+
return self._first_proxy(activity).install(
action=action,
is_editing=is_editing,