예제 #1
0
 def finish_web_import (self, reader):
     # Filter by mimetype...
     if reader.content_type:
         base_content_type=reader.content_type.split(';')[0]
         possible_plugins = [p for p in self.importer_plugins if base_content_type in p.mimetypes]
     else:
         possible_plugins = self.importer_plugins
     fallback = None; plugin = None
     for p in possible_plugins:
         result = p.test_url(reader.url,reader.data,reader.content_type)
         if result == -1:
             fallback = p
         elif result:
             plugin = p
             break
     if not plugin:
         plugin = fallback
     if not plugin:
         de.show_message(
             title=_('Unable to import URL'),
             label=_('Gourmet does not have a plugin capable of importing URL'),
             sublabel=_('Unable to import URL %(url)s of mimetype %(type)s. File saved to temporary location %(fn)s')%{
             'url':reader.url,
             'type':reader.content_type or 'Unknown',
             'fn':self.get_tempfilename(reader.url,reader.data,reader.content_type)
             },
             )
     else:
         print('Doing import of',reader.url,plugin)
         self.do_import(plugin, 'get_web_importer', reader.url,
                        reader.data.decode(), reader.content_type)
예제 #2
0
    def offer_single_export (self, rec, prefs, mult=1, parent=None):
        """Offer to export a single file.

        Return the filename if we have in fact exported said file.
        """
        default_extension = prefs.get('save_recipe_as','html')
        # strip the period if one ended up on our default extension
        if default_extension and default_extension[0]=='.':
            default_extension = default_extension[1:]
        exp_directory = prefs.get('rec_exp_directory',
                                  get_user_special_dir(USER_DIRECTORY_DOCUMENTS)
                                  )
        filename,exp_type = de.saveas_file(_('Save recipe as...'),
                                           filename='%s%s%s%s%s'%(exp_directory,
                                                                  os.path.sep,
                                                                  rec.title,
                                                                  os.path.extsep,
                                                                  default_extension),
                                           filters=self.get_single_filters(),
                                           parent=parent
                                           )
        if not filename: return
        if not exp_type or not self.can_export_type(exp_type):
            de.show_message(label=_('Gourmet cannot export file of type "%s"')%os.path.splitext(filename)[1])
            return
        return self.do_single_export(rec, filename, exp_type, mult)
예제 #3
0
 def show_traceback(self, button, errno, errname, traceback):
     import gourmet.gtk_extras.dialog_extras as de
     de.show_message(
         label=_('Error'),
         sublabel=_('Error %s: %s') % (errno, errname),
         expander=(_('Traceback'), traceback),
     )
예제 #4
0
    def offer_single_export(self, rec, prefs, mult=1, parent=None):
        """Offer to export a single file.

        Return the filename if we have in fact exported said file.
        """
        default_extension = prefs.get('save_recipe_as', 'html')
        # strip the period if one ended up on our default extension
        if default_extension and default_extension[0] == '.':
            default_extension = default_extension[1:]
        exp_directory = prefs.get(
            'rec_exp_directory',
            get_user_special_dir(USER_DIRECTORY_DOCUMENTS))
        filename, exp_type = de.saveas_file(
            _('Save recipe as...'),
            filename='%s%s%s%s%s' % (exp_directory, os.path.sep, rec.title,
                                     os.path.extsep, default_extension),
            filters=self.get_single_filters(),
            parent=parent)
        if not filename: return
        if not exp_type or not self.can_export_type(exp_type):
            de.show_message(
                label=_('Gourmet cannot export file of type "%s"') %
                os.path.splitext(filename)[1])
            return
        return self.do_single_export(rec, filename, exp_type, mult)
