Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/TProbe.py
diff options
context:
space:
mode:
authorerick <erick@sugar-dev-erick.(none)>2009-10-30 15:09:05 (GMT)
committer erick <erick@sugar-dev-erick.(none)>2009-10-30 15:09:05 (GMT)
commit37e2ab5dd552be9aec49ccf774c90da8b962ea9f (patch)
tree6d9d2530125c1ce594e4d1d0c5dcbcaed47f19d3 /tutorius/TProbe.py
parent580c2fd667bb803b96504eba3516d566f04e1688 (diff)
parentd5c9eac8fbf938c1874672b78272ba1bee41e573 (diff)
Merge branch 'master' of git://git.sugarlabs.org/tutorius/mainline into tutorialADT
Diffstat (limited to 'tutorius/TProbe.py')
-rw-r--r--tutorius/TProbe.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py
index e18ed67..f55547c 100644
--- a/tutorius/TProbe.py
+++ b/tutorius/TProbe.py
@@ -8,12 +8,12 @@ import dbus
import dbus.service
import cPickle as pickle
-import sugar.tutorius.addon as addon
-from sugar.tutorius.services import ObjectStore
-from sugar.tutorius.properties import TPropContainer
+from . import addon
+from .services import ObjectStore
+from .properties import TPropContainer
-from sugar.tutorius.dbustools import remote_call, save_args
+from .dbustools import remote_call, save_args
import copy
"""
@@ -195,7 +195,11 @@ class TProbe(dbus.service.Object):
# The actual method we will call on the probe to send events
def notify(self, event):
LOGGER.debug("TProbe :: notify event %s", str(event))
- self.eventOccured(pickle.dumps(event))
+ #Check that this event is even allowed
+ if event in self._subscribedEvents.values():
+ self.eventOccured(pickle.dumps(event))
+ else:
+ raise RuntimeWarning("Attempted to raise an unregistered event")
# Return a unique name for this action
def _generate_action_reference(self, action):
@@ -400,8 +404,8 @@ class ProbeProxy:
Detach the ProbeProxy from it's TProbe. All installed actions and
subscribed events should be removed.
"""
- for action in self._actions.keys():
- self.uninstall(action, block)
+ for action_addr in self._actions.keys():
+ self.uninstall(action_addr, block)
for address in self._subscribedEvents.keys():
self.unsubscribe(address, block)
@@ -414,7 +418,13 @@ class ProbeManager(object):
For now, it only handles one at a time, though.
Actually it doesn't do much at all. But it keeps your encapsulation happy
"""
- def __init__(self):
+ def __init__(self, proxy_class=ProbeProxy):
+ """Constructor
+ @param proxy_class Class to use for creating Proxies to activities.
+ The class should support the same interface as ProbeProxy. Exists
+ to make this class unit-testable by replacing the Proxy with a mock
+ """
+ self._ProxyClass = proxy_class
self._probes = {}
self._current_activity = None
@@ -431,7 +441,7 @@ class ProbeManager(object):
if activity_id in self._probes:
raise RuntimeWarning("Activity already attached")
- self._probes[activity_id] = ProbeProxy(activity_id)
+ self._probes[activity_id] = self._ProxyClass(activity_id)
#TODO what do we do with this? Raise something?
if self._probes[activity_id].isAlive():
print "Alive!"
@@ -442,6 +452,8 @@ class ProbeManager(object):
if activity_id in self._probes:
probe = self._probes.pop(activity_id)
probe.detach()
+ if self._current_activity == activity_id:
+ self._current_activity = None
def install(self, action, block=False):
"""