/[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 1826 - (show annotations) (download) (as text)
Fri Mar 23 13:25:22 2007 UTC (7 years, 4 months ago) by agaffney
File MIME type: text/x-python
File size: 10355 byte(s)
set verbose if -d/--debug on commandline
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 if '-d' in sys.argv or '--debug' in sys.argv:
75 # Enable debug mode via commandline argument
76 self._install_profile.set_verbose(None, True, None)
77 self.cc = GLIClientController.GLIClientController(self.install_profile)
78
79 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
80 self.title = _("Gentoo Linux Installer")
81 self.window.realize()
82 self.window.connect("delete_event", self.delete_event)
83 self.window.connect("destroy", self.destroy)
84 self.window.set_border_width(0)
85 self.window.set_default_size(800,600)
86 self.window.set_geometry_hints(None, min_width=800, min_height=600, max_width=800, max_height=600)
87 self.window.set_title(_("Gentoo Linux Installer"))
88 self.globalbox = gtk.VBox(False, 0)
89 self.window.add(self.globalbox)
90
91 # Banner image
92 self.headerbox = gtk.HBox(False, 0)
93 headerimg = gtk.Image()
94 headerimg.set_from_file(self.__full_path + '/installer-banner-800x64.png')
95 self.headerbox.pack_start(headerimg, padding=0)
96 self.globalbox.pack_start(self.headerbox, expand=False, fill=False, padding=0)
97
98 # Progress bar
99 # progress_box = gtk.HBox(False, 0)
100 # progress_box.pack_start(gtk.Label("Install Progress"), expand=False, fill=False, padding=10)
101 # self.progress_bar = gtk.ProgressBar()
102 # progress_box.pack_start(self.progress_bar, expand=True, fill=True, padding=10)
103 # self.globalbox.pack_start(progress_box, expand=False, fill=False, padding=5)
104 # self.globalbox.pack_start(gtk.HSeparator(), expand=False, fill=False, padding=0)
105
106 # Top box
107 self.topbox = gtk.HBox(False, 0)
108 self.globalbox.pack_start(self.topbox, expand=True, fill=True, padding=5)
109
110 # Left frame
111 self.leftframe = gtk.Frame()
112 self.leftframe.set_size_request(200, -1)
113 self.leftframe.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
114 self.textbuff = TextBufferMarkup.PangoBuffer()
115 self.textview = gtk.TextView(self.textbuff)
116 self.textview.set_editable(False)
117 self.textview.set_wrap_mode(gtk.WRAP_WORD)
118 self.textview.set_left_margin(5)
119 self.textview.set_right_margin(5)
120 self.textview.set_sensitive(False)
121 self.textviewscroll = gtk.ScrolledWindow()
122 self.textviewscroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
123 self.textviewscroll.add(self.textview)
124 self.leftframe.add(self.textviewscroll)
125 self.topbox.pack_start(self.leftframe, expand=True, fill=True, padding=5)
126
127 # Right frame
128 self.rightframe = gtk.VBox(False, 0)
129 self.rightframe.set_size_request(570, -1)
130 self.topbox.pack_end(self.rightframe, expand=True, fill=True, padding=5)
131 self.globalbox.show_all();
132
133 # Bottom box
134 self.bottombox = gtk.HBox(False, 0)
135 self.globalbox.pack_end(self.bottombox, expand=False, fill=False, padding=5)
136 self.globalbox.pack_end(gtk.HSeparator(), expand=False, fill=False, padding=0)
137
138 buttons_info = [ ('exit', _(" _Exit "), '/button_images/stock_exit.png', self.exit_button, 'start'),
139 # ('load', _(" _Load "), '/button_images/stock_open.png', self.load_button, 'start'),
140 # ('save', _(" _Save "), '/button_images/stock_save.png', self.save_button, 'start'),
141 ('log', _(" _View Log "), '', self.log_button, 'start'),
142 ('next', _(" _Next "), '/button_images/stock_right.png', self.next, 'end'),
143 ('previous', _(" _Previous "), '/button_images/stock_left.png', self.previous, 'end')
144 ]
145 self.buttons = {}
146 for button in buttons_info:
147 self.buttons[button[0]] = gtk.Button()
148 tmpbuttonbox = gtk.HBox(False, 0)
149 if button[2]:
150 tmpbuttonimg = gtk.Image()
151 tmpbuttonimg.set_from_file(self.__full_path + button[2])
152 tmpbuttonbox.pack_start(tmpbuttonimg)
153 tmpbuttonlabel = gtk.Label(button[1])
154 tmpbuttonlabel.set_use_underline(True)
155 tmpbuttonbox.pack_start(tmpbuttonlabel)
156 self.buttons[button[0]].add(tmpbuttonbox)
157 self.buttons[button[0]].connect("clicked", button[3], None)
158 if button[4] == "start":
159 self.bottombox.pack_start(self.buttons[button[0]], expand=False, fill=False, padding=5)
160 else:
161 self.bottombox.pack_end(self.buttons[button[0]], expand=False, fill=False, padding=5)
162
163 self.splash.destroy()
164 self.window.show_all()
165 self.load_screen("InstallMode")
166
167 def redraw_buttons(self):
168 self.bottombox.hide_all()
169 self.buttons['next'].set_sensitive(self.SHOW_BUTTON_FORWARD)
170 self.buttons['previous'].set_sensitive(self.SHOW_BUTTON_BACK)
171 self.bottombox.show_all()
172
173 def get_current_path(self):
174 # this will return the absolute path to the
175 # directory containing this file
176 # it will only work if this file is imported somewhere,
177 # not if it is run directly (__file__ will be undefined)
178 import os.path
179 return os.path.abspath(os.path.dirname(__file__))
180
181 def load_screen(self, name):
182 if self.cur_screen:
183 self.rightframe.remove(self.cur_screen)
184 del self.cur_screen
185 self.cur_screen = self.screens[name].Panel(self)
186 # percent = int((i) / float(len(self.screens) - 1) * 100)
187 # self.progress_bar.set_fraction(float(percent) / 100)
188 # self.progress_bar.set_text(str(percent) + "%")
189 self.rightframe.add(self.cur_screen)
190 self.cur_screen.activate()
191 helptext = self.cur_screen._helptext
192 # helptext = " ".join(helptext.split("\n"))
193 # helptext = "\n".join(helptext.split('<br>'))
194 self.textbuff.set_text(helptext)
195 self.rightframe.show_all()
196 self.redraw_buttons()
197
198 def run(self):
199 gtk.gdk.threads_init()
200 gtk.main()
201
202 def previous(self, widget, data=None):
203 self.cur_screen.previous()
204
205 def next(self, widget, data=None):
206 self.cur_screen.next()
207
208 def exit_button(self, widget, data=None):
209 if not self.install_done:
210 msgdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format="Are you sure you want to exit?")
211 resp = msgdlg.run()
212 msgdlg.destroy()
213 if resp == gtk.RESPONSE_YES:
214 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?")
215 resp = msgdlg.run()
216 msgdlg.destroy()
217 if resp == gtk.RESPONSE_YES:
218 progress = ProgressDialog(self, ("install_failed_cleanup", ), self.exit_callback)
219 progress.run()
220 else:
221 self.exit()
222 else:
223 self.exit()
224
225 def exit_callback(self, result):
226 self.exit()
227
228 def load_button(self, widget, data=None):
229 filesel = gtk.FileSelection(_("Select the install profile to load"))
230 if self.install_profile_xml_file == "":
231 filesel.set_filename("installprofile.xml")
232 else:
233 filesel.set_filename(self.install_profile_xml_file)
234 resp = filesel.run()
235 filename = filesel.get_filename()
236 filesel.destroy()
237 if resp == gtk.RESPONSE_OK:
238 self.install_profile_xml_file = filename
239 try:
240 tmp_install_profile = GLIInstallProfile.InstallProfile()
241 tmp_install_profile.parse(self.install_profile_xml_file)
242 self.install_profile = tmp_install_profile
243 msgdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK, message_format=_("Install profile loaded successfully!"))
244 msgdlg.run()
245 msgdlg.destroy()
246 except:
247 errdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format=_("An error occured loading the install profile"))
248 errdlg.run()
249 errdlg.destroy()
250
251 def save_button(self, widget, data=None):
252 filesel = gtk.FileSelection(_("Select the location to save the install profile"))
253 if self.install_profile_xml_file == "":
254 filesel.set_filename("installprofile.xml")
255 else:
256 filesel.set_filename(self.install_profile_xml_file)
257 resp = filesel.run()
258 filename = filesel.get_filename()
259 filesel.destroy()
260 if resp == gtk.RESPONSE_OK:
261 self.install_profile_xml_file = filename
262 try:
263 configuration = open(filename, "w")
264 configuration.write(self.install_profile.serialize())
265 configuration.close()
266 msgdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK, message_format=_("Install profile saved successfully!"))
267 msgdlg.run()
268 msgdlg.destroy()
269 except:
270 errdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format=_("An error occured saving the install profile"))
271 errdlg.run()
272 errdlg.destroy()
273
274 def log_button(self, widget, data=None):
275 os.system("xterm -e 'tail -f /var/log/installer.log' &")
276
277 def delete_event(self, widget, event, data=None):
278 self.exit_button(self.buttons['exit'])
279 return True
280
281 def destroy(self, widget, data=None):
282 gtk.main_quit()
283 return True
284
285 def exit(self, status=0):
286 gtk.main_quit()
287 sys.exit(status)
288
289 if __name__ == "__main__":
290 install = Installer()
291 install.run()

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20