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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20