- def _on_button_released(self, row, a):
- self._on_click_unit(row)
-
- def _on_click_unit(self, row):
- evil_globals.calcsuppress = 1 #suppress calculations
-
- #Determine the contents of the selected row.
- selected, iter = self._unitsView.get_selection().get_selected()
-
- selected_unit = selected.get_value(iter, 0)
-
- unit_spec = unitDataInCategory[selected_unit]
-
- #Clear out the description
- text_model = gtk.TextBuffer(None)
- self._unitDescription.set_buffer(text_model)
-
- enditer = text_model.get_end_iter()
- text_model.insert(enditer, unit_spec[2])
-
- if self._unitName.get_text() != selected_unit:
- self._previousUnitName.set_text(self._unitName.get_text())
- self._previousUnitValue.set_text(self._unitValue.get_text())
- if self._unitSymbol.get() == None:
- self._previousUnitSymbol.set_text('')
- else:
- self._previousUnitSymbol.set_text(self._unitSymbol.get())
- self._unitName.set_text(selected_unit)
-
- self._unitValue.set_text(selected.get_value(iter, 1))
-
- self._unitSymbol.set_text(unit_spec[1]) # put units into label text
- if self._unitValue.get_text() == '':
- if evil_globals.selected_category == "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 evil_globals.selected_category in evil_globals.selected_units:
- if evil_globals.selected_units[evil_globals.selected_category][0]:
- evil_globals.selected_units[evil_globals.selected_category] = [selected_unit, evil_globals.selected_units[evil_globals.selected_category][0]]
- else:
- evil_globals.selected_units[evil_globals.selected_category] = [selected_unit, '']
-
- # select the text so user can start typing right away
- self._unitValue.grab_focus()
- self._unitValue.select_region(0, -1)
-
- evil_globals.calcsuppress = 0 #enable calculations
-
- 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)
- category_keys = unit_data.list_dic.keys()
- category_keys.sort()
- total_categories = 0
- total_units = 0
- print 'gonvert-%s%s' % (
- constants.__version__,
- _(u' - Unit Conversion Utility - Convertible units listing: ')
- )
- for category_key in category_keys:
- total_categories = total_categories + 1
- print category_key, ": "
- unitDataInCategory = unit_data.list_dic[category_key]
- unit_keys = 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'
- messagebox_model = gtk.TextBuffer(None)
- messageboxtext.set_buffer(messagebox_model)
- messagebox_model.insert_at_cursor(_(u'The units list has been written to stdout. You can capture this printout by starting gonvert from the command line as follows: \n$ gonvert > file.txt'), -1)
-
- def top(self, a):
- global testvalue
-
- if evil_globals.calcsuppress == 1:
- #evil_globals.calcsuppress = 0
- return
- # determine if value to be calculated is empty
- if evil_globals.selected_category == "Computer Numbers":
- if self._unitValue.get_text() == '':