20 _moduleLogger = logging.getLogger("gonvert_glade")
22 gettext.bindtextdomain('gonvert', '/usr/share/locale')
23 gettext.textdomain('gonvert')
27 def change_menu_label(widgets, labelname, newtext):
28 item_label = widgets.get_widget(labelname).get_children()[0]
29 item_label.set_text(newtext)
32 class Gonvert(object):
35 os.path.join(os.path.dirname(__file__), "gonvert.glade"),
36 os.path.join(os.path.dirname(__file__), "../data/gonvert.glade"),
37 os.path.join(os.path.dirname(__file__), "../lib/gonvert.glade"),
38 '/usr/lib/gonvert/gonvert.glade',
42 self._unitDataInCategory = None
43 self._calcsuppress = False
44 self._unit_sort_direction = False
45 self._value_sort_direction = False
46 self._units_sort_direction = False
48 self._find_result = [] # empty find result list
49 self._find_count = 0 # default to find result number zero
51 self._selected_category = '' # preset to no selected category
52 self._selected_units = {} # empty dictionary for later use
54 #check to see if glade file is in current directory (user must be
55 # running from download untar directory)
56 for gladePath in self._glade_files:
57 if os.path.isfile(gladePath):
58 homepath = os.path.dirname(gladePath)
59 pixmapspath = "/".join((homepath, "pixmaps"))
60 widgets = gtk.glade.XML(gladePath)
65 self._mainWindow = widgets.get_widget('mainWindow')
67 change_menu_label(widgets, 'fileMenuItem', _('File'))
68 change_menu_label(widgets, 'exitMenuItem', _('Exit'))
69 change_menu_label(widgets, 'toolsMenuItem', _('Tools'))
70 change_menu_label(widgets, 'clearSelectionMenuItem', _('Clear selections'))
71 change_menu_label(widgets, 'writeUnitsMenuItem', _('Write Units'))
72 change_menu_label(widgets, 'helpMenuItem', _('Help'))
73 change_menu_label(widgets, 'aboutMenuItem', _('About'))
74 change_menu_label(widgets, 'findButton', _('Find'))
76 self._shortlistcheck = widgets.get_widget('shortlistcheck')
77 self._toggleShortList = widgets.get_widget('toggleShortList')
79 self._categoryView = widgets.get_widget('categoryView')
81 self._unitsView = widgets.get_widget('unitsView')
82 self._unitsView_selection = self._unitsView.get_selection()
84 self._unitName = widgets.get_widget('unitName')
85 self._unitValue = widgets.get_widget('unitValue')
86 self._previousUnitName = widgets.get_widget('previousUnitName')
87 self._previousUnitValue = widgets.get_widget('previousUnitValue')
88 self._about_box = widgets.get_widget('about_box')
89 messagebox = widgets.get_widget('msgbox')
90 messageboxtext = widgets.get_widget('msgboxtext')
92 about_image = widgets.get_widget('about_image')
93 about_image.set_from_file(pixmapspath +'gonvert.png')
94 versionlabel = widgets.get_widget('versionlabel')
95 versionlabel.set_text(constants.__version__)
97 self._unitSymbol = widgets.get_widget('unitSymbol')
98 self._previousUnitSymbol = widgets.get_widget('previousUnitSymbol')
100 self._unitDescription = widgets.get_widget('unitDescription')
102 self._findEntry = widgets.get_widget('findEntry')
103 self._findLabel = widgets.get_widget('findLabel')
104 findButton = widgets.get_widget('findButton')
106 #insert a self._categoryColumnumn into the units list even though the heading will not be seen
107 renderer = gtk.CellRendererText()
108 self._unitNameColumn = gtk.TreeViewColumn(_('Unit Name'), renderer)
109 self._unitNameColumn.set_property('resizable', 1)
110 self._unitNameColumn.add_attribute(renderer, 'text', 0)
111 self._unitNameColumn.set_clickable(True)
112 self._unitNameColumn.connect("clicked", self._on_click_unit_column)
113 self._unitsView.append_column(self._unitNameColumn)
115 self._unitValueColumn = gtk.TreeViewColumn(_('Value'), renderer)
116 self._unitValueColumn.set_property('resizable', 1)
117 self._unitValueColumn.add_attribute(renderer, 'text', 1)
118 self._unitValueColumn.set_clickable(True)
119 self._unitValueColumn.connect("clicked", self._on_click_unit_column)
120 self._unitsView.append_column(self._unitValueColumn)
122 self._unitSymbolColumn = gtk.TreeViewColumn(_('Units'), renderer)
123 self._unitSymbolColumn.set_property('resizable', 1)
124 self._unitSymbolColumn.add_attribute(renderer, 'text', 2)
125 self._unitSymbolColumn.set_clickable(True)
126 self._unitSymbolColumn.connect("clicked", self._on_click_unit_column)
127 self._unitsView.append_column(self._unitSymbolColumn)
129 #Insert a column into the category list even though the heading will not be seen
130 renderer = gtk.CellRendererText()
131 self._categoryColumn = gtk.TreeViewColumn('Title', renderer)
132 self._categoryColumn.set_property('resizable', 1)
133 self._categoryColumn.add_attribute(renderer, 'text', 0)
134 self._categoryView.append_column(self._categoryColumn)
136 self._categoryModel = gtk.ListStore(gobject.TYPE_STRING)
137 self._categoryView.set_model(self._categoryModel)
138 #colourize each row differently for easier reading
139 self._categoryView.set_property('rules_hint', 1)
141 #Populate the catagories list
142 keys = unit_data.list_dic.keys()
145 iter = self._categoryModel.append()
146 self._categoryModel.set(iter, 0, key)
148 ToolTips = gtk.Tooltips()
149 ToolTips.set_tip(findButton, _(u'Find unit (F6)'))
151 #--------- connections to GUI ----------------
153 "on_exit_menu_activate": self._on_user_exit,
154 "on_main_window_destroy": self._on_user_exit,
155 "on_categoryView_select_row": self._on_click_category,
156 "on_unitsView__on_click_unit_column": self._on_click_unit_column,
157 "on_unitValue_changed": self.top,
158 "on_previousUnitValue_changed": self.bottom,
159 "on_writeUnitsMenuItem_activate": self._on_user_write_units,
160 "on_findButton_clicked": self._on_user_find_units,
161 "on_findEntry_key_press_event": self._on_find_key_press,
162 "on_findEntry_changed": self._findEntry_changed,
163 "on_aboutMenuItem_activate": self._on_about_clicked,
164 "on_about_close_clicked": self._on_about_hide,
165 "on_messagebox_ok_clicked": self.messagebox_ok_clicked,
166 "on_clearSelectionMenuItem_activate": self._on_user_clear_selections,
167 "on_unitsView_cursor_changed": self._on_click_unit,
168 "on_unitsView_button_released": self._on_button_released,
169 "on_shortlistcheck_toggled": self._on_shortlist_changed,
170 "on_toggleShortList_activate": self._on_edit_shortlist,
172 widgets.signal_autoconnect(dic)
174 self._mainWindow.set_title('gonvert- %s - Unit Conversion Utility' % constants.__version__)
175 iconPath = pixmapspath + '/gonvert.png'
176 if os.path.exists(iconPath):
177 self._mainWindow.set_icon(gtk.gdk.pixbuf_new_from_file(iconPath))
179 _moduleLogger.warn("Error: Could not find gonvert icon: %s" % iconPath)
181 #Restore window size from previously saved settings if it exists and is valid.
182 windowDatPath = "/".join((constants._data_path_, "window.dat"))
183 if os.path.exists(windowDatPath):
184 #Retrieving previous window settings from ~/.gonvert/window.dat
185 saved_window = pickle.load(open(windowDatPath, "r"))
186 #If the 'size' has been stored, then extract size from saved_window.
187 if 'size' in saved_window:
188 a, b = saved_window['size']
189 self._mainWindow.resize(a, b)
191 #Maximize if no previous size was found
192 #self._mainWindow.maximize()
195 #Maximize if no previous window.dat file was found
196 #self._mainWindow.maximize()
199 #Restore selections from previously saved settings if it exists and is valid.
200 historical_catergory_found = False
201 selectionsDatPath = "/".join((constants._data_path_, "selections.dat"))
202 if os.path.exists(selectionsDatPath):
203 #Retrieving previous selections from ~/.gonvert/selections.dat
204 selections = pickle.load(open(selectionsDatPath, 'r'))
205 #Restoring previous selections.
207 #Make a list of categories to determine which one to select
208 categories = unit_data.list_dic.keys()
211 #If the 'selected_unts' has been stored, then extract self._selected_units from selections.
212 if 'selected_units' in selections:
213 self._selected_units = selections['selected_units']
214 #Make sure that the 'self._selected_category' has been stored.
215 if 'selected_category' in selections:
216 #Match an available category to the previously selected category.
217 for counter in range(len(categories)):
218 if selections['selected_category'] == categories[counter]:
219 # Restore the previously selected category.
220 self._categoryView.set_cursor(counter, self._categoryColumn, False)
221 self._categoryView.grab_focus()
222 historical_catergory_found = True
224 if not historical_catergory_found:
225 print "Couldn't find saved category, using default."
226 #If historical records were not kept then default to
227 # put the focus on the first category
228 self._categoryView.set_cursor(0, self._categoryColumn, False)
229 self._categoryView.grab_focus()
233 def _on_shortlist_changed(self, a):
235 if self._shortlistcheck.get_active():
240 def _on_edit_shortlist(self, a):
241 print "edit shortlist"
242 if self._toggleShortList.get_active():
247 def _on_user_clear_selections(self, a):
248 selectionsDatPath = "/".join((constants._data_path_, "selections.dat"))
249 os.remove(selectionsDatPath)
250 self._selected_units = {}
252 def _on_user_exit(self, a):
254 This routine saves the selections to a file, and
255 should therefore only be called when exiting the program.
257 Update selections dictionary which consists of the following keys:
258 'self._selected_category': full name of selected category
259 'self._selected_units': self._selected_units dictionary which contains:
260 [categoryname: #1 displayed unit, #2 displayed unit]
262 #Determine the contents of the selected category row
263 selected, iter = self._categoryView.get_selection().get_selected()
264 self._selected_category = self._categoryModel.get_value(iter, 0)
267 'selected_category': self._selected_category,
268 'selected_units': self._selected_units
270 selectionsDatPath = "/".join((constants._data_path_, "selections.dat"))
271 pickle.dump(selections, open(selectionsDatPath, 'w'))
273 #Get last size of app and save it
275 'size': self._mainWindow.get_size()
277 windowDatPath = "/".join((constants._data_path_, "window.dat"))
278 pickle.dump(window_settings, open(windowDatPath, 'w'))
283 def _findEntry_changed(self, a):
284 #Clear out find results since the user wants to look for something new
285 self._find_result = [] #empty find result list
286 self._find_count = 0 #default to find result number zero
287 self._findLabel.set_text('') #clear result
289 def _on_find_key_press(self, a, b):
290 #Check if the key pressed was an ASCII key
292 #Check if the key pressed was the 'Enter' key
293 if ord(b.string[0]) == 13:
294 #Execute the find units function
295 _on_user_find_units(1)
297 def _on_about_clicked(self, a):
298 self._about_box.show()
300 def _on_about_hide(self, *args):
301 self._about_box.hide()
304 def messagebox_ok_clicked(self, a):
307 def _on_user_find_units(self, a):
308 #check if 'new find' or 'last find' or 'next-find'
310 #new-find = run the find algorithm which also selects the first found unit
311 # = self._find_count = 0 and self._find_result = []
313 #last-find = restart from top again
314 # = self._find_count = len(self._find_result)
316 #next-find = continue to next found location
317 # = self._find_count = 0 and len(self._find_result)>0
320 if len(self._find_result) == 0:
321 find_string = string.lower(string.strip(self._findEntry.get_text()))
322 #Make sure that a valid find string has been requested
323 if len(find_string)>0:
324 categories = unit_data.list_dic.keys()
326 found_a_unit = 0 #reset the 'found-a-unit' flag
328 for category in categories:
329 units = unit_data.list_dic[category].keys()
331 del units[0] # do not display .base_unit description key
334 if string.find(string.lower(unit), find_string) >= 0:
335 found_a_unit = 1 #indicate that a unit was found
336 #print "'", find_string, "'", " found at category = ", category, " unit = ", unit
337 self._find_result.append((category, unit, cat_no, unit_no))
341 if found_a_unit == 1:
342 #select the first found unit
344 #check if next find is in a new category (prevent category changes when unnecessary
345 if self._selected_category != self._find_result[self._find_count][0]:
346 self._categoryView.set_cursor(self._find_result[0][2], self._categoryColumn, False)
347 self._unitsView.set_cursor(self._find_result[0][3], self._unitNameColumn, True)
348 if len(self._find_result)>1:
349 self._findLabel.set_text(('Press Find for next unit. '+ str(len(self._find_result))+' result(s).'))
351 self._findLabel.set_text('Text not found') #Display error
352 else: #must be next-find or last-find
354 if self._find_count == len(self._find_result)-1:
357 self._categoryView.set_cursor(self._find_result[self._find_count][2], self._categoryColumn, False)
358 self._unitsView.set_cursor(self._find_result[self._find_count][3], self._unitNameColumn, True)
359 else: #must be next-find
360 self._find_count = self._find_count+1
361 #check if next find is in a new category (prevent category changes when unnecessary
362 if self._selected_category != self._find_result[self._find_count][0]:
363 self._categoryView.set_cursor(self._find_result[self._find_count][2], self._categoryColumn, False)
364 self._unitsView.set_cursor(self._find_result[self._find_count][3], self._unitNameColumn, True)
366 def _on_click_unit_column(self, col):
368 Sort the contents of the col when the user clicks on the title.
370 #Determine which column requires sorting
371 if col is self._unitNameColumn:
372 selectedUnitColumn = 0
373 self._unitNameColumn.set_sort_indicator(True)
374 self._unitValueColumn.set_sort_indicator(False)
375 self._unitSymbolColumn.set_sort_indicator(False)
376 self._unitNameColumn.set_sort_order(not self._unit_sort_direction)
377 elif col is self._unitValueColumn:
378 selectedUnitColumn = 1
379 self._unitNameColumn.set_sort_indicator(False)
380 self._unitValueColumn.set_sort_indicator(True)
381 self._unitSymbolColumn.set_sort_indicator(False)
382 self._unitValueColumn.set_sort_order(not self._value_sort_direction)
383 elif col is self._unitSymbolColumn:
384 selectedUnitColumn = 2
385 self._unitNameColumn.set_sort_indicator(False)
386 self._unitValueColumn.set_sort_indicator(False)
387 self._unitSymbolColumn.set_sort_indicator(True)
388 self._unitSymbolColumn.set_sort_order(not self._units_sort_direction)
390 assert False, "Unknown column: %s" % (col.get_title(), )
392 #declare a spot to hold the sorted list
395 #point to the first row
396 iter = self._unitModel.get_iter_first()
400 #grab all text from columns for sorting
402 #get the text from each column
403 unit_text = self._unitModel.get_value(iter, 0)
404 units_text = self._unitModel.get_value(iter, 2)
406 #do not bother sorting if the value column is empty
407 if self._unitModel.get_value(iter, 1) == '' and selectedUnitColumn == 1:
410 #special sorting exceptions for ascii values (instead of float values)
411 if self._selected_category == "Computer Numbers":
412 value_text = self._unitModel.get_value(iter, 1)
414 if self._unitModel.get_value(iter, 1) == None or unit_model.get_value(iter, 1) == '':
417 value_text = float(self._unitModel.get_value(iter, 1))
419 if selectedUnitColumn == 0:
420 sorted_list.append((unit_text, value_text, units_text))
421 elif selectedUnitColumn == 1:
422 sorted_list.append((value_text, unit_text, units_text))
424 sorted_list.append((units_text, value_text, unit_text))
426 #point to the next row in the self._unitModel
427 iter = self._unitModel.iter_next(iter)
430 #check if no calculations have been made yet (don't bother sorting)
434 if selectedUnitColumn == 0:
435 if not self._unit_sort_direction:
436 sorted_list.sort(lambda (x, xx, xxx), (y, yy, yyy): cmp(string.lower(x), string.lower(y)))
437 self._unit_sort_direction = True
439 sorted_list.sort(lambda (x, xx, xxx), (y, yy, yyy): cmp(string.lower(y), string.lower(x)))
440 self._unit_sort_direction = False
441 elif selectedUnitColumn == 1:
443 if not self._value_sort_direction:
444 self._value_sort_direction = True
446 sorted_list.reverse()
447 self._value_sort_direction = False
449 if not self._units_sort_direction:
450 sorted_list.sort(lambda (x, xx, xxx), (y, yy, yyy): cmp(string.lower(x), string.lower(y)))
451 self._units_sort_direction = True
453 sorted_list.sort(lambda (x, xx, xxx), (y, yy, yyy): cmp(string.lower(y), string.lower(x)))
454 self._units_sort_direction = False
456 #Clear out the previous list of units
457 self._unitModel = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
458 self._unitsView.set_model(self._unitModel)
460 #colourize each row differently for easier reading
461 self._unitsView.set_property('rules_hint', 1)
463 #Clear out the description
464 text_model = gtk.TextBuffer(None)
465 self._unitDescription.set_buffer(text_model)
467 if selectedUnitColumn == 0:
468 for unit, value, units in sorted_list:
469 iter = self._unitModel.append()
470 self._unitModel.set(iter, 0, unit, 1, str(value), 2, units)
471 elif selectedUnitColumn == 1:
472 for value, unit, units in sorted_list:
473 iter = self._unitModel.append()
474 self._unitModel.set(iter, 0, unit, 1, str(value), 2, units)
476 for units, value, unit in sorted_list:
477 iter = self._unitModel.append()
478 self._unitModel.set(iter, 0, unit, 1, str(value), 2, units)
481 def _on_click_category(self, row):
482 #Clear out the previous list of units
483 self._unitModel = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
484 self._unitsView.set_model(self._unitModel)
486 #Colourize each row alternately for easier reading
487 self._unitsView.set_property('rules_hint', 1)
489 #Clear out the description
490 text_model = gtk.TextBuffer(None)
491 self._unitDescription.set_buffer(text_model)
493 #Determine the contents of the selected category row
494 selected, iter = row.get_selection().get_selected()
496 self._selected_category = self._categoryModel.get_value(iter, 0)
498 self._unit_sort_direction = False
499 self._value_sort_direction = False
500 self._units_sort_direction = False
501 self._unitNameColumn.set_sort_indicator(False)
502 self._unitValueColumn.set_sort_indicator(False)
503 self._unitSymbolColumn.set_sort_indicator(False)
505 self._unitDataInCategory = unit_data.list_dic[selected.get_value(iter, 0)]
506 keys = self._unitDataInCategory.keys()
508 del keys[0] # do not display .base_unit description key
510 #Fill up the units descriptions and clear the value cells
512 iter = self._unitModel.append()
513 self._unitModel.set(iter, 0, key, 1, '', 2, self._unitDataInCategory[key][1])
515 self._unitName.set_text('')
516 self._unitValue.set_text('')
517 self._previousUnitName.set_text('')
518 self._previousUnitValue.set_text('')
519 self._unitSymbol.set_text('')
520 self._previousUnitSymbol.set_text('')
524 def restore_units(self):
525 # Restore the previous historical settings of previously selected units in this newly selected category
526 #Since category has just been clicked, the list will be sorted already.
527 if self._selected_category in self._selected_units:
528 if self._selected_units[self._selected_category][0]:
530 #self._selected_units[self._selected_category] = [selected_unit, self._selected_units[self._selected_category][0]]
532 units = unit_data.list_dic[self._selected_category].keys()
534 del units[0] # do not display .base_unit description key
536 #Restore oldest selection first.
537 if self._selected_units[self._selected_category][1]:
540 if unit == self._selected_units[self._selected_category][1]:
541 self._unitsView.set_cursor(unit_no, self._unitNameColumn, True)
544 #Restore newest selection second.
547 if unit == self._selected_units[self._selected_category][0]:
548 self._unitsView.set_cursor(unit_no, self._unitNameColumn, True)
551 # select the text so user can start typing right away
552 self._unitValue.grab_focus()
553 self._unitValue.select_region(0, -1)
555 def _on_button_released(self, row, a):
556 self._on_click_unit(row)
558 def _on_click_unit(self, row):
559 self._calcsuppress = True #suppress calculations
561 #Determine the contents of the selected row.
562 selected, iter = self._unitsView.get_selection().get_selected()
564 selected_unit = selected.get_value(iter, 0)
566 unit_spec = self._unitDataInCategory[selected_unit]
568 #Clear out the description
569 text_model = gtk.TextBuffer(None)
570 self._unitDescription.set_buffer(text_model)
572 enditer = text_model.get_end_iter()
573 text_model.insert(enditer, unit_spec[2])
575 if self._unitName.get_text() != selected_unit:
576 self._previousUnitName.set_text(self._unitName.get_text())
577 self._previousUnitValue.set_text(self._unitValue.get_text())
578 if self._unitSymbol.get() == None:
579 self._previousUnitSymbol.set_text('')
581 self._previousUnitSymbol.set_text(self._unitSymbol.get())
582 self._unitName.set_text(selected_unit)
584 self._unitValue.set_text(selected.get_value(iter, 1))
586 self._unitSymbol.set_text(unit_spec[1]) # put units into label text
587 if self._unitValue.get_text() == '':
588 if self._selected_category == "Computer Numbers":
589 self._unitValue.set_text("0")
591 self._unitValue.set_text("0.0")
593 #For historical purposes, record this unit as the most recent one in this category.
594 # Also, if a previous unit exists, then shift that previous unit to oldest unit.
595 if self._selected_category in self._selected_units:
596 if self._selected_units[self._selected_category][0]:
597 self._selected_units[self._selected_category] = [selected_unit, self._selected_units[self._selected_category][0]]
599 self._selected_units[self._selected_category] = [selected_unit, '']
601 # select the text so user can start typing right away
602 self._unitValue.grab_focus()
603 self._unitValue.select_region(0, -1)
605 self._calcsuppress = False #enable calculations
607 def _on_user_write_units(self, a):
608 ''"Write the list of categories and units to stdout for documentation purposes.''"
609 messagebox_model = gtk.TextBuffer(None)
610 messageboxtext.set_buffer(messagebox_model)
611 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)
613 while gtk.events_pending():
614 gtk.mainiteration(False)
615 category_keys = unit_data.list_dic.keys()
619 print 'gonvert-%s%s' % (
620 constants.__version__,
621 _(u' - Unit Conversion Utility - Convertible units listing: ')
623 for category_key in category_keys:
624 total_categories = total_categories + 1
625 print category_key, ": "
626 self._unitDataInCategory = unit_data.list_dic[category_key]
627 unit_keys = self._unitDataInCategory.keys()
629 del unit_keys[0] # do not display .base_unit description key
630 for unit_key in unit_keys:
631 total_units = total_units + 1
633 print total_categories, ' categories'
634 print total_units, ' units'
635 messagebox_model = gtk.TextBuffer(None)
636 messageboxtext.set_buffer(messagebox_model)
637 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)
640 if self._calcsuppress:
641 #self._calcsuppress = False
643 # determine if value to be calculated is empty
644 if self._selected_category == "Computer Numbers":
645 if self._unitValue.get_text() == '':
648 value = self._unitValue.get_text()
650 if self._unitValue.get_text() == '':
653 value = float(self._unitValue.get_text())
655 if self._unitName.get_text() != '':
656 func, arg = self._unitDataInCategory[self._unitName.get_text()][0] #retrieve the conversion function and value from the selected unit
657 base = apply(func.to_base, (value, arg, )) #determine the base unit value
659 keys = self._unitDataInCategory.keys()
664 #point to the first row
665 iter = self._unitModel.get_iter_first()
668 #get the formula from the name at the row
669 func, arg = self._unitDataInCategory[self._unitModel.get_value(iter, 0)][0]
671 #set the result in the value column
672 self._unitModel.set(iter, 1, str(apply(func.from_base, (base, arg, ))))
674 #point to the next row in the self._unitModel
675 iter = self._unitModel.iter_next(iter)
677 # if the second row has a unit then update its value
678 if self._previousUnitName.get_text() != '':
679 self._calcsuppress = True
680 func, arg = self._unitDataInCategory[self._previousUnitName.get_text()][0]
681 self._previousUnitValue.set_text(str(apply(func.from_base, (base, arg, ))))
682 self._calcsuppress = False
685 if self._calcsuppress == True:
686 #self._calcsuppress = False
688 # determine if value to be calculated is empty
689 if self._selected_category == "Computer Numbers":
690 if self._previousUnitValue.get_text() == '':
693 value = self._previousUnitValue.get_text()
695 if self._previousUnitValue.get_text() == '':
698 value = float(self._previousUnitValue.get_text())
700 if self._previousUnitName.get_text() != '':
701 func, arg = self._unitDataInCategory[self._previousUnitName.get_text()][0] #retrieve the conversion function and value from the selected unit
702 base = apply(func.to_base, (value, arg, )) #determine the base unit value
704 keys = self._unitDataInCategory.keys()
709 #point to the first row
710 iter = self._unitModel.get_iter_first()
713 #get the formula from the name at the row
714 func, arg = self._unitDataInCategory[self._unitModel.get_value(iter, 0)][0]
716 #set the result in the value column
717 self._unitModel.set(iter, 1, str(apply(func.from_base, (base, arg, ))))
719 #point to the next row in the self._unitModel
720 iter = self._unitModel.iter_next(iter)
722 # if the second row has a unit then update its value
723 if self._unitName.get_text() != '':
724 self._calcsuppress = True
725 func, arg = self._unitDataInCategory[self._unitName.get_text()][0]
726 self._unitValue.set_text(str(apply(func.from_base, (base, arg, ))))
727 self._calcsuppress = False
731 logging.basicConfig(level = logging.DEBUG)
733 os.makedirs(constants._data_path_)
742 if __name__ == "__main__":