1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# Copyright (C) 2009 Lars Wirzenius <liw@liw.fi>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This is necessary for running under Python 2.5, which we need to
# do on Debian, for now.
from __future__ import with_statement
import os
import shutil
import gtk
import dimbola
class ExportOriginal(dimbola.BackgroundJob):
def __init__(self, mwc, photoid, dirname):
self.dirname = dirname
with mwc.db:
folderid, basename, c, d = mwc.db.get_basic_photo_metadata(photoid)
self.foldername = mwc.db.get_folder_name(folderid)
self.basename = basename
def run(self):
status = dimbola.BackgroundStatus('start',
'Exporting %s' % self.basename)
self.send_status(status)
shutil.copy(os.path.join(self.foldername, self.basename),
os.path.join(self.dirname, self.basename))
return dimbola.BackgroundStatus('stop', 'Exported %s' % self.basename)
class ExportJpeg(dimbola.BackgroundJob):
def __init__(self, mwc, photoid, dirname):
self.dirname = dirname
self.basename = 'foo'
with mwc.db:
self.preview = str(mwc.db.get_preview(photoid))
a, basename, c, rotate = mwc.db.get_basic_photo_metadata(photoid)
self.basename = basename
self.rotate = rotate
def run(self):
pixbuf = dimbola.image_data_to_pixbuf(self.preview)
pixbuf = dimbola.rotate_pixbuf(pixbuf, self.rotate)
basename, ext = os.path.splitext(self.basename)
new_basename = basename + '.jpg'
pixbuf.save(os.path.join(self.dirname, new_basename), "jpeg")
return dimbola.BackgroundStatus('stop', 'Exported %s' % new_basename)
class ExportFiles(dimbola.Plugin):
'''Export selected files using background jobs.'''
def __init__(self, mwc):
self.mwc = mwc
def enable(self):
self.mwc.add_to_menu('file_menu', 'export_menuitem',
'Export selected photos')
def disable(self):
self.mwc.remove_from_menu('file_menu', 'export_menuitem')
def on_export_menuitem_activate(self, menuitem):
chooser = self.mwc.widgets['export_filechooser']
chooser.set_transient_for(self.mwc.widgets['window'])
chooser.show()
response = chooser.run()
chooser.hide()
if response == gtk.RESPONSE_OK:
dirname = chooser.get_filenames()[0]
origs = self.mwc.widgets['export_original_radiobutton'].get_active()
selected = self.mwc.grid.model.selected
for photoid in selected:
if origs:
job = ExportOriginal(self.mwc, photoid, dirname)
else:
job = ExportJpeg(self.mwc, photoid, dirname)
self.mwc.add_bgjob(job)
def export_menuitem_is_sensitive(self):
return self.mwc.grid.model.selected
|