Пример #1
0
 def changed(self, *args):
     amt1 = convert.frac_to_float(self.amt1Entry.get_text())
     #amt2 = convert.frac_to_float(self.resultLabel.get_text())
     #amt2 = self.amt2
     unit1 = cb_get_active_text(self.unit1ComboBox)
     unit2 = cb_get_active_text(self.unit2ComboBox)
     if unit1 != self.last_unit1:
         self.get_possible_conversions()
     #self.unit2Model.refilter()
     if amt1 and unit2:
         self.convert(amt1, unit1, unit2)
     self.last_amt1 = amt1
     #self.last_amt2 = amt2
     self.last_unit1 = unit1
     self.last_unit2 = unit2
Пример #2
0
 def changed (self, *args):
     amt1 = convert.frac_to_float(self.amt1Entry.get_text())
     #amt2 = convert.frac_to_float(self.resultLabel.get_text())
     #amt2 = self.amt2
     unit1 = cb_get_active_text(self.unit1ComboBox)
     unit2 = cb_get_active_text(self.unit2ComboBox)
     if unit1 != self.last_unit1:
         self.get_possible_conversions()
     #self.unit2Model.refilter()
     if amt1 and unit2:
         self.convert(amt1, unit1, unit2)
     self.last_amt1 = amt1
     #self.last_amt2 = amt2
     self.last_unit1 = unit1
     self.last_unit2 = unit2
Пример #3
0
 def food_group_filter_changed_cb (self, fgcb):
     food_group = cb.cb_get_active_text(fgcb)
     if food_group==self.ALL_GROUPS:
         self.group = None
     else:
         self.group = food_group
     gobject.idle_add(self.search)
Пример #4
0
 def apply_amt_convert(self, *args):
     to_unit = cb.cb_get_active_text(self.toUnitCombo)
     base_convert = self.nd.conv.converter('g', to_unit)
     if not base_convert:
         self.densities, self.extra_units = self.nd.get_conversions(
             self.ingkey)
         if to_unit in self.extra_units:
             base_convert = 1 / self.extra_units[to_unit]
         else:
             # this is a density, we hope...
             if to_unit.find(' (') > 0:
                 to_unit, describer = to_unit.split(' (')
                 describer = describer[0:-1]
                 density = self.densities[describer]
             else:
                 if None not in self.densities:
                     raise RuntimeError(
                         "Unable to make sense of conversion from %s %s" %
                         (to_unit, self.ingkey))
                 density = self.densities[None]
             base_convert = self.nd.conv.converter('g',
                                                   to_unit,
                                                   density=density)
     to_amount = convert.frac_to_float(self.toAmountEntry.get_text())
     from_amount = convert.frac_to_float(self.fromAmountEntry.get_text())
     ratio = from_amount / to_amount
     factor = base_convert * ratio
     from_unit = self.fromUnit
     self.nd.set_conversion(self.ingkey, from_unit, factor)
Пример #5
0
 def doSearch (self):
     """Do the actual searching."""
     last_search = self.search_string
     self.search_string = self.searchEntry.get_text()
     last_by = self.search_by
     self.treeModel.search_by = self.search_by = cb.cb_get_active_text(self.searchByBox)
     last_regexp = self.use_regexp
     self.use_regexp = self.regexpTog.get_active()
     if (self.search_by==last_by and
         self.search_string==last_search and
         self.use_regexp==last_regexp):
         # Don't do anything...
         return
     # RESET THE VIEW IF NEED BE
     if (self.search_string.find(last_search)!=0 or
         self.search_by != last_by or
         self.use_regexp != last_regexp):
         self.treeModel.reset_views()
     if self.search_by == _('item'):
         self.treeModel.limit_on_ingkey(self.search_string,
                                        search_options={'use_regexp':self.use_regexp,}
                                        )
     elif self.search_by == _('key'):
         self.treeModel.limit_on_item(self.search_string,
                                      search_options={'use_regexp':self.use_regexp})
     else: # self.search_by == _('unit'):
         self.treeModel.limit(self.search_string,
                              'unit',
                              search_options={'use_regexp':self.use_regexp}
                              )
