_ = gettext.gettext
-def shortlist_changed(a):
+def _on_shortlist_changed(a):
print "shortlist"
if shortlistcheck.get_active():
print "1"
print "0"
-def edit_shortlist(a):
+def _on_edit_shortlist(a):
print "edit shortlist"
if toggleShortList.get_active():
print "1"
print "0"
-def app_size_changed(a, b):
- ''"get current size of window as it changes.''"
- evil_globals.window_size = mainWindow.get_size()
-
-
-def clear_selections(a):
+def _on_user_clear_selections(a):
selectionsDatPath = "/".join((constants._data_path_, "selections.dat"))
os.remove(selectionsDatPath)
evil_globals.selected_units = {}
-def exitprogram(a):
+def _on_user_exit(a):
"""
This routine saves the selections to a file, and
should therefore only be called when exiting the program.
selected, iter = categoryView.get_selection().get_selected()
evil_globals.selected_category = categoryModel.get_value(iter, 0)
- selections = {'evil_globals.selected_category': evil_globals.selected_category, 'evil_globals.selected_units': evil_globals.selected_units}
+ selections = {
+ 'selected_category': evil_globals.selected_category,
+ 'selected_units': evil_globals.selected_units
+ }
selectionsDatPath = "/".join((constants._data_path_, "selections.dat"))
pickle.dump(selections, open(selectionsDatPath, 'w'))
#Get last size of app and save it
- window_settings = {'size': evil_globals.window_size}
+ window_settings = {
+ 'size': mainWindow.get_size()
+ }
windowDatPath = "/".join((constants._data_path_, "window.dat"))
pickle.dump(window_settings, open(windowDatPath, 'w'))
findLabel.set_text('') #clear result
-def find_key_press(a, b):
+def _on_find_key_press(a, b):
#Check if the key pressed was an ASCII key
if len(b.string)>0:
#Check if the key pressed was the 'Enter' key
if ord(b.string[0]) == 13:
#Execute the find units function
- find_units(1)
+ _on_user_find_units(1)
-def about_clicked(a):
+def _on_about_clicked(a):
about_box.show()
-def about_hide(*args):
+def _on_about_hide(*args):
about_box.hide()
return gtk.TRUE
messagebox.hide()
-def find_units(a):
+def _on_user_find_units(a):
global unitNameColumn
global categoryColumn
#check if 'new find' or 'last find' or 'next-find'
unitsView.set_cursor(evil_globals.find_result[evil_globals.find_count][3], unitNameColumn, True)
-def click_unit_column(col):
+def _on_click_unit_column(col):
"""
Sort the contents of the col when the user clicks on the title.
"""
return
-def click_category(row):
+def _on_click_category(row):
global unitModel, categoryModel
- global unit_dic, list_dic
+ global unitDataInCategory, list_dic
#Clear out the previous list of units
unitModel = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
unitValueColumn.set_sort_indicator(False)
unitSymbolColumn.set_sort_indicator(False)
- unit_dic = unit_data.list_dic[selected.get_value(iter, 0)]
- keys = unit_dic.keys()
+ unitDataInCategory = unit_data.list_dic[selected.get_value(iter, 0)]
+ keys = 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 = unitModel.append()
- unitModel.set(iter, 0, key, 1, '', 2, unit_dic[key][1])
+ unitModel.set(iter, 0, key, 1, '', 2, unitDataInCategory[key][1])
unitName.set_text('')
unitValue.set_text('')
def restore_units():
- global unit_dic, list_dic
+ global unitDataInCategory, list_dic
# 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.
unitValue.select_region(0, -1)
-def button_released(row, a):
+def _on_button_released(row, a):
click_unit(row)
-def click_unit(row):
+def _on_click_unit(row):
evil_globals.calcsuppress = 1 #suppress calculations
#Determine the contents of the selected row.
selected_unit = selected.get_value(iter, 0)
- unit_spec = unit_dic[selected_unit]
+ unit_spec = unitDataInCategory[selected_unit]
#Clear out the description
text_model = gtk.TextBuffer(None)
evil_globals.calcsuppress = 0 #enable calculations
-def write_units(a):
+def _on_user_write_units(a):
''"Write the list of categories and units to stdout for documentation purposes.''"
messagebox_model = gtk.TextBuffer(None)
messageboxtext.set_buffer(messagebox_model)
for category_key in category_keys:
total_categories = total_categories + 1
print category_key, ": "
- unit_dic = unit_data.list_dic[category_key]
- unit_keys = unit_dic.keys()
+ 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:
value = float(unitValue.get_text())
if unitName.get_text() != '':
- func, arg = unit_dic[unitName.get_text()][0] #retrieve the conversion function and value from the selected unit
+ func, arg = unitDataInCategory[unitName.get_text()][0] #retrieve the conversion function and value from the selected unit
base = apply(func.to_base, (value, arg, )) #determine the base unit value
- keys = unit_dic.keys()
+ keys = unitDataInCategory.keys()
keys.sort()
del keys[0]
row = 0
while iter:
#get the formula from the name at the row
- func, arg = unit_dic[unitModel.get_value(iter, 0)][0]
+ func, arg = unitDataInCategory[unitModel.get_value(iter, 0)][0]
#set the result in the value column
unitModel.set(iter, 1, str(apply(func.from_base, (base, arg, ))))
# if the second row has a unit then update its value
if previousUnitName.get_text() != '':
evil_globals.calcsuppress = 1
- func, arg = unit_dic[previousUnitName.get_text()][0]
+ func, arg = unitDataInCategory[previousUnitName.get_text()][0]
previousUnitValue.set_text(str(apply(func.from_base, (base, arg, ))))
evil_globals.calcsuppress = 0
value = float(previousUnitValue.get_text())
if previousUnitName.get_text() != '':
- func, arg = unit_dic[previousUnitName.get_text()][0] #retrieve the conversion function and value from the selected unit
+ func, arg = unitDataInCategory[previousUnitName.get_text()][0] #retrieve the conversion function and value from the selected unit
base = apply(func.to_base, (value, arg, )) #determine the base unit value
- keys = unit_dic.keys()
+ keys = unitDataInCategory.keys()
keys.sort()
del keys[0]
row = 0
while iter:
#get the formula from the name at the row
- func, arg = unit_dic[unitModel.get_value(iter, 0)][0]
+ func, arg = unitDataInCategory[unitModel.get_value(iter, 0)][0]
#set the result in the value column
unitModel.set(iter, 1, str(apply(func.from_base, (base, arg, ))))
# if the second row has a unit then update its value
if unitName.get_text() != '':
evil_globals.calcsuppress = 1
- func, arg = unit_dic[unitName.get_text()][0]
+ func, arg = unitDataInCategory[unitName.get_text()][0]
unitValue.set_text(str(apply(func.from_base, (base, arg, ))))
evil_globals.calcsuppress = 0
#--------- connections to GUI ----------------
dic = {
- "on_exitMenuItem_activate": exitprogram,
- "on_mainWindow_destroy": exitprogram,
- "on_categoryView_select_row": click_category,
- "on_unitsView_click_unit_column": click_unit_column,
+ "on_exitMenuItem_activate": _on_user_exit,
+ "on_mainWindow_destroy": _on_user_exit,
+ "on_categoryView_select_row": _on_click_category,
+ "on_unitsView__on_click_unit_column": _on_click_unit_column,
"on_unitValue_changed": calculate.top,
"on_previousUnitValue_changed": calculate.bottom,
- "on_writeUnitsMenuItem_activate": write_units,
- "on_findButton_clicked": find_units,
- "on_findEntry_key_press_event": find_key_press,
+ "on_writeUnitsMenuItem_activate": _on_user_write_units,
+ "on_findButton_clicked": _on_user_find_units,
+ "on_findEntry_key_press_event": _on_find_key_press,
"on_findEntry_changed": findEntry_changed,
- "on_about1_activate": about_clicked,
- "on_about_close_clicked": about_hide,
+ "on_aboutMenuItem_activate": _on_about_clicked,
+ "on_about_close_clicked": _on_about_hide,
"on_messagebox_ok_clicked": messagebox_ok_clicked,
- "on_clearSelectionMenuItem_activate": clear_selections,
- "on_unitsView_cursor_changed": click_unit,
- "on_unitsView_button_released": button_released,
- "on_mainWindow_size_allocate": app_size_changed,
- "on_shortlistcheck_toggled": shortlist_changed,
- "on_toggleShortList_activate": edit_shortlist,
+ "on_clearSelectionMenuItem_activate": _on_user_clear_selections,
+ "on_unitsView_cursor_changed": _on_click_unit,
+ "on_unitsView_button_released": _on_button_released,
+ "on_shortlistcheck_toggled": _on_shortlist_changed,
+ "on_toggleShortList_activate": _on_edit_shortlist,
}
widgets.signal_autoconnect(dic)
- mainWindow.connect("destroy", exitprogram)
+ mainWindow.connect("destroy", _on_user_exit)
def change_menu_label(labelname, newtext):
item_label = widgets.get_widget(labelname).get_children()[0]
unitNameColumn.set_property('resizable', 1)
unitNameColumn.add_attribute(renderer, 'text', 0)
unitNameColumn.set_clickable(True)
- unitNameColumn.connect("clicked", click_unit_column)
+ unitNameColumn.connect("clicked", _on_click_unit_column)
unitsView.append_column(unitNameColumn)
unitValueColumn = gtk.TreeViewColumn(_('Value'), renderer)
unitValueColumn.set_property('resizable', 1)
unitValueColumn.add_attribute(renderer, 'text', 1)
unitValueColumn.set_clickable(True)
- unitValueColumn.connect("clicked", click_unit_column)
+ unitValueColumn.connect("clicked", _on_click_unit_column)
unitsView.append_column(unitValueColumn)
unitSymbolColumn = gtk.TreeViewColumn(_('Units'), renderer)
unitSymbolColumn.set_property('resizable', 1)
unitSymbolColumn.add_attribute(renderer, 'text', 2)
unitSymbolColumn.set_clickable(True)
- unitSymbolColumn.connect("clicked", click_unit_column)
+ unitSymbolColumn.connect("clicked", _on_click_unit_column)
unitsView.append_column(unitSymbolColumn)
#Insert a column into the category list even though the heading will not be seen
categories.sort()
#
#If the 'selected_unts' has been stored, then extract evil_globals.selected_units from selections.
- if 'evil_globals.selected_units' in selections:
- evil_globals.selected_units = selections['evil_globals.selected_units']
+ if 'selected_units' in selections:
+ evil_globals.selected_units = selections['selected_units']
#Make sure that the 'evil_globals.selected_category' has been stored.
- if 'evil_globals.selected_category' in selections:
+ if 'selected_category' in selections:
#Match an available category to the previously selected category.
for counter in range(len(categories)):
- if selections['evil_globals.selected_category'] == categories[counter]:
+ if selections['selected_category'] == categories[counter]:
# Restore the previously selected category.
categoryView.set_cursor(counter, categoryColumn, False)
categoryView.grab_focus()