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.py53
1 files changed, 49 insertions, 4 deletions
diff --git a/tutorius/actions.py b/tutorius/actions.py
index 75c9c9b..a32138f 100644
--- a/tutorius/actions.py
+++ b/tutorius/actions.py
@@ -26,14 +26,21 @@ from . import addon
from .services import ObjectStore
from .properties import *
+import pickle
+
+import logging
+
+LOGGER = logging.getLogger("actions")
+
class DragWrapper(object):
"""Wrapper to allow gtk widgets to be dragged around"""
- 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
@@ -45,6 +52,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 _pressed_cb(self, widget, evt):
@@ -79,10 +87,13 @@ class DragWrapper(object):
self._eventbox.grab_remove()
self._dragging = False
+ LOGGER.debug("DragWrapper :: Sending update notification...")
+ self.update_action_cb('position', self.position)
+
def _drag_end(self, *args):
"""Callback for end of drag (stolen focus)."""
self._dragging = False
-
+
def set_draggable(self, value):
"""Setter for the draggable property"""
if bool(value) ^ bool(self._drag_on):
@@ -139,6 +150,12 @@ class Action(TPropContainer):
TPropContainer.__init__(self)
self.position = (0,0)
self._drag = None
+ # The differences dictionary. This is a structure that holds all the
+ # modifications that were made to the properties since the action
+ # was last installed or the last moment the notification was executed.
+ # Every property change will be logged inside it and it will be sent
+ # to the creator to update its action edition dialog.
+ self._property_update_cb = None
def do(self, **kwargs):
"""
@@ -152,7 +169,35 @@ class Action(TPropContainer):
"""
pass #Should raise NotImplemented?
- def enter_editmode(self, **kwargs):
+
+ def set_notification_cb(self, notif_cb):
+ LOGGER.debug("Action :: Setting notification callback for creator...")
+ self._property_update_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)))
+ #property = getattr(self, name)
+ #property = value
+
+ #self._props[name] = 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, *args, **kwargs):
"""
Enters edit mode. The action should display itself in some way,
without affecting the currently running application. The default is
@@ -171,7 +216,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