/[gli]/branches/overhaul/src/fe/gtk/gtkfe.py
Gentoo

Contents of /branches/overhaul/src/fe/gtk/gtkfe.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1807 - (show annotations) (download) (as text)
Sun Mar 18 19:54:31 2007 UTC (7 years, 6 months ago) by agaffney
File MIME type: text/x-python
File size: 10204 byte(s)
bypass exit button checks if install finished/failed
1 #!/usr/bin/python
2
3 # Copyright 1999-2005 Gentoo Foundation
4 # This source code is distributed under the terms of version 2 of the GNU
5 # General Public License as published by the Free Software Foundation, a copy
6 # of which can be found in the main directory of this project.
7
8 import sys
9 sys.path.append("../..")
10
11 import os
12 import GLIInstallProfile
13 import GLIClientController
14 import GLIUtility
15 from SplashScreen import SplashScreen
16 import gtk
17 from gettext import gettext as _
18 import TextBufferMarkup
19 from ProgressDialog import *
20
21 class Installer:
22
23 SHOW_BUTTON_FORWARD = 1
24 SHOW_BUTTON_BACK = 1
25 install_profile_xml_file = ""
26 install_window = None
27 install_type = "standard"
28 cur_screen = None
29 install_done = False
30
31 screens = {
32 "InstallMode": None,
33 "Partition": None,
34 "LocalMounts": None,
35 "NetworkMounts": None,
36 "Stage": None,
37 "PortageTree": None,
38 "MakeDotConf": None,
39 "RootPass": None,
40 "Timezone": None,
41 "Kernel": None,
42 "KernelSources": None,
43 "KernelConfig": None,
44 "Networking": None,
45 "Logger": None,
46 "CronDaemon": None,
47 "Bootloader": None,
48 "Users": None,
49 "ExtraPackages": None,
50 "StartupServices": None,
51 "OtherSettings": None,
52 "InstallDone": None,
53 "InstallFailed": None
54 }
55
56 def __init__(self):
57 self.window = None
58 self.panel = None
59 self._cur_panel = 0
60 self.__full_path = self.get_current_path()
61
62 # Show splash screen
63 self.splash = SplashScreen(self.__full_path)
64 self.splash.show()
65 while gtk.events_pending():
66 gtk.main_iteration()
67
68 # Import screen modules
69 for screen in self.screens:
70 self.screens[screen] = __import__(screen)
71
72 # Instantiate installer objects
73 self.install_profile = GLIInstallProfile.InstallProfile()
74 self.cc = GLIClientController.GLIClientController(self.install_profile)
75
76 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
77 self.title = _("Gentoo Linux Installer")
78 self.window.realize()
79 self.window.connect("delete_event", self.delete_event)
80 self.window.connect("destroy", self.destroy)
81 self.window.set_border_width(0)
82 self.window.set_default_size(800,600)
83 self.window.set_geometry_hints(None, min_width=800, min_height=600, max_width=800, max_height=600)
84 self.window.set_title(_("Gentoo Linux Installer"))
85 self.globalbox = gtk.VBox(False, 0)
86 self.window.add(self.globalbox)
87
88 # Banner image
89 self.headerbox = gtk.HBox(False, 0)
90 headerimg = gtk.Image()
91 headerimg.set_from_file(self.__full_path + '/installer-banner-800x64.png')
92 self.headerbox.pack_start(headerimg, padding=0)
93 self.globalbox.pack_start(self.headerbox, expand=False, fill=False, padding=0)
94
95 # Progress bar
96 # progress_box = gtk.HBox(False, 0)
97 # progress_box.pack_start(gtk.Label("Install Progress"), expand=False, fill=False, padding=10)
98 # self.progress_bar = gtk.ProgressBar()
99 # progress_box.pack_start(self.progress_bar, expand=True, fill=True, padding=10)
100 # self.globalbox.pack_start(progress_box, expand=False, fill=False, padding=5)
101 # self.globalbox.pack_start(gtk.HSeparator(), expand=False, fill=False, padding=0)
102
103 # Top box
104 self.topbox = gtk.HBox(False, 0)
105 self.globalbox.pack_start(self.topbox, expand=True, fill=True, padding=5)
106
107 # Left frame
108 self.leftframe = gtk.Frame()
109 self.leftframe.set_size_request(200, -1)
110 self.leftframe.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
111 self.textbuff = TextBufferMarkup.PangoBuffer()
112 self.textview = gtk.TextView(self.textbuff)
113 self.textview.set_editable(False)
114 self.textview.set_wrap_mode(gtk.WRAP_WORD)
115 self.textview.set_left_margin(5)
116 self.textview.set_right_margin(5)
117 self.textview.set_sensitive(False)
118 self.textviewscroll = gtk.ScrolledWindow()
119 self.textviewscroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
120 self.textviewscroll.add(self.textview)
121 self.leftframe.add(self.textviewscroll)
122 self.topbox.pack_start(self.leftframe, expand=True, fill=True, padding=5)
123
124 # Right frame
125 self.rightframe = gtk.VBox(False, 0)
126 self.rightframe.set_size_request(570, -1)
127 self.topbox.pack_end(self.rightframe, expand=True, fill=True, padding=5)
128 self.globalbox.show_all();
129
130 # Bottom box
131 self.bottombox = gtk.HBox(False, 0)
132 self.globalbox.pack_end(self.bottombox, expand=False, fill=False, padding=5)
133 self.globalbox.pack_end(gtk.HSeparator(), expand=False, fill=False, padding=0)
134
135 buttons_info = [ ('exit', _(" _Exit "), '/button_images/stock_exit.png', self.exit_button, 'start'),
136 # ('load', _(" _Load "), '/button_images/stock_open.png', self.load_button, 'start'),
137 # ('save', _(" _Save "), '/button_images/stock_save.png', self.save_button, 'start'),
138 ('log', _(" _View Log "), '', self.log_button, 'start'),
139 ('next', _(" _Next "), '/button_images/stock_right.png', self.next, 'end'),
140 ('previous', _(" _Previous "), '/button_images/stock_left.png', self.previous, 'end')
141 ]
142 self.buttons = {}
143 for button in buttons_info:
144 self.buttons[button[0]] = gtk.Button()
145 tmpbuttonbox = gtk.HBox(False, 0)
146 if button[2]:
147 tmpbuttonimg = gtk.Image()
148 tmpbuttonimg.set_from_file(self.__full_path + button[2])
149 tmpbuttonbox.pack_start(tmpbuttonimg)
150 tmpbuttonlabel = gtk.Label(button[1])
151 tmpbuttonlabel.set_use_underline(True)
152 tmpbuttonbox.pack_start(tmpbuttonlabel)
153 self.buttons[button[0]].add(tmpbuttonbox)
154 self.buttons[button[0]].connect("clicked", button[3], None)
155 if button[4] == "start":
156 self.bottombox.pack_start(self.buttons[button[0]], expand=False, fill=False, padding=5)
157 else:
158 self.bottombox.pack_end(self.buttons[button[0]], expand=False, fill=False, padding=5)
159
160 self.splash.destroy()
161 self.window.show_all()
162 self.load_screen("InstallMode")
163
164 def redraw_buttons(self):
165 self.bottombox.hide_all()
166 self.buttons['next'].set_sensitive(self.SHOW_BUTTON_FORWARD)
167 self.buttons['previous'].set_sensitive(self.SHOW_BUTTON_BACK)
168 self.bottombox.show_all()
169
170 def get_current_path(self):
171 # this will return the absolute path to the
172 # directory containing this file
173 # it will only work if this file is imported somewhere,
174 # not if it is run directly (__file__ will be undefined)
175 import os.path
176 return os.path.abspath(os.path.dirname(__file__))
177
178 def load_screen(self, name):
179 if self.cur_screen:
180 self.rightframe.remove(self.cur_screen)
181 del self.cur_screen
182 self.cur_screen = self.screens[name].Panel(self)
183 # percent = int((i) / float(len(self.screens) - 1) * 100)
184 # self.progress_bar.set_fraction(float(percent) / 100)
185 # self.progress_bar.set_text(str(percent) + "%")
186 self.rightframe.add(self.cur_screen)
187 self.cur_screen.activate()
188 helptext = self.cur_screen._helptext
189 # helptext = " ".join(helptext.split("\n"))
190 # helptext = "\n".join(helptext.split('<br>'))
191 self.textbuff.set_text(helptext)
192 self.rightframe.show_all()
193 self.redraw_buttons()
194
195 def run(self):
196 gtk.gdk.threads_init()
197 gtk.main()
198
199 def previous(self, widget, data=None):
200 self.cur_screen.previous()
201
202 def next(self, widget, data=None):
203 self.cur_screen.next()
204
205 def exit_button(self, widget, data=None):
206 if not self.install_done:
207 msgdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format="Are you sure you want to exit?")
208 resp = msgdlg.run()
209 msgdlg.destroy()
210 if resp == gtk.RESPONSE_YES:
211 msgdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format="Do you want the installer to clean up after itself before exiting?")
212 resp = msgdlg.run()
213 msgdlg.destroy()
214 if resp == gtk.RESPONSE_YES:
215 progress = ProgressDialog(self, ("install_failed_cleanup", ), self.exit_callback)
216 progress.run()
217 else:
218 self.exit()
219 else:
220 self.exit()
221
222 def exit_callback(self, result):
223 self.exit()
224
225 def load_button(self, widget, data=None):
226 filesel = gtk.FileSelection(_("Select the install profile to load"))
227 if self.install_profile_xml_file == "":
228 filesel.set_filename("installprofile.xml")
229 else:
230 filesel.set_filename(self.install_profile_xml_file)
231 resp = filesel.run()
232 filename = filesel.get_filename()
233 filesel.destroy()
234 if resp == gtk.RESPONSE_OK:
235 self.install_profile_xml_file = filename
236 try:
237 tmp_install_profile = GLIInstallProfile.InstallProfile()
238 tmp_install_profile.parse(self.install_profile_xml_file)
239 self.install_profile = tmp_install_profile
240 msgdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK, message_format=_("Install profile loaded successfully!"))
241 msgdlg.run()
242 msgdlg.destroy()
243 except:
244 errdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format=_("An error occured loading the install profile"))
245 errdlg.run()
246 errdlg.destroy()
247
248 def save_button(self, widget, data=None):
249 filesel = gtk.FileSelection(_("Select the location to save the install profile"))
250 if self.install_profile_xml_file == "":
251 filesel.set_filename("installprofile.xml")
252 else:
253 filesel.set_filename(self.install_profile_xml_file)
254 resp = filesel.run()
255 filename = filesel.get_filename()
256 filesel.destroy()
257 if resp == gtk.RESPONSE_OK:
258 self.install_profile_xml_file = filename
259 try:
260 configuration = open(filename, "w")
261 configuration.write(self.install_profile.serialize())
262 configuration.close()
263 msgdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK, message_format=_("Install profile saved successfully!"))
264 msgdlg.run()
265 msgdlg.destroy()
266 except:
267 errdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format=_("An error occured saving the install profile"))
268 errdlg.run()
269 errdlg.destroy()
270
271 def log_button(self, widget, data=None):
272 os.system("xterm -e 'tail -f /var/log/installer.log' &")
273
274 def delete_event(self, widget, event, data=None):
275 self.exit_button(self.buttons['exit'])
276 return True
277
278 def destroy(self, widget, data=None):
279 gtk.main_quit()
280 return True
281
282 def exit(self, status=0):
283 gtk.main_quit()
284 sys.exit(status)
285
286 if __name__ == "__main__":
287 install = Installer()
288 install.run()

Properties

Name Value
svn:eol-style native
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20