# Copyright (C) 2009 Lars Wirzenius # # 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 . # 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 gtk import pyexiv2 import dimbola class PhotoInfoViewer(dimbola.Plugin): '''Show information about the selected photo in the right sidebar.''' def __init__(self, mwc): self.mwc = mwc self.photoid = None def enable(self): self.enable_signal(self.mwc.grid.model, 'selection-changed', self.remember_photo) self.enable_signal(self.mwc, 'photo-meta-changed', self.remember_photo) self.mwc.add_to_sidebar('right_sidebar', 'basic_info_expander') def disable(self): self.disable_signals() self.mwc.remove_from_sidebar('right_sidebar', 'basic_info_expander') def exifvalue(self, exifname): if self.photoid is None: return '' else: return self.mwc.db.get_exif(self.photoid, exifname) or '' @property def foldername(self): if self.photoid is None: return '' else: folderid, basename, rating, rotate = \ self.mwc.db.get_basic_photo_metadata(self.photoid) foldername = self.mwc.db.get_folder_name(folderid) if foldername: foldername = os.path.basename(foldername) return foldername or '' @property def filename(self): if self.photoid is None: return '' else: folderid, basename, rating, rotate = \ self.mwc.db.get_basic_photo_metadata(self.photoid) return basename @property def rating(self): if self.photoid is None: return '' else: folderid, basename, rating, rotate = \ self.mwc.db.get_basic_photo_metadata(self.photoid) return '*' * rating def draw_rating_stars(self): w = self.mwc.widgets['photo_info_rating'] gc = w.get_style().fg_gc[gtk.STATE_NORMAL] x = 0 y = 0 width, dim = w.window.get_size() with self.mwc.db: dimbola.draw_stars(len(self.rating), w.window, gc, x, y, dim) def on_photo_info_rating_expose_event(self, w, event): self.draw_rating_stars() def remember_photo(self, *args): if self.mwc.db is None: return if len(self.mwc.grid.model.selected) == 1: self.photoid = self.mwc.grid.model.selected[0] else: self.photoid = None with self.mwc.db: exiftable = { 'photo_info_camera': 'Exif.Image.Model', 'photo_info_datetime': 'Exif.Image.DateTime', 'photo_info_shutter': 'Exif.Photo.ExposureTime', 'photo_info_aperture': 'Exif.Photo.ApertureValue', 'photo_info_iso': 'Exif.Photo.ISOSpeedRatings', 'photo_info_focal_length': 'Exif.Photo.FocalLength', } for widget_name, exifname in exiftable.iteritems(): value = self.exifvalue(exifname) self.mwc.widgets[widget_name].set_text(value) misctable = { 'photo_info_photoid': '%s' % (self.photoid or ''), 'photo_info_folder': self.foldername, 'photo_info_filename': self.filename, } for widget_name, value in misctable.iteritems(): self.mwc.widgets[widget_name].set_text(value) self.draw_rating_stars()