From 71c8003735f6d34dce6058b90b460f8b3a42d8bc Mon Sep 17 00:00:00 2001 From: erick Date: Sat, 05 Dec 2009 20:42:38 +0000 Subject: First version of FrameProbe --- (limited to 'tutorius/TProbe.py') diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py index 41ebf29..acba26f 100644 --- a/tutorius/TProbe.py +++ b/tutorius/TProbe.py @@ -33,6 +33,7 @@ from . import properties from .services import ObjectStore from .dbustools import save_args, ignore, logError +from .gtkutils import find_widget, raddr_lookup import copy """ @@ -151,7 +152,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)) @@ -231,7 +232,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 @@ -307,6 +308,108 @@ 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:/// + 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:/// + 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. -- cgit v0.9.1