Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius
diff options
context:
space:
mode:
Diffstat (limited to 'tutorius')
-rw-r--r--tutorius/TProbe.py106
-rw-r--r--tutorius/actions.py9
-rw-r--r--tutorius/creator.py1
3 files changed, 94 insertions, 22 deletions
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://<view>/<path>
+ 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://<view>/<path>
+ 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:
"""
diff --git a/tutorius/actions.py b/tutorius/actions.py
index 40d9b03..fe64c95 100644
--- a/tutorius/actions.py
+++ b/tutorius/actions.py
@@ -23,7 +23,6 @@ from gettext import gettext as _
from sugar.graphics import icon
from . import addon
-from .services import ObjectStore
from .properties import *
from .constants import *
@@ -211,12 +210,16 @@ class Action(TPropContainer):
# Empty the diff dict as we just synchronized with the creator
self._diff_dict.clear()
- def enter_editmode(self, **kwargs):
+ def enter_editmode(self, overlayer=None, **kwargs):
"""
Enters edit mode. The action should display itself in some way,
without affecting the currently running application. The default is
a small box with the action icon.
+ @param overlayer Overlayer to draw on
"""
+ if overlayer is None:
+ raise TypeError("No overlayer supplied")
+
meta = addon.get_addon_meta(type(self).__name__)
actionicon = icon.Icon(icon_name=meta['icon'],
@@ -232,7 +235,7 @@ class Action(TPropContainer):
self.position = 0, 0
x, y = self.position
- ObjectStore().activity._overlayer.put(self.__edit_img, x, y)
+ overlayer.put(self.__edit_img, x, y)
self.__edit_img.show_all()
self._drag = DragWrapper(self.__edit_img, self.position, update_action_cb=self.update_property, draggable=True)
diff --git a/tutorius/creator.py b/tutorius/creator.py
index 8964b7f..2de21ac 100644
--- a/tutorius/creator.py
+++ b/tutorius/creator.py
@@ -33,7 +33,6 @@ from sugar.graphics import icon, style
import jarabe.frame
from . import overlayer, gtkutils, vault, addon
-from .services import ObjectStore
from .tutorial import Tutorial
from . import viewer
from .propwidgets import TextInputDialog