21 _moduleLogger = logging.getLogger("gonvert_glade")
23 gettext.bindtextdomain('gonvert', '/usr/share/locale')
24 gettext.textdomain('gonvert')
28 def shortlist_changed(a):
30 if shortlistcheck.get_active():
36 def edit_shortlist(a):
37 print "edit shortlist"
38 if toggleShortList.get_active():
44 def app_size_changed(a,b):
45 ''"get current size of window as it changes.''"
46 evil_globals.window_size=mainWindow.get_size()
49 def clear_selections(a):
50 selectionsDatPath = "/".join((constants._data_path_, "selections.dat"))
51 os.remove(selectionsDatPath)
52 evil_globals.selected_units={}
57 This routine saves the selections to a file, and
58 should therefore only be called when exiting the program.
60 Update selections dictionary which consists of the following keys:
61 'evil_globals.selected_category': full name of selected category
62 'evil_globals.selected_units': evil_globals.selected_units dictionary which contains:
63 [categoryname: #1 displayed unit, #2 displayed unit]
65 #Determine the contents of the selected category row
66 selected,iter= categoryView.get_selection().get_selected()
67 evil_globals.selected_category = categoryModel.get_value(iter,0)
69 selections = {'evil_globals.selected_category':evil_globals.selected_category, 'evil_globals.selected_units':evil_globals.selected_units}
70 selectionsDatPath = "/".join((constants._data_path_, "selections.dat"))
71 pickle.dump(selections, open(selectionsDatPath,'w'))
73 #Get last size of app and save it
74 window_settings = {'size':evil_globals.window_size}
75 windowDatPath = "/".join((constants._data_path_, "window.dat"))
76 pickle.dump(window_settings, open(windowDatPath,'w'))
82 def findEntry_changed(a):
83 #Clear out find results since the user wants to look for something new
84 evil_globals.find_result=[] #empty find result list
85 evil_globals.find_count=0 #default to find result number zero
86 findLabel.set_text('') #clear result
89 def find_key_press(a,b):
90 #Check if the key pressed was an ASCII key
92 #Check if the key pressed was the 'Enter' key
93 if ord(b.string[0])==13:
94 #Execute the find units function
102 def about_hide(*args):
107 def messagebox_ok_clicked(a):
112 global unitNameColumn
113 global categoryColumn
114 #check if 'new find' or 'last find' or 'next-find'
116 #new-find = run the find algorithm which also selects the first found unit
117 # = evil_globals.find_count=0 and evil_globals.find_result=[]
119 #last-find = restart from top again
120 # = evil_globals.find_count=len(evil_globals.find_result)
122 #next-find = continue to next found location
123 # = evil_globals.find_count=0 and len(evil_globals.find_result)>0
126 if len(evil_globals.find_result)==0:
127 find_string = string.lower(string.strip(findEntry.get_text()))
128 #Make sure that a valid find string has been requested
129 if len(find_string)>0:
130 categories = unit_data.list_dic.keys()
132 found_a_unit=0 #reset the 'found-a-unit' flag
134 for category in categories:
135 units=unit_data.list_dic[category].keys()
137 del units[0] # do not display .base_unit description key
140 if string.find(string.lower(unit), find_string)>=0:
141 found_a_unit=1 #indicate that a unit was found
142 #print "'",find_string,"'"," found at category=", category," unit =",unit
143 evil_globals.find_result.append((category,unit,cat_no,unit_no))
148 #select the first found unit
149 evil_globals.find_count=0
150 #check if next find is in a new category (prevent category changes when unnecessary
151 if evil_globals.selected_category!=evil_globals.find_result[evil_globals.find_count][0]:
152 categoryView.set_cursor(evil_globals.find_result[0][2],categoryColumn,False)
153 unitsView.set_cursor(evil_globals.find_result[0][3],unitNameColumn,True)
154 if len(evil_globals.find_result)>1:
155 findLabel.set_text(('Press Find for next unit. '+ str(len(evil_globals.find_result))+' result(s).'))
157 findLabel.set_text('Text not found') #Display error
158 else: #must be next-find or last-find
160 if evil_globals.find_count==len(evil_globals.find_result)-1:
162 evil_globals.find_count=0
163 categoryView.set_cursor(evil_globals.find_result[evil_globals.find_count][2],categoryColumn,False)
164 unitsView.set_cursor(evil_globals.find_result[evil_globals.find_count][3],unitNameColumn,True)
165 else: #must be next-find
166 evil_globals.find_count=evil_globals.find_count+1
167 #check if next find is in a new category (prevent category changes when unnecessary
168 if evil_globals.selected_category!=evil_globals.find_result[evil_globals.find_count][0]:
169 categoryView.set_cursor(evil_globals.find_result[evil_globals.find_count][2],categoryColumn,False)
170 unitsView.set_cursor(evil_globals.find_result[evil_globals.find_count][3],unitNameColumn,True)
173 def click_unit_column(col):
175 Sort the contents of the col when the user clicks on the title.
177 global unitNameColumn
178 global unitValueColumn
179 global unitSymbolColumn
182 #Determine which column requires sorting
183 if col is unitNameColumn:
185 unitNameColumn.set_sort_indicator(True)
186 unitValueColumn.set_sort_indicator(False)
187 unitSymbolColumn.set_sort_indicator(False)
188 unitNameColumn.set_sort_order(not evil_globals.unit_sort_direction)
189 elif col is unitValueColumn:
191 unitNameColumn.set_sort_indicator(False)
192 unitValueColumn.set_sort_indicator(True)
193 unitSymbolColumn.set_sort_indicator(False)
194 unitValueColumn.set_sort_order(not evil_globals.value_sort_direction)
195 elif col is unitSymbolColumn:
197 unitNameColumn.set_sort_indicator(False)
198 unitValueColumn.set_sort_indicator(False)
199 unitSymbolColumn.set_sort_indicator(True)
200 unitSymbolColumn.set_sort_order(not evil_globals.units_sort_direction)
202 assert False, "Unknown column: %s" % (col.get_title(), )
204 #declare a spot to hold the sorted list
207 #point to the first row
208 iter=unitModel.get_iter_first()
212 #grab all text from columns for sorting
214 #get the text from each column
215 unit_text = unitModel.get_value(iter,0)
216 units_text = unitModel.get_value(iter,2)
218 #do not bother sorting if the value column is empty
219 if unitModel.get_value(iter,1)=='' and selectedUnitColumn==1:
222 #special sorting exceptions for ascii values (instead of float values)
223 if evil_globals.selected_category == "Computer Numbers":
224 value_text = unitModel.get_value(iter,1)
226 if unitModel.get_value(iter,1)==None or unit_model.get_value(iter,1)=='':
229 value_text = float(unitModel.get_value(iter,1))
231 if selectedUnitColumn==0:
232 sorted_list.append((unit_text,value_text,units_text))
233 elif selectedUnitColumn==1:
234 sorted_list.append((value_text,unit_text,units_text))
236 sorted_list.append((units_text,value_text,unit_text))
238 #point to the next row in the unitModel
239 iter=unitModel.iter_next(iter)
242 #check if no calculations have been made yet (don't bother sorting)
246 if selectedUnitColumn==0:
247 if not evil_globals.unit_sort_direction:
248 sorted_list.sort(lambda (x,xx,xxx), (y,yy,yyy): cmp(string.lower(x),string.lower(y)))
249 evil_globals.unit_sort_direction=True
251 sorted_list.sort(lambda (x,xx,xxx), (y,yy,yyy): cmp(string.lower(y),string.lower(x)))
252 evil_globals.unit_sort_direction=False
253 elif selectedUnitColumn==1:
255 if not evil_globals.value_sort_direction:
256 evil_globals.value_sort_direction=True
258 sorted_list.reverse()
259 evil_globals.value_sort_direction=False
261 if not evil_globals.units_sort_direction:
262 sorted_list.sort(lambda (x,xx,xxx), (y,yy,yyy): cmp(string.lower(x),string.lower(y)))
263 evil_globals.units_sort_direction=True
265 sorted_list.sort(lambda (x,xx,xxx), (y,yy,yyy): cmp(string.lower(y),string.lower(x)))
266 evil_globals.units_sort_direction=False
268 #Clear out the previous list of units
269 unitModel = gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING)
270 unitsView.set_model(unitModel)
272 #colourize each row differently for easier reading
273 unitsView.set_property( 'rules_hint',1)
275 #Clear out the description
276 text_model = gtk.TextBuffer(None)
277 unitDescription.set_buffer(text_model)
279 if selectedUnitColumn==0:
280 for unit,value,units in sorted_list:
281 iter = unitModel.append()
282 unitModel.set(iter,0,unit,1,str(value),2,units)
283 elif selectedUnitColumn==1:
284 for value,unit,units in sorted_list:
285 iter = unitModel.append()
286 unitModel.set(iter,0,unit,1,str(value),2,units)
288 for units,value,unit in sorted_list:
289 iter = unitModel.append()
290 unitModel.set(iter,0,unit,1,str(value),2,units)
294 def click_category(row):
295 global unitModel, categoryModel
296 global unit_dic, list_dic
298 #Clear out the previous list of units
299 unitModel = gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING)
300 unitsView.set_model(unitModel)
302 #Colourize each row alternately for easier reading
303 unitsView.set_property( 'rules_hint',1)
305 #Clear out the description
306 text_model = gtk.TextBuffer(None)
307 unitDescription.set_buffer(text_model)
309 #Determine the contents of the selected category row
310 selected,iter= row.get_selection().get_selected()
312 evil_globals.selected_category = categoryModel.get_value(iter,0)
314 evil_globals.unit_sort_direction = False
315 evil_globals.value_sort_direction = False
316 evil_globals.units_sort_direction = False
317 unitNameColumn.set_sort_indicator(False)
318 unitValueColumn.set_sort_indicator(False)
319 unitSymbolColumn.set_sort_indicator(False)
321 unit_dic=unit_data.list_dic[selected.get_value(iter,0)]
322 keys = unit_dic.keys()
324 del keys[0] # do not display .base_unit description key
326 #Fill up the units descriptions and clear the value cells
328 iter = unitModel.append()
329 unitModel.set(iter,0,key,1,'',2,unit_dic[key][1])
331 unitName.set_text('')
332 unitValue.set_text('')
333 previousUnitName.set_text('')
334 previousUnitValue.set_text('')
335 unitSymbol.set_text('')
336 previousUnitSymbol.set_text('')
342 global unit_dic, list_dic
344 # Restore the previous historical settings of previously selected units in this newly selected category
345 #Since category has just been clicked, the list will be sorted already.
346 if evil_globals.selected_units.has_key(evil_globals.selected_category):
347 if evil_globals.selected_units[evil_globals.selected_category][0]:
349 #evil_globals.selected_units[evil_globals.selected_category]=[selected_unit,evil_globals.selected_units[evil_globals.selected_category][0]]
351 units=unit_data.list_dic[evil_globals.selected_category].keys()
353 del units[0] # do not display .base_unit description key
355 #Restore oldest selection first.
356 if evil_globals.selected_units[evil_globals.selected_category][1]:
359 if unit==evil_globals.selected_units[evil_globals.selected_category][1]:
360 unitsView.set_cursor(unit_no,unitNameColumn,True)
363 #Restore newest selection second.
366 if unit==evil_globals.selected_units[evil_globals.selected_category][0]:
367 unitsView.set_cursor(unit_no,unitNameColumn,True)
370 # select the text so user can start typing right away
371 unitValue.grab_focus()
372 unitValue.select_region(0,-1)
375 def button_released(row,a):
380 evil_globals.calcsuppress = 1 #suppress calculations
382 #Determine the contents of the selected row.
383 selected,iter= unitsView.get_selection().get_selected()
385 selected_unit=selected.get_value(iter,0)
387 unit_spec=unit_dic[selected_unit]
389 #Clear out the description
390 text_model = gtk.TextBuffer(None)
391 unitDescription.set_buffer(text_model)
393 enditer = text_model.get_end_iter()
394 text_model.insert(enditer,unit_spec[2])
396 if unitName.get_text() != selected_unit:
397 previousUnitName.set_text(unitName.get_text())
398 previousUnitValue.set_text(unitValue.get_text())
399 if unitSymbol.get() == None:
400 previousUnitSymbol.set_text('')
402 previousUnitSymbol.set_text(unitSymbol.get())
403 unitName.set_text(selected_unit)
405 unitValue.set_text(selected.get_value(iter,1))
407 unitSymbol.set_text(unit_spec[1]) # put units into label text
408 if unitValue.get_text() =='':
409 if evil_globals.selected_category == "Computer Numbers":
410 unitValue.set_text("0")
412 unitValue.set_text("0.0")
414 #For historical purposes, record this unit as the most recent one in this category.
415 # Also, if a previous unit exists, then shift that previous unit to oldest unit.
416 if evil_globals.selected_units.has_key(evil_globals.selected_category):
417 if evil_globals.selected_units[evil_globals.selected_category][0]:
418 evil_globals.selected_units[evil_globals.selected_category]=[selected_unit,evil_globals.selected_units[evil_globals.selected_category][0]]
420 evil_globals.selected_units[evil_globals.selected_category]=[selected_unit,'']
422 # select the text so user can start typing right away
423 unitValue.grab_focus()
424 unitValue.select_region(0,-1)
426 evil_globals.calcsuppress = 0 #enable calculations
430 ''"Write the list of categories and units to stdout for documentation purposes.''"
431 messagebox_model = gtk.TextBuffer(None)
432 messageboxtext.set_buffer(messagebox_model)
433 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)
435 while gtk.events_pending():
436 gtk.mainiteration (False)
437 category_keys=unit_data.list_dic.keys()
441 print 'gonvert-%s%s' % (
442 constants.__version__,
443 _(u' - Unit Conversion Utility - Convertible units listing:')
445 for category_key in category_keys:
446 total_categories = total_categories + 1
447 print category_key,":"
448 unit_dic=unit_data.list_dic[category_key]
449 unit_keys = unit_dic.keys()
451 del unit_keys[0] # do not display .base_unit description key
452 for unit_key in unit_keys:
453 total_units = total_units + 1
455 print total_categories,' categories'
456 print total_units,' units'
457 messagebox_model = gtk.TextBuffer(None)
458 messageboxtext.set_buffer(messagebox_model)
459 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)
462 class Ccalculate(object):
468 if evil_globals.calcsuppress == 1:
469 #evil_globals.calcsuppress = 0
471 # determine if value to be calculated is empty
472 if evil_globals.selected_category == "Computer Numbers":
473 if unitValue.get_text() =='':
476 value = unitValue.get_text()
478 if unitValue.get_text() =='':
481 value = float(unitValue.get_text())
483 if unitName.get_text() != '':
484 func,arg = unit_dic[unitName.get_text()][0] #retrieve the conversion function and value from the selected unit
485 base = apply(func.to_base,(value,arg,)) #determine the base unit value
487 keys = unit_dic.keys()
492 #point to the first row
493 iter=unitModel.get_iter_first()
496 #get the formula from the name at the row
497 func,arg = unit_dic[unitModel.get_value(iter,0)][0]
499 #set the result in the value column
500 unitModel.set(iter,1,str(apply(func.from_base,(base,arg,))))
502 #point to the next row in the unitModel
503 iter=unitModel.iter_next(iter)
505 # if the second row has a unit then update its value
506 if previousUnitName.get_text() != '':
507 evil_globals.calcsuppress=1
508 func,arg = unit_dic[previousUnitName.get_text()][0]
509 previousUnitValue.set_text(str(apply(func.from_base,(base,arg,))))
510 evil_globals.calcsuppress=0
513 if evil_globals.calcsuppress == 1:
514 #evil_globals.calcsuppress = 0
516 # determine if value to be calculated is empty
517 if evil_globals.selected_category == "Computer Numbers":
518 if previousUnitValue.get_text() =='':
521 value = previousUnitValue.get_text()
523 if previousUnitValue.get_text() =='':
526 value = float(previousUnitValue.get_text())
528 if previousUnitName.get_text() != '':
529 func,arg = unit_dic[previousUnitName.get_text()][0] #retrieve the conversion function and value from the selected unit
530 base = apply(func.to_base,(value,arg,)) #determine the base unit value
532 keys = unit_dic.keys()
537 #point to the first row
538 iter=unitModel.get_iter_first()
541 #get the formula from the name at the row
542 func,arg = unit_dic[unitModel.get_value(iter,0)][0]
544 #set the result in the value column
545 unitModel.set(iter,1,str(apply(func.from_base,(base,arg,))))
547 #point to the next row in the unitModel
548 iter=unitModel.iter_next(iter)
550 # if the second row has a unit then update its value
551 if unitName.get_text() != '':
552 evil_globals.calcsuppress=1
553 func,arg = unit_dic[unitName.get_text()][0]
554 unitValue.set_text(str(apply(func.from_base,(base,arg,))))
555 evil_globals.calcsuppress=0
558 # categoryView is categoryView
559 # unitConversionLayout
560 # selectedUnitLayouta
564 # previousSelectedUnitLayout
568 # unitsAndDescriptionPane
569 # unitListScrolledWindow
571 # unitDescriptionScrolledWindow
573 # searchLayout is the search box
583 global shortlistcheck
585 global unitDescription
586 global unitNameColumn
587 global unitValueColumn
588 global unitSymbolColumn
589 global previousUnitName
590 global previousUnitValue
591 global previousUnitSymbol
594 global categoryColumn
595 global toggleShortList
597 logging.basicConfig(level=logging.DEBUG)
600 os.makedirs(constants._data_path_)
605 #check to see if glade file is in current directory (user must be running from download untar directory)
607 os.path.join(os.path.dirname(__file__), "gonvert.glade"),
608 os.path.join(os.path.dirname(__file__), "../data/gonvert.glade"),
609 os.path.join(os.path.dirname(__file__), "../lib/gonvert.glade"),
610 '/usr/lib/gonvert/gonvert.glade',
612 for gladePath in _glade_files:
613 if os.path.isfile(gladePath):
614 homepath = os.path.dirname(gladePath)
615 pixmapspath = "/".join((homepath, "pixmaps"))
616 widgets = gtk.glade.XML(gladePath)
621 calculate = Ccalculate()
622 mainWindow = widgets.get_widget('mainWindow')
624 #Restore window size from previously saved settings if it exists and is valid.
625 windowDatPath = "/".join((constants._data_path_, "window.dat"))
626 if os.path.exists(windowDatPath):
627 #Retrieving previous window settings from ~/.gonvert/window.dat
628 saved_window = pickle.load(open(windowDatPath, "r"))
629 #If the 'size' has been stored, then extract size from saved_window.
630 if saved_window.has_key('size'):
631 a, b = saved_window['size']
632 mainWindow.resize(a, b)
634 #Maximize if no previous size was found
635 #mainWindow.maximize()
638 #Maximize if no previous window.dat file was found
639 #mainWindow.maximize()
642 mainWindow.set_title('gonvert- %s - Unit Conversion Utility' % constants.__version__);
643 iconPath = pixmapspath + '/gonvert.png'
644 if os.path.exists(iconPath):
645 mainWindow.set_icon(gtk.gdk.pixbuf_new_from_file(iconPath))
647 _moduleLogger.warn("Error: Could not find gonvert icon: %s" % iconPath)
649 #--------- connections to GUI ----------------
651 "on_exitMenuItem_activate": exitprogram,
652 "on_mainWindow_destroy": exitprogram,
653 "on_categoryView_select_row": click_category,
654 "on_unitsView_click_unit_column": click_unit_column,
655 "on_unitValue_changed": calculate.top,
656 "on_previousUnitValue_changed": calculate.bottom,
657 "on_writeUnitsMenuItem_activate": write_units,
658 "on_findButton_clicked": find_units,
659 "on_findEntry_key_press_event": find_key_press,
660 "on_findEntry_changed": findEntry_changed,
661 "on_about1_activate": about_clicked,
662 "on_about_close_clicked": about_hide,
663 "on_messagebox_ok_clicked": messagebox_ok_clicked,
664 "on_clearSelectionMenuItem_activate": clear_selections,
665 "on_unitsView_cursor_changed": click_unit,
666 "on_unitsView_button_released": button_released,
667 "on_mainWindow_size_allocate": app_size_changed,
668 "on_shortlistcheck_toggled": shortlist_changed,
669 "on_toggleShortList_activate": edit_shortlist,
672 widgets.signal_autoconnect (dic);
673 mainWindow.connect("destroy", exitprogram)
675 def change_menu_label(labelname,newtext):
676 item_label = widgets.get_widget(labelname).get_children()[0]
677 item_label.set_text(newtext)
678 def change_label(labelname,newtext):
679 item_label = widgets.get_widget(labelname)
680 item_label.set_text(newtext)
682 change_menu_label('fileMenuItem',_('File'))
683 change_menu_label('exitMenuItem',_('Exit'))
684 change_menu_label('toolsMenuItem',_('Tools'))
685 change_menu_label('clearSelectionMenuItem',_('Clear selections'))
686 change_menu_label('writeUnitsMenuItem',_('Write Units'))
687 change_menu_label('helpMenuItem',_('Help'))
688 change_menu_label('aboutMenuItem',_('About'))
690 change_menu_label('findButton',_('Find'))
692 shortlistcheck = widgets.get_widget('shortlistcheck')
693 toggleShortList = widgets.get_widget('toggleShortList')
695 categoryView = widgets.get_widget('categoryView' )
697 unitsView = widgets.get_widget('unitsView')
698 unitsView_selection=unitsView.get_selection()
700 unitName = widgets.get_widget('unitName')
701 unitValue = widgets.get_widget('unitValue')
702 previousUnitName = widgets.get_widget('previousUnitName')
703 previousUnitValue = widgets.get_widget('previousUnitValue')
704 about_box = widgets.get_widget('about_box')
705 messagebox = widgets.get_widget('msgbox')
706 messageboxtext = widgets.get_widget('msgboxtext')
708 about_image = widgets.get_widget('about_image')
709 about_image.set_from_file(pixmapspath +'gonvert.png')
710 versionlabel = widgets.get_widget('versionlabel')
711 versionlabel.set_text(constants.__version__)
713 unitSymbol =widgets.get_widget('unitSymbol')
714 previousUnitSymbol =widgets.get_widget('previousUnitSymbol')
716 unitDescription = widgets.get_widget('unitDescription' )
718 findEntry = widgets.get_widget('findEntry')
719 findLabel = widgets.get_widget('findLabel')
721 #insert a categoryColumnumn into the units list even though the heading will not be seen
722 renderer = gtk.CellRendererText()
723 unitNameColumn = gtk.TreeViewColumn( _('Unit Name'), renderer )
724 unitNameColumn.set_property( 'resizable', 1 )
725 unitNameColumn.add_attribute( renderer, 'text', 0 )
726 unitNameColumn.set_clickable(True)
727 unitNameColumn.connect("clicked",click_unit_column)
728 unitsView.append_column( unitNameColumn )
730 unitValueColumn = gtk.TreeViewColumn( _('Value'), renderer )
731 unitValueColumn.set_property( 'resizable', 1 )
732 unitValueColumn.add_attribute( renderer, 'text', 1 )
733 unitValueColumn.set_clickable(True)
734 unitValueColumn.connect("clicked",click_unit_column)
735 unitsView.append_column( unitValueColumn )
737 unitSymbolColumn = gtk.TreeViewColumn( _('Units'), renderer )
738 unitSymbolColumn.set_property( 'resizable', 1 )
739 unitSymbolColumn.add_attribute( renderer, 'text', 2 )
740 unitSymbolColumn.set_clickable(True)
741 unitSymbolColumn.connect("clicked",click_unit_column)
742 unitsView.append_column( unitSymbolColumn )
744 #Insert a column into the category list even though the heading will not be seen
745 renderer = gtk.CellRendererText()
746 categoryColumn = gtk.TreeViewColumn( 'Title', renderer )
747 categoryColumn.set_property( 'resizable', 1 )
748 categoryColumn.add_attribute( renderer, 'text', 0 )
749 categoryView.append_column( categoryColumn )
751 categoryModel = gtk.ListStore(gobject.TYPE_STRING)
752 categoryView.set_model(categoryModel)
753 #colourize each row differently for easier reading
754 categoryView.set_property( 'rules_hint',1)
756 #Populate the catagories list
757 keys = unit_data.list_dic.keys()
760 iter = categoryModel.append()
761 categoryModel.set(iter,0,key)
763 ToolTips=gtk.Tooltips()
764 findButton = widgets.get_widget('findButton')
765 ToolTips.set_tip(findButton,_(u'Find unit (F6)'))
767 #Restore selections from previously saved settings if it exists and is valid.
768 historical_catergory_found=False
769 selectionsDatPath = "/".join((constants._data_path_, "selections.dat"))
770 if os.path.exists(selectionsDatPath):
771 #Retrieving previous selections from ~/.gonvert/selections.dat
772 selections=pickle.load(open(selectionsDatPath,'r'))
773 #Restoring previous selections.
775 #Make a list of categories to determine which one to select
776 categories=unit_data.list_dic.keys()
779 #If the 'selected_unts' has been stored, then extract evil_globals.selected_units from selections.
780 if selections.has_key('evil_globals.selected_units'):
781 evil_globals.selected_units=selections['evil_globals.selected_units']
782 #Make sure that the 'evil_globals.selected_category' has been stored.
783 if selections.has_key('evil_globals.selected_category'):
784 #Match an available category to the previously selected category.
785 for counter in range(len(categories)):
786 if selections['evil_globals.selected_category']==categories[counter]:
787 # Restore the previously selected category.
788 categoryView.set_cursor(counter, categoryColumn, False )
789 categoryView.grab_focus()
790 historical_catergory_found=True
792 if not historical_catergory_found:
793 print "Couldn't find saved category, using default."
794 #If historical records were not kept then default to
795 # put the focus on the first category
796 categoryView.set_cursor(0, categoryColumn, False)
797 categoryView.grab_focus()
804 if __name__ == "__main__":