diff options
Diffstat (limited to 'trunk/dimbola/plugins/gimp_plugin.py')
-rw-r--r-- | trunk/dimbola/plugins/gimp_plugin.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/trunk/dimbola/plugins/gimp_plugin.py b/trunk/dimbola/plugins/gimp_plugin.py new file mode 100644 index 0000000..8653f98 --- /dev/null +++ b/trunk/dimbola/plugins/gimp_plugin.py @@ -0,0 +1,76 @@ +# 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 subprocess +import tempfile + +import dimbola + + +class ConvertToPNGAndGimpIt(dimbola.BackgroundJob): + + def __init__(self, mwc, photoid): + with mwc.db: + folderid, basename, c, d = mwc.db.get_basic_photo_metadata(photoid) + foldername = mwc.db.get_folder_name(folderid) + + self.pathname = os.path.join(foldername, basename) + self.pngname = self.pathname + '.png' + + def run(self): + if not os.path.exists(self.pngname): + p = subprocess.Popen(['dcraw', '-c', self.pathname], + stdout=subprocess.PIPE) + ppm, stderr = p.communicate('') + if p.returncode: + raise Exception('dcraw failed: exit code %s:\n%s' % + (p.returncode, stderr)) + + pixbuf = dimbola.image_data_to_pixbuf(ppm) + pixbuf.save(self.pngname, 'png') + + os.spawnlp(os.P_NOWAIT, "gimp", "gimp", self.pngname) + + +class Gimp(dimbola.Plugin): + + '''Edit selected photos using the GIMP.''' + + def __init__(self, mwc): + self.mwc = mwc + + def enable(self): + self.mwc.add_to_menu('photo_menu', 'gimp_menuitem', + 'Edit with the GIMP') + + def disable(self): + self.mwc.remove_from_menu('photo_menu', 'gimp_menuitem') + + def on_gimp_menuitem_activate(self, *args): + selected = self.mwc.grid.model.selected + for photoid in selected: + job = ConvertToPNGAndGimpIt(self.mwc, photoid) + self.mwc.add_bgjob(job) + + def gimp_menuitem_is_sensitive(self): + return self.mwc.grid.model.selected + |