예제 #5
0
 def finish_web_import (self, reader):
     # Filter by mimetype...
     if reader.content_type:
         base_content_type=reader.content_type.split(';')[0]
         possible_plugins = filter(
             lambda p: base_content_type in p.mimetypes,
             self.importer_plugins)
     else:
         possible_plugins = self.importer_plugins
     fallback = None; plugin = None
     for p in possible_plugins:
         result = p.test_url(reader.url,reader.data,reader.content_type)
         if result == -1:
             fallback = p
         elif result:
             plugin = p
             break
     if not plugin:
         plugin = fallback
     if not plugin:
         de.show_message(
             title=_('Unable to import URL'),
             label=_('Gourmet does not have a plugin capable of importing URL'),
             sublabel=_('Unable to import URL %(url)s of mimetype %(type)s. File saved to temporary location %(fn)s')%{
             'url':reader.url,
             'type':reader.content_type or 'Unknown',
             'fn':self.get_tempfilename(reader.url,reader.data,reader.content_type)
             },
             )
     else:
         print 'Doing import of',reader.url,plugin
         self.do_import(plugin,'get_web_importer',reader.url,reader.data,reader.content_type)
예제 #6
0
 def __init__ (self, *args, **kwargs):
     from gourmet.gtk_extras.dialog_extras import show_message
     show_message(
         label=_('Unable to print: no print plugins are active!'),
         sublabel=_("To print, activate a plugin that provides printing support, such as the 'Printing & PDF export' plugin."),
         )
     raise NotImplementedError
예제 #7
0
파일: printer.py 프로젝트: tmccombs/gourmet
 def __init__ (self, *args, **kwargs):
     from gourmet.gtk_extras.dialog_extras import show_message
     show_message(
         label=_('Unable to print: no print plugins are active!'),
         sublabel=_("To print, activate a plugin that provides printing support, such as the 'Printing & PDF export' plugin."),
         )
     raise NotImplementedError        
예제 #8
0
    def offer_multiple_export(self, recs, prefs, parent=None, prog=None):
        """Offer user a chance to export multiple recipes at once.

        Return the exporter class capable of doing this and a
        dictionary of arguments for the progress dialog.
        """
        if len(recs) < 950:
            # inelegantly avoid bug that happens when this code runs
            # on large numbers of recipes. The good news is that this
            # that that will almost only ever happen when we're
            # exporting all recipes, which makes this code irrelevant
            # anyway.
            self.app.rd.include_linked_recipes(recs)
        ext = prefs.get("save_recipes_as", "%sxml" % os.path.extsep)
        exp_directory = prefs.get("rec_exp_directory", get_user_special_dir(USER_DIRECTORY_DOCUMENTS))
        fn, exp_type = de.saveas_file(
            _("Export recipes"),
            filename="%s%s%s%s" % (exp_directory, os.path.sep, _("recipes"), ext),
            parent=parent,
            filters=self.get_multiple_filters(),
        )
        if fn:
            prefs["rec_exp_directory"] = os.path.split(fn)[0]
            prefs["save_recipes_as"] = os.path.splitext(fn)[1]
            instance = self.do_multiple_export(recs, fn, exp_type)
            if not instance:
                de.show_message(
                    okay=gtk.STOCK_CLOSE,
                    cancel=False,
                    label=_('Unable to export: unknown filetype "%s"' % fn),
                    sublabel=_("Please make sure to select a filetype from the dropdown menu when saving."),
                    message_type=gtk.MESSAGE_ERROR,
                )
                return
            return instance
예제 #9
0
 def set_document(self, filename, operation, context):
     try:
         from subprocess import Popen
         import _winreg
         regPathKey = _winreg.OpenKey(
             _winreg.HKEY_LOCAL_MACHINE,
             "Software\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe"
         )
         regPathValue, regPathType = _winreg.QueryValueEx(regPathKey, "")
         if regPathType != _winreg.REG_SZ:
             raise TypeError
     except:
         from gourmet.gtk_extras.dialog_extras import show_message
         show_message(
             label=_("Could not find Adobe Reader on your system."),
             sublabel=_(
                 "This version of Gourmet Recipe Manager "
                 "requires Adobe Reader "
                 "to be able to print; other PDF viewers will not work.\n"
                 "Please install Adobe Reader from http://get.adobe.com/reader/. \n"
                 "Alternatively, export your recipe(s) to PDF "
                 "and print it with another PDF viewer."))
     else:
         # Launch a new instance (/n) of Adobe Reader with our temporary
         # PDF to display the print dialog (/p).
         Popen(regPathValue + " /n /p " + os.path.realpath(filename))
