コード例 #1
0
 def __on_info_short(self, args):
     """
         Show track information popover
         @param args as []
     """
     if Lp().player.current_track.id == Type.EXTERNALS:
         from lollypop.pop_externals import ExternalsPopover
         expopover = ExternalsPopover()
         expopover.set_relative_to(self._infobox)
         expopover.populate()
         expopover.show()
     elif Lp().player.current_track.id is not None:
         if Lp().player.current_track.id == Type.RADIOS:
             if self.__pop_tunein is None:
                 from lollypop.pop_tunein import TuneinPopover
                 self.__pop_tunein = TuneinPopover()
                 self.__pop_tunein.populate()
                 self.__pop_tunein.set_relative_to(self._infobox)
             self.__pop_tunein.show()
         else:
             if self.__pop_info is None:
                 from lollypop.pop_info import InfoPopover
                 self.__pop_info = InfoPopover()
                 self.__pop_info.set_relative_to(self._infobox)
             self.__pop_info.show()
コード例 #2
0
 def _on_title_release_event(self, widget, event):
     """
         Show track information popover
         On long press/right click: show current track menu
         @param widget as Gtk.Widget
         @param event as Gdk.Event
     """
     if self._timeout_id is not None:
         GLib.source_remove(self._timeout_id)
         self._timeout_id = None
         if Lp().player.current_track.id == Type.EXTERNALS:
             expopover = ExternalsPopover()
             expopover.set_relative_to(widget)
             expopover.populate()
             expopover.show()
         elif Lp().player.current_track.id is not None:
             if event.button == 1:
                 if Lp().player.current_track.id == Type.RADIOS:
                     if self._pop_tunein is None:
                         self._pop_tunein = TuneinPopover()
                         self._pop_tunein.populate()
                         self._pop_tunein.set_relative_to(widget)
                     self._pop_tunein.show()
                 else:
                     if self._pop_info is None:
                         self._pop_info = InfoPopover()
                         self._pop_info.set_relative_to(widget)
                     self._pop_info.show()
             else:
                 self._show_track_menu()
     return True
コード例 #3
0
ファイル: toolbar_info.py プロジェクト: ferranroig/lollypop
 def _on_title_release_event(self, widget, event):
     """
         Show track information popover
         On long press/right click: show current track menu
         @param widget as Gtk.Widget
         @param event as Gdk.Event
     """
     if self._timeout_id is not None:
         GLib.source_remove(self._timeout_id)
         self._timeout_id = None
         if Lp().player.current_track.id == Type.EXTERNALS:
             expopover = ExternalsPopover()
             expopover.set_relative_to(widget)
             expopover.populate()
             expopover.show()
         elif Lp().player.current_track.id is not None:
             if event.button == 1:
                 if Lp().player.current_track.id == Type.RADIOS:
                     if self._pop_tunein is None:
                         self._pop_tunein = TuneinPopover()
                         self._pop_tunein.populate()
                         self._pop_tunein.set_relative_to(widget)
                     self._pop_tunein.show()
                 else:
                     if self._pop_info is None:
                         self._pop_info = InfoPopover()
                         self._pop_info.set_relative_to(widget)
                     self._pop_info.show()
             else:
                 self._show_track_menu()
     return True
コード例 #4
0
ファイル: view_artist.py プロジェクト: kostich/lollypop
 def _on_label_realize(self, eventbox):
     """
         Change cursor on label
         @param eventbox as Gtk.EventBox
     """
     if InfoPopover.should_be_shown() and self._artist_ids:
         eventbox.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.HAND1))
コード例 #5
0
ファイル: view_artist.py プロジェクト: Abogical/lollypop
 def _on_label_realize(self, eventbox):
     """
         Change cursor on label
         @param eventbox as Gtk.EventBox
     """
     if InfoPopover.should_be_shown() and self._artist_ids:
         eventbox.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.HAND2))
コード例 #6
0
 def __on_info_short(self, args):
     """
         Show track information popover
         @param args as []
     """
     if Lp().player.current_track.id == Type.EXTERNALS:
         from lollypop.pop_externals import ExternalsPopover
         expopover = ExternalsPopover()
         expopover.set_relative_to(self._infobox)
         expopover.populate()
         expopover.show()
     elif Lp().player.current_track.id is not None:
         if Lp().player.current_track.id == Type.RADIOS:
             if self.__pop_tunein is None:
                 from lollypop.pop_tunein import TuneinPopover
                 self.__pop_tunein = TuneinPopover()
                 self.__pop_tunein.populate()
                 self.__pop_tunein.set_relative_to(self._infobox)
             self.__pop_tunein.show()
         else:
             if self.__pop_info is None:
                 from lollypop.pop_info import InfoPopover
                 self.__pop_info = InfoPopover()
                 self.__pop_info.set_relative_to(self._infobox)
             self.__pop_info.show()
