Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/tutorius/actions.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/tutorius/actions.py')
-rw-r--r--src/tutorius/actions.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/tutorius/actions.py b/src/tutorius/actions.py
new file mode 100644
index 0000000..b52886d
--- /dev/null
+++ b/src/tutorius/actions.py
@@ -0,0 +1,78 @@
+# Copyright (C) 2009, Tutorius.org
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+"""
+This module defines Actions that can be done and undone on a state
+"""
+import gtk
+
+from gettext import gettext as _
+
+from sugar.graphics import icon
+
+from . import addon
+from .services import ObjectStore
+from .properties import *
+
+class Action(TPropContainer):
+ """Base class for Actions"""
+ def __init__(self):
+ TPropContainer.__init__(self)
+ self.position = (0,0)
+
+ def do(self, **kwargs):
+ """
+ Perform the action
+ """
+ raise NotImplementedError("Not implemented")
+
+ def undo(self):
+ """
+ Revert anything the action has changed
+ """
+ pass #Should raise NotImplemented?
+
+ def enter_editmode(self, **kwargs):
+ """
+ Enters edit mode. The action should display itself in some way,
+ without affecting the currently running application. The default is
+ a small box with the action icon.
+ """
+ meta = addon.get_addon_meta(type(self).__name__)
+
+ self.__edit_img = 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
+
+ self._handle = ObjectStore().activity._overlayer.put(
+ self.__edit_img,
+ x, y,
+ draggable=True,
+ position_cb=self._update_position)
+
+ self.__edit_img.show_all()
+
+ def _update_position(self, x, y):
+ self.position = [int(x), int(y)]
+
+ def exit_editmode(self, **kwargs):
+ ObjectStore().activity._overlayer.remove(self._handle)
+ self.__edit_img.destroy()
+