OSDN Git Service

2020.05.14 update
[rebornos/cnchi-gnome-osdn.git] / Cnchi / welcome.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # welcome.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 """ Welcome screen """
30
31 import os
32 import logging
33 import multiprocessing
34 import sys
35
36 import gi
37 gi.require_version('GdkPixbuf', '2.0')
38 from gi.repository import GdkPixbuf
39
40 import misc.extra as misc
41 from pages.gtkbasebox import GtkBaseBox
42
43 # When testing, no _() is available
44 try:
45     _("")
46 except NameError as err:
47     def _(message):
48         return message
49
50
51 class Welcome(GtkBaseBox):
52     """ Welcome screen class """
53
54     def __init__(self, params, prev_page=None, next_page="language"):
55         super().__init__(self, params, "welcome", prev_page, next_page)
56
57         data_dir = self.settings.get('data')
58         welcome_dir = os.path.join(data_dir, "images", "welcome")
59
60         self.main_window = params['main_window']
61
62         self.labels = {'welcome': self.gui.get_object("welcome_label"),
63                        'tryit': self.gui.get_object("tryit_welcome_label"),
64                        'installit': self.gui.get_object("installit_welcome_label"),
65                        'loading': self.gui.get_object("loading_label")}
66
67         self.buttons = {'tryit': self.gui.get_object("tryit_button"),
68                         # 'cli': self.gui.get_object("cli_button"),
69                         'graph': self.gui.get_object("graph_button")}
70
71         for key in self.buttons:
72             btn = self.buttons[key]
73             btn.set_name(key + "_btn")
74
75         self.images = {'tryit': self.gui.get_object("tryit_image"),
76                        # 'cli': self.gui.get_object("cli_image"),
77                        'graph': self.gui.get_object("graph_image")}
78
79         self.filenames = {
80             'tryit': {
81                 'path': os.path.join(welcome_dir, "try-it.svg"),
82                 'width': 211,
83                 'height': 185},
84             'graph': {
85                 'path': os.path.join(welcome_dir, "install-it.svg"),
86                 'width': 211,
87                 'height': 185}}
88
89         # a11y
90         self.labels['tryit'].set_mnemonic_widget(self.buttons['tryit'])
91         self.labels['installit'].set_mnemonic_widget(self.buttons['graph'])
92
93         for key in self.images:
94             image = self.filenames[key]
95             pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
96                 image['path'],
97                 image['width'],
98                 image['height'])
99             self.images[key].set_from_pixbuf(pixbuf)
100
101     def translate_ui(self):
102         """ Translates all ui elements """
103         if not self.no_tryit:
104             txt = _("Use RebornOS without making any changes to your system.")
105         else:
106             txt = ""
107         self.labels['tryit'].set_markup(txt)
108         self.labels['tryit'].set_name('tryit_label')
109
110         txt = _("Create a permanent place for RebornOS on your system.")
111         self.labels['installit'].set_markup(txt)
112         self.labels['installit'].set_name('installit_label')
113
114         txt = _("Try It")
115         self.buttons['tryit'].set_label(txt)
116
117         # txt = _("CLI Installer")
118         # self.buttons['cli'].set_label(txt)
119
120         txt = _("Install It")
121         self.buttons['graph'].set_label(txt)
122
123         txt = _("Welcome to RebornOS!")
124         self.header.set_subtitle(txt)
125
126     def quit_cnchi(self):
127         """ Quits installer """
128         misc.remove_temp_files(self.settings.get('temp'))
129         for proc in multiprocessing.active_children():
130             proc.terminate()
131         logging.shutdown()
132         sys.exit(0)
133
134     def on_tryit_button_clicked(self, _widget, _data=None):
135         """ Try live CD, quits installer """
136         self.quit_cnchi()
137
138     def on_graph_button_clicked(self, _widget, _data=None):
139         """ User wants to install """
140         self.show_loading_message()
141         # Tell timezone process to start searching now
142         self.settings.set('timezone_start', True)
143         # Simulate a forward button click
144         self.forward_button.clicked()
145
146     def show_loading_message(self, do_show=True):
147         """ Shows a message so the user knows Cnchi is loading pages
148             only when running from liveCD """
149         if do_show:
150             txt = _("Loading, please wait...")
151         else:
152             txt = ""
153         self.labels['loading'].set_markup(txt)
154         self.labels['loading'].queue_draw()
155         misc.gtk_refresh()
156
157     def store_values(self):
158         """ Store changes (none in this page) """
159         self.forward_button.show()
160         return True
161
162     def prepare(self, direction):
163         """ Prepare page before showing it """
164         self.translate_ui()
165         self.show_all()
166         self.forward_button.hide()
167
168         # a11y Set install option as default if ENTER is pressed
169         self.buttons['graph'].set_can_default(True)
170         self.main_window.set_default(self.buttons['graph'])
171
172         if self.no_tryit:
173             self.buttons['tryit'].set_sensitive(False)
174         if direction == "backwards":
175             self.show_loading_message(do_show=False)