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
|
#
# driveorderwidget.py: widget for reordering drives into BIOS order
#
# Jeremy Katz <katzj@redhat.com>
#
# Copyright 2001-2002 Red Hat, Inc.
#
# This software may be freely redistributed under the terms of the GNU
# library public license.
#
# You should have received a copy of the GNU Library Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
import gtk
import gobject
import iutil
import partedUtils
import gui
from rhpl.translate import _, N_
class DriveOrderWidget:
"""Widget to reorder drives according to BIOS drive order."""
def __init__(self, driveorder, diskset):
self.driveOrder = driveorder
self.diskset = diskset
hbox = gtk.HBox(gtk.FALSE, 5)
# different widget for this maybe?
self.driveOrderStore = gtk.ListStore(gobject.TYPE_STRING,
gobject.TYPE_STRING,
gobject.TYPE_STRING)
sw = gtk.ScrolledWindow()
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
self.driveOrderView = gtk.TreeView(self.driveOrderStore)
i = 0
for columnName in [ N_("Drive"), N_("Size"), N_("Model") ]:
renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn(columnName, renderer, text = i)
i = i + 1
column.set_clickable(gtk.FALSE)
self.driveOrderView.append_column(column)
self.driveOrderView.set_rules_hint(gtk.FALSE)
self.driveOrderView.set_headers_visible(gtk.FALSE)
self.driveOrderView.set_enable_search(gtk.FALSE)
self.makeDriveOrderStore()
sw.add(self.driveOrderView)
self.driveOrderView.set_size_request(375, 80)
hbox.pack_start(sw, gtk.FALSE)
arrowbox = gtk.VBox(gtk.FALSE, 5)
arrowButton = gtk.Button()
arrow = gtk.Arrow(gtk.ARROW_UP, gtk.SHADOW_ETCHED_IN)
arrowButton.add(arrow)
arrowButton.connect("clicked", self.arrowClicked, gtk.ARROW_UP)
arrowbox.pack_start(arrowButton, gtk.FALSE)
spacer = gtk.Label("")
spacer.set_size_request(10, 1)
arrowbox.pack_start(spacer, gtk.FALSE)
arrowButton = gtk.Button()
arrow = gtk.Arrow(gtk.ARROW_DOWN, gtk.SHADOW_ETCHED_IN)
arrowButton.add(arrow)
arrowButton.connect("clicked", self.arrowClicked, gtk.ARROW_DOWN)
arrowbox.pack_start(arrowButton, gtk.FALSE)
alignment = gtk.Alignment()
alignment.set(0, 0.5, 0, 0)
alignment.add(arrowbox)
hbox.pack_start(alignment, gtk.FALSE)
self.widget = hbox
def getWidget(self):
return self.widget
def getOrder(self):
return self.driveOrder
def arrowClicked(self, widget, direction, *args):
selection = self.driveOrderView.get_selection()
(model, iter) = selection.get_selected()
if not iter:
return
# there has got to be a better way to do this =\
drive = model.get_value(iter, 0)[5:]
index = self.driveOrder.index(drive)
if direction == gtk.ARROW_DOWN:
self.driveOrder.remove(drive)
self.driveOrder.insert(index + 1, drive)
elif direction == gtk.ARROW_UP:
self.driveOrder.remove(drive)
self.driveOrder.insert(index - 1, drive)
self.makeDriveOrderStore()
# make the store for the drive order
def makeDriveOrderStore(self):
disks = self.diskset.disks
self.driveOrderStore.clear()
iter = self.driveOrderStore.append()
for drive in self.driveOrder:
self.driveOrderStore.set_value(iter, 0, "/dev/%s" % (drive,))
# if we have it in the diskset, get the size and type of drive
if disks.has_key(drive):
size = partedUtils.getDeviceSizeMB(disks[drive].dev)
sizestr = "%8.0f MB" %(size,)
self.driveOrderStore.set_value(iter, 1, sizestr)
self.driveOrderStore.set_value(iter, 2, disks[drive].dev.model)
iter = self.driveOrderStore.append()
|