- def _on_click_unit_column(self, col):
- """
- Sort the contents of the col when the user clicks on the title.
- """
- try:
- #Determine which column requires sorting
- columns = self._get_column_sort_stuff()
- for column, directionName, col_cmp in columns:
- column.set_sort_indicator(False)
- for columnIndex, (maybeCol, directionName, col_cmp) in enumerate(columns):
- if col is maybeCol:
- direction = getattr(self, directionName)
- gtkDirection = gtk.SORT_ASCENDING if direction else gtk.SORT_DESCENDING
- # cause a sort
- self._sortedUnitModel.set_sort_column_id(columnIndex, gtkDirection)
- # set the visual for sorting
- col.set_sort_indicator(True)
- col.set_sort_order(not direction)
-
- setattr(self, directionName, not direction)
- break
- else:
- assert False, "Unknown column: %s" % (col.get_title(), )
- except Exception:
- _moduleLogger.exception()
-
- def _on_click_category(self, row):
- #Colourize each row alternately for easier reading
- self._unitsView.set_property('rules_hint', 1)
-
- #Clear out the description
- text_model = gtk.TextBuffer(None)
- self._unitDescription.set_buffer(text_model)
-
- #Determine the contents of the selected category row
- selected, iter = row.get_selection().get_selected()
-
- self._selected_category = self._categoryModel.get_value(iter, 0)
-
- self._unit_sort_direction = False
- self._value_sort_direction = False
- self._units_sort_direction = False
- self._unitNameColumn.set_sort_indicator(False)
- self._unitValueColumn.set_sort_indicator(False)
- self._unitSymbolColumn.set_sort_indicator(False)
-
- self._unitDataInCategory = unit_data.UNIT_DESCRIPTIONS[selected.get_value(iter, 0)]
- keys = self._unitDataInCategory.keys()
- keys.sort()
- del keys[0] # do not display .base_unit description key