Example #1
0
    def get_nutritional_info_as_text_blob(self, rec):
        if not get_prefs().get('include_nutritional_info_in_export', True):
            return None
        txt = ''
        footnotes = ''
        rd = default_rec_manager()
        nd = rd.nd
        nutinfo = nd.get_nutinfo_for_inglist(rd.get_ings(rec), rd)
        ings = rd.get_ings(rec)
        vapor = nutinfo._get_vapor()
        if len(vapor) == len(ings): return None
        if len(vapor) >= 1 and not get_prefs().get(
                'include_partial_nutritional_info', False):
            return None
        if rec.yields and rec.yield_unit:
            singular_unit = gourmet.defaults.get_pluralized_form(
                rec.yield_unit, 1)
            txt += '<i>%s</i>' % (
                (rec.yields
                 and _('Nutritional information reflects amount per %s.' %
                       singular_unit)) or
                _('Nutritional information reflects amounts for entire recipe')
            )

        if vapor:
            txt = txt + '*'
            footnotes = '\n*' + _(
                'Nutritional information is missing for %s ingredients: %s'
            ) % (len(vapor), ', '.join(
                [escape(nv.__ingobject__.item) for nv in vapor]))
        for itm in MAIN_NUT_LAYOUT:
            if itm == SEP:
                # We don't have any nice way of outputting separator
                # lines in our export
                continue
            else:
                label, typ, name, properties, show_percent, unit = itm
                if typ == MAJOR:
                    itm_text = '<b>' + label + '</b>'
                else:
                    itm_text = label
                if unit:
                    itm_text += ' (%s)' % unit
                if type(properties) == list:
                    amts = [getattr(nutinfo, att) for att in properties]
                    amt = sum(amts)
                else:
                    amt = getattr(nutinfo, properties)
                if rec.yields:
                    amt = amt / rec.yields
                itm_text += ' %d' % round(amt)
            txt += '\n' + itm_text
        return '\n'.join([txt, footnotes])
Example #2
0
 def __init__ (self, default_value = inch):
     gobject.GObject.__init__(self)
     gtk.HBox.__init__(self)
     self.__quiet__ = False
     self.unit_combo = gtk.combo_box_new_text()
     for key in self.units:
         self.unit_combo.append_text(key)
     unit = get_prefs().get('default_margin_unit',_('cm'))
     if unit not in self.units: unit = _('cm')
     self.last_unit = self.units[unit]
     cb_extras.setup_typeahead(self.unit_combo)
     cb_extras.cb_set_active_text(self.unit_combo,unit)
     self.unit_combo.connect('changed',self.unit_changed_cb)
     self.value_adjustment = gtk.Adjustment(
         value=self.adjust_to_unit(default_value),
         lower= self.min_val / self.last_unit,
         upper = self.max_val / self.last_unit,
         step_incr = self.adjustments[self.last_unit][0],
         page_incr = self.adjustments[self.last_unit][1],
         )
     def emit_changed (*args):
         self.emit('changed')
     self.value_adjustment.connect('changed',emit_changed)
     self.value_widget = gtk.SpinButton(self.value_adjustment,digits=2)
     self.value_widget.connect('changed',emit_changed)
     self.value_widget.show(); self.unit_combo.show()
     self.pack_start(self.value_widget)
     self.pack_start(self.unit_combo)
Example #3
0
    def __init__(self, default_value=inch):
        gobject.GObject.__init__(self)
        gtk.HBox.__init__(self)
        self.__quiet__ = False
        self.unit_combo = gtk.combo_box_new_text()
        for key in self.units:
            self.unit_combo.append_text(key)
        unit = get_prefs().get('default_margin_unit', _('cm'))
        if unit not in self.units: unit = _('cm')
        self.last_unit = self.units[unit]
        cb_extras.setup_typeahead(self.unit_combo)
        cb_extras.cb_set_active_text(self.unit_combo, unit)
        self.unit_combo.connect('changed', self.unit_changed_cb)
        self.value_adjustment = gtk.Adjustment(
            value=self.adjust_to_unit(default_value),
            lower=self.min_val / self.last_unit,
            upper=self.max_val / self.last_unit,
            step_incr=self.adjustments[self.last_unit][0],
            page_incr=self.adjustments[self.last_unit][1],
        )

        def emit_changed(*args):
            self.emit('changed')

        self.value_adjustment.connect('changed', emit_changed)
        self.value_widget = gtk.SpinButton(self.value_adjustment, digits=2)
        self.value_widget.connect('changed', emit_changed)
        self.value_widget.show()
        self.unit_combo.show()
        self.pack_start(self.value_widget)
        self.pack_start(self.unit_combo)
