~ubuntu-branches/ubuntu/precise/system-config-kickstart/precise

« back to all changes in this revision

Viewing changes to src/xconfig.py

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2005-04-04 15:16:36 UTC
  • Revision ID: james.westby@ubuntu.com-20050404151636-ihn83k6dkgc1i3dj
Tags: upstream-2.5.20
ImportĀ upstreamĀ versionĀ 2.5.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
## Kickstart Configurator - A graphical kickstart file generator
 
2
## Copyright (C) 2000, 2001, 2002, 2003 Red Hat, Inc.
 
3
## Copyright (C) 2000, 2001, 2002, 2003 Brent Fox <bfox@redhat.com>
 
4
##                                      Tammy Fox <tfox@redhat.com>
 
5
 
 
6
## This program is free software; you can redistribute it and/or modify
 
7
## it under the terms of the GNU General Public License as published by
 
8
## the Free Software Foundation; either version 2 of the License, or
 
9
## (at your option) any later version.
 
10
 
 
11
## This program is distributed in the hope that it will be useful,
 
12
## but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
## GNU General Public License for more details.
 
15
 
 
16
## You should have received a copy of the GNU General Public License
 
17
## along with this program; if not, write to the Free Software
 
18
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 
 
20
#Kickstart Configurator X Configuration
 
21
 
 
22
import gtk
 
23
import gtk.glade
 
24
import gobject
 
25
import string
 
26
import getopt
 
27
from rhpl.xhwstate import *
 
28
 
 
29
class xconfig:
 
30
 
 
31
    def __init__(self, xml, kickstartData):
 
32
        self.kickstartData = kickstartData
 
33
        self.xconfig_vbox = xml.get_widget("xconfig_vbox")
 
34
        self.xconfig_label_box = xml.get_widget("xconfig_label_box")
 
35
        self.config_x_button = xml.get_widget("config_x_button")
 
36
        self.card_view = xml.get_widget("card_view")
 
37
        self.monitor_view = xml.get_widget("monitor_view")
 
38
        self.sync_button = xml.get_widget("sync_button")
 
39
        self.sync_table = xml.get_widget("sync_table")        
 
40
        self.xconfig_notebook = xml.get_widget("xconfig_notebook")        
 
41
        self.hsync_entry = xml.get_widget("hsync_entry")
 
42
        self.vsync_entry = xml.get_widget("vsync_entry")
 
43
        self.color_depth_combo = xml.get_widget("color_depth_combo")
 
44
        self.resolution_combo = xml.get_widget("resolution_combo")
 
45
        self.videoram_combo = xml.get_widget("videoram_combo")
 
46
        self.gnome_radiobutton = xml.get_widget("gnome_radiobutton")
 
47
        self.kde_radiobutton = xml.get_widget("kde_radiobutton")
 
48
        self.startxonboot_checkbutton = xml.get_widget("startxonboot_checkbutton")
 
49
        self.firstboot_optionmenu = xml.get_widget("firstboot_optionmenu")
 
50
        self.card_vbox = xml.get_widget("card_vbox")
 
51
        self.monitor_vbox = xml.get_widget("monitor_vbox")
 
52
        self.card_probe_check = xml.get_widget("card_probe_check")
 
53
        self.monitor_probe_check = xml.get_widget("monitor_probe_check")
 
54
        
 
55
        self.card_store = gtk.ListStore(gobject.TYPE_STRING)
 
56
        self.card_view.set_model(self.card_store)
 
57
        self.card_col = gtk.TreeViewColumn("", gtk.CellRendererText(), text = 0)
 
58
        self.card_view.append_column(self.card_col)
 
59
        
 
60
        self.monitor_store = gtk.ListStore(gobject.TYPE_STRING)
 
61
        self.monitor_view.set_model(self.monitor_store)
 
62
        self.monitor_col = gtk.TreeViewColumn("", gtk.CellRendererText(), text = 0)
 
63
        self.monitor_view.append_column(self.monitor_col)
 
64
        self.upgrade_flag = gtk.FALSE
 