コード例 #7
0
 def _on_label_realize(self, eventbox):
     """
         Change pointer on label
         @param eventbox as Gtk.EventBox
     """
     if InfoPopover.should_be_shown() and\
             self._album.artist_ids[0] != Type.COMPILATIONS:
         eventbox.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.HAND1))
コード例 #8
0
 def _on_label_realize(self, eventbox):
     """
         Change pointer on label
         @param eventbox as Gtk.EventBox
     """
     if InfoPopover.should_be_shown() and\
             self._album.artist_ids[0] != Type.COMPILATIONS:
         eventbox.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.HAND1))
コード例 #9
0
ファイル: view_artist.py プロジェクト: Abogical/lollypop
 def _on_image_button_release(self, eventbox, event):
     """
         Show artist artwork manager
         @param eventbox as Gtk.EventBox
         @param event as Gdk.Event
     """
     if InfoPopover.should_be_shown() and self._artist_ids:
         pop = ArtworkPopover(self._artist_ids[0])
         pop.set_relative_to(eventbox)
         pop.show()
コード例 #10
0
ファイル: view_artist.py プロジェクト: kostich/lollypop
 def _on_image_button_release(self, eventbox, event):
     """
         Show artist artwork manager
         @param eventbox as Gtk.EventBox
         @param event as Gdk.Event
     """
     if InfoPopover.should_be_shown() and self._artist_ids:
         pop = ArtworkPopover(self._artist_ids[0])
         pop.set_relative_to(eventbox)
         pop.show()
コード例 #11
0
ファイル: view_artist.py プロジェクト: Abogical/lollypop
 def _on_label_button_release(self, eventbox, event):
     """
         Show artists information
         @param eventbox as Gtk.EventBox
         @param event as Gdk.Event
     """
     if InfoPopover.should_be_shown() and self._artist_ids:
         pop = InfoPopover(self._artist_ids, False)
         pop.set_relative_to(eventbox)
         pop.show()
コード例 #12
0
 def _on_label_button_release(self, eventbox, event):
     """
         On clicked label, show artist informations in a popover
         @param eventbox as Gtk.EventBox
         @param event as Gdk.Event
     """
     if InfoPopover.should_be_shown() and\
             self._artist_id is not None:
         pop = InfoPopover([self._artist_id], False)
         pop.set_relative_to(eventbox)
         pop.show()
コード例 #13
0
 def _on_label_button_release(self, eventbox, event):
     """
         On clicked label, show artist informations in a popover
         @param eventbox as Gtk.EventBox
         @param event as Gdk.Event
     """
     if InfoPopover.should_be_shown() and\
             self._album.artist_ids[0] != Type.COMPILATIONS:
         pop = InfoPopover(self._album.artist_ids)
         pop.set_relative_to(eventbox)
         pop.show()
コード例 #14
0
ファイル: view_artist.py プロジェクト: kostich/lollypop
 def _on_label_button_release(self, eventbox, event):
     """
         Show artists information
         @param eventbox as Gtk.EventBox
         @param event as Gdk.Event
     """
     if InfoPopover.should_be_shown() and self._artist_ids:
         pop = InfoPopover(self._artist_ids, False)
         pop.set_relative_to(eventbox)
         pop.show()
コード例 #15
0
 def _on_label_button_release(self, eventbox, event):
     """
         On clicked label, show artist informations in a popover
         @param eventbox as Gtk.EventBox
         @param event as Gdk.Event
     """
     if InfoPopover.should_be_shown() and\
             self._album.artist_ids[0] != Type.COMPILATIONS:
         pop = InfoPopover(self._album.artist_ids)
         pop.set_relative_to(eventbox)
         pop.show()
コード例 #16
0
ファイル: view_artist.py プロジェクト: coconutlulz/lollypop
 def _on_label_button_release(self, eventbox, event):
     """
         On clicked label, show artist informations in a popover
         @param eventbox as Gtk.EventBox
         @param event as Gdk.Event
     """
     if InfoPopover.should_be_shown() and\
             self._artist_id is not None:
         pop = InfoPopover([self._artist_id], False)
         pop.set_relative_to(eventbox)
         pop.show()