Example #4
0
    def get_nutritional_info_as_text_blob (self, rec):
        if not get_prefs().get('include_nutritional_info_in_export',True): return None
        txt = ''
        footnotes = ''
        rd = default_rec_manager()
        nd = rd.nd
        nutinfo = nd.get_nutinfo_for_inglist(rd.get_ings(rec),rd)
        ings = rd.get_ings(rec)
        vapor = nutinfo._get_vapor()
        if len(vapor)==len(ings): return None
        if len(vapor) >= 1 and not get_prefs().get('include_partial_nutritional_info',False):
            return None
        if rec.yields and rec.yield_unit:
            singular_unit = gourmet.defaults.get_pluralized_form(rec.yield_unit,1)
            txt += '<i>%s</i>'%((rec.yields and _('Nutritional information reflects amount per %s.'%singular_unit))
                                or
                                _('Nutritional information reflects amounts for entire recipe'))

        if vapor:
            txt = txt + '*'
            footnotes = '\n*' + _('Nutritional information is missing for %s ingredients: %s')%(
                len(vapor),
                ', '.join([escape(nv.__ingobject__.item) for nv in vapor])
                )
        for itm in MAIN_NUT_LAYOUT:
            if itm == SEP:
                # We don't have any nice way of outputting separator
                # lines in our export
                continue
            else:
                label,typ,name,properties,show_percent,unit = itm
                if typ==MAJOR:
                    itm_text = '<b>'+label+'</b>'
                else:
                    itm_text = label
                if unit:
                    itm_text += ' (%s)'%unit
                if type(properties) == list:
                    amts = [getattr(nutinfo,att) for att in properties]
                    amt = sum(amts)
                else:
                    amt = getattr(nutinfo,properties)
                if rec.yields:
                    amt = amt/rec.yields
                itm_text += ' %d'%round(amt)
            txt += '\n'+itm_text
        return '\n'.join([txt,footnotes])
Example #5
0
 def get_args_from_opts (self, opts):
     args = {}
     if not get_prefs().has_key('PDF_EXP'):
         get_prefs()['PDF_EXP'] = {}
     prefs = get_prefs()['PDF_EXP']
     args['pagesize'] = self.page_sizes[opts[self.OPT_PS][1]] # PAGE SIZE
     prefs['page_size'] = self.page_sizes_r[args['pagesize']]
     args['pagemode'] = self.page_modes[opts[self.OPT_PO][1]] # PAGE MODE
     prefs['orientation'] = self.page_modes_r[args['pagemode']]
     prefs['font_size'] = args['base_font_size'] = opts[self.OPT_FS][1] # FONT SIZE
     args['mode'] = self.layouts[opts[self.OPT_PL][1]] # LAYOUT/MODE
     prefs['page_layout'] = self.layouts_r[args['mode']]
     prefs['left_margin'] = args['left_margin'] = opts[self.OPT_LM][1]
     prefs['right_margin'] = args['right_margin'] = opts[self.OPT_RM][1]
     prefs['top_margin'] = args['top_margin'] = opts[self.OPT_TM][1]
     prefs['bottom_margin'] = args['bottom_margin'] = opts[self.OPT_BM][1]
     return args