Пример #6
0
    def set_search (self, txt):
        """Set the search to txt, ensuring there are results.

        If there are no results for the search, we'll try a partial
        search for only some of the words in txt. If that fails, we'll
        set the search to blank.
        """
        words = re.split('\W+',txt)
        # always search raw if possible... (it gets us the real thing
        # vs. canned/frozen/soup/babyfood, etc.)
        if 'raw' not in words:
            words += ['raw']
        search_terms = []
        search_in = self.rd.nutrition_table
        srch = []
        searchvw = None
        for w in words:
            if w in [',',' ',';','.']: continue
            result = self.rd.search_nutrition(srch+[w])
            if result:
                srch += [w]
                searchvw = result
        groups = self.rd.fetch_food_groups_for_search(srch)
        cur_active = cb.cb_get_active_text(self.foodGroupComboBox)
        groups = [self.ALL_GROUPS] + groups
        cb.set_model_from_list(self.foodGroupComboBox,groups)
        cb.cb_set_active_text(self.foodGroupComboBox,cur_active)
        self.__override_search__ = True # turn off any handling of text insertion
        search_text = ' '.join(srch)
        self.usdaSearchEntry.set_text(search_text)
        self.searchvw = searchvw or self.rd.fetch_all(self.rd.nutrition_table)
        self.nutrition_store.change_view(self.searchvw)
        self.__last_search__ = search_text
        self.__override_search__ = False # turn back on search handling!
Пример #7
0
 def food_group_filter_changed_cb(self, fgcb):
     food_group = cb.cb_get_active_text(fgcb)
     if food_group == self.ALL_GROUPS:
         self.group = None
     else:
         self.group = food_group
     GObject.idle_add(self.search)
Пример #8
0
    def set_search(self, txt):
        """Set the search to txt, ensuring there are results.

        If there are no results for the search, we'll try a partial
        search for only some of the words in txt. If that fails, we'll
        set the search to blank.
        """
        words = re.split(r'\W+', txt)
        # always search raw if possible... (it gets us the real thing
        # vs. canned/frozen/soup/babyfood, etc.)
        if 'raw' not in words:
            words += ['raw']
        search_terms = []
        search_in = self.rd.nutrition_table
        srch = []
        searchvw = None
        for w in words:
            if w in [',', ' ', ';', '.']: continue
            result = self.rd.search_nutrition(srch + [w])
            if result:
                srch += [w]
                searchvw = result
        groups = self.rd.fetch_food_groups_for_search(srch)
        cur_active = cb.cb_get_active_text(self.foodGroupComboBox)
        groups = [self.ALL_GROUPS] + groups
        cb.set_model_from_list(self.foodGroupComboBox, groups)
        cb.cb_set_active_text(self.foodGroupComboBox, cur_active)
        self.__override_search__ = True  # turn off any handling of text insertion
        search_text = ' '.join(srch)
        self.usdaSearchEntry.set_text(search_text)
        self.searchvw = searchvw or self.rd.fetch_all(self.rd.nutrition_table)
        self.nutrition_store.change_view(self.searchvw)
        self.__last_search__ = search_text
        self.__override_search__ = False  # turn back on search handling!
Пример #9
0
 def get_possible_conversions (self):
     density=self.densitySpinButton.get_value()
     #if self.useDensityCheckButton.get_active():
     #    density=self.densitySpinButton.get_value()
     if density <= 0 or not self.expander1.get_expanded(): density = None
     u1 = cb_get_active_text(self.unit1ComboBox)
     self.possible_conversions = self.conv.get_all_conversions(u1,density=density)
Пример #10
0
 def doSearch(self):
     """Do the actual searching."""
     last_search = self.search_string
     self.search_string = self.searchEntry.get_text()
     last_by = self.search_by
     self.treeModel.search_by = self.search_by = cb.cb_get_active_text(
         self.searchByBox)
     last_regexp = self.use_regexp
     self.use_regexp = self.regexpTog.get_active()
     if (self.search_by == last_by and self.search_string == last_search
             and self.use_regexp == last_regexp):
         # Don't do anything...
         return
     # RESET THE VIEW IF NEED BE
     if (self.search_string.find(last_search) != 0
             or self.search_by != last_by
             or self.use_regexp != last_regexp):
         self.treeModel.reset_views()
     if self.search_by == _('item'):
         self.treeModel.limit_on_ingkey(self.search_string,
                                        search_options={
                                            'use_regexp': self.use_regexp,
                                        })
     elif self.search_by == _('key'):
         self.treeModel.limit_on_item(
             self.search_string,
             search_options={'use_regexp': self.use_regexp})
     else:  # self.search_by == _('unit'):
         self.treeModel.limit(
             self.search_string,
             'unit',
             search_options={'use_regexp': self.use_regexp})
