From dbf88e0f12fe015467ecf89d95a2ba4303d9f73a Mon Sep 17 00:00:00 2001 From: erick Date: Sat, 05 Dec 2009 00:19:19 +0000 Subject: Merge branch 'master' into frame_integration --- (limited to 'tutorius/actions.py') diff --git a/tutorius/actions.py b/tutorius/actions.py index 75c9c9b..8cc5f08 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,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): """ @@ -152,6 +166,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, @@ -171,7 +211,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 -- cgit v0.9.1