65
 
 
66
        self.config_x_button.connect("toggled", self.toggleXconfig)
 
67
        self.monitor_probe_check.connect("toggled", self.on_monitor_probe_check_toggled)
 
68
        self.card_probe_check.connect("toggled", self.on_card_probe_check_toggled)
 
69
        self.sync_button.connect("toggled", self.toggle_sync)
 
70
 
 
71
        self.fill_card_list()
 
72
        self.fill_monitor_list()
 
73
 
 
74
        #add color depths
 
75
        color_depths = ["8", "16", "24", "32"]
 
76
        self.color_depth_combo.set_popdown_strings(color_depths)
 
77
        self.color_depth_combo.entry.set_editable(gtk.FALSE)
 
78
 
 
79
        #add resolutions
 
80
        resolutions = ["640x480", "800x600", "1024x768", "1152x864", "1280x1024", "1400x1050",
 
81
                       "1600x1200", "1920x1440", "2048x1536"]
 
82
        self.resolution_combo.set_popdown_strings(resolutions)
 
83
        self.resolution_combo.entry.set_editable(gtk.FALSE)
 
84
        
 
85
        #add video card RAM sizes to option menu
 
86
        vram_list = ["256 KB", "512 KB", "1 MB", "2 MB", "4 MB", "8 MB", "16 MB", "32 MB", "64 MB"]
 
87
        self.videoram_combo.set_popdown_strings(vram_list)
 
88
        self.videoram_combo.entry.set_editable(gtk.FALSE)
 
89
 
 
90
        self.ramsize_dict = {"256 KB" : "256",
 
91
                             "512 KB" : "512",
 
92
                             "1 MB" : "1024",
 
93
                             "2 MB" : "2048",
 
94
                             "4 MB" : "4096",
 
95
                             "8 MB" : "8192",
 
96
                             "16 MB" : "16384",
 
97
                             "32 MB" : "32768",
 
98
                             "64 MB" : "65536",
 
99
                             }
 
100
 
 
101
    def fill_card_list(self):
 
102
        #add video cards to list
 
103
        try:
 
104
            cardsFile = open("/usr/share/hwdata/Cards", "r")
 
105
        except:
 
106
            raise RuntimeError, (_("Could not read video card database"))
 
107
            
 
108
        lines = cardsFile.readlines ()
 
109
        cardsFile.close ()
 
110
        lines.sort()
 
111
        for line in lines:
 
112
            line = string.strip (line)
 
113
 
 
114
            if len (line) > 4 and line[0:4] == 'NAME':
 
115
                name = line[5:]
 
116
                iter = self.card_store.append()
 
117
                self.card_store.set_value(iter, 0, name)
 
118
 
 
119
    def fill_monitor_list(self):
 
120
 
 
121
        hardware_state = XF86HardwareState(None)
 
122
        db = hardware_state.monitor.readMonitorsDB()
 
123
        l = db.keys()
 
124
        l.sort()
 
125
        mon_list = []
 
126
        
 
127
        #put Generic LCD and Generic CRT at the front of the list
 
128
        tmp = l[l.index("Generic LCD Display")]
 
129
        l.remove(l[l.index("Generic LCD Display")])
 
130
        l = [tmp] + l
 
131
                                                                                                                             
 
132
        tmp = l[l.index("Generic CRT Display")]
 
133
        l.remove(l[l.index("Generic CRT Display")])
 
134
        l = [tmp] + l
 
135
 
 
136
        
 
137
        for manufacturer in l:
 
138
                for mon in db[manufacturer]:
 
139
                        model = mon[0]
 
140
                        id = mon[1]
 
141
                        hsync = mon[2]
 
142
                        vsync = mon[3]
 
143
                        if model not in mon_list:
 
144
                            mon_list.append(model)
 
145
                            iter = self.monitor_store.append()
 
146
                            self.monitor_store.set_value(iter, 0, model)
 
147
 
 
148
    def on_card_probe_check_toggled(self, *args):
 
149
        self.card_vbox.set_sensitive(not self.card_probe_check.get_active())
 
150
 
 
151
    def on_monitor_probe_check_toggled(self, *args):
 
