Commit from One Laptop Per Child: Translation System by user HoboPrimate. 31 of 31...
[journal-activity.git] / keepicon.py
blobba0f180073dd0ebeb778e6dca9d994fd7fdf1067
1 # Copyright (C) 2006, Red Hat, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 import gobject
18 import hippo
20 from sugar.graphics.icon import CanvasIcon
21 from sugar.graphics import style
22 from sugar import profile
24 class KeepIcon(CanvasIcon):
25 __gproperties__ = {
26 'keep' : (bool, None, None, False,
27 gobject.PARAM_READWRITE)
30 def __init__(self, keep):
31 CanvasIcon.__init__(self, icon_name='emblem-favorite',
32 box_width=style.GRID_CELL_SIZE * 3 / 5,
33 size=style.SMALL_ICON_SIZE)
34 self.connect('motion-notify-event', self.__motion_notify_event_cb)
36 self._keep = None
37 self._set_keep(keep)
39 def _set_keep(self, keep):
40 if keep == self._keep:
41 return
43 self._keep = keep
44 if keep:
45 self.props.xo_color = profile.get_color()
46 else:
47 self.props.stroke_color = style.COLOR_BUTTON_GREY.get_svg()
48 self.props.fill_color = style.COLOR_TRANSPARENT.get_svg()
50 def do_set_property(self, pspec, value):
51 if pspec.name == 'keep':
52 self._set_keep(value)
53 else:
54 CanvasIcon.do_set_property(self, pspec, value)
56 def do_get_property(self, pspec):
57 if pspec.name == 'keep':
58 return self._keep
59 else:
60 return CanvasIcon.do_get_property(self, pspec)
62 def __motion_notify_event_cb(self, icon, event):
63 if not self._keep:
64 if event.detail == hippo.MOTION_DETAIL_ENTER:
65 icon.props.fill_color = style.COLOR_BUTTON_GREY.get_svg()
66 elif event.detail == hippo.MOTION_DETAIL_LEAVE:
67 icon.props.fill_color = style.COLOR_TRANSPARENT.get_svg()