Example #6
0
 def get_args_from_opts (self, opts):
     args = {}
     if not get_prefs().has_key('PDF_EXP'):
         get_prefs()['PDF_EXP'] = {}
     prefs = get_prefs()['PDF_EXP']
     args['pagesize'] = self.page_sizes[opts[self.OPT_PS][1]] # PAGE SIZE
     prefs['page_size'] = self.page_sizes_r[args['pagesize']]
     args['pagemode'] = self.page_modes[opts[self.OPT_PO][1]] # PAGE MODE
     prefs['orientation'] = self.page_modes_r[args['pagemode']]
     prefs['font_size'] = args['base_font_size'] = opts[self.OPT_FS][1] # FONT SIZE
     args['mode'] = self.layouts[opts[self.OPT_PL][1]] # LAYOUT/MODE
     prefs['page_layout'] = self.layouts_r[args['mode']]
     prefs['left_margin'] = args['left_margin'] = opts[self.OPT_LM][1]
     prefs['right_margin'] = args['right_margin'] = opts[self.OPT_RM][1]
     prefs['top_margin'] = args['top_margin'] = opts[self.OPT_TM][1]
     prefs['bottom_margin'] = args['bottom_margin'] = opts[self.OPT_BM][1]
     return args
 def __init__ (self, url):
     self.url = url
     self.prefs = get_prefs()
     self.logged_in = True
     gourmet.threadManager.SuspendableThread.__init__(
         self,
         name=_('Downloading %s'%url)
         )
    def __init__(self, *args, **kwargs):
        """
        Sets up the Evernote preference pane.
        """
        # Create main widget
        self.widget = gtk.VBox()
        self.prefs = get_prefs()

        # developer token label and help
        dtHBox = gtk.HBox()
        devTokenLabel = gtk.Label(_('Developer Token'))
        devTokenLabel.set_alignment(xalign=0, yalign=0.5)
        dtHBox.pack_start(devTokenLabel, expand=False, fill=False, padding=5)

        dtEBox = gtk.EventBox()
        dtEBox.connect("button_press_event", self.press_help, 'devkey')
        img = gtk.Image()
        img.set_from_stock(gtk.STOCK_ABOUT, gtk.ICON_SIZE_MENU)
        dtEBox.add(img)
        dtEBox.set_visible_window(False)
        dtEBox.modify_bg(gtk.STATE_NORMAL,
                         dtEBox.get_colormap().alloc_color("white"))
        dtHBox.pack_start(dtEBox, expand=False, fill=False, padding=5)
        self.widget.pack_start(dtHBox, expand=False, fill=False)

        # developer token entry
        self.devTokenEntry = gtk.Entry(max=0)
        self.devTokenEntry.set_text(self.prefs.get(PREF_DEVTOKEN, ''))
        self.devTokenEntry.connect('changed', self.save_change, PREF_DEVTOKEN)
        self.widget.pack_start(self.devTokenEntry, expand=False, fill=False)

        # Notebook label
        nbHBox = gtk.HBox()
        notebookLabel = gtk.Label(_('Shopping List Notebook'))
        notebookLabel.set_alignment(xalign=0, yalign=0.5)
        nbHBox.pack_start(notebookLabel, expand=False, fill=False, padding=5)

        nbEBox = gtk.EventBox()
        nbEBox.connect("button_press_event", self.press_help, 'notebook')
        img = gtk.Image()
        img.set_from_stock(gtk.STOCK_ABOUT, gtk.ICON_SIZE_MENU)
        nbEBox.add(img)
        nbEBox.set_visible_window(False)
        nbHBox.pack_start(nbEBox, expand=False, fill=False, padding=5)
        self.widget.pack_start(nbHBox, expand=False, fill=False)

        # Notebook entry
        self.notebookEntry = gtk.Entry(max=0)
        self.notebookEntry.set_text(
            self.prefs.get(PREF_NOTEBOOK, DEFAULT_NOTEBOOK))
        self.notebookEntry.connect('changed', self.save_change, PREF_NOTEBOOK)
        self.widget.pack_start(self.notebookEntry, expand=False, fill=False)

        # Show
        self.widget.set_border_width(12)
        self.widget.set_spacing(6)
        self.widget.show_all()
