- gtk.mainquit
- sys.exit()
-
- def _findEntry_changed(self, a):
- #Clear out find results since the user wants to look for something new
- evil_globals.find_result = [] #empty find result list
- evil_globals.find_count = 0 #default to find result number zero
- self._findLabel.set_text('') #clear result
-
- def _on_find_key_press(self, 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
- _on_user_find_units(1)
-
- def _on_about_clicked(self, a):
- self._about_box.show()
-
- def _on_about_hide(self, *args):
- self._about_box.hide()
- return gtk.TRUE
-
- def messagebox_ok_clicked(self, a):
- messagebox.hide()
-
- def _on_user_find_units(self, a):
- #check if 'new find' or 'last find' or 'next-find'
-
- #new-find = run the find algorithm which also selects the first found unit
- # = evil_globals.find_count = 0 and evil_globals.find_result = []
-
- #last-find = restart from top again
- # = evil_globals.find_count = len(evil_globals.find_result)
-
- #next-find = continue to next found location
- # = evil_globals.find_count = 0 and len(evil_globals.find_result)>0
-
- #check for new-find
- if len(evil_globals.find_result) == 0:
- find_string = string.lower(string.strip(self._findEntry.get_text()))
- #Make sure that a valid find string has been requested
- if len(find_string)>0:
- categories = unit_data.list_dic.keys()
- categories.sort()
- found_a_unit = 0 #reset the 'found-a-unit' flag
- cat_no = 0
- for category in categories:
- units = unit_data.list_dic[category].keys()
- units.sort()
- del units[0] # do not display .base_unit description key
- unit_no = 0
- for unit in units:
- if string.find(string.lower(unit), find_string) >= 0:
- found_a_unit = 1 #indicate that a unit was found
- #print "'", find_string, "'", " found at category = ", category, " unit = ", unit
- evil_globals.find_result.append((category, unit, cat_no, unit_no))
- unit_no = unit_no+1
- cat_no = cat_no+1
-
- if found_a_unit == 1:
- #select the first found unit
- evil_globals.find_count = 0
- #check if next find is in a new category (prevent category changes when unnecessary
- if evil_globals.selected_category != evil_globals.find_result[evil_globals.find_count][0]:
- self._categoryView.set_cursor(evil_globals.find_result[0][2], self._categoryColumn, False)
- self._unitsView.set_cursor(evil_globals.find_result[0][3], self._unitNameColumn, True)
- if len(evil_globals.find_result)>1:
- self._findLabel.set_text(('Press Find for next unit. '+ str(len(evil_globals.find_result))+' result(s).'))
- else:
- self._findLabel.set_text('Text not found') #Display error
- else: #must be next-find or last-find
- #check for last-find
- if evil_globals.find_count == len(evil_globals.find_result)-1:
- #select first result
- evil_globals.find_count = 0
- self._categoryView.set_cursor(evil_globals.find_result[evil_globals.find_count][2], self._categoryColumn, False)
- self._unitsView.set_cursor(evil_globals.find_result[evil_globals.find_count][3], self._unitNameColumn, True)
- else: #must be next-find
- evil_globals.find_count = evil_globals.find_count+1
- #check if next find is in a new category (prevent category changes when unnecessary
- if evil_globals.selected_category != evil_globals.find_result[evil_globals.find_count][0]:
- self._categoryView.set_cursor(evil_globals.find_result[evil_globals.find_count][2], self._categoryColumn, False)
- self._unitsView.set_cursor(evil_globals.find_result[evil_globals.find_count][3], self._unitNameColumn, True)
-
- 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 evil_globals.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 evil_globals.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 evil_globals.units_sort_direction)
- else:
- assert False, "Unknown column: %s" % (col.get_title(), )
-
- #declare a spot to hold the sorted list
- sorted_list = []