Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/addons/dialogmessage.py
blob: 298466a508fc07c0457428a63becc69336ee1671 (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
# Copyright (C) 2009, Tutorius.org
# Copyright (C) 2009, Simon Poirier <simpoir@gmail.com>
#
#
# 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

from sugar.tutorius.actions import *

class DialogMessage(Action):
    message = TStringProperty("Message")
    position = TArrayProperty([0, 0], 2, 2)

    def __init__(self, message=None, position=None):
        """
        Shows a dialog with a given text, at the given position on the screen.

        @param message A string to display to the user
        @param position A list of the form [x, y]
        """
        super(DialogMessage, self).__init__()
        self._dialog = None
        
        if message:
            self.message = message
        if position: self.position = position

    def do(self):
        """
            Show the dialog
        """
        self._dialog = TutoriusDialog(self.message)
        self._dialog.set_button_clicked_cb(self._dialog.close_self)
        self._dialog.set_modal(False)
        self._dialog.move(self.position[0], self.position[1])
        self._dialog.show()

    def undo(self):
        """
            Destroy the dialog
        """
        if self._dialog:
            self._dialog.destroy()
            self._dialog = None

__action__ = {
    "name" : "DialogMessage",
    "display_name" : "Message Dialog",
    "icon" : "window_fullscreen",
    "class" : DialogMessage,
    "mandatory_props" : ["message"]
}

# vim:set ts=4 sts=4 sw=4 et: