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 gobject
import gtk
import dimbola
class RatePhotosPlugin(dimbola.Plugin):
'''Allow user to use a 0-5 star rating for photos.'''
def __init__(self, mwc):
self.mwc = mwc
mwc.new_hook('photo-rating-requested', gobject.TYPE_NONE,
(gobject.TYPE_INT,))
def enable(self):
self.mwc.add_to_menu('photo_menu', 'rate_as_0_stars',
'Rate as 0 stars')
self.mwc.add_to_menu('photo_menu', 'rate_as_1_star',
'Rate as 1 stars')
self.mwc.add_to_menu('photo_menu', 'rate_as_2_stars',
'Rate as 2 stars')
self.mwc.add_to_menu('photo_menu', 'rate_as_3_stars',
'Rate as 3 stars')
self.mwc.add_to_menu('photo_menu', 'rate_as_4_stars',
'Rate as 4 stars')
self.mwc.add_to_menu('photo_menu', 'rate_as_5_stars',
'Rate as 5 stars')
self.enable_signal(self.mwc, 'photo-rating-requested', self.rate_cb)
def disable(self):
self.mwc.remove_from_menu('photo_menu', 'rate_as_0_stars')
self.mwc.remove_from_menu('photo_menu', 'rate_as_1_star')
self.mwc.remove_from_menu('photo_menu', 'rate_as_2_stars')
self.mwc.remove_from_menu('photo_menu', 'rate_as_3_stars')
self.mwc.remove_from_menu('photo_menu', 'rate_as_4_stars')
self.mwc.remove_from_menu('photo_menu', 'rate_as_5_stars')
def rate(self, stars):
'''Rate selected photos with stars.'''
with self.mwc.db:
for photoid in self.mwc.grid.model.selected:
self.mwc.db.set_rating(photoid, stars)
for photoid in self.mwc.grid.model.selected:
self.mwc.photo_meta_changed(photoid)
def rate_cb(self, mwc, stars):
self.rate(stars)
def on_rate_as_0_stars_activate(self, menuitem):
self.rate(0)
def on_rate_as_1_star_activate(self, menuitem):
self.rate(1)
def on_rate_as_2_stars_activate(self, menuitem):
self.rate(2)
def on_rate_as_3_stars_activate(self, menuitem):
self.rate(3)
def on_rate_as_4_stars_activate(self, menuitem):
self.rate(4)
def on_rate_as_5_stars_activate(self, menuitem):
self.rate(5)
def menuitem_is_sensitive(self):
return self.mwc.grid.model.selected
rate_as_0_stars_is_sensitive = menuitem_is_sensitive
rate_as_1_star_is_sensitive = menuitem_is_sensitive
rate_as_2_stars_is_sensitive = menuitem_is_sensitive
rate_as_3_stars_is_sensitive = menuitem_is_sensitive
rate_as_4_stars_is_sensitive = menuitem_is_sensitive
rate_as_5_stars_is_sensitive = menuitem_is_sensitive
|