aboutsummaryrefslogtreecommitdiff
blob: 0ded4e257a8b89e151f69e4c96f9737eac359a4f (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#
# pixmapRadioButtonGroup_gui.py: general purpose radio button group with pixmaps
#                                and descriptions
#
# Copyright (C) 2000, 2001, 2002  Red Hat, Inc.  All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import gtk
from constants import *

class pixmapRadioButtonGroup:

    def toggled (self, widget):
	if self.togglecb is not None:

	    name = None
	    for b in self.buttonToEntry.keys():
		if b == widget:
		    name = self.buttonToEntry[b]
	    
	    self.togglecb(widget, name)
	    
#        if not widget.get_active ():
#	    return

    #
    # expects a gtk pixmap for pixmap
    #
    def pixRadioButton (self, group, labelstr, pixmap, description=None):
        pix = pixmap

	hbox = gtk.HBox (False, 18)
	if pix != None:
	    hbox.pack_start (pix, True, True, 0)

	label = gtk.Label("")
	label.set_line_wrap(True)
	label.set_markup("<b>"+labelstr+"</b>")
	label.set_alignment (0.0, 0.5)
	if description is not None:
	    label.set_markup ("<b>%s</b>\n<small>%s</small>" %(labelstr,
                                                               description))
	    label.set_line_wrap(True)
	    if  gtk.gdk.screen_width() > 640:
		wraplen = 600
	    else:
		wraplen = 250
		
	    label.set_size_request(wraplen, -1)
	label.set_use_markup (True)
	label.set_use_underline(True)
	    
	hbox.pack_start (label, True, True, 0)
	button = gtk.RadioButton (group)
	button.add (hbox)
	label.set_mnemonic_widget(button)
        return button

    # add a entry to end of list
    # (label and descr should already be passed through _())
    def addEntry(self, name, label, pixmap=None, descr=None, userdata=None):
	node = {}
	node["name"] = name
	node["label"] = label
	node["descr"] = descr
	node["pixmap"] = pixmap
	node["userdata"] = userdata
	self.entries.append(node)

    #
    # finds entry matching name and makes it current
    #
    # MUST call AFTER calling render, since widgets are not created yet otherwise
    #
    def setCurrent(self, name):
	for b in self.buttonToEntry.keys():
	    if self.buttonToEntry[b] == name:
		b.set_active(1)

	

    #
    # returns name of current selection
    #
    # MUST call AFTER calling render, since widgets are not created yet otherwise
    #
    def getCurrent(self):
	for b in self.buttonToEntry.keys():
	    if b.get_active():
		return self.buttonToEntry[b]


    #
    # MUST call AFTER calling render, since widgets are not created yet otherwise
    #
    def packWidgetInEntry(self, name, widget):
	# find button for name
	for b in self.buttonToEntry.keys():
	    if self.buttonToEntry[b] == name:
		# now find box for button
		for (button, box, buttons) in self.topLevelButtonList:
		    if button == b:
			box.pack_end(widget)
			return

    def setToggleCallback(self, cb):
	self.togglecb = cb
	    
    # render resulting list, returns a box you can pack
    #
    # call this after adding all parents and nodes
    def render(self):

	radioGroup = None
	buttons = []
	for item in self.entries:
	    box = gtk.VBox (False, 6)
	    name = item["name"]
	    label = item["label"]
	    pixmap = item["pixmap"]
	    descr = item["descr"]
	    radioGroup = self.pixRadioButton(radioGroup, label, pixmap,
					     description=descr)
	    buttons.append(radioGroup)
	    self.buttonToEntry[radioGroup] = name

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

	finalVBox = gtk.VBox(False, 6)
	finalVBox.set_border_width (5)

	for (button, box, buttons) in self.topLevelButtonList:
	    vbox = gtk.VBox (False, 6)
	    finalVBox.pack_start(vbox, False, False)
	    vbox.pack_start (button, False, False)
	    
	    if box:
		tmphbox = gtk.HBox(False)

		crackhbox = gtk.HBox(False)
		crackhbox.set_size_request(50, -1)

		tmphbox.pack_start(crackhbox, False, False)
		tmphbox.pack_start(box, True, True)
		vbox.pack_start(tmphbox, False, False)
		
        return finalVBox
    
    
    # InstallPathWindow tag="instpath"
    def __init__(self):
	self.entries = []
	self.topLevelButtonList = []
	self.buttonToEntry = {}
	self.togglecb = None


if __name__ == "__main__":
    def readPixmap(fn):
	pixbuf = gtk.gdk.pixbuf_new_from_file(fn)

	source = gtk.IconSource()
	source.set_pixbuf(pixbuf)
	source.set_size(gtk.ICON_SIZE_DIALOG)
	source.set_size_wildcarded(False)
	iconset = gtk.IconSet()
	iconset.add_source(source)
	p = gtk.image_new_from_icon_set(iconset, gtk.ICON_SIZE_DIALOG)

	return p

    def nowquit(widget):
	global r

	print("selection -> %s" % (r.getCurrent(),))

	gtk.mainquit()
	
    win = gtk.Window()
    win.connect('destroy', nowquit)


    if 0:
	opts = ['8.0 - /dev/hda1', '7.1 - /dev/hda5']
    else:
	opts = ['8.0 - /dev/hda1']

    label = "The following installed system will be upgraded:"
    upgradeoption = gtk.OptionMenu()
    upgradeoptionmenu = gtk.Menu()
    for lev in opts:
	item = gtk.MenuItem(lev)
	item.show()        
	upgradeoptionmenu.add(item)

    upboxtmp = gtk.VBox(False, 5)
    l = gtk.Label(label)
    l.set_alignment(0.0, 0.0)
    upboxtmp.pack_start(l)
    upboxtmp.pack_start(upgradeoption)
    upgradeoption.set_menu(upgradeoptionmenu)

    upgradeoption.set_sensitive(0)
    
    # hack indent it
    upbox = gtk.HBox(False)

    crackhbox = gtk.HBox(False)
    crackhbox.set_size_request(80, -1)

    upbox.pack_start(crackhbox, False, False)
    upbox.pack_start(upboxtmp, True, True)

    r = pixmapRadioButtonGroup()
    r.addEntry("upgrade", "_Upgrade Existing Installation", pixmap=readPixmap("/usr/share/anaconda/pixmaps/upgrade.png"),  descr="Choose this option if you would like to upgrade your existing %s system.  This option will preserve the data on your drive" % (productName,), userdata="data")

    r.addEntry("install", "_Reinstall %s" %(productName,), pixmap=readPixmap("../pixmaps/install.png"),
	       descr="Choose this option to reinstall your system.  Depending on how you partition your system, your previous data may be lost.", userdata="data2")
    b = r.render()
    r.setCurrent("Don't Upgrade")

    r.packWidgetInEntry("Upgrade Existing Installation", upbox)

    vbox = gtk.VBox()
    vbox.pack_start(b, False, False)
    
    button = gtk.Button("Quit")
    button.connect("pressed", nowquit)
    vbox.pack_start(button, False, False)
    
    win.add(vbox)
    win.show_all()

    gtk.main()