def _select_default_unit(self): # Restore the previous historical settings of previously selected units # in this newly selected category defaultPrimary = unit_data.get_base_unit(self._selectedCategoryName) defaultSecondary = "" if self._selectedCategoryName in self._defaultUnitForCategory: if self._defaultUnitForCategory[self._selectedCategoryName][0]: defaultPrimary = self._defaultUnitForCategory[self._selectedCategoryName][0] if self._defaultUnitForCategory[self._selectedCategoryName][1]: defaultSecondary = self._defaultUnitForCategory[self._selectedCategoryName][1] units = unit_data.get_units(self._selectedCategoryName) #Restore oldest selection first. if defaultPrimary: try: unitIndex = units.index(defaultPrimary) except ValueError: unitIndex = 0 self._unitsView.set_cursor(unitIndex, self._unitNameColumn, True) #Restore newest selection second. if defaultSecondary: try: unitIndex = units.index(defaultSecondary) except ValueError: unitIndex = 0 self._unitsView.set_cursor(unitIndex, self._unitNameColumn, True) # select the text so user can start typing right away self._unitValue.grab_focus() self._unitValue.select_region(0, -1)
def _switch_category(self, category): self._selectedCategoryName = category self._unitDataInCategory = unit_data.UNIT_DESCRIPTIONS[self._selectedCategoryName] #Fill up the units descriptions and clear the value cells self._clear_visible_unit_data() for key in unit_data.get_units(self._selectedCategoryName): iter = self._unitModel.append() self._unitModel.set(iter, 0, key, 1, '', 2, self._unitDataInCategory[key][1]) self._sortedUnitModel.sort_column_changed() self._select_default_unit()
def _find_first(self): assert len(self._find_result) == 0 assert self._findIndex == 0 findString = self._findEntry.get_text().strip().lower() if not findString: return # Gather info on all the matching units from all categories for catIndex, category in enumerate(unit_data.UNIT_CATEGORIES): units = unit_data.get_units(category) for unitIndex, unit in enumerate(units): loweredUnit = unit.lower() if loweredUnit in findString or findString in loweredUnit: self._find_result.append((category, unit, catIndex, unitIndex))
def _on_search_edited(self, *args): userInput = self._searchEntry.text() if len(userInput) < self.MINIMAL_ENTRY: return self._resultsBox.clear() lowerInput = str(userInput).lower() for catIndex, category in enumerate(unit_data.UNIT_CATEGORIES): units = unit_data.get_units(category) for unitIndex, unit in enumerate(units): loweredUnit = unit.lower() if lowerInput in loweredUnit: twi = QtGui.QTreeWidgetItem(self._resultsBox) twi.setText(0, category) twi.setText(1, unit)
def _switch_category(self, category): self._selectedCategoryName = category self._unitDataInCategory = unit_data.UNIT_DESCRIPTIONS[self._selectedCategoryName] #Fill up the units descriptions and clear the value cells self._clear_visible_unit_data() nameLength = 0 for key in unit_data.get_units(self._selectedCategoryName): row = key, '0.0', self._unitDataInCategory[key][1], '0.', '0' self._unitModel.append(row) nameLength = max(nameLength, len(key)) self._sortedUnitModel.sort_column_changed() if constants.FORCE_HILDON_LIKE: maxCatCharWidth = int(nameLength * 0.75) maxCharWidth = int(len("nibble | hexit | quadbit") * 0.75) charWidth = min(maxCatCharWidth, maxCharWidth) self._unitsNameRenderer.set_property("width-chars", charWidth) self._select_default_unit()