Esempio n. 1
0
 def __init__(self, nd, prefs, rec=None, in_string=''):
     self.ui = Gtk.Builder()
     self.ui.add_from_file(os.path.join(current_path, 'nutritionDruid.ui'))
     self.mm = MnemonicManager()
     self.mm.add_builder(self.ui)
     self.mm.fix_conflicts_peacefully()
     self.prefs = prefs
     self.nd = nd
     self.rec = rec
     self.in_string = in_string or (rec and _('recipe') or _('selection'))
     self.rd = self.nd.db
     self.def_ingredient_amounts = {
     }  # For default amounts for nutritional label...
     self.amounts = {}  # List amounts by ingredient
     self.ing_to_index = {
     }  # A way to keep track of the order of our ingredients...
     self._setup_widgets_()
     # keep track of pages/setups we've been on
     self.path = []
     self.curpage = 0
     self.prevDruidButton.set_sensitive(False)
     # Initiate our gobject-ness so we can emit signals.
     GObject.GObject.__init__(self)
     # Save our position with our widget saver...
     WidgetSaver.WindowSaver(self.ui.get_object('window'),
                             self.prefs.get('nutritionDruid', {}))
Esempio n. 2
0
 def __init__(self, rd, prefs, widgets):
     self.rd = rd
     self.prefs = prefs
     for name, w in widgets:
         setattr(self, name, w)
     self._setup_nuttree_()
     self.__last_search__ = ''
     self.__override_search__ = False
     # TODO: Fixing saving usdaSearchAsYouTypeToggle state
     # Button state is not being saved across sessions and always starts off
     # inactive. Of note, this problem seemed to also exist in the last
     # release (0.17.4), but the button always started off active.
     WidgetSaver.WidgetSaver(self.usdaSearchAsYouTypeToggle,
                             self.prefs.get('sautTog', {'active': True}),
                             ['toggled'])
     # Ensure usdaFindButton is shown if usdaSearchAsYouTypeToggle is
     # inactive
     self.toggle_saut()
     # search
     self.usdaSearchEntry.connect('changed', self.search_type_cb)
     self.usdaFindButton.connect('clicked', self.search_cb)
     self.usdaSearchAsYouTypeToggle.connect('toggled', self.toggle_saut)
     cb.set_model_from_list(
         self.foodGroupComboBox, [self.ALL_GROUPS] +
         self.rd.get_unique_values('foodgroup', self.rd.nutrition_table))
     cb.cb_set_active_text(self.foodGroupComboBox, self.ALL_GROUPS)
Esempio n. 3
0
 def __init__(self, rd, prefs, widgets):
     self.rd = rd
     self.prefs = prefs
     for name, w in widgets:
         setattr(self, name, w)
     self._setup_nuttree_()
     self.__last_search__ = ''
     self.__override_search__ = False
     WidgetSaver.WidgetSaver(self.usdaSearchAsYouTypeToggle,
                             self.prefs.get('sautTog', {'active': True}),
                             ['toggled'])
     # search
     self.usdaSearchEntry.connect('changed', self.search_type_cb)
     self.usdaFindButton.connect('clicked', self.search_cb)
     self.usdaSearchAsYouTypeToggle.connect('toggled', self.toggle_saut)
     cb.set_model_from_list(
         self.foodGroupComboBox, [self.ALL_GROUPS] +
         self.rd.get_unique_values('foodgroup', self.rd.nutrition_table))
     cb.cb_set_active_text(self.foodGroupComboBox, self.ALL_GROUPS)
Esempio n. 4
0
 def __init__(self, rd=None, rg=None):
     self.ui = gtk.Builder()
     self.ui.add_from_file(os.path.join(current_path, 'keyeditor.ui'))
     self.rd = rd
     self.rg = rg
     self.widget_names = [
         'treeview', 'searchByBox', 'searchEntry', 'searchButton', 'window',
         'searchAsYouTypeToggle', 'regexpTog', 'changeKeyEntry',
         'changeItemEntry', 'changeUnitEntry', 'changeAmountEntry',
         'applyEntriesButton', 'clearEntriesButton'
     ]
     for w in self.widget_names:
         setattr(self, w, self.ui.get_object(w))
     self.entries = {
         'ingkey': self.changeKeyEntry,
         'item': self.changeItemEntry,
         'unit': self.changeUnitEntry,
         'amount': self.changeAmountEntry,
     }
     # setup entry callback to sensitize/desensitize apply
     self.applyEntriesButton.set_sensitive(False)
     self.clearEntriesButton.set_sensitive(False)
     for e in self.entries.values():
         e.connect('changed', self.entryChangedCB)
     # Make our lovely model
     self.makeTreeModel()
     # setup completion in entry
     model = gtk.ListStore(str)
     for k in self.rd.get_unique_values('ingkey',
                                        table=self.rd.ingredients_table):
         model.append([k])
     cb.make_completion(self.changeKeyEntry, model)
     # Setup next/prev/first/last buttons for view
     self.prev_button = self.ui.get_object('prevButton')
     self.next_button = self.ui.get_object('nextButton')
     self.first_button = self.ui.get_object('firstButton')
     self.last_button = self.ui.get_object('lastButton')
     self.showing_label = self.ui.get_object('showingLabel')
     self.prev_button.connect('clicked',
                              lambda *args: self.treeModel.prev_page())
     self.next_button.connect('clicked',
                              lambda *args: self.treeModel.next_page())
     self.first_button.connect(
         'clicked', lambda *args: self.treeModel.goto_first_page())
     self.last_button.connect('clicked',
                              lambda *args: self.treeModel.goto_last_page())
     # Setup search stuff
     self.search_string = ""
     self.search_by = _('key')
     self.use_regexp = True
     self.setupTreeView()
     self.treeview.set_model(self.treeModel)
     self.treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
     #self.treeview.set_model(self.treeModel)
     self.ui.connect_signals({
         'iSearch':
         self.isearchCB,
         'search':
         self.searchCB,
         'search_as_you_type_toggle':
         self.search_as_you_typeCB,
         'applyEntries':
         self.applyEntriesCB,
         'clearEntries':
         self.clearEntriesCB,
         'close_window':
         lambda *args: self.window.hide(),
         #'editNutritionalInfo':self.editNutritionalInfoCB,
     })
     # setup mnemonic manager
     self.mm = mnemonic_manager.MnemonicManager()
     self.mm.sacred_cows.append('search for')
     self.mm.add_builder(self.ui)
     self.mm.add_treeview(self.treeview)
     self.mm.fix_conflicts_peacefully()
     # to set our regexp_toggled variable
     cb.set_model_from_list(
         self.searchByBox,
         [_('key'), _('item'), _('unit')])
     self.searchByBox.set_active(0)
     self.dont_ask = self.rg.prefs.get('dontAskDeleteKey', False)
     # setup WidgetSavers
     self.rg.conf.append(
         WidgetSaver.WidgetSaver(
             self.searchAsYouTypeToggle,
             self.rg.prefs.get(
                 'sautTog',
                 {'active': self.searchAsYouTypeToggle.get_active()}),
             ['toggled']))
     self.rg.conf.append(
         WidgetSaver.WidgetSaver(
             self.regexpTog,
             self.rg.prefs.get('regexpTog',
                               {'active': self.regexpTog.get_active()}),
             ['toggled']))