예제 #10
0
    def offer_multiple_export (self, recs, prefs, parent=None, prog=None):
        """Offer user a chance to export multiple recipes at once.

        Return the exporter class capable of doing this and a
        dictionary of arguments for the progress dialog.
        """
        self.app.rd.include_linked_recipes(recs)
        ext = prefs.get('save_recipes_as','%sxml'%os.path.extsep)
        exp_directory = prefs.get('rec_exp_directory','~')
        fn,exp_type=de.saveas_file(_("Export recipes"),
                                     filename="%s/%s%s"%(exp_directory,_('recipes'),ext),
                                     parent=parent,
                                     filters=self.get_multiple_filters())
        if fn:
            prefs['rec_exp_directory']=os.path.split(fn)[0]
            prefs['save_recipes_as']=os.path.splitext(fn)[1]
            instance = self.do_multiple_export(recs, fn, exp_type)
            if not instance:
                de.show_message(
                    okay=gtk.STOCK_CLOSE,
                    cancel=False,
                    label=_('Unable to export: unknown filetype "%s"'%fn),
                    sublabel=_('Please make sure to select a filetype from the dropdown menu when saving.'),
                    message_type=gtk.MESSAGE_ERROR,
                    )
                return
            import gourmet.GourmetRecipeManager
            main_app =  gourmet.GourmetRecipeManager.get_application()
            print 'Connect',instance,'to show dialog when done'
            instance.connect('completed',
                             lambda *args: main_app.offer_url('Export complete!',
                                                              'Recipes exported to %s'%fn,
                                                              url='file:///%s'%fn))
            return instance
예제 #11
0
 def finish_web_import(self, reader):
     # Filter by mimetype...
     if reader.content_type:
         base_content_type = reader.content_type.split(";")[0]
         possible_plugins = filter(lambda p: base_content_type in p.mimetypes, self.importer_plugins)
     else:
         possible_plugins = self.importer_plugins
     fallback = None
     plugin = None
     for p in possible_plugins:
         result = p.test_url(reader.url, reader.data, reader.content_type)
         if result == -1:
             fallback = p
         elif result:
             plugin = p
             break
     if not plugin:
         plugin = fallback
     if not plugin:
         de.show_message(
             title=_("Unable to import URL"),
             label=_("Gourmet does not have a plugin capable of importing URL"),
             sublabel=_("Unable to import URL %(url)s of mimetype %(type)s. File saved to temporary location %(fn)s")
             % {
                 "url": reader.url,
                 "type": reader.content_type or "Unknown",
                 "fn": self.get_tempfilename(reader.url, reader.data, reader.content_type),
             },
         )
     else:
         print "Doing import of", reader.url, plugin
         self.do_import(plugin, "get_web_importer", reader.url, reader.data, reader.content_type)
예제 #12
0
 def do_run (self):
     if os.path.getsize(self.filename) > MAX_PLAINTEXT_LENGTH*16:
         del data
         import gourmet.gtk_extras.dialog_extras as de
         de.show_message(title=_('Big File'),
                         label=_('File %s is too big to import'%self.filename),
                         sublabel=_('Your file exceeds the maximum length of %s characters. You probably didn\'t mean to import it anyway. If you really do want to import this file, use a text editor to split it into smaller files and try importing again.')%MAX_PLAINTEXT_LENGTH,
                         message_type=Gtk.MessageType.ERROR)
         return
     with open(self.filename, 'rb') as ifi:
         data = '\n'.join(check_encodings.get_file(ifi))
     self.set_text(data)
     return InteractiveImporter.do_run(self)