Пример #11
0
 def close(self, *args):
     self.window.hide()
     if self.okcb:
         self.okcb(cb_get_active_text(self.unit2ComboBox),
                   resultLabel.get_text())
     if __name__ == '__main__':
         gtk.main_quit()
Пример #12
0
 def get_possible_conversions(self):
     density = self.densitySpinButton.get_value()
     #if self.useDensityCheckButton.get_active():
     #    density=self.densitySpinButton.get_value()
     if density <= 0 or not self.expander1.get_expanded(): density = None
     u1 = cb_get_active_text(self.unit1ComboBox)
     self.possible_conversions = self.conv.get_all_conversions(
         u1, density=density)
Пример #13
0
 def fieldChangedCB(self, combobox):
     name = cb.cb_get_active_text(combobox)
     self.field = gglobals.NAME_TO_ATTR.get(name, name)
     self.populate_treeview()
     other_fields = self.fields[:]
     if self.field != 'category':
         other_fields.remove(gglobals.REC_ATTR_DIC[self.field])
     cb.set_model_from_list(self.otherFieldCombo, other_fields)
Пример #14
0
 def density_itm_changed (self, *args):
     debug('density_itm_changed',5)
     self.changing_item=True
     itm=cb_get_active_text(self.itemComboBox)
     if itm != _('None'):
         self.densitySpinButton.set_value(self.conv.density_table[itm])
     else:
         self.densitySpinButton.set_value(0)
     self.changed()
     self.changing_item=False
Пример #15
0
 def density_itm_changed(self, *args):
     debug('density_itm_changed', 5)
     self.changing_item = True
     itm = cb_get_active_text(self.itemComboBox)
     if itm != _('None'):
         self.densitySpinButton.set_value(self.conv.density_table[itm])
     else:
         self.densitySpinButton.set_value(0)
     self.changed()
     self.changing_item = False
Пример #16
0
 def fieldChangedCB (self, combobox):
     name = cb.cb_get_active_text(combobox)
     self.field = gglobals.NAME_TO_ATTR.get(name,name)
     self.populate_treeview()
     other_fields = self.fields[:]
     if self.field != 'category':
         other_fields.remove(gglobals.REC_ATTR_DIC[self.field])
     cb.set_model_from_list(
         self.otherFieldCombo,
         other_fields
         )
Пример #17
0
    def play_tune(self):
        sound = self.sounds_and_files[cb.cb_get_active_text(
            self.soundComboBox)]
        data = get_data('gourmet', f'data/sound/{sound}')
        assert data

        # FIXME: Delete the tempfile when we're done
        # TODO: Figure out how to make GStreamer play raw bytes
        fd, fname = mkstemp('.opus')
        os.write(fd, data)
        os.close(fd)
        self.player.play_file(fname)
Пример #18
0
 def otherFieldComboChangedCB (self, combobox):
     name = cb.cb_get_active_text(combobox)
     self.other_field = gglobals.NAME_TO_ATTR.get(name,name)
     if self.other_field == 'category':
         self.otherValueBlurbLabel.hide()
     else:
         self.otherValueBlurbLabel.show()
     mod = self.make_model_for_field(self.other_field)
     self.otherNewValueComboBoxEntry.set_model(mod)
     if self.otherNewValueComboBoxEntry.get_text_column()==-1:
         self.otherNewValueComboBoxEntry.set_text_column(0)
     self.otherNewValueEntryCompletion.set_model(mod)
     self.otherNewValueEntryCompletion.set_text_column(0)
Пример #19
0
 def otherFieldComboChangedCB (self, combobox):
     name = cb.cb_get_active_text(combobox)
     self.other_field = gglobals.NAME_TO_ATTR.get(name,name)
     if self.other_field == 'category':
         self.otherValueBlurbLabel.hide()
     else:
         self.otherValueBlurbLabel.show()
     mod = self.make_model_for_field(self.other_field)
     self.otherNewValueComboBoxEntry.set_model(mod)
     if self.otherNewValueComboBoxEntry.get_text_column()==-1:
         self.otherNewValueComboBoxEntry.set_text_column(0)
     self.otherNewValueEntryCompletion.set_model(mod)
     self.otherNewValueEntryCompletion.set_text_column(0)
