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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20