Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/actions.py
diff options
context:
space:
mode:
Diffstat (limited to 'tutorius/actions.py')
-rw-r--r--tutorius/actions.py45
1 files changed, 42 insertions, 3 deletions
diff --git a/tutorius/actions.py b/tutorius/actions.py
index b24d14e..7811dfd 100644
--- a/tutorius/actions.py
+++ b/tutorius/actions.py
@@ -28,6 +28,12 @@ from .properties import *
from .constants import *
+import pickle
+
+import logging
+
+LOGGER = logging.getLogger("actions")
+
class DragWrapper(object):
"""Wrapper to allow gtk widgets to be dragged around"""
@@ -35,12 +41,13 @@ class DragWrapper(object):
LOGGER = logging.getLogger("sugar.tutorius.actions.DragWrapper")
- def __init__(self, widget, position, draggable=False):
+ def __init__(self, widget, position, update_action_cb, draggable=False):
"""
Creates a wrapper to allow gtk widgets to be mouse dragged, if the
parent container supports the move() method, like a gtk.Layout.
@param widget the widget to enhance with drag capability
@param position the widget's position. Will translate the widget if needed
+ @param update_action_cb The callback to trigger
@param draggable wether to enable the drag functionality now
"""
self._widget = widget
@@ -51,6 +58,7 @@ class DragWrapper(object):
self.position = position # position of the widget
self.moved = False
+ self.update_action_cb = update_action_cb
self.draggable = draggable
def _drag_begin(self, widget, drag_context, *args):
@@ -88,11 +96,13 @@ class DragWrapper(object):
self.position = (int(xparent-xrel), int(yparent-yrel))
self.LOGGER.debug("%s drag-end pos: (%s,%s)"%(str(widget),self.position))
+ LOGGER.debug("DragWrapper :: Sending update notification...")
+ self.update_action_cb('position', self.position)
+
self._widget.parent.move(self._eventbox, *self.position)
self._widget.parent.move(self._widget, *self.position)
self._widget.parent.queue_draw()
-
def set_draggable(self, value):
"""Setter for the draggable property"""
if bool(value) ^ bool(self._drag_on):
@@ -150,6 +160,9 @@ class Action(TPropContainer):
TPropContainer.__init__(self)
self.position = (0,0)
self._drag = None
+ # The callback that will be triggered when the action is requested
+ # to notify all its changes
+ self._properties_updated_cb = None
def do(self, **kwargs):
"""
@@ -163,6 +176,32 @@ class Action(TPropContainer):
"""
pass #Should raise NotImplemented?
+
+ def set_notification_cb(self, notif_cb):
+ LOGGER.debug("Action :: Setting notification callback for creator...")
+ self._properties_updated_cb = notif_cb
+
+ def update_property(self, name, value):
+ """
+ Callback used in the wrapper to send a new value to an action.
+ """
+ LOGGER.debug("Action :: update_property on %s with value '%s'"%(name, str(value)))
+ # Set the property itself - this will modify the diff dict and we will
+ # be able to notify the owner with the new value
+ self.__setattr__(name, value)
+
+ # Send the notification to the creator
+ self.notify()
+
+ def notify(self):
+ LOGGER.debug("Action :: Notifying creator with new values in dict : %s"%(str(self._diff_dict)))
+ # If a notification callback was registered
+ if self._property_update_cb:
+ # Propagate it
+ self._property_update_cb(self._diff_dict)
+ # Empty the diff dict as we just synchronized with the creator
+ self._diff_dict.clear()
+
def enter_editmode(self, **kwargs):
"""
Enters edit mode. The action should display itself in some way,
@@ -182,7 +221,7 @@ class Action(TPropContainer):
ObjectStore().activity._overlayer.put(self.__edit_img, x, y)
self.__edit_img.show_all()
- self._drag = DragWrapper(self.__edit_img, self.position, True)
+ self._drag = DragWrapper(self.__edit_img, self.position, update_action_cb=self.update_property, draggable=True)
def exit_editmode(self, **kwargs):
x, y = self._drag.position