Example #9
0
    def __init__(self, ):
        self.prefs = get_prefs()
        defaults = self.prefs.get('PDF_EXP', PDF_PREF_DEFAULT)
        self.size_strings = self.page_sizes.keys()
        self.size_strings.sort()
        for n in range(2, 5):
            self.layouts[ngettext('%s Column', '%s Columns', n) %
                         n] = ('column', n)
        self.make_reverse_dicts()
        self.layout_strings = self.layouts.keys()
        self.layout_strings.sort()
        margin_widgets = [
            CustomUnitOption(defaults.get(pref, PDF_PREF_DEFAULT[pref]))
            for pref in
            ['left_margin', 'right_margin', 'top_margin', 'bottom_margin']
        ]
        # Make unit changes to one widget affect all the others!
        for m in margin_widgets:
            for mm in margin_widgets:
                if mm is not m:
                    m.sync_to_other_cuo(mm)

        self.opts = [
            [
                _('Paper _Size') + ':',
                (defaults.get('page_size', PDF_PREF_DEFAULT['page_size']),
                 self.size_strings)
            ],
            [
                _('_Orientation') + ':',
                (defaults.get('orientation', PDF_PREF_DEFAULT['orientation']),
                 self.page_modes.keys())
            ],
            [
                _('_Font Size') + ':',
                int(defaults.get('font_size', PDF_PREF_DEFAULT['font_size']))
            ],
            [
                _('Page _Layout'),
                (defaults.get('page_layout', PDF_PREF_DEFAULT['page_layout']),
                 self.layout_strings)
            ],
            [_('Left Margin') + ':', margin_widgets[0]],
            [_('Right Margin') + ':', margin_widgets[1]],
            [_('Top Margin') + ':', margin_widgets[2]],
            [_('Bottom Margin') + ':', margin_widgets[3]],
        ]

        self.page_drawer = PdfPageDrawer(yalign=0.0)
        self.in_ccb = False
        self.setup_widgets()
        self.table.connect('changed', self.change_cb)
        self.table.emit('changed')
        self.page_drawer.set_size_request(200, 100)
        self.page_drawer.show()
Example #10
0
 def unit_changed_cb (self, widget):
     new_unit = self.units[self.unit_combo.get_active_text()]
     get_prefs()['default_margin_unit'] = self.unit_combo.get_active_text()
     old_val = self.value_adjustment.get_value() * self.last_unit
     self.last_unit = self.units[self.unit_combo.get_active_text()]
     new_val = self.adjust_to_unit(old_val)
     self.value_adjustment.set_upper(self.max_val / self.last_unit)
     self.value_adjustment.set_lower(self.min_val / self.last_unit)
     self.value_adjustment.set_step_increment(self.adjustments[self.last_unit][0])
     self.value_adjustment.set_page_increment(self.adjustments[self.last_unit][1])
     self.value_adjustment.set_value(new_val)
     if not self.__quiet__:
         self.emit('changed')
Example #11
0
 def unit_changed_cb (self, widget):
     new_unit = self.units[self.unit_combo.get_active_text()]
     get_prefs()['default_margin_unit'] = self.unit_combo.get_active_text()
     old_val = self.value_adjustment.get_value() * self.last_unit
     self.last_unit = self.units[self.unit_combo.get_active_text()]
     new_val = self.adjust_to_unit(old_val)
     self.value_adjustment.set_upper(self.max_val / self.last_unit)
     self.value_adjustment.set_lower(self.min_val / self.last_unit)
     self.value_adjustment.set_step_increment(self.adjustments[self.last_unit][0])
     self.value_adjustment.set_page_increment(self.adjustments[self.last_unit][1])
     self.value_adjustment.set_value(new_val)
     if not self.__quiet__:
         self.emit('changed')
