Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/TProbe.py
diff options
context:
space:
mode:
Diffstat (limited to 'tutorius/TProbe.py')
-rw-r--r--tutorius/TProbe.py139
1 files changed, 113 insertions, 26 deletions
diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py
index 0c79690..7d1b91a 100644
--- a/tutorius/TProbe.py
+++ b/tutorius/TProbe.py
@@ -10,6 +10,7 @@ import cPickle as pickle
from . import addon
+from . import properties
from .services import ObjectStore
from .properties import TPropContainer
@@ -113,11 +114,12 @@ class TProbe(dbus.service.Object):
# ------------------ Action handling --------------------------------------
@dbus.service.method("org.tutorius.ProbeInterface",
- in_signature='s', out_signature='s')
- def install(self, pickled_action):
+ in_signature='sb', out_signature='s')
+ def install(self, pickled_action, is_editing):
"""
Install an action on the Activity
@param pickled_action string pickled action
+ @param is_editing whether this action comes from the editor
@return string address of installed action
"""
loaded_action = pickle.loads(str(pickled_action))
@@ -130,17 +132,21 @@ class TProbe(dbus.service.Object):
if action._props:
action._props.update(loaded_action._props)
- action.do(activity=self._activity)
-
+ if not is_editing:
+ action.do(activity=self._activity)
+ else:
+ action.enter_editmode()
+
return address
@dbus.service.method("org.tutorius.ProbeInterface",
- in_signature='ss', out_signature='')
- def update(self, address, action_props):
+ in_signature='ssb', out_signature='')
+ def update(self, address, action_props, is_editing):
"""
Update an already registered action
@param address string address returned by install()
@param action_props pickled action properties
+ @param is_editing whether this action comes from the editor
@return None
"""
action = self._installedActions[address]
@@ -148,26 +154,67 @@ class TProbe(dbus.service.Object):
if action._props:
props = pickle.loads(str(action_props))
action._props.update(props)
- action.undo()
- action.do()
+ if not is_editing:
+ action.undo()
+ action.do()
+ else:
+ action.exit_editmode()
+ action.enter_editmode()
@dbus.service.method("org.tutorius.ProbeInterface",
- in_signature='s', out_signature='')
- def uninstall(self, address):
+ in_signature='sb', out_signature='')
+ def uninstall(self, address, is_editing):
"""
Uninstall an action
@param address string address returned by install()
+ @param is_editing whether this action comes from the editor
@return None
"""
if self._installedActions.has_key(address):
action = self._installedActions[address]
- action.undo()
+ if not is_editing:
+ action.undo()
+ else:
+ action.exit_editmode()
self._installedActions.pop(address)
# ------------------ Event handling ---------------------------------------
@dbus.service.method("org.tutorius.ProbeInterface",
in_signature='s', out_signature='s')
+ def create_event(self, addon_name):
+ # avoid recursive imports
+ from .creator import WidgetSelector, SignalInputDialog, TextInputDialog
+
+ event = addon.create(addon_name)
+ addonname = type(event).__name__
+ meta = addon.get_addon_meta(addonname)
+ for propname in meta['mandatory_props']:
+ prop = getattr(type(event), propname)
+ if isinstance(prop, properties.TUAMProperty):
+ selector = WidgetSelector(self._activity)
+ setattr(event, propname, selector.select())
+ elif isinstance(prop, properties.TEventType):
+ try:
+ dlg = SignalInputDialog(self._activity,
+ text="Mandatory property",
+ field=propname,
+ addr=event.object_id)
+ setattr(event, propname, dlg.pop())
+ except AttributeError:
+ pass
+ elif isinstance(prop, properties.TStringProperty):
+ dlg = TextInputDialog(self._activity,
+ text="Mandatory property",
+ field=propname)
+ setattr(event, propname, dlg.pop())
+ else:
+ raise NotImplementedError()
+
+ return pickle.dumps(event)
+
+ @dbus.service.method("org.tutorius.ProbeInterface",
+ in_signature='s', out_signature='s')
def subscribe(self, pickled_event):
"""
Subscribe to an Event
@@ -304,39 +351,49 @@ class ProbeProxy:
def __clear_action(self, action):
self._actions.pop(action, None)
- def install(self, action, block=False):
+ def install(self, action, block=False, is_editing=False):
"""
Install an action on the TProbe's activity
@param action Action to install
@param block Force a synchroneous dbus call if True
+ @param is_editing whether this action comes from the editor
@return None
"""
- return remote_call(self._probe.install, (pickle.dumps(action),),
- save_args(self.__update_action, action),
- block=block)
+ return remote_call(self._probe.install,
+ (pickle.dumps(action), is_editing),
+ save_args(self.__update_action, action),
+ block=block)
- def update(self, action, newaction, block=False):
+ def update(self, action, newaction, block=False, is_editing=False):
"""
Update an already installed action's properties and run it again
@param action Action to update
@param newaction Action to update it with
@param block Force a synchroneous dbus call if True
+ @param is_editing whether this action comes from the editor
@return None
"""
#TODO review how to make this work well
- if not action in self._actions:
+ if not action in self._actions.keys():
raise RuntimeWarning("Action not installed")
#TODO Check error handling
- return remote_call(self._probe.update, (self._actions[action], pickle.dumps(newaction._props)), block=block)
+ return remote_call(self._probe.update,
+ (self._actions[action],
+ pickle.dumps(newaction._props),
+ is_editing),
+ block=block)
- def uninstall(self, action, block=False):
+ def uninstall(self, action, block=False, is_editing=False):
"""
Uninstall an installed action
@param action Action to uninstall
@param block Force a synchroneous dbus call if True
+ @param is_editing whether this action comes from the editor
"""
- if action in self._actions:
- remote_call(self._probe.uninstall,(self._actions.pop(action),), block=block)
+ if action in self._actions.keys():
+ remote_call(self._probe.uninstall,
+ (self._actions.pop(action), is_editing),
+ block=block)
def __update_event(self, event, callback, address):
LOGGER.debug("ProbeProxy :: Registered event %s with address %s", str(hash(event)), str(address))
@@ -386,6 +443,16 @@ class ProbeProxy:
else:
LOGGER.debug("ProbeProxy :: unsubsribe address %s inconsistency : not registered", address)
+ def create_event(self, addon_name):
+ """
+ Create an event on the app side and request the user to fill the
+ properties before returning it.
+
+ @param addon_name: the add-on name of the event
+ @returns: an eventfilter instance
+ """
+ return pickle.loads(str(self._probe.create_event(addon_name)))
+
def subscribe(self, event, callback, block=True):
"""
Register an event listener
@@ -441,6 +508,8 @@ class ProbeManager(object):
"""
_LOGGER = logging.getLogger("sugar.tutorius.ProbeManager")
+ default_instance = None
+
def __init__(self, proxy_class=ProbeProxy):
"""Constructor
@param proxy_class Class to use for creating Proxies to activities.
@@ -455,6 +524,8 @@ class ProbeManager(object):
ProbeManager._LOGGER.debug("__init__()")
+ ProbeManager.default_instance = self
+
def setCurrentActivity(self, activity_id):
if not activity_id in self._probes:
raise RuntimeError("Activity not attached")
@@ -465,36 +536,52 @@ class ProbeManager(object):
currentActivity = property(fget=getCurrentActivity, fset=setCurrentActivity)
- def install(self, action, block=False):
+ def install(self, action, block=False, is_editing=False):
"""
Install an action on the current activity
@param action Action to install
@param block Force a synchroneous dbus call if True
+ @param is_editing whether this action comes from the editor
@return None
"""
if self.currentActivity:
- return self._first_proxy(self.currentActivity).install(action, block)
+ return self._first_proxy(self.currentActivity).install(action, block, is_editing)
else:
raise RuntimeWarning("No activity attached")
- def update(self, action, newaction, block=False):
+ def update(self, action, newaction, block=False, is_editing=False):
"""
Update an already installed action's properties and run it again
@param action Action to update
@param newaction Action to update it with
@param block Force a synchroneous dbus call if True
+ @param is_editing whether this action comes from the editor
@return None
"""
if self.currentActivity:
- return self._first_proxy(self.currentActivity).update(action, newaction, block)
+ return self._first_proxy(self.currentActivity).update(action, newaction, block, is_editing)
else:
raise RuntimeWarning("No activity attached")
- def uninstall(self, action, block=False):
+ def uninstall(self, action, block=False, is_editing=False):
"""
Uninstall an installed action
@param action Action to uninstall
@param block Force a synchroneous dbus call if True
+ @param is_editing whether this action comes from the editor
+ """
+ if self.currentActivity:
+ return self._probes[self.currentActivity].uninstall(action, block, is_editing)
+ else:
+ raise RuntimeWarning("No activity attached")
+
+ def create_event(self, addon_name):
+ """
+ Create an event on the app side and request the user to fill the
+ properties before returning it.
+
+ @param addon_name: the add-on name of the event
+ @returns: an eventfilter instance
"""
if self.currentActivity:
return self._first_proxy(self.currentActivity).uninstall(action, block)