- for units, value, unit in sorted_list:
- iter = self._unitModel.append()
- self._unitModel.set(iter, 0, unit, 1, str(value), 2, units)
- return
-
- def _on_click_category(self, row):
- #Clear out the previous list of units
- self._unitModel = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
- self._unitsView.set_model(self._unitModel)
-
- #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
-
- #Fill up the units descriptions and clear the value cells
- for key in keys:
- iter = self._unitModel.append()
- self._unitModel.set(iter, 0, key, 1, '', 2, self._unitDataInCategory[key][1])
-
- self._unitName.set_text('')
- self._unitValue.set_text('')
- self._previousUnitName.set_text('')
- self._previousUnitValue.set_text('')
- self._unitSymbol.set_text('')
- self._previousUnitSymbol.set_text('')
-
- self.restore_units()
-
- def restore_units(self):
- # Restore the previous historical settings of previously selected units in this newly selected category
- #Since category has just been clicked, the list will be sorted already.
- if self._selected_category in self._selected_units:
- if self._selected_units[self._selected_category][0]:
- #self._selected_units[self._selected_category] = [selected_unit, self._selected_units[self._selected_category][0]]
-
- units = unit_data.UNIT_DESCRIPTIONS[self._selected_category].keys()
- units.sort()
- del units[0] # do not display .base_unit description key
-
- #Restore oldest selection first.
- if self._selected_units[self._selected_category][1]:
- unit_no = 0
- for unit in units:
- if unit == self._selected_units[self._selected_category][1]:
- self._unitsView.set_cursor(unit_no, self._unitNameColumn, True)
- unit_no = unit_no+1
-
- #Restore newest selection second.
- unit_no = 0
- for unit in units:
- if unit == self._selected_units[self._selected_category][0]:
- self._unitsView.set_cursor(unit_no, self._unitNameColumn, True)
- unit_no = unit_no+1
-
- # select the text so user can start typing right away
- self._unitValue.grab_focus()
- self._unitValue.select_region(0, -1)
-
- def _on_click_unit(self, row):
- self._calcsuppress = True #suppress calculations
-
- #Determine the contents of the selected row.
- selected, iter = self._unitsView.get_selection().get_selected()
-
- selected_unit = selected.get_value(iter, 0)