OSDN Git Service

Initial commit
[rebornos/cnchi-gnome-mac-osdn.git] / Cnchi / show_message.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # show_message.py
5 #
6 # Copyright © 2013-2018 Antergos
7 #
8 # This file is part of Cnchi.
9 #
10 # Cnchi is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Cnchi is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # The following additional terms are in effect as per Section 7 of the license:
21 #
22 # The preservation of all legal notices and author attributions in
23 # the material or in the Appropriate Legal Notices displayed
24 # by works containing it is required.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with Cnchi; If not, see <http://www.gnu.org/licenses/>.
28
29 """ Helper functions to show Gtk message dialogs """
30
31 import sys
32 import os
33 #import multiprocessing
34
35 import gi
36 gi.require_version('Gtk', '3.0')
37 from gi.repository import Gtk
38
39 # When testing, no _() is available
40 try:
41     _("")
42 except NameError as err:
43     def _(msg):
44         return msg
45
46
47 def fatal_error(parent, my_message):
48     """ Shows an error message and quits """
49
50     path = "/var/tmp/cnchi/.setup-running"
51     if os.path.exists(path):
52         os.remove(path)
53
54     # multiprocessing.active_children()
55
56     error(parent, my_message)
57     sys.exit(1)
58
59
60 def error(parent, my_message):
61     """ Shows an error message """
62
63     if not isinstance(parent, Gtk.Window):
64         parent = None
65
66     my_message = str(my_message)
67     msg_dialog = Gtk.MessageDialog(transient_for=parent,
68                                    modal=True,
69                                    destroy_with_parent=True,
70                                    message_type=Gtk.MessageType.ERROR,
71                                    buttons=Gtk.ButtonsType.CLOSE,
72                                    text=_("RebornOS Installer - Error"))
73     msg_dialog.format_secondary_text(my_message)
74     msg_dialog.run()
75     msg_dialog.destroy()
76
77
78 def warning(parent, my_message):
79     """ Shows a warning message """
80
81     if not isinstance(parent, Gtk.Window):
82         parent = None
83
84     my_message = str(my_message)
85     msg_dialog = Gtk.MessageDialog(transient_for=parent,
86                                    modal=True,
87                                    destroy_with_parent=True,
88                                    message_type=Gtk.MessageType.WARNING,
89                                    buttons=Gtk.ButtonsType.CLOSE,
90                                    text=_("RebornOS Installer - Warning"))
91     msg_dialog.format_secondary_text(my_message)
92     msg_dialog.run()
93     msg_dialog.destroy()
94
95
96 def message(parent, my_message):
97     """ Show message """
98
99     if not isinstance(parent, Gtk.Window):
100         parent = None
101
102     my_message = str(my_message)
103     msg_dialog = Gtk.MessageDialog(transient_for=parent,
104                                    modal=True,
105                                    destroy_with_parent=True,
106                                    message_type=Gtk.MessageType.INFO,
107                                    buttons=Gtk.ButtonsType.CLOSE,
108                                    text=_("RebornOS Installer - Information"))
109     msg_dialog.format_secondary_text(my_message)
110     msg_dialog.run()
111     msg_dialog.destroy()
112
113
114 def question(parent, my_message):
115     """ Shows a question message """
116
117     if not isinstance(parent, Gtk.Window):
118         parent = None
119
120     my_message = str(my_message)
121     msg_dialog = Gtk.MessageDialog(transient_for=parent,
122                                    modal=True,
123                                    destroy_with_parent=True,
124                                    message_type=Gtk.MessageType.QUESTION,
125                                    buttons=Gtk.ButtonsType.YES_NO,
126                                    text=_("RebornOS Installer - Confirmation"))
127     msg_dialog.format_secondary_text(my_message)
128     response = msg_dialog.run()
129     msg_dialog.destroy()
130     return response