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

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

 



> 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

Why do you need to do all this?  DeviceDisplayer.addColumn should
already be setting sort up correctly by calling set_sort_column_id.

> @@ -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)
>  

Adding self.enableSort means that some DeviceDisplayers are going to
work like the user expects, and some are not, despite the two instances
looking basically identical.  I think it would be confusing from a UI
standpoint.  NAK.

> @@ -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))

Adding a sort function looks fine.

My original intention here was to add a Units class so that sorting of
MB/GB/whatever would just magically work.  However, time pressure got
in the way.  I think it's still worth investigating.

- Chris

_______________________________________________
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