~vorlon/ubuntu/saucy/gourmet/trunk

« back to all changes in this revision

Viewing changes to src/lib/exporters/exportManager.py

  • Committer: Bazaar Package Importer
  • Author(s): Rolf Leggewie
  • Date: 2009-02-10 17:34:51 UTC
  • mfrom: (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090210173451-bt0a6j0ut71oxqes
Tags: 0.14.5-1
* new upstream release
* 0.14.5 no longer conflicts with newer versions of python-pysqlite and
  python-sqlalchemy.  Relax dependencies accordingly.
* all patches have been pushed upstream, so they can be dropped in Debian.
  The manpage was forgotten when preparing the tarball upstream, so it
  will stick around for another release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
from gourmet.threadManager import get_thread_manager, get_thread_manager_gui
5
5
import os.path
6
6
 
 
7
EXTRA_PREFS_AUTOMATIC = -1
 
8
EXTRA_PREFS_DEFAULT = 0
 
9
 
7
10
class ExportManager (plugin_loader.Pluggable):
8
11
 
9
12
    '''A class to manage exporters.
39
42
                                           )
40
43
        if not filename: return
41
44
        if not exp_type or not self.can_export_type(exp_type):
42
 
            de.show_message(label=_('Gourmet cannot export file of type "%s"')%os.path.splitext(fn)[1])
 
45
            de.show_message(label=_('Gourmet cannot export file of type "%s"')%os.path.splitext(filename)[1])
43
46
            return
 
47
        return self.do_single_export(rec, filename, exp_type, mult)
 
48
        
 
49
    def do_single_export (self, rec, filename, exp_type, mult=1):
44
50
        exporter_plugin = self.get_exporter(exp_type)
45
51
        extra_prefs = exporter_plugin.run_extra_prefs_dialog() or {}
46
52
        if hasattr(exporter_plugin,'mode'):
69
75
                           _('Recipe exported to %s')%filename,
70
76
                           url='file:///%s'%filename)
71
77
        return filename
72
 
    
73
78
 
74
79
    def offer_multiple_export (self, recs, prefs, parent=None, prog=None):
75
80
        """Offer user a chance to export multiple recipes at once.
88
93
        if fn:
89
94
            prefs['rec_exp_directory']=os.path.split(fn)[0]
90
95
            prefs['save_recipes_as']=os.path.splitext(fn)[1]
91
 
            expClass=None
92
 
            if self.can_export_type(exp_type):
93
 
                myexp = self.get_exporter(exp_type)
 
96
            instance = self.do_multiple_export(recs, fn, exp_type)
 
97
            import gourmet.GourmetRecipeManager
 
98
            main_app =  gourmet.GourmetRecipeManager.get_application()
 
99
            print 'Connect',instance,'to show dialog when done'
 
100
            instance.connect('completed',
 
101
                             lambda *args: main_app.offer_url('Export complete!',
 
102
                                                              'Recipes exported to %s'%fn,
 
103
                                                              url='file:///%s'%fn))
 
104
 
 
105
    def do_multiple_export (self, recs, fn, exp_type=None,
 
106
                                           setup_gui=True, extra_prefs=EXTRA_PREFS_AUTOMATIC):
 
107
        if not exp_type:
 
108
            exp_type = de.get_type_for_filters(fn,self.get_multiple_filters())
 
109
        if self.can_export_type(exp_type):
 
110
            myexp = self.get_exporter(exp_type)
 
111
            if extra_prefs == EXTRA_PREFS_AUTOMATIC:
94
112
                extra_prefs = myexp.run_extra_prefs_dialog() or {}
95
 
                pd_args={'label':myexp.label,'sublabel':myexp.sublabel%{'file':fn}}
96
 
                print 'exporting',len(recs),'recs'
97
 
                exporterInstance = myexp.get_multiple_exporter({'rd':self.app.rd,
98
 
                                                             'rv': recs,
99
 
                                                             'conv':self.app.conv,
100
 
                                                             'prog':prog,
101
 
                                                             'file':fn,
102
 
                                                             'extra_prefs':extra_prefs,
103
 
                                                             })
104
 
                import gourmet.GourmetRecipeManager
105
 
                main_app =  gourmet.GourmetRecipeManager.get_application()
106
 
                tm = get_thread_manager()
 
113
            elif extra_prefs == EXTRA_PREFS_DEFAULT:
 
114
                extra_prefs = myexp.get_default_prefs()
 
115
            else:
 
116
                extra_prefs = extra_prefs
 
117
            pd_args={'label':myexp.label,'sublabel':myexp.sublabel%{'file':fn}}
 
118
            exporterInstance = myexp.get_multiple_exporter({'rd':self.app.rd,
 
119
                                                         'rv': recs,
 
120
                                                            #'conv':self.app.conv,
 
121
                                                            #'prog':,
 
122
                                                         'file':fn,
 
123
                                                         'extra_prefs':extra_prefs,
 
124
                                                         })
 
125
            tm = get_thread_manager()
 
126
            tm.add_thread(exporterInstance)
 
127
            if setup_gui:
107
128
                tmg = get_thread_manager_gui()
108
 
                tm.add_thread(exporterInstance)
109
129
                tmg.register_thread_with_dialog(_('Export')+'('+myexp.label+')',exporterInstance)
110
130
                tmg.show()
111
 
                exporterInstance.connect('completed',
112
 
                                         lambda *args: main_app.offer_url('Export complete!',
113
 
                                                                          'Recipes exported to %s'%fn,
114
 
                                                                          url='file:///%s'%fn))
115
 
                
 
131
            print 'Return exporter instance'
 
132
            return exporterInstance  
116
133
 
117
134
    def can_export_type (self, name): return self.plugins_by_name.has_key(name)
118
135