コード例 #17
0
class ToolbarInfo(Gtk.Bin, InfosController):
    """
        Informations toolbar
    """

    def __init__(self):
        """
            Init toolbar
        """
        Gtk.Bin.__init__(self)
        InfosController.__init__(self, ArtSize.SMALL)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/ToolbarInfo.ui')
        builder.connect_signals(self)
        self.__pop_tunein = None
        self.__pop_info = None
        self.__timeout_id = None
        self.__width = 0

        self._infobox = builder.get_object('info')
        self.add(self._infobox)

        helper = TouchHelper(self._infobox, None, None)
        helper.set_long_func(self.__on_info_long)
        helper.set_short_func(self.__on_info_short)

        self._spinner = builder.get_object('spinner')

        self.__labels = builder.get_object('nowplaying_labels')
        self.__labels.connect('query-tooltip', self.__on_query_tooltip)
        self.__labels.set_property('has-tooltip', True)

        self._title_label = builder.get_object('title')
        self._artist_label = builder.get_object('artist')
        self._cover = builder.get_object('cover')
        self._cover.set_property('has-tooltip', True)
        # Since GTK 3.20, we can set cover full height
        if Gtk.get_minor_version() > 18:
            self._cover.get_style_context().add_class('toolbar-cover-frame')
        else:
            self._cover.get_style_context().add_class('small-cover-frame')

        self.connect('realize', self.__on_realize)
        Lp().player.connect('loading-changed', self.__on_loading_changed)
        Lp().art.connect('album-artwork-changed', self.__update_cover)
        Lp().art.connect('radio-artwork-changed', self.__update_logo)

    def do_get_preferred_width(self):
        """
            We force preferred width
            @return (int, int)
        """
        return (self.__width, self.__width)

    def get_preferred_height(self):
        """
            Return preferred height
            @return (int, int)
        """
        return self.__labels.get_preferred_height()

    def set_width(self, width):
        """
            Set widget width
            @param width as int
        """
        self.__width = width
        self.set_property('width-request', width)

#######################
# PROTECTED           #
#######################
    def _on_eventbox_realize(self, eventbox):
        """
            Show hand cursor over
        """
        eventbox.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.HAND2))

#######################
# PRIVATE             #
#######################
    def __update_cover(self, art, album_id):
        """
            Update cover for album_id
            @param art as Art
            @param album id as int
        """
        if Lp().player.current_track.album.id == album_id:
            surface = Lp().art.get_album_artwork(
                                       Lp().player.current_track.album,
                                       self._artsize,
                                       self._cover.get_scale_factor())
            self._cover.set_from_surface(surface)
            del surface

    def __update_logo(self, art, name):
        """
            Update logo for name
            @param art as Art
            @param name as str
        """
        if Lp().player.current_track.album_artist == name:
            pixbuf = Lp().art.get_radio_artwork(name, self._artsize)
            self._cover.set_from_surface(pixbuf)
            del pixbuf

    def __on_info_long(self, args):
        """
            Show current track menu
            @param args as []
        """
        if Lp().player.current_track.id >= 0:
            from lollypop.pop_menu import PlaylistsMenu
            from lollypop.pop_menu import TrackMenuPopover
            popover = TrackMenuPopover(
                        Lp().player.current_track,
                        PlaylistsMenu(Lp().player.current_track))
            popover.set_relative_to(self._infobox)
            popover.show()

    def __on_info_short(self, args):
        """
            Show track information popover
            @param args as []
        """
        if Lp().player.current_track.id == Type.EXTERNALS:
            from lollypop.pop_externals import ExternalsPopover
            expopover = ExternalsPopover()
            expopover.set_relative_to(self._infobox)
            expopover.populate()
            expopover.show()
        elif Lp().player.current_track.id is not None:
            if Lp().player.current_track.id == Type.RADIOS:
                if self.__pop_tunein is None:
                    from lollypop.pop_tunein import TuneinPopover
                    self.__pop_tunein = TuneinPopover()
                    self.__pop_tunein.populate()
                    self.__pop_tunein.set_relative_to(self._infobox)
                self.__pop_tunein.show()
            else:
                if self.__pop_info is None:
                    from lollypop.pop_info import InfoPopover
                    self.__pop_info = InfoPopover()
                    self.__pop_info.set_relative_to(self._infobox)
                self.__pop_info.show()

    def __on_loading_changed(self, player, show):
        """
            Show spinner based on loading status
            @param player as player
            @param show as bool
        """
        if show:
            self._title_label.hide()
            self._artist_label.hide()
            self._cover.hide()
            self._spinner.show()
            self._spinner.start()
            self._infobox.show()
        else:
            self._spinner.hide()
            self._spinner.stop()

    def __on_realize(self, toolbar):
        """
            Calculate art size
            @param toolbar as ToolbarInfos
        """
        style = self.get_style_context()
        padding = style.get_padding(style.get_state())
        self._artsize = self.get_allocated_height()\
            - padding.top - padding.bottom
        # Since GTK 3.20, we can set cover full height
        if Gtk.get_minor_version() < 20:
            self._artsize -= 2

    def __on_query_tooltip(self, widget, x, y, keyboard, tooltip):
        """
            Show tooltip if needed
            @param widget as Gtk.Widget
            @param x as int
            @param y as int
            @param keyboard as bool
            @param tooltip as Gtk.Tooltip
        """
        layout_title = self._title_label.get_layout()
        layout_artist = self._artist_label.get_layout()
        if layout_title.is_ellipsized() or layout_artist.is_ellipsized():
            artist = GLib.markup_escape_text(self._artist_label.get_text())
            title = GLib.markup_escape_text(self._title_label.get_text())
            tooltip.set_markup("<b>%s</b> - %s" % (artist, title))
        else:
            return False
        return True
