/[gli]/branches/overhaul/src/fe/gtk/OtherSettings.py
Gentoo

Contents of /branches/overhaul/src/fe/gtk/OtherSettings.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1623 - (show annotations) (download) (as text)
Fri Jan 19 10:19:38 2007 UTC (7 years, 7 months ago) by agaffney
File MIME type: text/x-python
File size: 12382 byte(s)
remove Help button
rearrange Stage screen
1 # Copyright 1999-2006 Gentoo Foundation
2 # This source code is distributed under the terms of version 2 of the GNU
3 # General Public License as published by the Free Software Foundation, a copy
4 # of which can be found in the main directory of this project.
5
6 import gtk
7 import os
8 import GLIScreen
9 import GLIUtility
10 from Widgets import Widgets
11
12 class Panel(GLIScreen.GLIScreen):
13 """
14 Other settings for an install.
15
16 @author: John N. Laliberte <allanonjl@gentoo.org>
17 @license: GPL
18 """
19 # Attributes:
20 #title="Other Settings"
21 _helptext = """
22 <b><u>Other Settings</u></b>
23
24 Display Manager:
25 If you installed gnome, choose gdm. If you installed kde, choose kdm. If you
26 installed anything else specified in XSession, choose xdm.
27
28 Console Font:
29 You probably don't want to mess with this.
30
31 Extended Keymaps:
32 You probably don't want to mess with this.
33
34 Windowkeys:
35 If installing on x86 you are safe with Yes, otherwise you'll probably want to
36 say No.
37
38 Keymap:
39 This defaults to "us" if not set (recommended). If you don't want an English
40 keymap, choose it from the list.
41
42 XSession:
43 Choose this only if you didn't choose gdm or kdm from the Display Manager list.
44
45 Clock:
46 If you chose a local timezone, you'll want to choose "local" for the clock
47 setting. Otherwise if you chose UTC in the Timezone screen, choose UTC here.
48
49 Default Editor:
50 Pick one. Nano is the default and recommended.
51 """
52
53 # Operations
54 def __init__(self, controller):
55 GLIScreen.GLIScreen.__init__(self, controller)
56
57 vert = gtk.VBox(False, 10) # This box is content so it should fill space to force title to top
58 horiz = gtk.HBox(False, 0)
59 horiz2 = gtk.HBox(False, 0)
60 horiz3 = gtk.HBox(False, 0)
61
62 addme_to_vert = []
63
64 # this code could be reduced, but would it make things any clearer?
65
66 # create the CLOCK object
67 self.clock = self.Option("Clock")
68 self.clock.HelpText = "Should CLOCK be set to UTC or local? Unless you set your timezone to UTC you will want to choose local."
69 self.clock.Options = ["UTC","local"]
70 self.clock.Type = self.Option.OptionType.COMBO
71 clock_gtk = self.clock.Generate_GTK()
72 addme_to_vert.append(clock_gtk)
73
74 # create the Windowkeys object
75 self.windowkeys = self.Option("Windowkeys")
76 self.windowkeys.HelpText = "Should we first load the 'windowkeys' console keymap?"
77 self.windowkeys.Options = ["Yes","No"]
78 self.windowkeys.Type = self.Option.OptionType.COMBO
79 clock_gtk = self.windowkeys.Generate_GTK()
80 addme_to_vert.append(clock_gtk)
81
82 # create the Display Manager object
83 self.displaymanager = self.Option("Display Manager")
84 self.displaymanager.HelpText = "Choose your display manager for Xorg-x11 (note you must make sure that package also gets installed for it to work)"
85 self.displaymanager.Options = ["xdm","kdm","gdm"]
86 self.displaymanager.Type = self.Option.OptionType.COMBO_ENTRY
87 clock_gtk = self.displaymanager.Generate_GTK()
88 addme_to_vert.append(clock_gtk)
89
90 # create the Default Editor object
91 self.editor = self.Option("Default Editor")
92 self.editor.HelpText = "Choose your default editor"
93 self.editor.Options = ["/bin/nano","/usr/bin/vim","/usr/bin/emacs"]
94 self.editor.Type = self.Option.OptionType.COMBO
95 editor_gtk = self.editor.Generate_GTK()
96 addme_to_vert.append(editor_gtk)
97
98 # create the Keymap object
99 self.keymap = self.Option("Keymap")
100 self.keymap.HelpText = "Choose your desired keymap"
101 self.keymap.Options = [""] + GLIUtility.generate_keymap_list()
102 self.keymap.Type = self.Option.OptionType.COMBO
103 editor_gtk = self.keymap.Generate_GTK()
104 addme_to_vert.append(editor_gtk)
105
106 # create the Console Font object
107 self.font = self.Option("Console Font")
108 self.font.HelpText = "Choose your default console font"
109 self.font.Options = [""] + GLIUtility.generate_consolefont_list()
110 self.font.Type = self.Option.OptionType.COMBO
111 editor_gtk = self.font.Generate_GTK()
112 addme_to_vert.append(editor_gtk)
113
114 # create a last bogus one to make it look pretty.
115 bogus = self.Option("")
116 bogus.HelpText = ""
117 bogus.Type = self.Option.OptionType.NONE
118 bogus = bogus.Generate_GTK()
119 addme_to_vert.append(bogus)
120
121 # create the XSession object
122 self.xsession = self.Option("XSession")
123 self.xsession.HelpText = "Choose what window manager you want to start default with X if run with xdm, startx, or xinit. (common options are Gnome or Xsession)"
124 self.xsession.Options = ["Gnome","Xsession","fluxbox"]
125 self.xsession.Type = self.Option.OptionType.COMBO_ENTRY
126 editor_gtk = self.xsession.Generate_GTK()
127 addme_to_vert.append(editor_gtk)
128
129 # create the Extended Keymaps object
130 self.extkeymap = self.Option("Extended Keymaps")
131 self.extkeymap.HelpText = "This sets the maps to load for extended keyboards. Most users will leave this as is."
132 self.extkeymap.Type = self.Option.OptionType.TEXT
133 editor_gtk = self.extkeymap.Generate_GTK()
134 addme_to_vert.append(editor_gtk)
135
136 addme_to_vert.reverse()
137 for i,item in enumerate(addme_to_vert):
138 if i< 3:
139 horiz.pack_start(item, expand=True, fill=True, padding=10)
140 elif i<6:
141 horiz2.pack_start(item, expand=True, fill=True, padding=10)
142 else:
143 horiz3.pack_start(item, expand=True, fill=True, padding=10)
144
145 self.add_content(horiz)
146 self.add_content(horiz2)
147 self.add_content(horiz3)
148
149 def create_etc_files(self, etc_files):
150 if not "conf.d/keymaps" in etc_files:
151 etc_files['conf.d/keymaps'] = {}
152 # if not "conf.d/consolefont" in etc_files:
153 # etc_files['conf.d/consolefont'] = {}
154 if not "conf.d/clock" in etc_files:
155 etc_files['conf.d/clock'] = {}
156 if not "rc.conf" in etc_files:
157 etc_files['rc.conf'] = {}
158
159 return etc_files
160
161 def activate(self):
162
163 etc_files = self.controller.install_profile.get_etc_files()
164 etc_files = self.create_etc_files(etc_files)
165
166 if 'conf.d/keymaps' in etc_files:
167 if 'KEYMAP' in etc_files['conf.d/keymaps']:
168 self.keymap.SetValue(etc_files['conf.d/keymaps']['KEYMAP'])
169 if 'SET_WINDOWKEYS' in etc_files['conf.d/keymaps']:
170 self.windowkeys.SetValue(etc_files['conf.d/keymaps']['SET_WINDOWKEYS'])
171 if 'EXTENDED_KEYMAPS' in etc_files['conf.d/keymaps']:
172 self.extkeymap.SetValue(etc_files['conf.d/keymaps']['EXTENDED_KEYMAPS'])
173
174 if 'conf.d/consolefont' in etc_files:
175 if 'CONSOLEFONT' in etc_files['conf.d/consolefont']:
176 self.font.SetValue(etc_files['conf.d/consolefont']['CONSOLEFONT'])
177
178 if 'conf.d/clock' in etc_files:
179 if 'CLOCK' in etc_files['conf.d/clock']:
180 self.clock.SetValue(etc_files['conf.d/clock']['CLOCK'])
181
182 if 'rc.conf' in etc_files:
183 if 'EDITOR' in etc_files['rc.conf']:
184 self.editor.SetValue(etc_files['rc.conf']['EDITOR'])
185 if 'DISPLAYMANAGER' in etc_files['rc.conf']:
186 self.displaymanager.SetValue(etc_files['rc.conf']['DISPLAYMANAGER'])
187 if 'XSESSION' in etc_files['rc.conf']:
188 self.xsession.SetValue(etc_files['rc.conf']['XSESSION'])
189
190
191 self.controller.SHOW_BUTTON_EXIT = True
192 # self.controller.SHOW_BUTTON_HELP = True
193 self.controller.SHOW_BUTTON_BACK = True
194 self.controller.SHOW_BUTTON_FORWARD = True
195 self.controller.SHOW_BUTTON_FINISH = False
196
197 def deactivate(self):
198 value = True
199
200 etc_files = self.controller.install_profile.get_etc_files()
201 etc_files = self.create_etc_files(etc_files)
202
203 if self.keymap.GetValue():
204 etc_files['conf.d/keymaps']['KEYMAP'] = self.keymap.GetValue()
205 etc_files['conf.d/keymaps']['SET_WINDOWKEYS'] = self.windowkeys.GetValue()
206 if self.extkeymap.GetValue() != "":
207 etc_files['conf.d/keymaps']['EXTENDED_KEYMAPS'] = self.extkeymap.GetValue()
208 if self.font.GetValue():
209 if not "conf.d/consolefont" in etc_files:
210 etc_files['conf.d/consolefont'] = {}
211 etc_files['conf.d/consolefont']['CONSOLEFONT'] = self.font.GetValue()
212 etc_files['conf.d/clock']['CLOCK'] = self.clock.GetValue()
213 etc_files['rc.conf']['EDITOR'] = self.editor.GetValue()
214 if self.displaymanager.GetValue() != "":
215 etc_files['rc.conf']['DISPLAYMANAGER'] = self.displaymanager.GetValue()
216 if self.xsession.GetValue() != "":
217 etc_files['rc.conf']['XSESSION'] = self.xsession.GetValue()
218
219 try:
220 self.controller.install_profile.set_etc_files(etc_files)
221 except:
222 msgbox=Widgets().error_Box("Error","An internal error occurred!")
223 msgbox.run()
224 msgbox.destroy()
225
226 return value
227
228 class Option:
229
230 class Property(object):
231 class __metaclass__(type):
232 def __init__(cls, name, bases, dct):
233 for fname in ['get', 'set', 'delete']:
234 if fname in dct:
235 setattr(cls, fname, staticmethod(dct[fname]))
236 def __get__(cls, obj, objtype=None):
237 if obj is None:
238 return cls
239 fget = getattr(cls, 'get')
240 return fget(obj)
241 def __set__(cls, obj, value):
242 fset = getattr(cls, 'set')
243 fset(obj, value)
244 def __delete__(cls, obj):
245 fdel = getattr(cls, 'delete')
246 fdel(obj)
247
248 class OptionType:
249 NONE = 0
250 TEXT = 1
251 COMBO = 2
252 COMBO_ENTRY = 3
253
254 def __init__(self, name):
255 self.Name = name
256 self.HelpText = ""
257 # by default we make a combo
258 self.Type = self.OptionType.COMBO
259 self.Options = []
260
261 class Name(Property):
262 """ Name property """
263 def get(self):
264 return self._name
265 def set(self):
266 self._name = val
267
268 class HelpText(Property):
269 """ HelpText property """
270 def get(self):
271 return self._helptext
272 def set(self):
273 self._helptext = val
274
275 class Type(Property):
276 """ Name property """
277 def get(self):
278 return self._type
279 def set(self):
280 self._type = val
281
282 class Options(Property):
283 """ Options property """
284 def get(self):
285 return self._options
286 def set(self):
287 self._name = self._options
288
289 class GtkElement(Property):
290 """ GtkElement Property """
291 def get(self):
292 return self._gtkelement
293 def set(self):
294 self._gtkelement = val
295
296 def GetValue(self):
297 if self.Type == self.OptionType.TEXT:
298 return self.GtkElement.get_text()
299 elif self.Type == self.OptionType.COMBO:
300 model = self.GtkElement.get_model()
301 active = self.GtkElement.get_active()
302 return model[active][0]
303 elif self.Type == self.OptionType.COMBO_ENTRY:
304 return self.GtkElement.get_child().get_text()
305
306 def SetValue(self, text):
307 if self.Type == self.OptionType.TEXT:
308 self.GtkElement.set_text(text)
309 elif self.Type == self.OptionType.COMBO:
310 # iterate through all the elements,
311 # get the number and set it.
312 model = self.GtkElement.get_model()
313
314 for i,item in enumerate(model):
315 if item[0] == text:
316 self.GtkElement.set_active(i)
317 elif self.Type == self.OptionType.COMBO_ENTRY:
318 self.GtkElement.get_child().set_text(text)
319
320 def Generate_GTK(self):
321
322 box = gtk.VBox(False, 0)
323
324 # the name of the setting
325 hbox = gtk.HBox(False,0)
326 label = gtk.Label("")
327 label.set_markup('<span weight="bold">'+self.Name+'</span>')
328
329 label.set_size_request(150, -1)
330 hbox.pack_start(label, expand=False, fill=False, padding=0)
331 box.pack_start(hbox, expand=False, fill=False, padding=5)
332
333 # the description of the option
334 hbox = gtk.HBox(False,0)
335 label = gtk.Label(self.HelpText)
336 label.set_size_request(200, -1)
337 label.set_line_wrap(True)
338 label.set_justify(gtk.JUSTIFY_FILL)
339 hbox.pack_start(label, expand=False, fill=False, padding=0)
340 box.pack_start(hbox, expand=False, fill=False, padding=5)
341
342 # switch here based on type of gui element.
343 if self.Type == self.OptionType.TEXT:
344 gui_element = gtk.Entry()
345 elif self.Type == self.OptionType.NONE:
346 gui_element = gtk.Label("")
347 # but we want to HIDE the entry so its not visible
348 gui_element.hide()
349 elif self.Type == self.OptionType.COMBO:
350 gui_element = gtk.combo_box_new_text()
351 #gui_element.set_wrap_width(5)
352 elif self.Type == self.OptionType.COMBO_ENTRY:
353 gui_element = gtk.combo_box_entry_new_text()
354
355 # store it for later :)
356 self.GtkElement = gui_element
357
358 for option_text in self.Options:
359 gui_element.append_text(option_text)
360
361 gui_element.set_name(self.Name)
362 gui_element.set_size_request(150, -1)
363
364 # what we do by default
365 if self.Type == self.OptionType.TEXT or self.Type == self.OptionType.NONE:
366 #gui_element.set_text(()
367 pass
368 elif self.Type == self.OptionType.COMBO:
369 gui_element.set_active(0)
370
371 hbox = gtk.HBox(False,0)
372 hbox.pack_start(gui_element, expand=False, fill=False, padding=0)
373 box.pack_start(hbox, expand=False, fill=False, padding=5)
374 return box
375

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20