예제 #13
0
 def email (self, address=None):
     if address: self.emailaddress=address
     if self.email_options['email_include_body']:
         self.write_email_text()
     if self.email_options['email_include_html']:
         self.write_email_html()
     if self.email_options['email_include_pdf']:
         self.write_email_pdf()
     if not self.email_options['email_include_body'] and not self.email_options['email_include_body']:
         de.show_message(_("E-mail not sent"),
                         sublabel=_("You have not chosen to include the recipe in the body of the message or as an attachment.")
                         )
     else:
         self.send_email()
예제 #14
0
 def do_run (self):
     if os.path.getsize(self.filename) > MAX_PLAINTEXT_LENGTH*16:
         del data
         ifi.close()
         import gourmet.gtk_extras.dialog_extras as de
         de.show_message(title=_('Big File'),
                         label=_('File %s is too big to import'%self.filename),
                         sublabel=_('Your file exceeds the maximum length of %s characters. You probably didn\'t mean to import it anyway. If you really do want to import this file, use a text editor to split it into smaller files and try importing again.')%MAX_PLAINTEXT_LENGTH,
                         message_type=gtk.MESSAGE_ERROR)
         return
     ifi = file(self.filename,'r')
     data = '\n'.join(check_encodings.get_file(ifi))
     ifi.close()
     self.set_text(data)
     return InteractiveImporter.do_run(self)
예제 #15
0
    def offer_multiple_export(self, recs, prefs, parent=None, prog=None):
        """Offer user a chance to export multiple recipes at once.

        Return the exporter class capable of doing this and a
        dictionary of arguments for the progress dialog.
        """
        if len(recs) < 950:
            # inelegantly avoid bug that happens when this code runs
            # on large numbers of recipes. The good news is that this
            # that that will almost only ever happen when we're
            # exporting all recipes, which makes this code irrelevant
            # anyway.
            self.app.rd.include_linked_recipes(recs)
        ext = prefs.get('save_recipes_as', '%sxml' % os.path.extsep)
        exp_directory = prefs.get(
            'rec_exp_directory',
            get_user_special_dir(USER_DIRECTORY_DOCUMENTS))
        fn, exp_type = de.saveas_file(
            _("Export recipes"),
            filename="%s%s%s%s" %
            (exp_directory, os.path.sep, _('recipes'), ext),
            parent=parent,
            filters=self.get_multiple_filters())
        if fn:
            prefs['rec_exp_directory'] = os.path.split(fn)[0]
            prefs['save_recipes_as'] = os.path.splitext(fn)[1]
            instance = self.do_multiple_export(recs, fn, exp_type)
            if not instance:
                de.show_message(
                    okay=gtk.STOCK_CLOSE,
                    cancel=False,
                    label=_('Unable to export: unknown filetype "%s"' % fn),
                    sublabel=
                    _('Please make sure to select a filetype from the dropdown menu when saving.'
                      ),
                    message_type=gtk.MESSAGE_ERROR,
                )
                return
            import gourmet.GourmetRecipeManager
            main_app = gourmet.GourmetRecipeManager.get_application()
            print 'Connect', instance, 'to show dialog when done'
            instance.connect(
                'completed',
                lambda *args: main_app.offer_url('Export complete!',
                                                 'Recipes exported to %s' % fn,
                                                 url='file:///%s' % fn))
            return instance