コード例 #18
0
ファイル: toolbar_info.py プロジェクト: lexruee/lollypop
class ToolbarInfo(Gtk.Bin, InfoController):
    """
        Informations toolbar
    """

    def __init__(self):
        """
            Init toolbar
        """
        Gtk.Bin.__init__(self)
        InfoController.__init__(self, ArtSize.SMALL)
        builder = Gtk.Builder()
        builder.add_from_resource("/org/gnome/Lollypop/ToolbarInfo.ui")
        builder.connect_signals(self)
        self.__pop_tunein = None
        self.__pop_info = None
        self.__timeout_id = None
        self.__width = 0

        self._infobox = builder.get_object("info")
        self.add(self._infobox)

        self.__helper = TouchHelper(self._infobox, None, None)
        self.__helper.set_long_func(self.__on_info_long)
        self.__helper.set_short_func(self.__on_info_short)

        self._spinner = builder.get_object("spinner")

        self.__labels = builder.get_object("nowplaying_labels")
        self.__labels.connect("query-tooltip", self.__on_query_tooltip)
        self.__labels.set_property("has-tooltip", True)

        self._title_label = builder.get_object("title")
        self._artist_label = builder.get_object("artist")
        self._cover = builder.get_object("cover")
        self._cover.set_property("has-tooltip", True)
        # Since GTK 3.20, we can set cover full height
        if Gtk.get_minor_version() > 18:
            self._cover.get_style_context().add_class("toolbar-cover-frame")
        else:
            self._cover.get_style_context().add_class("small-cover-frame")

        self.connect("realize", self.__on_realize)
        Lp().player.connect("loading-changed", self.__on_loading_changed)
        Lp().art.connect("album-artwork-changed", self.__update_cover)
        Lp().art.connect("radio-artwork-changed", self.__update_logo)

    def do_get_preferred_width(self):
        """
            We force preferred width
            @return (int, int)
        """
        return (self.__width, self.__width)

    def get_preferred_height(self):
        """
            Return preferred height
            @return (int, int)
        """
        return self.__labels.get_preferred_height()

    def set_width(self, width):
        """
            Set widget width
            @param width as int
        """
        self.__width = width
        self.set_property("width-request", width)

#######################
# PROTECTED           #
#######################
    def _on_eventbox_realize(self, eventbox):
        """
            Show hand cursor over
        """
        eventbox.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.HAND2))

