diff options
Diffstat (limited to 'src/sugar/tutorius/actions.py')
-rw-r--r-- | src/sugar/tutorius/actions.py | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/src/sugar/tutorius/actions.py b/src/sugar/tutorius/actions.py index d81e3c2..d2516f7 100644 --- a/src/sugar/tutorius/actions.py +++ b/src/sugar/tutorius/actions.py @@ -29,7 +29,7 @@ class Action(object): """Base class for Actions""" def __init__(self): object.__init__(self) - self.properties = {} + self.properties = None def do(self, **kwargs): """ @@ -44,7 +44,12 @@ class Action(object): pass #Should raise NotImplemented? def get_properties(self): - if self.properties is None or len(self.properties) == 0: + """ + Fills self.property with a dict of TutoriusProperty and return the list + of property names. get_properties has to be called before accessing + self.property + """ + if self.properties is None: self.properties = {} for i in dir(self): if isinstance(getattr(self,i), TutoriusProperty): @@ -130,9 +135,9 @@ class BubbleMessage(Action): Action.__init__(self) self.message = TStringProperty(message) # Create the position as an array of fixed-size 2 - self.position = TArrayProperty(pos, 2, 2) + self.position = TArrayProperty(pos or [0,0], 2, 2) # Do the same for the tail position - self.tail_pos = TArrayProperty(tailpos, 2, 2) + self.tail_pos = TArrayProperty(tailpos or [0,0], 2, 2) self.overlay = None self._bubble = None @@ -217,53 +222,54 @@ class DisableWidgetAction(Action): self._widget = gtkutils.find_widget(os.activity, self._target) if self._widget: self._widget.set_sensitive(False) - - def undo(self): + + def undo(self): """Action undo""" if self._widget: self._widget.set_sensitive(True) - + + class TypeTextAction(Action): - """ + """ Simulate a user typing text in a widget Work on any widget that implements a insert_text method - + @param widget The treehish representation of the widget @param text the text that is typed - """ + """ def __init__(self, widget, text): Action.__init__(self) - + self._widget = widget self._text = text - + def do(self, **kwargs): - """ - Type the text - """ + """ + Type the text + """ widget = gtkutils.find_widget(ObjectStore().activity, self._widget) if hasattr(widget, "insert_text"): widget.insert_text(self._text, -1) - - def undo(self): - """ - no undo - """ - pass - + + def undo(self): + """ + no undo + """ + pass + class ClickAction(Action): - """ + """ Action that simulate a click on a widget Work on any widget that implements a clicked() method - + @param widget The threehish representation of the widget - """ + """ def __init__(self, widget): Action.__init__(self) self._widget = widget - - def do(self): - """ + + def do(self): + """ click the widget """ widget = gtkutils.find_widget(ObjectStore().activity, self._widget) @@ -275,3 +281,4 @@ class ClickAction(Action): No undo """ pass + |