Example #12
0
 def __init__ (self, *args, **kwargs):
     # Create main widget
     self.widget = gtk.VBox()
     self.prefs = get_prefs()
     label = gtk.Label('Hello world')
     self.include_tb = gtk.CheckButton('Include nutritional information in print-outs and exports')
     self.partial_tb = gtk.CheckButton('Include partial nutritional information in print-outs and exports?')
     self.include_tb.set_active(self.prefs.get(includep,True))
     self.partial_tb.set_active(self.prefs.get(partialp,False))
     self.include_tb.connect('toggled',self.toggle_cb)
     self.partial_tb.connect('toggled',self.toggle_cb)
     self.widget.pack_start(self.include_tb, expand=False, fill=False)
     self.widget.pack_start(self.partial_tb, expand=False, fill=False)
     self.widget.set_border_width(12)
     self.widget.set_spacing(6)
     self.widget.show_all()
 def create_nutrition_window (self):
     self.nutrition_window = gtk.Dialog(_('Nutritional Information'),
                         self.pluggable.w,
                         buttons=(gtk.STOCK_CLOSE,gtk.RESPONSE_CLOSE)
                         )
     self.nutrition_window.set_default_size(400,550)
     self.nutrition_window.set_icon(
         self.nutrition_window.render_icon('nutritional-info',
                                           gtk.ICON_SIZE_MENU)
         )
     self.nl = NutritionLabel(get_prefs())
     self.sw = gtk.ScrolledWindow(); self.sw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_AUTOMATIC)
     self.sw.add_with_viewport(self.nl); self.sw.show()
     self.nutrition_window.vbox.pack_start(self.sw)
     self.nutrition_window.connect('response',self.response_cb)
     self.nutrition_window.connect('close',self.response_cb)
     self.nl.yieldLabel.set_markup('<b>'+_('Amount for Shopping List')+'</b>')
     self.nl.show()
Example #14
0
 def create_nutrition_window (self):
     self.nutrition_window = gtk.Dialog(_('Nutritional Information'),
                         self.pluggable.w,
                         buttons=(gtk.STOCK_CLOSE,gtk.RESPONSE_CLOSE)
                         )
     self.nutrition_window.set_default_size(400,550)
     self.nutrition_window.set_icon(
         self.nutrition_window.render_icon('nutritional-info',
                                           gtk.ICON_SIZE_MENU)
         )
     self.nl = NutritionLabel(get_prefs())
     self.sw = gtk.ScrolledWindow(); self.sw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_AUTOMATIC)
     self.sw.add_with_viewport(self.nl); self.sw.show()
     self.nutrition_window.vbox.pack_start(self.sw)
     self.nutrition_window.connect('response',self.response_cb)
     self.nutrition_window.connect('close',self.response_cb)
     self.nl.yieldLabel.set_markup('<b>'+_('Amount for Shopping List')+'</b>')
     self.nl.show()
Example #15
0
    def __init__ (self,):
        self.prefs = get_prefs()
        defaults = self.prefs.get('PDF_EXP',PDF_PREF_DEFAULT)
        self.size_strings = self.page_sizes.keys()
        self.size_strings.sort()
        for n in range(2,5):
            self.layouts[ngettext('%s Column','%s Columns',n)%n]=('column',n)
        self.make_reverse_dicts()        
        self.layout_strings = self.layouts.keys()
        self.layout_strings.sort()
        margin_widgets = [
            CustomUnitOption(defaults.get(pref,PDF_PREF_DEFAULT[pref]))
            for pref in ['left_margin','right_margin','top_margin','bottom_margin']
            ]
        # Make unit changes to one widget affect all the others!
        for m in margin_widgets:
            for mm in margin_widgets:
                if mm is not m:
                    m.sync_to_other_cuo(mm)
            
        self.opts = [
            [_('Paper _Size')+':',(defaults.get('page_size',PDF_PREF_DEFAULT['page_size']),
                                  self.size_strings)],
            [_('_Orientation')+':',(defaults.get('orientation',PDF_PREF_DEFAULT['orientation']),
                                    self.page_modes.keys())],
            [_('_Font Size')+':',int(defaults.get('font_size',PDF_PREF_DEFAULT['font_size']))]
            ,
            [_('Page _Layout'),(defaults.get('page_layout',PDF_PREF_DEFAULT['page_layout']),

                                self.layout_strings)],
            [_('Left Margin')+':',margin_widgets[0]],
            [_('Right Margin')+':',margin_widgets[1]],
            [_('Top Margin')+':',margin_widgets[2]],
            [_('Bottom Margin')+':',margin_widgets[3]],
            ]
        
        self.page_drawer = PdfPageDrawer(yalign=0.0)    
        self.in_ccb = False
        self.setup_widgets()
        self.table.connect('changed',self.change_cb)
        self.table.emit('changed')
        self.page_drawer.set_size_request(200,100)
        self.page_drawer.show()
