[PATCH] cleardisks / filter ui enable per column sorting by clicking headings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 iw/DeviceSelector.py |   32 ++++++++++++++++++++++++++++++--
 iw/cleardisks_gui.py |    4 ++--
 iw/filter_gui.py     |   11 ++++++-----
 3 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/iw/DeviceSelector.py b/iw/DeviceSelector.py
index 17b977c..a1cb31e 100644
--- a/iw/DeviceSelector.py
+++ b/iw/DeviceSelector.py
@@ -42,7 +42,21 @@ class DeviceDisplayer(object):
         # down menu, and obviously makes a column visible (or not).
         col.set_visible(not col.get_visible())
 
-    def __init__(self, store, model, view, active=ACTIVE_COL, visible=VISIBLE_COL):
+    def _column_clicked(self, col, num):
+        sortOrder = gtk.SORT_ASCENDING
+        if self.lastSortCol == col:
+            if self.sortOrder == gtk.SORT_ASCENDING:
+                sortOrder = gtk.SORT_DESCENDING
+        elif self.lastSortCol:
+            self.lastSortCol.set_sort_indicator(False)
+
+        self.store.set_sort_column_id(num, sortOrder)
+        col.set_sort_indicator(True)
+        col.set_sort_order(sortOrder)
+        self.sortOrder = sortOrder
+        self.lastSortCol = col
+
+    def __init__(self, store, model, view, active=ACTIVE_COL, visible=VISIBLE_COL, enableSort=True):
         self.store = store
         self.model = model
         self.view = view
@@ -51,8 +65,11 @@ class DeviceDisplayer(object):
 
         self.active = active
         self.visible = visible
+        self.enableSort = enableSort
+        self.sortOrder = gtk.SORT_ASCENDING
+        self.lastSortCol = None
 
-    def addColumn(self, title, num, displayed=True):
+    def addColumn(self, title, num, displayed=True, sortFunc=None):
         cell = gtk.CellRendererText()
         cell.set_property("yalign", 0)
 
@@ -65,6 +82,11 @@ class DeviceDisplayer(object):
         # This needs to be set on all columns or it will be impossible to sort
         # by that column.
         col.set_sort_column_id(num)
+        if self.enableSort:
+            col.set_clickable(True)
+            col.connect("clicked", self._column_clicked, num)
+            if sortFunc:
+                self.store.set_sort_func(num, sortFunc, num)
 
         if self.menu:
             # Add a new entry to the drop-down menu.
@@ -199,3 +221,9 @@ class DeviceSelector(DeviceDisplayer):
 
         if cb:
             cb(not is_checked, self.store.get_value(iter, OBJECT_COL))
+
+def capacitySortFunc(model, iter1, iter2, colNum):
+    # -3 to strip the " MB" at the end
+    val1 = model.get(iter1, colNum)[0][:-3]
+    val2 = model.get(iter2, colNum)[0][:-3]
+    return cmp(int(val1), int(val2))
diff --git a/iw/cleardisks_gui.py b/iw/cleardisks_gui.py
index ec026ec..377ac7f 100644
--- a/iw/cleardisks_gui.py
+++ b/iw/cleardisks_gui.py
@@ -104,7 +104,7 @@ class ClearDisksWindow (InstallWindow):
                                      active=self.leftActive)
         self.leftDS.createMenu()
         self.leftDS.addColumn(_("Model"), 5)
-        self.leftDS.addColumn(_("Capacity"), 6)
+        self.leftDS.addColumn(_("Capacity"), 6, sortFunc=capacitySortFunc)
         self.leftDS.addColumn(_("Vendor"), 7)
         self.leftDS.addColumn(_("Interconnect"), 8, displayed=False)
         self.leftDS.addColumn(_("Serial Number"), 9, displayed=False)
@@ -120,7 +120,7 @@ class ClearDisksWindow (InstallWindow):
 
         self.rightDS = DeviceSelector(self.store, self.rightFilteredModel,
                                       self.rightTreeView, visible=self.rightVisible,
-                                      active=self.rightActive)
+                                      active=self.rightActive, enableSort=False)
         self.rightDS.createSelectionCol(title=_("Boot"), radioButton=True)
         self.rightDS.addColumn(_("Model"), 5)
         self.rightDS.addColumn(_("Capacity"), 6)
diff --git a/iw/filter_gui.py b/iw/filter_gui.py
index a0f6704..ff787a3 100644
--- a/iw/filter_gui.py
+++ b/iw/filter_gui.py
@@ -411,7 +411,7 @@ class FilterWindow(InstallWindow):
         np = NotebookPage(self.store, "basic", self.xml, Callbacks(self.xml))
 
         np.ds.addColumn(_("Model"), MODEL_COL)
-        np.ds.addColumn(_("Capacity"), CAPACITY_COL)
+        np.ds.addColumn(_("Capacity"), CAPACITY_COL, sortFunc=capacitySortFunc)
         np.ds.addColumn(_("Vendor"), VENDOR_COL)
         np.ds.addColumn(_("Interconnect"), INTERCONNECT_COL)
         np.ds.addColumn(_("Serial Number"), SERIAL_COL)
@@ -421,14 +421,14 @@ class FilterWindow(InstallWindow):
         np = NotebookPage(self.store, "raid", self.xml, RAIDCallbacks(self.xml))
 
         np.ds.addColumn(_("Model"), MODEL_COL)
-        np.ds.addColumn(_("Capacity"), CAPACITY_COL)
+        np.ds.addColumn(_("Capacity"), CAPACITY_COL, sortFunc=capacitySortFunc)
         return np
 
     def _makeMPath(self):
         np = NotebookPage(self.store, "mpath", self.xml, MPathCallbacks(self.xml))
 
         np.ds.addColumn(_("WWID"), WWID_COL)
-        np.ds.addColumn(_("Capacity"), CAPACITY_COL)
+        np.ds.addColumn(_("Capacity"), CAPACITY_COL, sortFunc=capacitySortFunc)
         np.ds.addColumn(_("Vendor"), VENDOR_COL)
         np.ds.addColumn(_("Interconnect"), INTERCONNECT_COL)
         np.ds.addColumn(_("Paths"), PATHS_COL)
@@ -438,7 +438,7 @@ class FilterWindow(InstallWindow):
         np = NotebookPage(self.store, "other", self.xml, OtherCallbacks(self.xml))
 
         np.ds.addColumn(_("WWID"), WWID_COL)
-        np.ds.addColumn(_("Capacity"), CAPACITY_COL)
+        np.ds.addColumn(_("Capacity"), CAPACITY_COL, sortFunc=capacitySortFunc)
         np.ds.addColumn(_("Vendor"), VENDOR_COL)
         np.ds.addColumn(_("Interconnect"), INTERCONNECT_COL)
         np.ds.addColumn(_("Serial Number"), SERIAL_COL, displayed=False)
@@ -448,7 +448,8 @@ class FilterWindow(InstallWindow):
         np = NotebookPage(self.store, "search", self.xml, SearchCallbacks(self.xml))
 
         np.ds.addColumn(_("Model"), MODEL_COL)
-        np.ds.addColumn(_("Capacity"), CAPACITY_COL, displayed=False)
+        np.ds.addColumn(_("Capacity"), CAPACITY_COL, displayed=False,
+                        sortFunc=capacitySortFunc)
         np.ds.addColumn(_("Vendor"), VENDOR_COL)
         np.ds.addColumn(_("Interconnect"), INTERCONNECT_COL, displayed=False)
         np.ds.addColumn(_("Serial Number"), SERIAL_COL, displayed=False)
-- 
1.6.5.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux