diff options
Diffstat (limited to 'trunk/dimbola/plugins/rotate_plugin.py')
-rw-r--r-- | trunk/dimbola/plugins/rotate_plugin.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/trunk/dimbola/plugins/rotate_plugin.py b/trunk/dimbola/plugins/rotate_plugin.py new file mode 100644 index 0000000..5c63656 --- /dev/null +++ b/trunk/dimbola/plugins/rotate_plugin.py @@ -0,0 +1,81 @@ +# 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 RotatePhotos(dimbola.Plugin): + + '''Rotate selected photos in 90 degree steps.''' + + def __init__(self, mwc): + self.mwc = mwc + + def enable(self): # pragma: no cover + self.mwc.add_to_menu('photo_menu', 'rotate_90_left_menuitem', + 'Rotate photos left') + self.mwc.add_to_menu('photo_menu', 'rotate_90_right_menuitem', + 'Rotate photos right') + + def disable(self): # pragma: no cover + self.mwc.remove_from_menu('file_menu', 'rotate_90_left_menuitem') + self.mwc.remove_from_menu('file_menu', 'rotate_90_right_menuitem') + + def new_angle(self, old_angle, step): + '''Compute angle given old angle and number of steps. + + Positive steps are clockwise, negative steps are counter-clockwise. + + ''' + angles = [0, 90, 180, 270] + try: + i = angles.index(old_angle) + except ValueError: + return 0 + else: + return (angles + angles)[i - step] + + def rotate(self, step): # pragma: no cover + with self.mwc.db: + for photoid in self.mwc.grid.model.selected: + a, b, c, angle = self.mwc.db.get_basic_photo_metadata(photoid) + self.mwc.db.set_rotate(photoid, self.new_angle(angle, step)) + new_value = self.new_angle(angle, step) + for photoid in self.mwc.grid.model.selected: + self.mwc.photo_meta_changed(photoid) + + def on_rotate_90_left_menuitem_activate(self, menuitem): #pragma: no cover + self.rotate(-1) + + def on_rotate_90_right_menuitem_activate(self, menuitem): #pragma: no cover + self.rotate(1) + + def menuitem_is_sensitive(self): # pragma: no cover + return self.mwc.grid.model.selected + + rotate_90_left_menuitem_is_sensitive = menuitem_is_sensitive + rotate_90_right_menuitem_is_sensitive = menuitem_is_sensitive + |