Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/tutorius/actions.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/sugar/tutorius/actions.py')
-rw-r--r--src/sugar/tutorius/actions.py173
1 files changed, 35 insertions, 138 deletions
diff --git a/src/sugar/tutorius/actions.py b/src/sugar/tutorius/actions.py
index 570bff8..4269cd7 100644
--- a/src/sugar/tutorius/actions.py
+++ b/src/sugar/tutorius/actions.py
@@ -18,12 +18,13 @@ This module defines Actions that can be done and undone on a state
"""
from gettext import gettext as _
-from sugar.tutorius import gtkutils
+from sugar.tutorius import gtkutils, addon
from dialog import TutoriusDialog
import overlayer
from sugar.tutorius.editor import WidgetIdentifier
from sugar.tutorius.services import ObjectStore
from sugar.tutorius.properties import *
+from sugar.graphics import icon
import gtk.gdk
class DragWrapper(object):
@@ -131,11 +132,12 @@ class DragWrapper(object):
widget = property(fset=set_widget, fget=get_widget)
-class Action(object):
+class Action(TPropContainer):
"""Base class for Actions"""
def __init__(self):
- object.__init__(self)
- self.properties = None
+ TPropContainer.__init__(self)
+ self.position = (0,0)
+ self._drag = None
def do(self, **kwargs):
"""
@@ -149,37 +151,47 @@ class Action(object):
"""
pass #Should raise NotImplemented?
- def get_properties(self):
- """
- 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):
- self.properties[i] = getattr(self,i)
- return self.properties.keys()
-
def enter_editmode(self, **kwargs):
"""
Enters edit mode. The action should display itself in some way,
- without affecting the currently running application.
+ without affecting the currently running application. The default is
+ a small box with the action icon.
"""
- raise NotImplementedError("Not implemented")
+ meta = addon.get_addon_meta(type(self).__name__)
+
+ actionicon = icon.Icon(icon_name=meta['icon'],
+ icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
+ # Eventbox create a visible window for the icon, so it clips correctly
+ self.__edit_img = gtk.EventBox()
+ self.__edit_img.set_visible_window(True)
+ self.__edit_img.add(actionicon)
+
+ x, y = self.position
+
+ ObjectStore().activity._overlayer.put(self.__edit_img, x, y)
+ self.__edit_img.show_all()
+ self._drag = DragWrapper(self.__edit_img, self.position, True)
+
+ def exit_editmode(self, **kwargs):
+ x, y = self._drag.position
+ self.position = [int(x), int(y)]
+ self.__edit_img.destroy()
-class OnceWrapper(object):
+class OnceWrapper(Action):
"""
Wraps a class to perform an action once only
This ConcreteActions's do() method will only be called on the first do()
and the undo() will be callable after do() has been called
"""
+
+ _action = TAddonProperty()
+
def __init__(self, action):
- self._action = action
+ Action.__init__(self)
self._called = False
self._need_undo = False
+ self._action = action
def do(self):
"""
@@ -197,126 +209,10 @@ class OnceWrapper(object):
if self._need_undo:
self._action.undo()
self._need_undo = False
-
- def get_properties(self):
- return self._action.get_properties()
-
-class DialogMessage(Action):
- """
- Shows a dialog with a given text, at the given position on the screen.
-
- @param message A string to display to the user
- @param pos A list of the form [x, y]
- """
- def __init__(self, message, pos=None):
- super(DialogMessage, self).__init__()
- self._dialog = None
-
- self.message = TStringProperty(message)
- self.position = TArrayProperty(pos or [0, 0], 2, 2)
-
- def do(self):
- """
- Show the dialog
- """
- 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.value[0], self.position.value[1])
- self._dialog.show()
-
- def undo(self):
- """
- Destroy the dialog
- """
- if self._dialog:
- self._dialog.destroy()
- self._dialog = None
-
-
-class BubbleMessage(Action):
- """
- Shows a dialog with a given text, at the given position on the screen.
-
- @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=None, speaker=None, tailpos=None):
- Action.__init__(self)
- self.message = TStringProperty(message)
- # Create the position as an array of fixed-size 2
- self.position = TArrayProperty(pos or [0,0], 2, 2)
- # Do the same for the tail position
- self.tail_pos = TArrayProperty(tailpos or [0,0], 2, 2)
-
- self.overlay = None
- self._bubble = None
- self._speaker = None
- self.__drag = None
-
- def do(self):
- """
- Show the dialog
- """
- # get or inject overlayer
- self.overlay = ObjectStore().activity._overlayer
- # FIXME: subwindows, are left to overlap this. This behaviour is
- # undesirable. subwindows (i.e. child of top level windows) should be
- # handled either by rendering over them, or by finding different way to
- # draw the overlay.
-
- if not self.overlay:
- self.overlay = ObjectStore().activity._overlayer
- if not self._bubble:
- x, y = self.position.value
- # TODO: tails are relative to tailpos. They should be relative to
- # the speaking widget. Same of the bubble position.
- self._bubble = overlayer.TextBubble(text=self.message.value,
- tailpos=self.tail_pos.value)
- self._bubble.show()
- self.overlay.put(self._bubble, x, y)
- self.overlay.queue_draw()
-
- def undo(self):
- """
- Destroy the dialog
- """
- if self._bubble:
- self._bubble.destroy()
- self._bubble = None
-
- def enter_editmode(self, *args):
- """
- Enters edit mode. The action should display itself in some way,
- without affecting the currently running application.
- """
- if not self.overlay:
- self.overlay = ObjectStore().activity._overlayer
- assert not self.__drag, "bubble action set to editmode twice"
- x, y = self.position.value
- self._bubble = overlayer.TextBubble(text=self.message.value,
- tailpos=self.tail_pos.value)
- self.overlay.put(self._bubble, x, y)
- self._bubble.show()
-
- self.__drag = DragWrapper(self._bubble, self.position.value, True)
-
- def exit_editmode(self, *args):
- x,y = self.__drag.position
- self.position.set([int(x), int(y)])
- if self.__drag:
- self.__drag.draggable = False
- self.__drag = None
- if self._bubble:
- self.overlay.remove(self._bubble)
- self._bubble = None
- self.overlay = None
class WidgetIdentifyAction(Action):
def __init__(self):
+ Action.__init__(self)
self.activity = None
self._dialog = None
@@ -337,6 +233,7 @@ class ChainAction(Action):
"""Utility class to allow executing actions in a specific order"""
def __init__(self, *actions):
"""ChainAction(action1, ... ) builds a chain of actions"""
+ Action.__init__(self)
self._actions = actions
def do(self,**kwargs):