Changeset 822:08829c45f0a9 for src


Ignore:
Timestamp:
09/25/16 06:45:38 (8 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

A column descriptor can be marked as the default sortable one instead of hardwiring column 2 (re #307).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/flightlist.py

    r821 r822  
    1313    def __init__(self, attribute, heading, type = str,
    1414                 convertFn = None, renderer = gtk.CellRendererText(),
    15                  extraColumnAttributes = None, sortable = False):
     15                 extraColumnAttributes = None, sortable = False,
     16                 defaultSortable = False):
    1617        """Construct the descriptor."""
    1718        self._attribute = attribute
     
    2223        self._extraColumnAttributes = extraColumnAttributes
    2324        self._sortable = sortable
     25        self._defaultSortable = defaultSortable
     26
     27    @property
     28    def defaultSortable(self):
     29        """Determine if this column is the default sortable one."""
     30        return self._defaultSortable
    2431
    2532    def appendType(self, types):
     
    6572        ColumnDescriptor("callsign", xstr("flightsel_no")),
    6673        ColumnDescriptor("departureTime", xstr("flightsel_deptime"),
    67                          sortable = True),
     74                         sortable = True, defaultSortable = True),
    6875        ColumnDescriptor("departureICAO", xstr("flightsel_from"),
    6976                         sortable = True),
     
    8087
    8188        types = [int]
     89        defaultSortableIndex = None
    8290        for columnDescriptor in self._columnDescriptors:
     91            if columnDescriptor.defaultSortable:
     92                defaultSortableIndex = len(types)
    8393            columnDescriptor.appendType(types)
    8494
    8595        self._model = gtk.ListStore(*types)
    86         self._model.set_sort_column_id(2, SORT_ASCENDING)
     96        if defaultSortableIndex is not None:
     97            self._model.set_sort_column_id(defaultSortableIndex,
     98                                           SORT_ASCENDING)
    8799        self._view = gtk.TreeView(self._model)
    88100
     
    213225        ColumnDescriptor("callsign", xstr("flightsel_no")),
    214226        ColumnDescriptor("departureTime", xstr("flightsel_deptime"),
    215                          sortable = True),
     227                         sortable = True, defaultSortable = True),
    216228        ColumnDescriptor("departureICAO", xstr("flightsel_from"),
    217229                         sortable = True),
Note: See TracChangeset for help on using the changeset viewer.