summaryrefslogtreecommitdiff
path: root/trunk/dimbola/plugins/phototags_plugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'trunk/dimbola/plugins/phototags_plugin.py')
-rw-r--r--trunk/dimbola/plugins/phototags_plugin.py107
1 files changed, 107 insertions, 0 deletions
diff --git a/trunk/dimbola/plugins/phototags_plugin.py b/trunk/dimbola/plugins/phototags_plugin.py
new file mode 100644
index 0000000..e2fc1d2
--- /dev/null
+++ b/trunk/dimbola/plugins/phototags_plugin.py
@@ -0,0 +1,107 @@
+# 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 gtk
+
+import dimbola
+
+
+class PhotoTags(dimbola.Plugin):
+
+ '''Show/edit selected photo's tags.'''
+
+ def __init__(self, mwc):
+ self.mwc = mwc
+ mwc.connect('setup-widgets', self.setup_widgets)
+
+ def setup_widgets(self, mwc):
+ self.textview = mwc.widgets['tags_textview']
+ self.popup = mwc.widgets['tags_textview_popup']
+ self.remove_menuitem = mwc.widgets['remove_photo_tag_menuitem']
+ self.taglist = dimbola.Taglist(self.textview, self.popup,
+ self.prepare_popup)
+ self.photoid = None
+
+ def enable(self):
+ self.enable_signal(self.mwc.grid.model, 'selection-changed',
+ self.selection_changed)
+ self.enable_signal(self.mwc, 'tagtree-changed',
+ lambda *args: self.refresh_tags())
+ self.mwc.add_to_sidebar('right_sidebar', 'photo_tags_expander')
+
+ def disable(self):
+ self.disable_signals()
+ self.mwc.remove_from_sidebar('right_sidebar', 'photo_tags_expander')
+
+ def refresh_tags(self):
+ with self.mwc.db:
+ tags = []
+ for tagid in self.mwc.db.get_tagids(self.photoid):
+ tagname = self.mwc.db.get_tagname(tagid)
+ if tagname is not None:
+ tags.append((tagid, tagname))
+ tags.sort()
+ self.taglist.set_tags(self.photoid, tags)
+
+ def selection_changed(self, model):
+ if self.mwc.db:
+ if len(model.selected) == 1:
+ self.photoid = model.selected[0]
+ self.refresh_tags()
+ else:
+ self.taglist.clear()
+ self.photoid = None
+ else:
+ self.photoid = None
+
+ def tags_textview_is_sensitive(self):
+ return len(self.mwc.grid.model.selected) == 1
+
+ def prepare_popup(self):
+ self.remove_menuitem.set_sensitive(
+ self.taglist.buf.get_has_selection())
+
+ def on_tags_textview_button_press_event(self, widget, event):
+ return self.taglist.button_press_event(widget, event)
+
+ def on_remove_photo_tag_menuitem_activate(self, *args):
+ photoid, tagid = self.taglist.selected_tag()
+ if photoid is not None:
+ with self.mwc.db:
+ self.mwc.db.remove_tagid(photoid, tagid)
+ self.refresh_tags()
+
+ def on_tags_textview_drag_motion(self, *args):
+ return self.taglist.drag_motion(*args)
+
+ def on_tags_textview_drag_leave(self, *args):
+ return self.taglist.drag_leave(*args)
+
+ def on_tags_textview_drag_data_received(self, *args):
+ if self.photoid is None:
+ return
+
+ tagids = self.taglist.drag_data_received(*args)
+ with self.mwc.db:
+ for tagid in tagids:
+ self.mwc.db.add_tagid(self.photoid, tagid)
+ self.refresh_tags()
+