152
        self.monitor_vbox.set_sensitive(not self.monitor_probe_check.get_active())
 
153
 
 
154
    def toggleXconfig (self, args):
 
155
        config = self.config_x_button.get_active()
 
156
        #disable xconfig notebook
 
157
        self.xconfig_notebook.set_sensitive(config)
 
158
 
 
159
    def toggle_sync (self, args):
 
160
        sync_instead = self.sync_button.get_active()
 
161
        self.sync_table.set_sensitive(sync_instead)
 
162
        self.monitor_view.set_sensitive(not sync_instead)        
 
163
 
 
164
    def setSensitive(self, boolean):
 
165
        if boolean == gtk.FALSE:
 
166
            self.xconfig_vbox.hide()
 
167
            self.xconfig_label_box.show()
 
168
            self.upgrade_flag = gtk.TRUE
 
169
        else:
 
170
            self.xconfig_vbox.show()
 
171
            self.xconfig_label_box.hide()
 
172
            self.upgrade_flag = gtk.FALSE
 
173
 
 
174
    def getData(self):
 
175
        if self.upgrade_flag == gtk.TRUE:
 
176
            self.kickstartData.setXconfig(None)
 
177
            self.kickstartData.setFirstboot(None)
 
178
            return
 
179
 
 
180
        if self.config_x_button.get_active():
 
181
            if self.firstboot_optionmenu.get_history() == 0:
 
182
                self.kickstartData.setFirstboot(None)
 
183
            elif self.firstboot_optionmenu.get_history() == 1:
 
184
                self.kickstartData.setFirstboot(["--enable"])
 
185
            elif self.firstboot_optionmenu.get_history() == 2:
 
186
                self.kickstartData.setFirstboot(["--reconfig"])
 
187
 
 
188
            self.kickstartData.setSkipX(None)
 
189
            buf = ""
 
190
            #color depth - translate
 
191
            buf = "--depth=" + self.color_depth_combo.entry.get_text()
 
192
            #resolution
 
193
            buf = buf + " --resolution=" + self.resolution_combo.entry.get_text()            
 
194
            #default desktop
 
195
            if self.gnome_radiobutton.get_active():
 
196
                buf = buf + " --defaultdesktop=GNOME"
 
197
            elif self.kde_radiobutton.get_active():
 
198
                buf = buf + " --defaultdesktop=KDE"
 
199
            #startxonboot
 
200
            if self.startxonboot_checkbutton.get_active():
 
201
                buf = buf + " --startxonboot"
 
202
 
 
203
            if not self.card_probe_check.get_active():
 
204
                #video card and monitor
 
205
                temp, iter = self.card_view.get_selection().get_selected()
 
206
                card = self.card_store.get_value(iter, 0)
 
207
                buf = buf + " --card=\"" + card + "\""
 
208
 
 
209
                #translate MB to KB 
 
210
                buf = buf + " --videoram=" + self.ramsize_dict [self.videoram_combo.entry.get_text()]
 
211
 
 
212
            if not self.monitor_probe_check.get_active():
 
213
                if self.sync_button.get_active():
 
214
                    buf = buf + " --hsync=" + self.hsync_entry.get_text()
 
215
                    buf = buf + " --vsync=" + self.vsync_entry.get_text()
 
216
                else:
 
217
                    temp, iter = self.monitor_view.get_selection().get_selected()
 
218
                    name = self.monitor_store.get_value(iter, 0)
 
219
                    buf = buf + " --monitor=\"" + name + "\""
 
220
 
 
221
            self.kickstartData.setXconfig([buf])
 
222
        else:
 
223
            self.kickstartData.setSkipX(["skipx"])
 
224
            self.kickstartData.setXconfig(None)
 
225
 
 
226
    def fillData(self):
 
227
        if self.kickstartData.getSkipX():
 
228
            self.config_x_button.set_active(gtk.FALSE)
 
229
        elif self.kickstartData.getXconfig():
 
230
            self.config_x_button.set_active(gtk.TRUE)
 
