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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20