#######################
# PRIVATE             #
#######################
    def __update_cover(self, art, album_id):
        """
            Update cover for album_id
            @param art as Art
            @param album id as int
        """
        if Lp().player.current_track.album.id == album_id:
            surface = Lp().art.get_album_artwork(
                                       Lp().player.current_track.album,
                                       self._artsize,
                                       self._cover.get_scale_factor())
            self._cover.set_from_surface(surface)

    def __update_logo(self, art, name):
        """
            Update logo for name
            @param art as Art
            @param name as str
        """
        if Lp().player.current_track.album_artist == name:
            pixbuf = Lp().art.get_radio_artwork(name, self._artsize)
            self._cover.set_from_surface(pixbuf)

    def __on_info_long(self, args):
        """
            Show current track menu
            @param args as []
        """
        if Lp().player.current_track.id >= 0:
            from lollypop.pop_menu import PlaylistsMenu
            from lollypop.pop_menu import TrackMenuPopover
            popover = TrackMenuPopover(
                        Lp().player.current_track,
                        PlaylistsMenu(Lp().player.current_track))
            popover.set_relative_to(self._infobox)
            popover.show()

    def __on_info_short(self, args):
        """
            Show track information popover
            @param args as []
        """
        if Lp().player.current_track.id == Type.EXTERNALS:
            from lollypop.pop_externals import ExternalsPopover
            expopover = ExternalsPopover()
            expopover.set_relative_to(self._infobox)
            expopover.populate()
            expopover.show()
        elif Lp().player.current_track.id is not None:
            if self.__pop_info is None:
                from lollypop.pop_info import InfoPopover
                self.__pop_info = InfoPopover([])
                self.__pop_info.set_relative_to(self._infobox)
            if Lp().player.current_track.id == Type.RADIOS:
                view_type = Type.RADIOS
            else:
                view_type = Type.ALBUMS
            self.__pop_info.set_view_type(view_type)
            self.__pop_info.show()

    def __on_loading_changed(self, player, show):
        """
            Show spinner based on loading status
            @param player as player
            @param show as bool
        """
        if show:
            self._title_label.hide()
            self._artist_label.hide()
            self._cover.hide()
            self._spinner.show()
            self._spinner.start()
            self._infobox.show()
        else:
            self._spinner.hide()
            self._spinner.stop()

    def __on_realize(self, toolbar):
        """
            Calculate art size
            @param toolbar as ToolbarInfos
        """
        style = self.get_style_context()
        padding = style.get_padding(style.get_state())
        self._artsize = self.get_allocated_height()\
            - padding.top - padding.bottom
        # Since GTK 3.20, we can set cover full height
        if Gtk.get_minor_version() < 20:
            self._artsize -= 2

    def __on_query_tooltip(self, widget, x, y, keyboard, tooltip):
        """
            Show tooltip if needed
            @param widget as Gtk.Widget
            @param x as int
            @param y as int
            @param keyboard as bool
            @param tooltip as Gtk.Tooltip
        """
        layout_title = self._title_label.get_layout()
        layout_artist = self._artist_label.get_layout()
        if layout_title.is_ellipsized() or layout_artist.is_ellipsized():
            artist = GLib.markup_escape_text(self._artist_label.get_text())
            title = GLib.markup_escape_text(self._title_label.get_text())
            tooltip.set_markup("<b>%s</b> - %s" % (artist, title))
        else:
            return False
        return True
コード例 #19
0
ファイル: toolbar_info.py プロジェクト: ferranroig/lollypop
class ToolbarInfo(Gtk.Bin, InfosController):
    """
        Informations toolbar
    """

    def __init__(self):
        """
            Init toolbar
        """
        Gtk.Bin.__init__(self)
        InfosController.__init__(self, ArtSize.SMALL)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/ToolbarInfo.ui')
        builder.connect_signals(self)
        self._pop_tunein = None
        self._pop_info = None
        self._timeout_id = None
        self._width = 0

        self._infobox = builder.get_object('info')
        self.add(self._infobox)

        self._labels = builder.get_object('nowplaying_labels')

        self._title_label = builder.get_object('title')
        self._artist_label = builder.get_object('artist')
        self._cover_frame = builder.get_object('frame')
        self._cover = builder.get_object('cover')
        self._cover.set_property('has-tooltip', True)
        # Since GTK 3.20, we can set cover full height
        if Gtk.get_minor_version() > 18:
            self._cover.get_style_context().add_class('toolbar-cover-frame')
        else:
            self._cover.get_style_context().add_class('small-cover-frame')

        self.connect('realize', self._on_realize)
        Lp().art.connect('album-artwork-changed', self._update_cover)
        Lp().art.connect('radio-artwork-changed', self._update_logo)

    def do_get_preferred_width(self):
        """
            We force preferred width
            @return (int, int)
        """
        return (self._width, self._width)

    def get_preferred_height(self):
        """
            Return preferred height
            @return (int, int)
        """
        return self._labels.get_preferred_height()

    def set_width(self, width):
        """
            Set widget width
            @param width as int
        """
        self._width = width
        self.set_property('width-request', width)

