From 034e36d4983da0c2d44c56d4efd9af922b2cab4e Mon Sep 17 00:00:00 2001 From: Vincent Vinet Date: Mon, 07 Dec 2009 20:50:52 +0000 Subject: pass the overlayer as a keyword argument for do, enter_editmode and subscribe, remove object store references --- (limited to 'tutorius/TProbe.py') diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py index e3189fe..5508d49 100644 --- a/tutorius/TProbe.py +++ b/tutorius/TProbe.py @@ -17,6 +17,7 @@ import logging LOGGER = logging.getLogger("sugar.tutorius.TProbe") import os +import gtk import gobject @@ -29,8 +30,6 @@ from jarabe.model.shell import get_model from sugar.bundle.activitybundle import ActivityBundle from . import addon -from . import properties -from .services import ObjectStore from .dbustools import save_args, ignore, logError from .gtkutils import find_widget, raddr_lookup @@ -62,28 +61,26 @@ class TProbe(dbus.service.Object): a DBUS Interface. """ - def __init__(self, activity, activity_name, unique_id, service_proxy=None): + def __init__(self, widget, activity_name, unique_id, overlayer=None, service_proxy=None): """ Create and register a TProbe for an activity. - @param activity activity reference, must be a gtk container + @param widget top widget reference, must be a gtk container @param activity_name generic name for the activity @param unique_id specific name for this instance + @param overlayer overlayer to draw actions on @param service_proxy A Service proxy object to do the registering """ - # Moving the ObjectStore assignment here, in the meantime - # the reference to the activity shouldn't be share as a - # global variable but passed by the Probe to the objects - # that requires it - self._activity = activity + self._activity = widget + + #Legacy way to access the overlayer, do it here instead of everywhere + self._overlayer = overlayer or getattr(self._activity, "_overlayer", None) if service_proxy == None: from .service import ServiceProxy self._service_proxy = service_proxy or ServiceProxy() - ObjectStore().activity = activity - self._activity_name = activity_name self._unique_id = unique_id @@ -157,7 +154,7 @@ class TProbe(dbus.service.Object): action._props.update(loaded_action._props) if not is_editing: - action.do(activity=self._activity, probe=self) + action.do(activity=self._activity, probe=self, overlayer=self._overlayer) else: # force mandatory props addon_name = addon.get_name_from_type(type(action)) @@ -171,7 +168,7 @@ class TProbe(dbus.service.Object): propname) updated_props[propname] = getattr(action, propname) - action.enter_editmode() + action.enter_editmode(overlayer=self._overlayer) action.set_notification_cb(partial(self.update_action, address)) pickled_value = pickle.dumps((address, updated_props)) @@ -194,10 +191,10 @@ class TProbe(dbus.service.Object): action._props.update(props) if not is_editing: action.undo() - action.do() + action.do(activity=self._activity, overlayer=self._overlayer) else: action.exit_editmode() - action.enter_editmode() + action.enter_editmode(overlayer=self._overlayer) @dbus.service.method("org.tutorius.ProbeInterface", in_signature='sb', out_signature='') @@ -250,7 +247,7 @@ class TProbe(dbus.service.Object): def callback(*args): self.notify(eventfilter) - eventfilter.install_handlers(callback, activity=self._activity, probe=self) + eventfilter.install_handlers(callback, activity=self._activity, probe=self, overlayer=self._overlayer) name = self._generate_event_reference(eventfilter) self._subscribedEvents[name] = eventfilter @@ -384,8 +381,6 @@ class FrameProbe(TProbe): 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): """ @@ -427,6 +422,81 @@ class FrameProbe(TProbe): return "frame://"+window+"/"+(".".join(name)) +class DesktopProbe(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: + + desktop:/// + where view: home | group | mesh + path: number[.number]* + + @param base the parent widget + @param path fqdn-style target object name + + @return widget found + """ + protocol, p = path.split("://") + assert protocol == "desktop" + + window, object_id = p.split("/") + if window == "home": + return find_widget(base._top_panel, object_id, ignore_errors) + elif window == "group": + return find_widget(base._bottom_panel, object_id, ignore_errors) + elif window == "mesh": + return find_widget(base._left_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: + + desktop:/// + where view: home | group | mesh + 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.insert(0,str(parent.get_children().index(child))) + child = parent + parent = child.parent + + name.insert(0,"0") # root object itself + + 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 "desktop://"+window+"/"+(".".join(name)) + class ProbeProxy: """ -- cgit v0.9.1