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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20