231
 
 
232
            if self.kickstartData.getFirstboot() == "--enable":
 
233
                self.firstboot_optionmenu.set_history(1)
 
234
            elif self.kickstartData.getFirstboot() == "--reconfig":
 
235
                self.firstboot_optionmenu.set_history(2)
 
236
                
 
237
            xLine = self.kickstartData.getXconfig()
 
238
            xLine = string.join (xLine, " ")
 
239
            xList = string.split(xLine, " --")
 
240
 
 
241
            for item in xList:
 
242
                if item[:2] != "--":
 
243
                    xList[xList.index(item)] = ("--" + item)
 
244
 
 
245
            for opt in xList:
 
246
                opt = string.replace(opt, "=", " ")
 
247
            
 
248
                if opt == "--startxonboot":
 
249
                    self.startxonboot_checkbutton.set_active(gtk.TRUE)
 
250
 
 
251
                if opt[:16] == "--defaultdesktop":
 
252
                    value = opt[16:]
 
253
                    if string.lower(value) == "gnome":
 
254
                        self.gnome_radiobutton.set_active(gtk.TRUE)
 
255
                    if string.lower(value) == "kde":
 
256
                        self.kde_radiobutton.set_active(gtk.TRUE)
 
257
 
 
258
                if opt[:7] == "--depth":
 
259
                    value = opt[7:]
 
260
                    self.color_depth_combo.entry.set_text(string.strip(value))
 
261
 
 
262
                if opt[:12] == "--resolution":
 
263
                    value = opt[12:]
 
264
                    self.resolution_combo.entry.set_text(string.strip(value))
 
265
 
 
266
                if opt[:6] == "--card":
 
267
                    value = string.strip(opt[6:])
 
268
                    self.card_probe_check.set_active(gtk.FALSE)
 
269
                    value = string.replace(value, '"', '')
 
270
 
 
271
                    iter = self.card_store.get_iter_first()
 
272
 
 
273
                    while iter:
 
274
                        if self.card_store.get_value(iter, 0) == value:
 
275
                            path = self.card_store.get_path(iter)
 
276
                            self.card_view.set_cursor(path, self.card_col, gtk.FALSE)
 
277
                            self.card_view.scroll_to_cell(path, self.card_col, gtk.TRUE, 0.5, 0.5)
 
278
                        iter = self.card_store.iter_next(iter)
 
279
 
 
280
                if opt[:10] == "--videoram":
 
281
                    value = opt[10:]
 
282
 
 
283
                    for size in self.ramsize_dict.keys():
 
284
                        if int(value) == int(self.ramsize_dict[size]):
 
285
                            self.videoram_combo.entry.set_text(size)                            
 
286
 
 
287
                if opt[:9] == "--monitor":
 
288
                    opt = string.strip(opt[9:])
 
289
                    self.monitor_probe_check.set_active(gtk.FALSE)
 
290
                    value = string.replace(value, '"', '')
 
291
 
 
292
                    iter = self.monitor_store.get_iter_first()
 
293
 
 
294
                    while iter:
 
295
                        if self.monitor_store.get_value(iter, 0) == value:
 
296
                            path = self.monitor_store.get_path(iter)
 
297
                            self.monitor_view.set_cursor(path, self.monitor_col, gtk.FALSE)
 
298
                            self.monitor_view.scroll_to_cell(path, self.monitor_col, gtk.TRUE, 0.5, 0.5)
 
299
                        iter = self.monitor_store.iter_next(iter)
 
300
 
 
301
                if opt[:7] == "--hsync":
 
302
                    value = opt[7:]
 
303
                    self.sync_button.set_active(gtk.TRUE)
 
304
                    self.hsync_entry.set_text(string.strip(value))
 
305
                    self.monitor_probe_check.set_active(gtk.FALSE)
 
306
 
 
307
                if opt[:7] == "--vsync":
 
308
                    value = opt[7:]
 
309
                    self.sync_button.set_active(gtk.TRUE)
 
310
                    self.vsync_entry.set_text(string.strip(value))
 
311
                    self.monitor_probe_check.set_active(gtk.FALSE)