Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/addons/closeactivity.py
blob: f5c6d7bcc6a0fc32dc5c6e1cb108f2fa2ec30ff1 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# 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

import gtk, gtk.gdk

from sugar.tutorius.filters import EventFilter
from sugar.tutorius.properties import TStringProperty
from sugar.tutorius import overlayer
from sugar.tutorius.services import ObjectStore

class CloseActivity(EventFilter):
    """
    CloseActivity
    """
    message = TStringProperty("Message")

    def __init__(self, message=None):
        """Constructor.

        @param message message to display
        """
        super(CloseActivity,self).__init__()

        self.message = None
        if message:
            self.message = message

        self.overlay = None
        self.msgnext = None

        self.act = None

    def install_handlers(self, callback, **kwargs):
        """install_handlers creates the close activity message and shows it"""
        super(CloseActivity,self).install_handlers(callback, **kwargs)
        if not "activity" in kwargs:
            raise TypeError("activity argument is Mandatory")

        self.act = kwargs["activity"]

        # get or inject overlayer
        self.overlay = ObjectStore().activity._overlayer

        if not self.overlay:
            self.overlay = ObjectStore().activity._overlayer

        self.msgnext = None

        self.btntext = "CLOSE"

        self.msgnext = overlayer.MsgNext(text=self.message,btntext=self.btntext)

        self.msgnext._btnnext.connect("clicked", self.btnnext_clicked)

        # add space around minimum need size
        wid_width, wid_height = self.msgnext.size_request()
        self.msgnext.set_size_request(wid_width+40, wid_height+40)

        self.msgnext.show()

        # set position
        wid_width, wid_height = self.msgnext.size_request()

        # get position (center of screen)
        screen = gtk.gdk.Screen()
        scr_width_half = screen.get_width()/2
        scr_height_half = screen.get_height()/2

        self.position = (scr_width_half-wid_width/2, scr_height_half-wid_height/2)
        x, y = self.position

        self.overlay.put(self.msgnext, x, y)
        
        self.overlay.queue_draw()
        
    def remove_handlers(self):
        """remove handler removes the close activity message"""
        super(CloseActivity,self).remove_handlers()

        if self.msgnext:
            self.msgnext.destroy()
            self.msgnext = None

    def btnnext_clicked(self, widget):
        self.act.close()
        self.do_callback()

__event__ = {
    "name" : "CloseActivity",
    "display_name" : "Close activity message",
    "icon" : "message-bubble",
    "class" : CloseActivity,
    "mandatory_props" : ["message"]
}