- #check to see if glade file is in current directory (user must be running from download untar directory)
- _glade_files = [
- os.path.join(os.path.dirname(__file__), "gonvert.glade"),
- os.path.join(os.path.dirname(__file__), "../data/gonvert.glade"),
- os.path.join(os.path.dirname(__file__), "../lib/gonvert.glade"),
- '/usr/lib/gonvert/gonvert.glade',
- ]
- for gladePath in _glade_files:
- if os.path.isfile(gladePath):
- homepath = os.path.dirname(gladePath)
- pixmapspath = "/".join((homepath, "pixmaps"))
- widgets = gtk.glade.XML(gladePath)
- break
- else:
- return
-
- calculate = Ccalculate()
- mainWindow = widgets.get_widget('mainWindow')
-
- #Restore window size from previously saved settings if it exists and is valid.
- windowDatPath = "/".join((constants._data_path_, "window.dat"))
- if os.path.exists(windowDatPath):
- #Retrieving previous window settings from ~/.gonvert/window.dat
- saved_window = pickle.load(open(windowDatPath, "r"))
- #If the 'size' has been stored, then extract size from saved_window.
- if saved_window.has_key('size'):
- a, b = saved_window['size']
- mainWindow.resize(a, b)
- else:
- #Maximize if no previous size was found
- #mainWindow.maximize()
- pass
- else:
- #Maximize if no previous window.dat file was found
- #mainWindow.maximize()
- pass
-
- mainWindow.set_title('gonvert- %s - Unit Conversion Utility' % constants.__version__);
- iconPath = pixmapspath + '/gonvert.png'
- if os.path.exists(iconPath):
- mainWindow.set_icon(gtk.gdk.pixbuf_new_from_file(iconPath))
- else:
- _moduleLogger.warn("Error: Could not find gonvert icon: %s" % iconPath)
-
- #--------- connections to GUI ----------------
- dic = {
- "on_exitMenuItem_activate": exitprogram,
- "on_mainWindow_destroy": exitprogram,
- "on_cat_clist_select_row": click_category,
- "on_unitsView_click_column": click_column,
- "on_unitValue_changed": calculate.top,
- "on_previousUnitValue_changed": calculate.bottom,
- "on_write_units1_activate": write_units,
- "on_find_button_clicked": find_units,
- "on_find_entry_key_press_event": find_key_press,
- "on_find_entry_changed": find_entry_changed,
- "on_about1_activate": about_clicked,
- "on_about_close_clicked": about_hide,
- "on_messagebox_ok_clicked": messagebox_ok_clicked,
- "on_clear_selections1_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_edit_shortlist1_activate": edit_shortlist,
- }
-
- widgets.signal_autoconnect (dic);
- mainWindow.connect("destroy", exitprogram)
-
- def change_menu_label(labelname,newtext):
- item_label = widgets.get_widget(labelname).get_children()[0]
- item_label.set_text(newtext)
- def change_label(labelname,newtext):
- item_label = widgets.get_widget(labelname)
- item_label.set_text(newtext)
-
- change_menu_label('fileMenuItem',_('File'))
- change_menu_label('exitMenuItem',_('Exit'))
- change_menu_label('toolsMenuItem',_('Tools'))
- change_menu_label('clear_selections1',_('Clear selections'))
- change_menu_label('write_units1',_('Write Units'))
- change_menu_label('helpMenuItem',_('Help'))
- change_menu_label('aboutMenuItem',_('About'))
-
- change_menu_label('find_button',_('Find'))
-
- shortlistcheck = widgets.get_widget('shortlistcheck')
- edit_shortlist1 = widgets.get_widget('edit_shortlist1')
-
- cat_clist = widgets.get_widget('cat_clist' )
-
- unitsView = widgets.get_widget('unitsView')
- unitsView_selection=unitsView.get_selection()
-
- unitName = widgets.get_widget('unitName')
- unitValue = widgets.get_widget('unitValue')
- previousUnitName = widgets.get_widget('previousUnitName')
- previousUnitValue = widgets.get_widget('previousUnitValue')
- about_box = widgets.get_widget('about_box')
- messagebox = widgets.get_widget('msgbox')
- messageboxtext = widgets.get_widget('msgboxtext')
-
- about_image = widgets.get_widget('about_image')
- about_image.set_from_file(pixmapspath +'gonvert.png')
- versionlabel = widgets.get_widget('versionlabel')
- versionlabel.set_text(constants.__version__)
-
- unitSymbol =widgets.get_widget('unitSymbol')
- previousUnitSymbol =widgets.get_widget('previousUnitSymbol')
-
- unitDescription = widgets.get_widget('unitDescription' )
-
- find_entry = widgets.get_widget('find_entry')
- find_label = widgets.get_widget('find_label')
-
- #insert a column into the units list even though the heading will not be seen
- renderer = gtk.CellRendererText()
- column1 = gtk.TreeViewColumn( _('Unit Name'), renderer )
- column1.set_property( 'resizable', 1 )
- column1.add_attribute( renderer, 'text', 0 )
- column1.set_clickable(True)
- column1.connect("clicked",click_column)
- unitsView.append_column( column1 )
-
- column2 = gtk.TreeViewColumn( _('Value'), renderer )
- column2.set_property( 'resizable', 1 )
- column2.add_attribute( renderer, 'text', 1 )
- column2.set_clickable(True)
- column2.connect("clicked",click_column)
- unitsView.append_column( column2 )
-
- column3 = gtk.TreeViewColumn( _('Units'), renderer )
- column3.set_property( 'resizable', 1 )
- column3.add_attribute( renderer, 'text', 2 )
- column3.set_clickable(True)
- column3.connect("clicked",click_column)
- unitsView.append_column( column3 )
-
- #Insert a column into the category list even though the heading will not be seen
- renderer = gtk.CellRendererText()
- col = gtk.TreeViewColumn( 'Title', renderer )
- col.set_property( 'resizable', 1 )
- col.add_attribute( renderer, 'text', 0 )
- cat_clist.append_column( col )
-
- cat_model = gtk.ListStore(gobject.TYPE_STRING)
- cat_clist.set_model(cat_model)
- #colourize each row differently for easier reading
- cat_clist.set_property( 'rules_hint',1)
-
- #Populate the catagories list
- keys = unit_data.list_dic.keys()
- keys.sort()
- for key in keys:
- iter = cat_model.append()
- cat_model.set(iter,0,key)
-
- ToolTips=gtk.Tooltips()
- find_button = widgets.get_widget('find_button')
- ToolTips.set_tip(find_button,_(u'Find unit (F6)'))
-
- #Restore selections from previously saved settings if it exists and is valid.
- historical_catergory_found=False
- selectionsDatPath = "/".join((constants._data_path_, "selections.dat"))
- if os.path.exists(selectionsDatPath):
- #Retrieving previous selections from ~/.gonvert/selections.dat
- selections=pickle.load(open(selectionsDatPath,'r'))
- #Restoring previous selections.
- #
- #Make a list of categories to determine which one to select
- categories=unit_data.list_dic.keys()
- categories.sort()
- #
- #If the 'selected_unts' has been stored, then extract evil_globals.selected_units from selections.
- if selections.has_key('evil_globals.selected_units'):
- evil_globals.selected_units=selections['evil_globals.selected_units']
- #Make sure that the 'evil_globals.selected_category' has been stored.
- if selections.has_key('evil_globals.selected_category'):
- #Match an available category to the previously selected category.
- for counter in range(len(categories)):
- if selections['evil_globals.selected_category']==categories[counter]:
- # Restore the previously selected category.
- cat_clist.set_cursor(counter, col, False )
- cat_clist.grab_focus()
- historical_catergory_found=True
-
- if not historical_catergory_found:
- print "Couldn't find saved category, using default."
- #If historical records were not kept then default to
- # put the focus on the first category
- cat_clist.set_cursor(0, col, False)
- cat_clist.grab_focus()
-
- restore_units()
-
- gtk.main()
-
-
-if __name__ == "__main__":
- main()