summaryrefslogtreecommitdiffstats
path: root/iw/installpath_gui.py
blob: 0d676a64dbb1cbc87999a86780b4a0dc5965adf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
from gtk import *
from translate import _, N_
import installclass
from iw_gui import InstallWindow
from flags import flags

UPGRADE = 0
INSTALL = 1

CUSTOM = 2
WORKSTATION_GNOME = 3
WORKSTATION_KDE = 4
SERVER = 5

def D_(x):
    return x

class InstallPathWindow (InstallWindow):		

    installTypes = installclass.availableClasses()
    htmlTag = "instpath"
    windowTitle = N_("Installation Type")

    def getNext(self):
	# Hack to let backing out of upgrades work properly
	#if self.flags.setupFilesystems() and self.id.fstab:
	    #self.id.fstab.turnOffSwap()

	for (button, box, buttons) in self.topLevelButtonList:
	    if not button.get_active(): continue

	    if buttons:
		for b in buttons:
		    if b.get_active(): selection = self.buttonToObject[b]
	    else:
		selection = self.buttonToObject[button]

	if not isinstance (self.id.instClass, selection):
	    c = selection(self.flags.expert)
	    c.setSteps(self.dispatch)
	    c.setInstallData(self.id)
	    needNewDruid = 1

    def toggled (self, widget):
        if not widget.get_active (): return

	for (button, box, buttons) in self.topLevelButtonList:
	    if not box: continue
	    sensitive = (button == widget)
	    box.set_sensitive(sensitive)

    def pixRadioButton (self, group, label, pixmap):
        pix = self.ics.readPixmap (pixmap)
        if pix:
            hbox = GtkHBox (FALSE, 5)
            hbox.pack_start (pix, FALSE, FALSE, 0)
            label = GtkLabel (label)
            label.set_alignment (0.0, 0.5)
            hbox.pack_start (label, TRUE, TRUE, 15)
            button = GtkRadioButton (group)
            button.add (hbox)
        else:
            button = GtkRadioButton (group, label)
        return button

    # InstallPathWindow tag="instpath"
    def getScreen (self, dispatch, id, method, intf):
	self.dispatch = dispatch
	self.id = id
	self.flags = flags
	self.method = method
	self.intf = intf

	topButtons = {}

	defaultClass = None
	# this points to the class for the current install class object
	currentClass = None

        names = []
	for (name, object, pixmap) in self.installTypes:
	    (parentName, parentPixmap) = object.parentClass
	    if not topButtons.has_key(parentName):
		topButtons[parentName] = []
                names.append(parentName)

	    topButtons[parentName].append(object)

	    if isinstance(id.instClass, object):
		currentClass = object
	    if object.default:
		defaultClass = object

	if not currentClass:
	    currentClass = defaultClass

	topLevelGroup = None
	tableRows = 0
	# tuples of (button, box) (box may be None)
	self.topLevelButtonList = []
	self.buttonToObject = {}

	for item in names:
	    buttons = []
	    if len(topButtons[item]) == 1:
		name = topButtons[item][0].name
		pixmap = topButtons[item][0].pixmap
		topLevelGroup = self.pixRadioButton(topLevelGroup,
				    _(name), pixmap)
		self.buttonToObject[topLevelGroup] = topButtons[item][0]
		box = None

		if currentClass == topButtons[item][0]:
		    topLevelGroup.set_active(1)
	    else:
		(parentName, parentPixmap) = topButtons[item][0].parentClass

		topLevelGroup = self.pixRadioButton(topLevelGroup,
		    _(parentName), parentPixmap)

		box = GtkVBox (FALSE, 0)
		box.set_usize(300, -1)
		group = None

		for obj in topButtons[item]:
		    name = obj.name
		    pixmap = obj.pixmap
		    group = self.pixRadioButton(group, _(name), pixmap)
		    self.buttonToObject[group] = obj
		    buttons.append(group)
		    box.pack_start (group, FALSE)

		    if currentClass == obj:
			group.set_active(1)
			topLevelGroup.set_active(1)

	    self.topLevelButtonList.append((topLevelGroup, box, buttons))
	    topLevelGroup.connect("toggled", self.toggled)

	    tableRows = tableRows + 1
	    if box:
		tableRows = tableRows + 1

	table = GtkTable(2, tableRows + 1)
	row = 0

	for (button, box, buttons) in self.topLevelButtonList:
	    table.attach(button, 0, 3, row, row + 1, xoptions = FILL | EXPAND)

	    #table.attach(align, 2, 3, row, row + 1, xoptions = FALSE)
	    row = row + 1

	    if box:
		table.attach(box, 1, 3, row, row + 1)
		row = row + 1

	box = GtkVBox (FALSE, 5)
	box.pack_start(table, FALSE)
        box.set_border_width (5)

        return box