示例#1
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)
示例#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 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
示例#4
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
示例#5
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
示例#6
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
示例#7
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