1# Copyright © 2018 The GNOME Music developers
2#
3# GNOME Music 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.
7#
8# GNOME Music 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.
12#
13# You should have received a copy of the GNU General Public License along
14# with GNOME Music; if not, write to the Free Software Foundation, Inc.,
15# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16#
17# The GNOME Music authors hereby grant permission for non-GPL compatible
18# GStreamer plugins to be used and distributed together with GStreamer
19# and GNOME Music.  This permission is above and beyond the permissions
20# granted by the GPL license by which GNOME Music is covered.  If you
21# modify this code, you may extend this exception to your version of the
22# code, but you are not obligated to do so.  If you do not wish to do so,
23# delete this exception statement from your version.
24
25from gi.repository import GObject, Gtk
26
27
28class StarImage(Gtk.Image):
29    """GtkImage for starring songs"""
30    __gtype_name__ = 'StarImage'
31
32    def __init__(self):
33        super().__init__()
34
35        self._favorite = False
36        self._hover = False
37
38        self.get_style_context().add_class("star")
39        self.props.visible = True
40
41    @GObject.Property(type=bool, default=False)
42    def favorite(self):
43        """Return the current state of the widget
44
45        :return: The state of the widget
46        :rtype: bool
47        """
48        return self._favorite
49
50    @favorite.setter  # type: ignore
51    def favorite(self, value):
52        """Set favorite
53
54        Set the current widget as favorite or not.
55
56        :param bool value: Value to switch the widget state to
57        """
58        self._favorite = value
59
60        if self._favorite:
61            self.set_state_flags(Gtk.StateFlags.SELECTED, False)
62        else:
63            self.unset_state_flags(Gtk.StateFlags.SELECTED)
64
65    @GObject.Property(type=bool, default=False)
66    def hover(self):
67        return self._hover
68
69    @hover.setter  # type: ignore
70    def hover(self, value):
71        if value:
72            self.set_state_flags(Gtk.StateFlags.PRELIGHT, False)
73        else:
74            self.unset_state_flags(Gtk.StateFlags.PRELIGHT)
75