#######################
# PRIVATE             #
#######################
    def _update_cover(self, art, album_id):
        """
            Update cover for album_id
            @param art as Art
            @param album id as int
        """
        if Lp().player.current_track.album.id == album_id:
            surface = Lp().art.get_album_artwork(
                                       Lp().player.current_track.album,
                                       ArtSize.SMALL)
            self._cover.set_from_surface(surface)
            del surface

    def _update_logo(self, art, name):
        """
            Update logo for name
            @param art as Art
            @param name as str
        """
        if Lp().player.current_track.album_artist == name:
            pixbuf = Lp().art.get_radio_artwork(name, ArtSize.SMALL)
            self._cover.set_from_surface(pixbuf)
            del pixbuf

    def _show_track_menu(self):
        """
            Show current track menu
        """
        self._timeout_id = None
        if Lp().player.current_track.id >= 0:
            popover = TrackMenuPopover(
                        Lp().player.current_track.id,
                        PopToolbarMenu(Lp().player.current_track.id))
            popover.set_relative_to(self._infobox)
            popover.show()

    def _on_title_press_event(self, widget, event):
        """
            On long press: show current track menu
            @param widget as Gtk.Widget
            @param event as Gdk.Event

        """
        self._timeout_id = GLib.timeout_add(500, self._show_track_menu)
        return True

    def _on_title_release_event(self, widget, event):
        """
            Show track information popover
            On long press/right click: show current track menu
            @param widget as Gtk.Widget
            @param event as Gdk.Event
        """
        if self._timeout_id is not None:
            GLib.source_remove(self._timeout_id)
            self._timeout_id = None
            if Lp().player.current_track.id == Type.EXTERNALS:
                expopover = ExternalsPopover()
                expopover.set_relative_to(widget)
                expopover.populate()
                expopover.show()
            elif Lp().player.current_track.id is not None:
                if event.button == 1:
                    if Lp().player.current_track.id == Type.RADIOS:
                        if self._pop_tunein is None:
                            self._pop_tunein = TuneinPopover()
                            self._pop_tunein.populate()
                            self._pop_tunein.set_relative_to(widget)
                        self._pop_tunein.show()
                    else:
                        if self._pop_info is None:
                            self._pop_info = InfoPopover()
                            self._pop_info.set_relative_to(widget)
                        self._pop_info.show()
                else:
                    self._show_track_menu()
        return True

    def _on_query_tooltip(self, widget, x, y, keyboard, tooltip):
        """
            Show tooltip if needed
            @param widget as Gtk.Widget
            @param x as int
            @param y as int
            @param keyboard as bool
            @param tooltip as Gtk.Tooltip
        """
        # Can't add a \n in markup
        # GTK bug => https://bugzilla.gnome.org/show_bug.cgi?id=749965
        layout_title = self._title_label.get_layout()
        layout_artist = self._artist_label.get_layout()
        if layout_title.is_ellipsized() or layout_artist.is_ellipsized():
            artist = escape(self._artist_label.get_text())
            title = escape(self._title_label.get_text())
            tooltip.set_markup("<b>%s</b> - %s" % (artist, title))
        else:
            return False
        return True

    def _on_realize(self, toolbar):
        """
            @param toolbar as ToolbarInfos
        """
        style = self.get_style_context()
        padding = style.get_padding(style.get_state())
        self._artsize = self.get_allocated_height()\
            - padding.top - padding.bottom
        # Since GTK 3.20, we can set cover full height
        if Gtk.get_minor_version() < 20:
            self._artsize -= 2

    def _on_eventbox_realize(self, eventbox):
        """
            Show hand cursor over
        """
        eventbox.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.HAND1))
