X-Git-Url: http://git.maemo.org/git/?p=gonvert;a=blobdiff_plain;f=src%2Fgonvert_glade.py;h=cfe0d4a0c57b41dbe8a7cc93c2143c8871f9e344;hp=2d13136324c41a6b369ca0f24282f6e6af4d1eda;hb=d74656e2fb9557bb0270bfc6aeafe0d8061dbc7d;hpb=1819074175106351b2d32b4cccf632852edfa202 diff --git a/src/gonvert_glade.py b/src/gonvert_glade.py index 2d13136..cfe0d4a 100755 --- a/src/gonvert_glade.py +++ b/src/gonvert_glade.py @@ -4,7 +4,6 @@ import os import pickle import string -import sys import gettext import logging @@ -44,12 +43,13 @@ class Gonvert(object): self._unit_sort_direction = False self._value_sort_direction = False self._units_sort_direction = False + self._isFullScreen = False self._find_result = [] # empty find result list - self._find_count = 0 # default to find result number zero + self._findIndex = 0 # default to find result number zero - self._selected_category = '' # preset to no selected category - self._selected_units = {} # empty dictionary for later use + self._selectedCategory = '' # preset to no selected category + self._defaultUnitForCategory = {} # empty dictionary for later use #check to see if glade file is in current directory (user must be # running from download untar directory) @@ -60,6 +60,8 @@ class Gonvert(object): widgets = gtk.glade.XML(gladePath) break else: + _moduleLogger.error("UI Descriptor not found!") + gtk.main_quit() return self._mainWindow = widgets.get_widget('mainWindow') @@ -79,6 +81,7 @@ class Gonvert(object): self._categoryView = widgets.get_widget('categoryView') self._unitsView = widgets.get_widget('unitsView') + self._unitsView.set_property('rules_hint', 1) self._unitsView_selection = self._unitsView.get_selection() self._unitName = widgets.get_widget('unitName') @@ -93,11 +96,13 @@ class Gonvert(object): self._unitDescription = widgets.get_widget('unitDescription') + self._searchLayout = widgets.get_widget('searchLayout') + self._searchLayout.hide() self._findEntry = widgets.get_widget('findEntry') self._findLabel = widgets.get_widget('findLabel') - findButton = widgets.get_widget('findButton') + self._findButton = widgets.get_widget('findButton') ToolTips = gtk.Tooltips() - ToolTips.set_tip(findButton, _(u'Find unit (F6)')) + ToolTips.set_tip(self._findButton, _(u'Find unit (F6)')) #insert a self._categoryColumnumn into the units list even though the heading will not be seen renderer = gtk.CellRendererText() @@ -122,6 +127,13 @@ class Gonvert(object): self._unitSymbolColumn.connect("clicked", self._on_click_unit_column) self._unitsView.append_column(self._unitSymbolColumn) + self._unitModel = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING) + self._sortedUnitModel = gtk.TreeModelSort(self._unitModel) + columns = self._get_column_sort_stuff() + for columnIndex, (column, sortDirection, col_cmp) in enumerate(columns): + self._sortedUnitModel.set_sort_func(columnIndex, col_cmp) + self._unitsView.set_model(self._sortedUnitModel) + #Insert a column into the category list even though the heading will not be seen renderer = gtk.CellRendererText() self._categoryColumn = gtk.TreeViewColumn('Title', renderer) @@ -144,7 +156,6 @@ class Gonvert(object): "on_exit_menu_activate": self._on_user_exit, "on_main_window_destroy": self._on_user_exit, "on_categoryView_select_row": self._on_click_category, - "on_unitsView__on_click_unit_column": self._on_click_unit_column, "on_unitValue_changed": self._on_unit_value_changed, "on_previousUnitValue_changed": self._on_previous_unit_value_changed, "on_writeUnitsMenuItem_activate": self._on_user_write_units, @@ -155,11 +166,12 @@ class Gonvert(object): "on_messagebox_ok_clicked": self.messagebox_ok_clicked, "on_clearSelectionMenuItem_activate": self._on_user_clear_selections, "on_unitsView_cursor_changed": self._on_click_unit, - "on_unitsView_button_released": self._on_button_released, "on_shortlistcheck_toggled": self._on_shortlist_changed, "on_toggleShortList_activate": self._on_edit_shortlist, } widgets.signal_autoconnect(dic) + self._mainWindow.connect("key-press-event", self._on_key_press) + self._mainWindow.connect("window-state-event", self._on_window_state_change) self._mainWindow.set_title('gonvert- %s - Unit Conversion Utility' % constants.__version__) iconPath = pixmapspath + '/gonvert.png' @@ -196,10 +208,10 @@ class Gonvert(object): #Retrieving previous selections from ~/.gonvert/selections.dat selections = pickle.load(open(selectionsDatPath, 'r')) #Restoring previous selections. - #If the 'selected_unts' has been stored, then extract self._selected_units from selections. + #If the 'selected_unts' has been stored, then extract self._defaultUnitForCategory from selections. if 'selected_units' in selections: - self._selected_units = selections['selected_units'] - #Make sure that the 'self._selected_category' has been stored. + self._defaultUnitForCategory = selections['selected_units'] + #Make sure that the 'self._selectedCategory' has been stored. if 'selected_category' in selections: #Match an available category to the previously selected category. for counter in range(len(unit_data.UNIT_CATEGORIES)): @@ -216,7 +228,7 @@ class Gonvert(object): self._categoryView.set_cursor(0, self._categoryColumn, False) self._categoryView.grab_focus() - self.restore_units() + self._select_default_unit() def _save_settings(self): """ @@ -224,17 +236,17 @@ class Gonvert(object): should therefore only be called when exiting the program. Update selections dictionary which consists of the following keys: - 'self._selected_category': full name of selected category - 'self._selected_units': self._selected_units dictionary which contains: + 'self._selectedCategory': full name of selected category + 'self._defaultUnitForCategory': self._defaultUnitForCategory dictionary which contains: [categoryname: #1 displayed unit, #2 displayed unit] """ #Determine the contents of the selected category row selected, iter = self._categoryView.get_selection().get_selected() - self._selected_category = self._categoryModel.get_value(iter, 0) + self._selectedCategory = self._categoryModel.get_value(iter, 0) selections = { - 'selected_category': self._selected_category, - 'selected_units': self._selected_units + 'selected_category': self._selectedCategory, + 'selected_units': self._defaultUnitForCategory } selectionsDatPath = "/".join((constants._data_path_, "selections.dat")) pickle.dump(selections, open(selectionsDatPath, 'w')) @@ -249,14 +261,14 @@ class Gonvert(object): def _clear_find(self): # switch to "new find" state self._find_result = [] - self._find_count = 0 + self._findIndex = 0 # Clear our user message self._findLabel.set_text('') def _find_first(self): assert len(self._find_result) == 0 - assert self._find_count == 0 + assert self._findIndex == 0 findString = string.lower(string.strip(self._findEntry.get_text())) if not findString: return @@ -269,288 +281,267 @@ class Gonvert(object): if loweredUnit in findString or findString in loweredUnit: self._find_result.append((category, unit, catIndex, unitIndex)) - if not self._find_result: - return - - self._select_found_unit() - - def _find_wrap_around(self): - assert 0 < len(self._find_result) - assert self._find_count + 1 == len(self._find_result) - #select first result - self._find_count = 0 - self._select_found_unit() - - def _find_next(self): - assert 0 < len(self._find_result) - assert self._find_count + 1 < len(self._find_result) - self._find_count += 1 - self._select_found_unit() - - def _select_found_unit(self): + def _update_find_selection(self): assert 0 < len(self._find_result) #check if next find is in a new category (prevent category changes when unnecessary - if self._selected_category != self._find_result[self._find_count][0]: + if self._selectedCategory != self._find_result[self._findIndex][0]: self._categoryView.set_cursor( - self._find_result[self._find_count][2], self._categoryColumn, False + self._find_result[self._findIndex][2], self._categoryColumn, False ) self._unitsView.set_cursor( - self._find_result[self._find_count][3], self._unitNameColumn, True + self._find_result[self._findIndex][3], self._unitNameColumn, True ) - def _on_findEntry_changed(self, *args): - """ - Clear out find results since the user wants to look for something new - """ - try: - self._clear_find() - except Exception: - _moduleLogger.exception() - - def _on_shortlist_changed(self, *args): - try: - raise NotImplementedError("%s" % self._shortlistcheck.get_active()) - except Exception: - _moduleLogger.exception() - - def _on_edit_shortlist(self, *args): - try: - raise NotImplementedError("%s" % self._toggleShortList.get_active()) - except Exception: - _moduleLogger.exception() - - def _on_user_clear_selections(self, *args): - try: - selectionsDatPath = "/".join((constants._data_path_, "selections.dat")) - os.remove(selectionsDatPath) - self._selected_units = {} - except Exception: - _moduleLogger.exception() - - def _on_find_activate(self, a): + def _find_next(self): """ check if 'new find' or 'last find' or 'next-find' new-find = run the find algorithm which also selects the first found unit - = self._find_count = 0 and self._find_result = [] + = self._findIndex = 0 and self._find_result = [] last-find = restart from top again - = self._find_count = len(self._find_result) + = self._findIndex = len(self._find_result) next-find = continue to next found location - = self._find_count = 0 and len(self._find_result)>0 + = self._findIndex = 0 and len(self._find_result)>0 """ - try: - if len(self._find_result) == 0: - self._find_first() - else: - if self._find_count == len(self._find_result)-1: - self._find_wrap_around() - else: - self._find_next() - - if not self._find_result: - self._findLabel.set_text('Text not found') + if len(self._find_result) == 0: + self._find_first() + else: + if self._findIndex == len(self._find_result)-1: + self._findIndex = 0 else: - resultsLeft = len(self._find_result) - self._find_count - 1 - self._findLabel.set_text( - '%s result(s) left' % (resultsLeft, ) - ) - except Exception: - _moduleLogger.exception() + self._findIndex += 1 - def _on_click_unit_column(self, col): - """ - Sort the contents of the col when the user clicks on the title. - """ - #Determine which column requires sorting - if col is self._unitNameColumn: - selectedUnitColumn = 0 - self._unitNameColumn.set_sort_indicator(True) - self._unitValueColumn.set_sort_indicator(False) - self._unitSymbolColumn.set_sort_indicator(False) - self._unitNameColumn.set_sort_order(not self._unit_sort_direction) - elif col is self._unitValueColumn: - selectedUnitColumn = 1 - self._unitNameColumn.set_sort_indicator(False) - self._unitValueColumn.set_sort_indicator(True) - self._unitSymbolColumn.set_sort_indicator(False) - self._unitValueColumn.set_sort_order(not self._value_sort_direction) - elif col is self._unitSymbolColumn: - selectedUnitColumn = 2 - self._unitNameColumn.set_sort_indicator(False) - self._unitValueColumn.set_sort_indicator(False) - self._unitSymbolColumn.set_sort_indicator(True) - self._unitSymbolColumn.set_sort_order(not self._units_sort_direction) + if not self._find_result: + self._findLabel.set_text('Text not found') else: - assert False, "Unknown column: %s" % (col.get_title(), ) - - #declare a spot to hold the sorted list - sorted_list = [] - - #point to the first row - iter = self._unitModel.get_iter_first() - row = 0 - - while iter: - #grab all text from columns for sorting - - #get the text from each column - unit_text = self._unitModel.get_value(iter, 0) - units_text = self._unitModel.get_value(iter, 2) - - #do not bother sorting if the value column is empty - if self._unitModel.get_value(iter, 1) == '' and selectedUnitColumn == 1: - return + self._update_find_selection() + resultsLeft = len(self._find_result) - self._findIndex - 1 + self._findLabel.set_text( + '%s result(s) left' % (resultsLeft, ) + ) - #special sorting exceptions for ascii values (instead of float values) - if self._selected_category == "Computer Numbers": - value_text = self._unitModel.get_value(iter, 1) - else: - if self._unitModel.get_value(iter, 1) == None or self._unitModel.get_value(iter, 1) == '': - value_text = '' - else: - value_text = float(self._unitModel.get_value(iter, 1)) + def _find_previous(self): + """ + check if 'new find' or 'last find' or 'next-find' - if selectedUnitColumn == 0: - sorted_list.append((unit_text, value_text, units_text)) - elif selectedUnitColumn == 1: - sorted_list.append((value_text, unit_text, units_text)) - else: - sorted_list.append((units_text, value_text, unit_text)) + new-find = run the find algorithm which also selects the first found unit + = self._findIndex = 0 and self._find_result = [] - #point to the next row in the self._unitModel - iter = self._unitModel.iter_next(iter) - row = row+1 + last-find = restart from top again + = self._findIndex = len(self._find_result) - #check if no calculations have been made yet (don't bother sorting) - if row == 0: - return + next-find = continue to next found location + = self._findIndex = 0 and len(self._find_result)>0 + """ + if len(self._find_result) == 0: + self._find_first() else: - if selectedUnitColumn == 0: - if not self._unit_sort_direction: - sorted_list.sort(lambda (x, xx, xxx), (y, yy, yyy): cmp(string.lower(x), string.lower(y))) - self._unit_sort_direction = True - else: - sorted_list.sort(lambda (x, xx, xxx), (y, yy, yyy): cmp(string.lower(y), string.lower(x))) - self._unit_sort_direction = False - elif selectedUnitColumn == 1: - sorted_list.sort() - if not self._value_sort_direction: - self._value_sort_direction = True - else: - sorted_list.reverse() - self._value_sort_direction = False + if self._findIndex == 0: + self._findIndex = len(self._find_result)-1 else: - if not self._units_sort_direction: - sorted_list.sort(lambda (x, xx, xxx), (y, yy, yyy): cmp(string.lower(x), string.lower(y))) - self._units_sort_direction = True - else: - sorted_list.sort(lambda (x, xx, xxx), (y, yy, yyy): cmp(string.lower(y), string.lower(x))) - self._units_sort_direction = False - - #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 differently 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) - - if selectedUnitColumn == 0: - for unit, value, units in sorted_list: - iter = self._unitModel.append() - self._unitModel.set(iter, 0, unit, 1, str(value), 2, units) - elif selectedUnitColumn == 1: - for value, unit, units in sorted_list: - iter = self._unitModel.append() - self._unitModel.set(iter, 0, unit, 1, str(value), 2, units) - else: - 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) + self._findIndex -= 1 - #Determine the contents of the selected category row - selected, iter = row.get_selection().get_selected() - - self._selected_category = self._categoryModel.get_value(iter, 0) + if not self._find_result: + self._findLabel.set_text('Text not found') + else: + self._update_find_selection() + resultsLeft = len(self._find_result) - self._findIndex - 1 + self._findLabel.set_text( + '%s result(s) left' % (resultsLeft, ) + ) - 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) + def _toggle_find(self): + if self._searchLayout.get_property("visible"): + self._searchLayout.hide() + else: + self._searchLayout.show() + + def _unit_model_cmp(self, sortedModel, leftItr, rightItr): + leftUnitText = self._unitModel.get_value(leftItr, 0) + rightUnitText = self._unitModel.get_value(rightItr, 0) + return cmp(leftUnitText, rightUnitText) + + def _symbol_model_cmp(self, sortedModel, leftItr, rightItr): + leftSymbolText = self._unitModel.get_value(leftItr, 2) + rightSymbolText = self._unitModel.get_value(rightItr, 2) + return cmp(leftSymbolText, rightSymbolText) + + def _value_model_cmp(self, sortedModel, leftItr, rightItr): + #special sorting exceptions for ascii values (instead of float values) + if self._selectedCategory == "Computer Numbers": + leftValue = self._unitModel.get_value(leftItr, 1) + rightValue = self._unitModel.get_value(rightItr, 1) + else: + leftValueText = self._unitModel.get_value(leftItr, 1) + leftValue = float(leftValueText) if leftValueText else 0.0 + + rightValueText = self._unitModel.get_value(rightItr, 1) + rightValue = float(rightValueText) if rightValueText else 0.0 + return cmp(leftValue, rightValue) + + def _get_column_sort_stuff(self): + columns = ( + (self._unitNameColumn, "_unit_sort_direction", self._unit_model_cmp), + (self._unitValueColumn, "_value_sort_direction", self._value_model_cmp), + (self._unitSymbolColumn, "_units_sort_direction", self._symbol_model_cmp), + ) + return columns - 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 + def _switch_category(self, category): + self._selectedCategory = category + self._unitDataInCategory = unit_data.UNIT_DESCRIPTIONS[self._selectedCategory] #Fill up the units descriptions and clear the value cells - for key in keys: + self._clear_visible_unit_data() + for key in unit_data.get_units(self._selectedCategory): 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 _clear_visible_unit_data(self): + self._unitDescription.get_buffer().set_text("") self._unitName.set_text('') self._unitValue.set_text('') + self._unitSymbol.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 + self._unitModel.clear() + + def _select_default_unit(self): + # Restore the previous historical settings of previously selected units + # in this newly selected category + if self._selectedCategory in self._defaultUnitForCategory: + units = unit_data.get_units(self._selectedCategory) + + #Restore oldest selection first. + if self._defaultUnitForCategory[self._selectedCategory][1]: + unitIndex = units.index(self._defaultUnitForCategory[self._selectedCategory][1]) + self._unitsView.set_cursor(unitIndex, self._unitNameColumn, True) + + #Restore newest selection second. + if self._defaultUnitForCategory[self._selectedCategory][0]: + unitIndex = units.index(self._defaultUnitForCategory[self._selectedCategory][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 _on_button_released(self, row, a): - self._on_click_unit(row) + def _on_shortlist_changed(self, *args): + try: + raise NotImplementedError("%s" % self._shortlistcheck.get_active()) + except Exception: + _moduleLogger.exception("") + + def _on_edit_shortlist(self, *args): + try: + raise NotImplementedError("%s" % self._toggleShortList.get_active()) + except Exception: + _moduleLogger.exception("") + + def _on_user_clear_selections(self, *args): + try: + selectionsDatPath = "/".join((constants._data_path_, "selections.dat")) + os.remove(selectionsDatPath) + self._defaultUnitForCategory = {} + except Exception: + _moduleLogger.exception("") + + def _on_key_press(self, widget, event, *args): + """ + @note Hildon specific + """ + RETURN_TYPES = (gtk.keysyms.Return, gtk.keysyms.ISO_Enter, gtk.keysyms.KP_Enter) + try: + if ( + event.keyval == gtk.keysyms.F6 or + event.keyval in RETURN_TYPES and event.get_state() & gtk.gdk.CONTROL_MASK + ): + if self._isFullScreen: + self._mainWindow.unfullscreen() + else: + self._mainWindow.fullscreen() + elif event.keyval == gtk.keysyms.f and event.get_state() & gtk.gdk.CONTROL_MASK: + self._toggle_find() + elif event.keyval == gtk.keysyms.p and event.get_state() & gtk.gdk.CONTROL_MASK: + self._find_previous() + elif event.keyval == gtk.keysyms.n and event.get_state() & gtk.gdk.CONTROL_MASK: + self._find_next() + except Exception, e: + _moduleLogger.exception("") + + def _on_window_state_change(self, widget, event, *args): + """ + @note Hildon specific + """ + try: + if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN: + self._isFullScreen = True + else: + self._isFullScreen = False + except Exception, e: + _moduleLogger.exception("") + + def _on_findEntry_changed(self, *args): + """ + Clear out find results since the user wants to look for something new + """ + try: + self._clear_find() + except Exception: + _moduleLogger.exception("") + + def _on_find_activate(self, a): + try: + self._find_next() + self._findButton.grab_focus() + except Exception: + _moduleLogger.exception("") + + 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 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: + maybeCol.set_sort_indicator(False) + else: + assert False, "Unknown column: %s" % (col.get_title(), ) + except Exception: + _moduleLogger.exception("") + + def _on_click_category(self, *args): + try: + selected, iter = self._categoryView.get_selection().get_selected() + selectedCategory = self._categoryModel.get_value(iter, 0) + self._switch_category(selectedCategory) + except Exception: + _moduleLogger.exception("") def _on_click_unit(self, row): self._calcsuppress = True #suppress calculations @@ -582,18 +573,18 @@ class Gonvert(object): self._unitSymbol.set_text(unit_spec[1]) # put units into label text if self._unitValue.get_text() == '': - if self._selected_category == "Computer Numbers": + if self._selectedCategory == "Computer Numbers": self._unitValue.set_text("0") else: self._unitValue.set_text("0.0") #For historical purposes, record this unit as the most recent one in this category. # Also, if a previous unit exists, then shift that previous unit to oldest unit. - 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]] + if self._selectedCategory in self._defaultUnitForCategory: + if self._defaultUnitForCategory[self._selectedCategory][0]: + self._defaultUnitForCategory[self._selectedCategory] = [selected_unit, self._defaultUnitForCategory[self._selectedCategory][0]] else: - self._selected_units[self._selected_category] = [selected_unit, ''] + self._defaultUnitForCategory[self._selectedCategory] = [selected_unit, ''] # select the text so user can start typing right away self._unitValue.grab_focus() @@ -601,43 +592,12 @@ class Gonvert(object): self._calcsuppress = False #enable calculations - def messagebox_ok_clicked(self, a): - messagebox.hide() - - def _on_user_write_units(self, a): - ''"Write the list of categories and units to stdout for documentation purposes.''" - messagebox_model = gtk.TextBuffer(None) - messageboxtext.set_buffer(messagebox_model) - messagebox_model.insert_at_cursor(_(u'The units are being written to stdout. You can capture this printout by starting gonvert from the command line as follows: \n$ gonvert > file.txt'), -1) - messagebox.show() - while gtk.events_pending(): - gtk.mainiteration(False) - - total_categories = 0 - total_units = 0 - print 'gonvert-%s%s' % ( - constants.__version__, - _(u' - Unit Conversion Utility - Convertible units listing: ') - ) - for category_key in unit_data.UNIT_CATEGORIES: - total_categories = total_categories + 1 - print category_key, ": " - self._unitDataInCategory = unit_data.UNIT_DESCRIPTIONS[category_key] - unit_keys = self._unitDataInCategory.keys() - unit_keys.sort() - del unit_keys[0] # do not display .base_unit description key - for unit_key in unit_keys: - total_units = total_units + 1 - print "\t", unit_key - print total_categories, ' categories' - print total_units, ' units' - def _on_unit_value_changed(self, a): if self._calcsuppress: #self._calcsuppress = False return # determine if value to be calculated is empty - if self._selected_category == "Computer Numbers": + if self._selectedCategory == "Computer Numbers": if self._unitValue.get_text() == '': value = '0' else: @@ -682,7 +642,7 @@ class Gonvert(object): #self._calcsuppress = False return # determine if value to be calculated is empty - if self._selected_category == "Computer Numbers": + if self._selectedCategory == "Computer Numbers": if self._previousUnitValue.get_text() == '': value = '0' else: @@ -722,6 +682,37 @@ class Gonvert(object): self._unitValue.set_text(str(apply(func.from_base, (base, arg, )))) self._calcsuppress = False + def messagebox_ok_clicked(self, a): + messagebox.hide() + + def _on_user_write_units(self, a): + ''"Write the list of categories and units to stdout for documentation purposes.''" + messagebox_model = gtk.TextBuffer(None) + messageboxtext.set_buffer(messagebox_model) + messagebox_model.insert_at_cursor(_(u'The units are being written to stdout. You can capture this printout by starting gonvert from the command line as follows: \n$ gonvert > file.txt'), -1) + messagebox.show() + while gtk.events_pending(): + gtk.mainiteration(False) + + total_categories = 0 + total_units = 0 + print 'gonvert-%s%s' % ( + constants.__version__, + _(u' - Unit Conversion Utility - Convertible units listing: ') + ) + for category_key in unit_data.UNIT_CATEGORIES: + total_categories = total_categories + 1 + print category_key, ": " + self._unitDataInCategory = unit_data.UNIT_DESCRIPTIONS[category_key] + unit_keys = self._unitDataInCategory.keys() + unit_keys.sort() + del unit_keys[0] # do not display .base_unit description key + for unit_key in unit_keys: + total_units = total_units + 1 + print "\t", unit_key + print total_categories, ' categories' + print total_units, ' units' + def _on_about_clicked(self, a): dlg = gtk.AboutDialog() dlg.set_name(constants.__pretty_app_name__) @@ -737,7 +728,7 @@ class Gonvert(object): try: self._save_settings() except Exception: - _moduleLogger.exception() + _moduleLogger.exception("") finally: gtk.main_quit()