예제 #16
0
    def offer_multiple_export (self, recs, prefs, parent=None, prog=None):
        """Offer user a chance to export multiple recipes at once.

        Return the exporter class capable of doing this and a
        dictionary of arguments for the progress dialog.
        """
        if len(recs) < 950:
            # inelegantly avoid bug that happens when this code runs
            # on large numbers of recipes. The good news is that this
            # that that will almost only ever happen when we're
            # exporting all recipes, which makes this code irrelevant
            # anyway.
            self.app.rd.include_linked_recipes(recs)
        ext = prefs.get('save_recipes_as','%sxml'%os.path.extsep)
        exp_directory = prefs.get('rec_exp_directory',
                                  get_user_special_dir(USER_DIRECTORY_DOCUMENTS)
                                  )
        fn,exp_type=de.saveas_file(_("Export recipes"),
                                     filename="%s%s%s%s"%(exp_directory,
                                                          os.path.sep,
                                                          _('recipes'),
                                                          ext),
                                     parent=parent,
                                     filters=self.get_multiple_filters())
        if fn:
            prefs['rec_exp_directory']=os.path.split(fn)[0]
            prefs['save_recipes_as']=os.path.splitext(fn)[1]
            instance = self.do_multiple_export(recs, fn, exp_type)
            if not instance:
                de.show_message(
                    okay=gtk.STOCK_CLOSE,
                    cancel=False,
                    label=_('Unable to export: unknown filetype "%s"'%fn),
                    sublabel=_('Please make sure to select a filetype from the dropdown menu when saving.'),
                    message_type=gtk.MESSAGE_ERROR,
                    )
                return
            import gourmet.GourmetRecipeManager
            main_app =  gourmet.GourmetRecipeManager.get_application()
            print 'Connect',instance,'to show dialog when done'
            instance.connect('completed',
                             lambda *args: main_app.offer_url('Export complete!',
                                                              'Recipes exported to %s'%fn,
                                                              url='file:///%s'%fn))
            return instance
예제 #17
0
 def email(self, address=None):
     if address: self.emailaddress = address
     if self.email_options['email_include_body']:
         self.write_email_text()
     if self.email_options['email_include_html']:
         self.write_email_html()
     if self.email_options['email_include_pdf']:
         self.write_email_pdf()
     if not self.email_options[
             'email_include_body'] and not self.email_options[
                 'email_include_body']:
         de.show_message(
             _("E-mail not sent"),
             sublabel=
             _("You have not chosen to include the recipe in the body of the message or as an attachment."
               ))
     else:
         self.send_email()
예제 #18
0
    def offer_multiple_export(self,
                              recs,
                              prefs,
                              parent=None,
                              prog=None,
                              export_all=False):
        """Offer user a chance to export multiple recipes at once.

        Return the exporter class capable of doing this and a
        dictionary of arguments for the progress dialog.
        """
        if (not export_all) or (len(recs) < 950):
            # inelegantly avoid bug that happens when this code runs
            # on large numbers of recipes. The good news is that this
            # that that will almost only ever happen when we're
            # exporting all recipes, which makes this code irrelevant
            # anyway.
            self.app.rd.include_linked_recipes(recs)
        ext = prefs.get('save_recipes_as', '%sxml' % os.path.extsep)
        exp_directory = prefs.get(
            'rec_exp_directory',
            get_user_special_dir(USER_DIRECTORY_DOCUMENTS))
        fn, exp_type = de.saveas_file(
            _("Export recipes"),
            filename="%s%s%s%s" %
            (exp_directory, os.path.sep, _('recipes'), ext),
            parent=parent,
            filters=self.get_multiple_filters())
        if fn:
            prefs['rec_exp_directory'] = os.path.split(fn)[0]
            prefs['save_recipes_as'] = os.path.splitext(fn)[1]
            instance = self.do_multiple_export(recs, fn, exp_type)
            if not instance:
                de.show_message(
                    okay=Gtk.STOCK_CLOSE,
                    cancel=False,
                    label=_('Unable to export: unknown filetype "%s"' % fn),
                    sublabel=
                    _('Please make sure to select a filetype from the dropdown menu when saving.'
                      ),
                    message_type=Gtk.MessageType.ERROR,
                )
                return
            return instance
