diff options
Diffstat (limited to 'src/sugar/tutorius/actions.py')
-rw-r--r-- | src/sugar/tutorius/actions.py | 70 |
1 files changed, 21 insertions, 49 deletions
diff --git a/src/sugar/tutorius/actions.py b/src/sugar/tutorius/actions.py index ad91fb4..d81e3c2 100644 --- a/src/sugar/tutorius/actions.py +++ b/src/sugar/tutorius/actions.py @@ -23,12 +23,13 @@ from dialog import TutoriusDialog import overlayer from sugar.tutorius.editor import WidgetIdentifier from sugar.tutorius.services import ObjectStore - +from sugar.tutorius.properties import * class Action(object): """Base class for Actions""" def __init__(self): object.__init__(self) + self.properties = {} def do(self, **kwargs): """ @@ -43,12 +44,12 @@ class Action(object): pass #Should raise NotImplemented? def get_properties(self): - if not hasattr(self, "_props") or self._props is None: - self._props = [] - for i in dir(self.__class__): - if type(getattr(self.__class__,i)) is property: - self._props.append(i) - return self._props + if self.properties is None or len(self.properties) == 0: + self.properties = {} + for i in dir(self): + if isinstance(getattr(self,i), TutoriusProperty): + self.properties[i] = getattr(self,i) + return self.properties.keys() class OnceWrapper(object): """ @@ -89,36 +90,21 @@ class DialogMessage(Action): @param message A string to display to the user @param pos A list of the form [x, y] """ - def __init__(self, message, pos=[0,0]): + def __init__(self, message, pos=None): super(DialogMessage, self).__init__() - self._message = message - self._position = pos self._dialog = None - - def set_message(self, msg): - self._message = msg - - def get_message(self): - return self._message - - message = property(fget=get_message, fset=set_message) - - def set_pos(self, x, y): - self._position = [x, y] - def get_pos(self): - return self._position - - position = property(fget=get_pos, fset=set_pos) + self.message = TStringProperty(message) + self.position = TArrayProperty(pos or [0, 0], 2, 2) def do(self): """ Show the dialog """ - self._dialog = TutoriusDialog(self._message) + self._dialog = TutoriusDialog(self.message.value) self._dialog.set_button_clicked_cb(self._dialog.close_self) self._dialog.set_modal(False) - self._dialog.move(self.position[0], self.position[1]) + self._dialog.move(self.position.value[0], self.position.value[1]) self._dialog.show() def undo(self): @@ -137,34 +123,20 @@ class BubbleMessage(Action): @param message A string to display to the user @param pos A list of the form [x, y] @param speaker treeish representation of the speaking widget + @param tailpos The position of the tail of the bubble; useful to point to + specific elements of the interface """ def __init__(self, message, pos=[0,0], speaker=None, tailpos=None): Action.__init__(self) - self._message = message - self._position = pos - + self.message = TStringProperty(message) + # Create the position as an array of fixed-size 2 + self.position = TArrayProperty(pos, 2, 2) + # Do the same for the tail position + self.tail_pos = TArrayProperty(tailpos, 2, 2) + self.overlay = None self._bubble = None self._speaker = None - self._tailpos = tailpos - - def set_message(self, msg): - self._message = msg - def get_message(self): - return self._message - message = property(fget=get_message, fset=set_message, doc="Message displayed to the user") - - def set_pos(self, x, y): - self._position = [x, y] - def get_pos(self): - return self.position - position = property(fget=get_pos, fset=set_pos, doc="Position in [x, y] on the screen") - - def set_tail_pos(self, x, y): - self._tailpos = [x, y] - def get_tail_pos(self): - return self._tailpos - tail_pos = property(fget=get_tail_pos, fset=set_tail_pos, doc="Position the tail of the bubble must point to") def do(self): """ |