while 1:
- self.allow_ok_button()
+ self.allow_ok_button(self._total_selected_members( ))
rc = self.dialog.run()
# user hit cancel, do nothing
@@ -497,15 +497,12 @@ class RaidEditor:
# now the number-of-spares spin button:
spareAdj = gtk.Adjustment(value=0, upper=0, step_incr=1)
self.sparesb = gtk.SpinButton(spareAdj)
- numparts = len(availraidparts)
- self.sparesb.set_data("numparts", numparts)
# adjust the max number of spares depending on the default raid level
level_index = self.levelcombo.get_active()
selected_level = self.levelcombo.get_model()[level_index][0]
- self._adjust_spares_button(selected_level)
+ self._adjust_spares_button(selected_level, origrequest.totalDevices)
# if there's a specific spares number request, set it
- if origrequest.spares:
- self.sparesb.set_value(origrequest.spares)
+ self.sparesb.set_value(origrequest.spares)
lbl.set_mnemonic_widget(self.levelcombo)
else:
self.sparesb = gtk.Label(str(origrequest.spares))
@@ -569,15 +566,24 @@ class RaidEditor:
self.dialog = dialog
return
- def allow_ok_button(self, path=None):
+ def allow_ok_button(self, selected_count):
"""
Determine if the OK button should be enabled.
-
+
+ The OK button is enabled whenever at least one row is selected.
+ """
+ self.ok_button.set_sensitive(selected_count > 0)
+
+ def _total_selected_members(self, path=None):
+ """
+ Determine how many raid members are checked (selected) at the moment.
+
If path is given it points to the row where the toggle state is about to
- change.
+ change. Unfortunately its value is opposite of the value it is *going to
+ have* after the callback thus the complication below.
"""
+ ret = 0
model = self.raidlist.get_model()
- allow = False
iter = model.get_iter_first()
toggled_iter = None
if path:
@@ -589,14 +595,19 @@ class RaidEditor:
model.get_value(iter, 1):
# this is being toggled, negate the value:
if not val:
- allow = True
+ ret += 1
else:
if val:
- allow = True
+ ret += 1
iter = model.iter_next(iter)
- self.ok_button.set_sensitive(allow)
+ return ret