예제 #19
0
 def apply_cb (self, *args):
     page = self.notebook.get_current_page()
     if page == self.NUT_PAGE:
         self.apply_nut_equivalent()
         self.check_next_amount()
     elif page == self.UNIT_PAGE:
         self.apply_amt_convert()
         # if out of amounts, this will move to the next ingredient
         self.check_next_amount()
     elif page == self.CUSTOM_PAGE:
         if not self.custom_factor:
             de.show_message(_("To apply nutritional information, Gourmet needs a valid amount and unit."))
             return
         self.apply_custom()
         self.check_next_amount()
     elif page == self.DENSITY_PAGE:
         self.apply_density()
         self.check_next_amount()
     self.curpage += 1
     self.prevDruidButton.set_sensitive(True)
예제 #20
0
 def apply_cb (self, *args):
     page = self.notebook.get_current_page()
     if page == self.NUT_PAGE:
         self.apply_nut_equivalent()
         self.check_next_amount()
     elif page == self.UNIT_PAGE:
         self.apply_amt_convert()
         # if out of amounts, this will move to the next ingredient
         self.check_next_amount()
     elif page == self.CUSTOM_PAGE:
         if not self.custom_factor:
             de.show_message(_("To apply nutritional information, Gourmet needs a valid amount and unit."))
             return
         self.apply_custom()
         self.check_next_amount()
     elif page == self.DENSITY_PAGE:
         self.apply_density()
         self.check_next_amount()
     self.curpage += 1
     self.prevDruidButton.set_sensitive(True)
예제 #21
0
 def set_document (self, filename, operation,context):
     try:
         from subprocess import Popen
         import _winreg
         regPathKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
                                      "Software\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe")
         regPathValue, regPathType = _winreg.QueryValueEx(regPathKey, "")
         if regPathType != _winreg.REG_SZ:
             raise TypeError
     except:
         from gourmet.gtk_extras.dialog_extras import show_message
         show_message(label=_("Could not find Adobe Reader on your system."),
                      sublabel=_("This version of Gourmet Recipe Manager "
                      "requires Adobe Reader "
                      "to be able to print; other PDF viewers will not work.\n"
                      "Please install Adobe Reader from http://get.adobe.com/reader/. \n"
                      "Alternatively, export your recipe(s) to PDF "
                      "and print it with another PDF viewer."))
     else:
         # Launch a new instance (/n) of Adobe Reader with our temporary
         # PDF to display the print dialog (/p).
         Popen(regPathValue + " /n /p " + os.path.realpath(filename))
예제 #22
0
파일: printer.py 프로젝트: eginhard/gourmet
 def __init__(self, *args, **kwargs):
     from gourmet.gtk_extras.dialog_extras import show_message
     show_message(label=_('Unable to print: no print plugins are active!'),
                  sublabel=_(ERR_NO_PLUGIN_MSG))
     raise NotImplementedError
예제 #23
0
파일: printer.py 프로젝트: tmccombs/gourmet
 def show_error (self, *args):
     from gourmet.gtk_extras.dialog_extras import show_message
     show_message(sublabel='There was an error printing. Apologies')
예제 #24
0
파일: printer.py 프로젝트: Zanthess/gourmet
    def show_error(self, *args):
        from gourmet.gtk_extras.dialog_extras import show_message

        show_message(sublabel="There was an error printing. Apologies")
예제 #25
0
 def show_traceback (self, button, errno, errname, traceback):
     import gourmet.gtk_extras.dialog_extras as de
     de.show_message(label=_('Error'),
                     sublabel=_('Error %s: %s')%(errno,errname),
                     expander=(_('Traceback'),traceback),
                     )
예제 #26
0
파일: printer.py 프로젝트: eginhard/gourmet
 def show_error(self, *args):
     show_message(sublabel='There was an error printing. Apologies')
예제 #27
0
 def show_traceback(self, button: Gtk.Button, errno: int, errname: str,
                    traceback: str):
     show_message(label=_('Error'),
                  sublabel=_('Error %s: %s') % (errno, errname),
                  expander=(_('Traceback'), traceback))