コード例 #20
0
class ToolbarInfo(Gtk.Bin, InfosController):
    """
        Informations toolbar
    """
    def __init__(self):
        """
            Init toolbar
        """
        Gtk.Bin.__init__(self)
        InfosController.__init__(self, ArtSize.SMALL)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/ToolbarInfo.ui')
        builder.connect_signals(self)
        self._pop_tunein = None
        self._pop_info = None
        self._timeout_id = None
        self._width = 0

        self._infobox = builder.get_object('info')
        self.add(self._infobox)

        self._labels = builder.get_object('nowplaying_labels')

        self._title_label = builder.get_object('title')
        self._artist_label = builder.get_object('artist')
        self._cover_frame = builder.get_object('frame')
        self._cover = builder.get_object('cover')
        self._cover.set_property('has-tooltip', True)

        self.connect('realize', self._on_realize)
        Lp().art.connect('album-artwork-changed', self._update_cover)
        Lp().art.connect('radio-artwork-changed', self._update_logo)

    def do_get_preferred_width(self):
        """
            We force preferred width
            @return (int, int)
        """
        return (self._width, self._width)

    def get_preferred_height(self):
        """
            Return preferred height
            @return (int, int)
        """
        return self._labels.get_preferred_height()

    def set_width(self, width):
        """
            Set widget width
            @param width as int
        """
        self._width = width
        self.set_property('width-request', width)

#######################
# PRIVATE             #
#######################

    def _update_cover(self, art, album_id):
        """
            Update cover for album_id
            @param art as Art
            @param album id as int
        """
        if Lp().player.current_track.album.id == album_id:
            surface = Lp().art.get_album_artwork(
                Lp().player.current_track.album, ArtSize.SMALL)
            self._cover.set_from_surface(surface)
            del surface

    def _update_logo(self, art, name):
        """
            Update logo for name
            @param art as Art
            @param name as str
        """
        if Lp().player.current_track.album_artist == name:
            pixbuf = Lp().art.get_radio_artwork(name, ArtSize.SMALL)
            self._cover.set_from_surface(pixbuf)
            del pixbuf

    def _show_track_menu(self):
        """
            Show current track menu
        """
        self._timeout_id = None
        if Lp().player.current_track.id >= 0:
            popover = TrackMenuPopover(
                Lp().player.current_track.id,
                PopToolbarMenu(Lp().player.current_track.id))
            popover.set_relative_to(self._infobox)
            popover.show()

    def _on_title_press_event(self, widget, event):
        """
            On long press: show current track menu
            @param widget as Gtk.Widget
            @param event as Gdk.Event

        """
        self._timeout_id = GLib.timeout_add(500, self._show_track_menu)
        return True

    def _on_title_release_event(self, widget, event):
        """
            Show track information popover
            On long press/right click: show current track menu
            @param widget as Gtk.Widget
            @param event as Gdk.Event
        """
        if self._timeout_id is not None:
            GLib.source_remove(self._timeout_id)
            self._timeout_id = None
            if Lp().player.current_track.id == Type.EXTERNALS:
                expopover = ExternalsPopover()
                expopover.set_relative_to(widget)
                expopover.populate()
                expopover.show()
            elif Lp().player.current_track.id is not None:
                if event.button == 1:
                    if Lp().player.current_track.id == Type.RADIOS:
                        if self._pop_tunein is None:
                            self._pop_tunein = TuneinPopover()
                            self._pop_tunein.populate()
                            self._pop_tunein.set_relative_to(widget)
                        self._pop_tunein.show()
                    else:
                        if self._pop_info is None:
                            self._pop_info = InfoPopover()
                            self._pop_info.set_relative_to(widget)
                        self._pop_info.show()
                else:
                    self._show_track_menu()
        return True

    def _on_query_tooltip(self, widget, x, y, keyboard, tooltip):
        """
            Show tooltip if needed
            @param widget as Gtk.Widget
            @param x as int
            @param y as int
            @param keyboard as bool
            @param tooltip as Gtk.Tooltip
        """
        # Can't add a \n in markup
        # GTK bug => https://bugzilla.gnome.org/show_bug.cgi?id=749965
        layout_title = self._title_label.get_layout()
        layout_artist = self._artist_label.get_layout()
        if layout_title.is_ellipsized() or layout_artist.is_ellipsized():
            artist = escape(self._artist_label.get_text())
            title = escape(self._title_label.get_text())
            tooltip.set_markup("<b>%s</b> - %s" % (artist, title))
        else:
            return False
        return True

    def _on_realize(self, toolbar):
        """
            @param toolbar as ToolbarInfos
        """
        style = self.get_style_context()
        padding = style.get_padding(style.get_state())
        self._artsize = self.get_allocated_height()\
            - padding.top - padding.bottom - 2

    def _on_eventbox_realize(self, eventbox):
        """
            Show hand cursor over
        """
        eventbox.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.HAND1))