Example #16
0
 def create_nutrition_window(self):
     self.nutrition_window = Gtk.Dialog(_('Nutritional Information'),
                                        self.pluggable.w,
                                        buttons=(Gtk.STOCK_CLOSE,
                                                 Gtk.ResponseType.CLOSE))
     self.nutrition_window.set_default_size(400, 550)
     self.nutrition_window.set_icon(
         self.nutrition_window.render_icon('nutritional-info',
                                           Gtk.IconSize.MENU))
     self.nl = NutritionLabel(get_prefs())
     self.sw = Gtk.ScrolledWindow()
     self.sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
     self.sw.add_with_viewport(self.nl)
     self.sw.show()
     self.nutrition_window.vbox.pack_start(self.sw, True, True, 0)
     self.nutrition_window.connect('response', self.response_cb)
     self.nutrition_window.connect('close', self.response_cb)
     self.nl.yieldLabel.set_markup('<b>' + _('Amount for Shopping List') +
                                   '</b>')
     self.nl.show()
    def save_as_evernote(self, *args):
        """
        Build and post the shopping list to evernote.  If there are
        any failures and dialog box will be created to infrom the user.

        @raises EDAMUserException: Authentication failure posting to
                EverNote or a non-configuration related EDAMUserException.
        @raises Exception: Any other error is generating during posting.

        The errors get caught by gourmet and printed to the console, so we
        allow them propagate up, up the user has already been informed
        via dialog message.
        """
        prefs = get_prefs()
        if not prefs.get(PREF_DEVTOKEN, None) or not prefs.get(PREF_NOTEBOOK, DEFAULT_NOTEBOOK):
            # No token provided, abort
            self.error_dialog(_("The Evernote Key and Notebook must be set in Preferences."))

        # build evernote formatted shopping list.
        note = self.build_note()
        self.send_to_evernote(note, prefs)
Example #18
0
 def get_amount_and_unit_hook (self, db, *args, **kwargs):
     kwargs['preferred_unit_groups'] = get_prefs().get('preferred_unit_groups',[])
     return args,kwargs
Example #19
0
 def __init__(self, reccards):
     self.reccards = reccards
     self.prefs = get_prefs()
Example #20
0
 def remove(self):
     get_prefs()['utf-16'] = False
Example #21
0
 def activate(self, pluggable):
     get_prefs()['utf-16'] = True
Example #22
0
 def __init__ (self):
     BaseExporterPlugin.__init__(self)
     if get_prefs().get('include_nutritional_info_in_export',True):
         self.add_field('Nutritional Information',
                        self.get_nutritional_info_as_text_blob,
                        self.TEXT)
Example #23
0
 def __init__(self, url):
     self.url = url
     self.prefs = get_prefs()
     self.logged_in = True
     gourmet.threadManager.SuspendableThread.__init__(
         self, name=_('Downloading %s' % url))
Example #24
0
 def activate (self, pluggable):
     get_prefs()['utf-16'] = True
Example #25
0
 def remove (self):
     get_prefs()['utf-16'] = False
Example #26
0
 def __init__ (self, reccards):
     self.reccards = reccards
     self.prefs = get_prefs()
Example #27
0
 def __init__ (self):
     BaseExporterPlugin.__init__(self)
     if get_prefs().get('include_nutritional_info_in_export',True):
         self.add_field('Nutritional Information',
                        self.get_nutritional_info_as_text_blob,
                        self.TEXT)