Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/tutorius/actions.py
blob: b52886de55b7a9275af53523abaf453ee7f9e2a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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()