Пример #20
0
 def search(self):
     txt = self.usdaSearchEntry.get_text()
     if self.__last_search__ == txt and self.group == self.__last_group__:
         return
     words = re.split(r'\W+', txt)
     groups = self.rd.fetch_food_groups_for_search(words)
     cur_active = cb.cb_get_active_text(self.foodGroupComboBox)
     groups = [self.ALL_GROUPS] + groups
     if cur_active not in groups:
         groups += [cur_active]
     cb.set_model_from_list(self.foodGroupComboBox, groups)
     cb.cb_set_active_text(self.foodGroupComboBox, cur_active)
     self.searchvw = self.rd.search_nutrition(words, group=self.group)
     self.__last_search__ = txt
     self.__last_group__ = self.group
     self.nutrition_store.change_view(self.searchvw)
     self.nutrition_store.set_page(0)
Пример #21
0
 def search (self):
     txt = self.usdaSearchEntry.get_text()
     if self.__last_search__ == txt and self.group == self.__last_group__:
         return
     words = re.split('\W+',txt)
     groups = self.rd.fetch_food_groups_for_search(words)
     cur_active = cb.cb_get_active_text(self.foodGroupComboBox)
     groups = [self.ALL_GROUPS] + groups
     if cur_active not in groups:
         groups += [cur_active]
     cb.set_model_from_list(self.foodGroupComboBox,groups)
     cb.cb_set_active_text(self.foodGroupComboBox,cur_active)
     self.searchvw = self.rd.search_nutrition(words,group=self.group)
     self.__last_search__ = txt
     self.__last_group__ = self.group
     self.nutrition_store.change_view(self.searchvw)
     self.nutrition_store.set_page(0)
Пример #22
0
 def apply_amt_convert (self,*args):
     to_unit = cb.cb_get_active_text(self.toUnitCombo)
     base_convert = self.nd.conv.converter('g',to_unit)
     if not base_convert:
         self.densities,self.extra_units = self.nd.get_conversions(self.ingkey)
         if self.extra_units.has_key(to_unit):
             base_convert = 1/self.extra_units[to_unit]
         else:
             # this is a density, we hope...
             if to_unit.find(' (')>0:
                 to_unit,describer = to_unit.split(' (')
                 describer = describer[0:-1]
                 density = self.densities[describer]
             else:
                 if not self.densities.has_key(None):
                     raise RuntimeError("Unable to make sense of conversion from %s %s"%(to_unit,self.ingkey))
                 density = self.densities[None]
             base_convert = self.nd.conv.converter('g',to_unit,density=density)
     to_amount = convert.frac_to_float(self.toAmountEntry.get_text())
     from_amount = convert.frac_to_float(self.fromAmountEntry.get_text())
     ratio = from_amount / to_amount
     factor = base_convert * ratio
     from_unit = self.fromUnit
     self.nd.set_conversion(self.ingkey,from_unit,factor)
Пример #23
0
 def custom_unit_changed (self, *args):
     amount = self.customNutritionAmountEntry.get_value()
     unit = cb.cb_get_active_text(self.massUnitComboBox)
     if amount and unit:
         base_convert = self.nd.conv.converter(unit,'g')/float(100)
         self.custom_factor = 1/(base_convert * amount)
Пример #24
0
 def custom_unit_changed(self, *args):
     amount = self.customNutritionAmountEntry.get_value()
     unit = cb.cb_get_active_text(self.massUnitComboBox)
     if amount and unit:
         base_convert = self.nd.conv.converter(unit, 'g') / float(100)
         self.custom_factor = 1 / (base_convert * amount)
Пример #25
0
 def close (self, *args):
     self.window.hide()
     if self.okcb:
         self.okcb(cb_get_active_text(self.unit2ComboBox),resultLabel.get_text())
     if __name__ == '__main__':
         gtk.main_quit()
Пример #26
0
 def play_tune(self):
     sound_file = self.sounds_and_files[cb.cb_get_active_text(
         self.soundComboBox)]
     sound_file = os.path.join(gglobals.data_dir, 'sound', sound_file)
     self.player.play_file(sound_file)