Example #1
0
    def __init__(self, app):
        """
            Init toolbar
            @param app as Gtk.Application
        """
        Gtk.HeaderBar.__init__(self)
        self.__width = WindowSize.SMALL
        self.set_title("Lollypop")
        self.__toolbar_playback = ToolbarPlayback()
        self.__toolbar_playback.show()
        self.__toolbar_info = ToolbarInfo()
        self.__toolbar_info.show()
        self.__toolbar_title = ToolbarTitle()
        self.__toolbar_title.show()
        self.__toolbar_end = ToolbarEnd(app)
        self.__toolbar_end.show()
        self.pack_start(self.__toolbar_playback)
        self.pack_start(self.__toolbar_info)
        self.set_custom_title(self.__toolbar_title)
        self.pack_end(self.__toolbar_end)

        Lp().player.connect('status-changed', self.__on_status_changed)
        Lp().player.connect('current-changed', self.__on_current_changed)
        Lp().player.connect('next-changed', self.__on_next_changed)
        Lp().player.connect('prev-changed', self.__on_prev_changed)
Example #2
0
    def __init__(self, window):
        """
            Init toolbar
            @param window as Window
        """
        Gtk.HeaderBar.__init__(self)
        self.__width = Sizing.SMALL
        self.set_title("Lollypop")
        self.__toolbar_playback = ToolbarPlayback(window)
        self.__toolbar_playback.show()
        self.__toolbar_info = ToolbarInfo()
        self.__toolbar_info.show()
        self.__toolbar_title = ToolbarTitle()
        self.__toolbar_end = ToolbarEnd()
        self.__toolbar_end.show()
        self.pack_start(self.__toolbar_playback)
        self.pack_start(self.__toolbar_info)
        self.set_custom_title(self.__toolbar_title)
        self.pack_end(self.__toolbar_end)

        App().player.connect("status-changed", self.__on_status_changed)
        App().player.connect("current-changed", self.__on_current_changed)
        App().player.connect("next-changed", self.__on_next_changed)
        App().player.connect("prev-changed", self.__on_prev_changed)
        window.connect("adaptive-changed", self.__on_adaptive_changed)
Example #3
0
    def __init__(self, app):
        """
            Init toolbar
            @param app as Gtk.Application
        """
        Gtk.HeaderBar.__init__(self)
        self._width = WindowSize.SMALL
        self.set_title("Lollypop")
        self._toolbar_playback = ToolbarPlayback()
        self._toolbar_playback.show()
        self._toolbar_info = ToolbarInfo()
        self._toolbar_info.show()
        self._toolbar_title = ToolbarTitle()
        self._toolbar_title.show()
        self._toolbar_end = ToolbarEnd(app)
        self._toolbar_end.show()
        self.pack_start(self._toolbar_playback)
        self.pack_start(self._toolbar_info)
        self.set_custom_title(self._toolbar_title)
        self.pack_end(self._toolbar_end)

        Lp().player.connect('status-changed', self._on_status_changed)
        Lp().player.connect('current-changed', self._on_current_changed)
        Lp().player.connect('next-changed', self._on_next_changed)
        Lp().player.connect('prev-changed', self._on_prev_changed)
Example #4
0
    def __init__(self, app):
        """
            Init toolbar
            @param app as Gtk.Application
        """
        Gtk.HeaderBar.__init__(self)

        self._toolbar_playback = ToolbarPlayback()
        self._toolbar_playback.show()
        self._toolbar_infos = ToolbarInfos()
        self._toolbar_infos.show()
        self._toolbar_title = ToolbarTitle()
        self._toolbar_title.show()
        self._toolbar_end = ToolbarEnd(app)
        self._toolbar_end.show()
        self.pack_start(self._toolbar_playback)
        self.pack_start(self._toolbar_infos)
        self.set_custom_title(self._toolbar_title)
        self.pack_end(self._toolbar_end)

        Lp.player.connect('status-changed', self._on_status_changed)
        Lp.player.connect('current-changed', self._on_current_changed)
Example #5
0
 def __init__(self, window):
     """
         Init toolbar
         @param window as Window
     """
     Gtk.HeaderBar.__init__(self)
     SizeAllocationHelper.__init__(self)
     self.__width = Size.MINI
     self.__timeout_id = None
     self.set_title("Lollypop")
     self.__toolbar_playback = ToolbarPlayback(window)
     self.__toolbar_playback.show()
     self.__toolbar_info = ToolbarInfo()
     self.__toolbar_info.show()
     self.__toolbar_title = ToolbarTitle()
     self.__toolbar_end = ToolbarEnd(window)
     self.__toolbar_end.show()
     self.pack_start(self.__toolbar_playback)
     self.pack_start(self.__toolbar_info)
     self.set_custom_title(self.__toolbar_title)
     self.pack_end(self.__toolbar_end)
     return [(App().player, "current-changed", "_on_current_changed"),
             (App().window.container.widget, "notify::folded",
              "_on_container_folded")]
Example #6
0
    def __init__(self):
        """
            Init toolbar
        """
        Gtk.HeaderBar.__init__(self)
        self.__width = WindowSize.SMALL
        self.set_title("Lollypop")
        self.__toolbar_playback = ToolbarPlayback()
        self.__toolbar_playback.show()
        self.__toolbar_info = ToolbarInfo()
        self.__toolbar_info.show()
        self.__toolbar_title = ToolbarTitle()
        self.__toolbar_title.show()
        self.__toolbar_end = ToolbarEnd()
        self.__toolbar_end.show()
        self.pack_start(self.__toolbar_playback)
        self.pack_start(self.__toolbar_info)
        self.set_custom_title(self.__toolbar_title)
        self.pack_end(self.__toolbar_end)

        Lp().player.connect("status-changed", self.__on_status_changed)
        Lp().player.connect("current-changed", self.__on_current_changed)
        Lp().player.connect("next-changed", self.__on_next_changed)
        Lp().player.connect("prev-changed", self.__on_prev_changed)
Example #7
0
    def __init__(self, app):
        """
            Init toolbar
            @param app as Gtk.Application
        """
        Gtk.HeaderBar.__init__(self)

        self._toolbar_playback = ToolbarPlayback()
        self._toolbar_playback.show()
        self._toolbar_infos = ToolbarInfos()
        self._toolbar_infos.show()
        self._toolbar_title = ToolbarTitle()
        self._toolbar_title.show()
        self._toolbar_end = ToolbarEnd(app)
        self._toolbar_end.show()
        self.pack_start(self._toolbar_playback)
        self.pack_start(self._toolbar_infos)
        self.set_custom_title(self._toolbar_title)
        self.pack_end(self._toolbar_end)

        Lp.player.connect('status-changed', self._on_status_changed)
        Lp.player.connect('current-changed', self._on_current_changed)
Example #8
0
class Toolbar(Gtk.HeaderBar):
    """
        Lollypop toolbar
    """

    def __init__(self, app):
        """
            Init toolbar
            @param app as Gtk.Application
        """
        Gtk.HeaderBar.__init__(self)
        self._width = WindowSize.SMALL
        self.set_title("Lollypop")
        self._toolbar_playback = ToolbarPlayback()
        self._toolbar_playback.show()
        self._toolbar_info = ToolbarInfo()
        self._toolbar_info.show()
        self._toolbar_title = ToolbarTitle()
        self._toolbar_title.show()
        self._toolbar_end = ToolbarEnd(app)
        self._toolbar_end.show()
        self.pack_start(self._toolbar_playback)
        self.pack_start(self._toolbar_info)
        self.set_custom_title(self._toolbar_title)
        self.pack_end(self._toolbar_end)

        Lp().player.connect('status-changed', self._on_status_changed)
        Lp().player.connect('current-changed', self._on_current_changed)
        Lp().player.connect('next-changed', self._on_next_changed)
        Lp().player.connect('prev-changed', self._on_prev_changed)

    def do_get_preferred_height(self):
        """
            Here, we calculate height based on:
            - playback toolbar if bigger
            - infos toolbar to adapt to font size then
        """
        style = self.get_style_context()
        padding = style.get_padding(style.get_state())
        info_height = self._toolbar_info.get_preferred_height()
        if info_height[0]+padding.top+padding.bottom > 47:
            height = info_height[0]+padding.top+padding.bottom
        else:
            height = 47
        return (height, height)

    def do_get_preferred_width(self):
        """
            Allow snapping for screen with width > 1400
            @return (int, int)
        """
        return (WindowSize.SMALL, self._width)

    def set_content_width(self, window_width):
        """
            Calculate infos/title width
            @param window width as int
        """
        width = self._toolbar_playback.get_preferred_width()[1]
        if window_width < WindowSize.MONSTER:
            self._toolbar_info.hide()
        else:
            self._toolbar_info.show()
        if window_width < WindowSize.BIG:
            self._toolbar_end.hide()
        else:
            width += self._toolbar_end.get_preferred_width()[1]
            self._toolbar_end.show()
        window = self.get_window()
        if window is not None:
            available = window.get_width() - width
            if available > 0:
                if window_width >= WindowSize.MONSTER:
                    title = available/2
                else:
                    title = available
                self._toolbar_title.set_width(title)
                if window_width >= WindowSize.MEDIUM:
                    self._toolbar_info.set_width((available-title)/2)
            self._width = window.get_width()

    def update_position(self, value=None):
        """
            Update progress bar position
            @param value as int
        """
        self._toolbar_title._update_position(value)

    def setup_menu(self, menu):
        """
            Add an application menu to menu button
            @parma: menu as Gio.Menu
        """
        self._toolbar_end.setup_menu(menu)

    def set_mark(self):
        """
            Mark toolbar with previously saved position
        """
        try:
            if Lp().settings.get_value('save-state'):
                position = load(open(DataPath + "/position.bin", "rb"))
                self._toolbar_title.add_mark(position/1000000)
        except Exception as e:
            print("Toolbar::restore_state():", e)

    @property
    def artsize(self):
        """
            Art size as int
        """
        return self._toolbar_info.artsize

#######################
# PRIVATE             #
#######################
    def _on_current_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        debug("Toolbar::_on_current_changed")
        self._toolbar_playback.on_current_changed(player)
        self._toolbar_info.on_current_changed(player)
        self._toolbar_title.on_current_changed(player)

    def _on_prev_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_prev_changed(player)

    def _on_next_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_next_changed(player)
        self._toolbar_end.on_next_changed(player)

    def _on_status_changed(self, player):
        """
            Update buttons and progress bar
            @param player as Player
        """
        self._toolbar_playback.on_status_changed(player)
        self._toolbar_title.on_status_changed(player)
        self._toolbar_end.on_status_changed(player)
Example #9
0
class Toolbar(Gtk.HeaderBar):
    """
        Lollypop toolbar
    """
    def __init__(self):
        """
            Init toolbar
        """
        Gtk.HeaderBar.__init__(self)
        self.__width = WindowSize.SMALL
        self.set_title("Lollypop")
        self.__toolbar_playback = ToolbarPlayback()
        self.__toolbar_playback.show()
        self.__toolbar_info = ToolbarInfo()
        self.__toolbar_info.show()
        self.__toolbar_title = ToolbarTitle()
        self.__toolbar_title.show()
        self.__toolbar_end = ToolbarEnd()
        self.__toolbar_end.show()
        self.pack_start(self.__toolbar_playback)
        self.pack_start(self.__toolbar_info)
        self.set_custom_title(self.__toolbar_title)
        self.pack_end(self.__toolbar_end)

        Lp().player.connect("status-changed", self.__on_status_changed)
        Lp().player.connect("current-changed", self.__on_current_changed)
        Lp().player.connect("next-changed", self.__on_next_changed)
        Lp().player.connect("prev-changed", self.__on_prev_changed)

    def do_get_preferred_height(self):
        """
            Here, we calculate height based on:
            - playback toolbar if bigger
            - infos toolbar to adapt to font size then
        """
        style = self.get_style_context()
        padding = style.get_padding(style.get_state())
        info_height = self.__toolbar_info.get_preferred_height()
        if info_height[0] + padding.top + padding.bottom > 47:
            height = info_height[0] + padding.top + padding.bottom
        else:
            height = Gtk.HeaderBar.do_get_preferred_height(self)[0]
        return (height, height)

    def do_get_preferred_width(self):
        """
            Allow snapping for screen with width > 1400
            @return (int, int)
        """
        return (WindowSize.SMALL, self.__width)

    def set_content_width(self, window_width):
        """
            Calculate infos/title width
            @param window width as int
        """
        width = self.__toolbar_playback.get_preferred_width()[1]
        if window_width < WindowSize.MONSTER:
            self.__toolbar_info.hide()
        else:
            self.__toolbar_info.show()
        if window_width < WindowSize.BIG:
            self.__toolbar_end.hide()
        else:
            width += self.__toolbar_end.get_preferred_width()[1]
            self.__toolbar_end.show()
        window = self.get_window()
        if window is not None:
            available = window.get_width() - width
            if available > 0:
                if window_width >= WindowSize.MONSTER:
                    title = available / 2
                else:
                    title = available
                self.__toolbar_title.set_width(title)
                if window_width >= WindowSize.MEDIUM:
                    self.__toolbar_info.set_width((available - title) / 2)
            self.__width = window.get_width()

    def update_position(self, value=None):
        """
            Update progress bar position
            @param value as int
        """
        if not self.__toolbar_title._show_volume_control:
            self.__toolbar_title._update_position(value)

    def setup_menu(self, menu):
        """
            Add an application menu to menu button
            @parma: menu as Gio.Menu
        """
        self.__toolbar_end.setup_menu(menu)

    def set_mark(self):
        """
            Mark toolbar with previously saved position
        """
        try:
            if Lp().settings.get_value("save-state"):
                from pickle import load
                position = load(open(DataPath + "/position.bin", "rb"))
                self.__toolbar_title.add_mark(position / Gst.SECOND)
        except Exception as e:
            print("Toolbar::restore_state():", e)

    def search(self, search):
        """
            Search item
            @param search as str
        """
        self.__toolbar_end.search(search)

    def show_hide_volume_control(self):
        """
            Show/Hide volume control
        """
        self.__toolbar_title.show_hide_volume_control()

    @property
    def artsize(self):
        """
            Art size as int
        """
        return self.__toolbar_info.artsize

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

    def __on_current_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        debug("Toolbar::_on_current_changed")
        self.__toolbar_playback.on_current_changed(player)
        self.__toolbar_info.on_current_changed(player)
        self.__toolbar_title.on_current_changed(player)

    def __on_prev_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self.__toolbar_playback.on_prev_changed(player)

    def __on_next_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self.__toolbar_playback.on_next_changed(player)
        self.__toolbar_end.on_next_changed(player)

    def __on_status_changed(self, player):
        """
            Update buttons and progress bar
            @param player as Player
        """
        self.__toolbar_playback.on_status_changed(player)
        self.__toolbar_title.on_status_changed(player)
        self.__toolbar_end.on_status_changed(player)
Example #10
0
class Toolbar(Gtk.HeaderBar):
    """
        Lollypop toolbar
    """

    def __init__(self, app):
        """
            Init toolbar
            @param app as Gtk.Application
        """
        Gtk.HeaderBar.__init__(self)

        self._toolbar_playback = ToolbarPlayback()
        self._toolbar_playback.show()
        self._toolbar_infos = ToolbarInfos()
        self._toolbar_infos.show()
        self._toolbar_title = ToolbarTitle()
        self._toolbar_title.show()
        self._toolbar_end = ToolbarEnd(app)
        self._toolbar_end.show()
        self.pack_start(self._toolbar_playback)
        self.pack_start(self._toolbar_infos)
        self.set_custom_title(self._toolbar_title)
        self.pack_end(self._toolbar_end)

        Lp().player.connect('status-changed', self._on_status_changed)
        Lp().player.connect('current-changed', self._on_current_changed)
        Lp().player.connect('next-changed', self._on_next_changed)

    def do_get_preferred_height(self):
        """
            Here, we calculate height based on left widget
            We want to ignore titlebox height, like in original Gtk+ code
            Simplified version here
        """
        style = self.get_style_context()
        padding = style.get_padding(style.get_state())
        toolbar_height = self._toolbar_playback.get_preferred_height()
        return (toolbar_height[0]+padding.top+padding.bottom,
                toolbar_height[1]+padding.top+padding.bottom)

    def update_position(self, value=None):
        """
            Update progress bar position
            @param value as int
        """
        self._toolbar_title._update_position(value)

    def set_progress_width(self, width):
        """
            Set Gtk.Scale progress width
            @param width as int
        """
        self._toolbar_title.set_progress_width(width)

    def setup_menu_btn(self, menu):
        """
            Add an application menu to menu button
            @parma: menu as Gio.Menu
        """
        self._toolbar_end.setup_menu_btn(menu)

#######################
# PRIVATE             #
#######################
    def _on_current_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_current_changed(player)
        self._toolbar_infos.on_current_changed(player)
        self._toolbar_title.on_current_changed(player)

    def _on_next_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_next_changed(player)
        self._toolbar_end.on_next_changed(player)

    def _on_status_changed(self, player):
        """
            Update buttons and progress bar
            @param player as Player
        """
        self._toolbar_playback.on_status_changed(player)
        self._toolbar_infos.on_status_changed(player)
        self._toolbar_title.on_status_changed(player)
        self._toolbar_end.on_status_changed(player)
Example #11
0
class Toolbar(Gtk.HeaderBar):
    """
        Lollypop toolbar
    """

    def __init__(self, app):
        """
            Init toolbar
            @param app as Gtk.Application
        """
        Gtk.HeaderBar.__init__(self)

        self._toolbar_playback = ToolbarPlayback()
        self._toolbar_playback.show()
        self._toolbar_infos = ToolbarInfos()
        self._toolbar_infos.show()
        self._toolbar_title = ToolbarTitle()
        self._toolbar_title.show()
        self._toolbar_end = ToolbarEnd(app)
        self._toolbar_end.show()
        self.pack_start(self._toolbar_playback)
        self.pack_start(self._toolbar_infos)
        self.set_custom_title(self._toolbar_title)
        self.pack_end(self._toolbar_end)

        Lp().player.connect('status-changed', self._on_status_changed)
        Lp().player.connect('current-changed', self._on_current_changed)
        Lp().player.connect('next-changed', self._on_next_changed)

    def do_get_preferred_height(self):
        """
            Here, we calculate height based on:
            - playback toolbar if bigger
            - infos toolbar to adapt to font size then
        """
        style = self.get_style_context()
        padding = style.get_padding(style.get_state())
        playback_height = self._toolbar_playback.get_preferred_height()
        info_height = self._toolbar_infos.get_preferred_height()
        if playback_height > info_height:
            return (playback_height[0]+padding.top+padding.bottom,
                    playback_height[1]+padding.top+padding.bottom)
        else:
            return (info_height[0]+padding.top+padding.bottom+1,
                    info_height[1]+padding.top+padding.bottom+1)

    def update_position(self, value=None):
        """
            Update progress bar position
            @param value as int
        """
        self._toolbar_title._update_position(value)

    def set_progress_width(self, width):
        """
            Set Gtk.Scale progress width
            @param width as int
        """
        self._toolbar_title.set_progress_width(width)

    def setup_menu_btn(self, menu):
        """
            Add an application menu to menu button
            @parma: menu as Gio.Menu
        """
        self._toolbar_end.setup_menu_btn(menu)

#######################
# PRIVATE             #
#######################
    def _on_current_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_current_changed(player)
        self._toolbar_infos.on_current_changed(player)
        self._toolbar_title.on_current_changed(player)

    def _on_next_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_next_changed(player)
        self._toolbar_end.on_next_changed(player)

    def _on_status_changed(self, player):
        """
            Update buttons and progress bar
            @param player as Player
        """
        self._toolbar_playback.on_status_changed(player)
        self._toolbar_infos.on_status_changed(player)
        self._toolbar_title.on_status_changed(player)
        self._toolbar_end.on_status_changed(player)
Example #12
0
class Toolbar(Gtk.HeaderBar):
    """
        Lollypop toolbar
    """
    def __init__(self, window):
        """
            Init toolbar
            @param window as Window
        """
        Gtk.HeaderBar.__init__(self)
        self.__width = Sizing.SMALL
        self.set_title("Lollypop")
        self.__toolbar_playback = ToolbarPlayback(window)
        self.__toolbar_playback.show()
        self.__toolbar_info = ToolbarInfo()
        self.__toolbar_info.show()
        self.__toolbar_title = ToolbarTitle()
        self.__toolbar_end = ToolbarEnd()
        self.__toolbar_end.show()
        self.pack_start(self.__toolbar_playback)
        self.pack_start(self.__toolbar_info)
        self.set_custom_title(self.__toolbar_title)
        self.pack_end(self.__toolbar_end)

        App().player.connect("status-changed", self.__on_status_changed)
        App().player.connect("current-changed", self.__on_current_changed)
        App().player.connect("next-changed", self.__on_next_changed)
        App().player.connect("prev-changed", self.__on_prev_changed)
        window.connect("adaptive-changed", self.__on_adaptive_changed)

    def do_get_preferred_width(self):
        """
            Allow snapping for screen with width < 1400
            @return (int, int)
        """
        return (Sizing.SMALL, self.__width)

    def set_content_width(self, window_width):
        """
            Calculate infos/title width
            @param window width as int
        """
        width = self.__toolbar_playback.get_preferred_width()[1]
        width += self.__toolbar_end.get_preferred_width()[1]
        window = self.get_window()
        if window is not None:
            available = window.get_width() - width
            if available > 0:
                if window_width >= Sizing.MEDIUM:
                    title = available / 2
                else:
                    title = available
                self.__toolbar_title.set_width(title)
                self.__toolbar_info.set_width((available - title) / 2)
            self.__width = window.get_width()

    def update_position(self, value=None):
        """
            Update progress bar position
            @param value as int
        """
        if not self.__toolbar_title.show_volume_control:
            self.__toolbar_title.update_position(value)

    def set_mini(self, mini):
        """
            Set toolbar working when small
            @param mini as bool
        """
        self.__toolbar_info.set_mini(mini)
        self.__toolbar_title.set_mini(mini)

    @property
    def end(self):
        """
            Return end toolbar
            @return ToolbarEnd
        """
        return self.__toolbar_end

    @property
    def info(self):
        """
            Return info toolbar
            @return ToolbarInfo
        """
        return self.__toolbar_info

    @property
    def title(self):
        """
            Return title toolbar
            @return ToolbarTitle
        """
        return self.__toolbar_title

    @property
    def playback(self):
        """
            Return playback toolbar
            @return ToolbarPlayback
        """
        return self.__toolbar_playback

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

    def __on_current_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        Logger.debug("Toolbar::_on_current_changed()")
        self.__toolbar_playback.on_current_changed(player)
        self.__toolbar_info.on_current_changed(player)
        if App().player.current_track.id is None:
            self.__toolbar_title.hide()
        elif not App().window.miniplayer:
            self.__toolbar_title.show()
        self.__toolbar_title.on_current_changed(player)

    def __on_prev_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self.__toolbar_playback.on_prev_changed(player)

    def __on_next_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self.__toolbar_playback.on_next_changed(player)
        self.__toolbar_end.on_next_changed(player)

    def __on_status_changed(self, player):
        """
            Update buttons and progress bar
            @param player as Player
        """
        self.__toolbar_playback.on_status_changed(player)
        self.__toolbar_title.on_status_changed(player)

    def __on_adaptive_changed(self, window, adaptive):
        """
            Show/hide next popover
            @param window as Window
            @param adaptive as bool
        """
        if adaptive:
            self.__toolbar_end.next_popover.hide()
        elif self.__toolbar_end.next_popover.should_be_shown():
            self.__toolbar_end.next_popover.popup()
Example #13
0
class Toolbar(Gtk.HeaderBar, SizeAllocationHelper, SignalsHelper):
    """
        Lollypop toolbar
    """
    @signals
    def __init__(self, window):
        """
            Init toolbar
            @param window as Window
        """
        Gtk.HeaderBar.__init__(self)
        SizeAllocationHelper.__init__(self)
        self.__width = Size.MINI
        self.__timeout_id = None
        self.set_title("Lollypop")
        self.__toolbar_playback = ToolbarPlayback(window)
        self.__toolbar_playback.show()
        self.__toolbar_info = ToolbarInfo()
        self.__toolbar_info.show()
        self.__toolbar_title = ToolbarTitle()
        self.__toolbar_end = ToolbarEnd(window)
        self.__toolbar_end.show()
        self.pack_start(self.__toolbar_playback)
        self.pack_start(self.__toolbar_info)
        self.set_custom_title(self.__toolbar_title)
        self.pack_end(self.__toolbar_end)
        return [(App().player, "current-changed", "_on_current_changed"),
                (App().window.container.widget, "notify::folded",
                 "_on_container_folded")]

    def do_get_preferred_width(self):
        """
            Allow window resize
            @return (int, int)
        """
        width = max(Size.PHONE, self.__width)
        return (Size.PHONE, width)

    def hide_info_and_buttons(self, folded):
        """
            Hide information and buttons
            @param folded as bool
        """
        def show_children():
            self.__timeout_id = None
            self.__toolbar_info.show_children()

        if self.__timeout_id is not None:
            GLib.source_remove(self.__timeout_id)
            self.__timeout_id = None

        if folded:
            self.__toolbar_playback.player_buttons.hide()
            self.__toolbar_title.hide()
            self.__toolbar_info.hide_children()
        else:
            if App().player.current_track.id is not None:
                self.__toolbar_title.show()
            # If user double click headerbar to maximize window
            # We do not want info bar to receive click signal
            self.__timeout_id = GLib.timeout_add(200, show_children)
            self.__toolbar_playback.player_buttons.show()

    @property
    def end(self):
        """
            Return end toolbar
            @return ToolbarEnd
        """
        return self.__toolbar_end

    @property
    def info(self):
        """
            Return info toolbar
            @return ToolbarInfo
        """
        return self.__toolbar_info

    @property
    def title(self):
        """
            Return title toolbar
            @return ToolbarTitle
        """
        return self.__toolbar_title

    @property
    def playback(self):
        """
            Return playback toolbar
            @return ToolbarPlayback
        """
        return self.__toolbar_playback

#######################
# PROTECTED           #
#######################

    def _handle_width_allocate(self, allocation):
        """
            Update artwork
            @param allocation as Gtk.Allocation
        """
        if SizeAllocationHelper._handle_width_allocate(self, allocation):
            width = self.__toolbar_playback.get_preferred_width()[1]
            width += self.__toolbar_end.get_preferred_width()[1]
            available = allocation.width - width
            if allocation.width < Size.BIG:
                title_width = available / 3
            else:
                title_width = available / 2.5
            self.__toolbar_title.set_width(title_width)
            self.__toolbar_info.set_width((available - title_width) / 2)

    def _on_current_changed(self, player):
        """
            Update buttons and progress bar
            @param player as Player
        """
        if player.current_track.id is not None and\
                not App().window.folded:
            if isinstance(player.current_track, Track):
                self.__toolbar_title.show()
            else:
                self.__toolbar_title.hide()
            self.__toolbar_info.show_children()
        else:
            self.__toolbar_title.hide()
            self.__toolbar_info.hide_children()

    def _on_container_folded(self, leaflet, folded):
        """
            Update internal widgets
            @param leaflet as Handy.Leaflet
            @param folded as Gparam
        """
        self.hide_info_and_buttons(App().window.folded)
Example #14
0
class Toolbar(Gtk.HeaderBar):
    """
        Lollypop toolbar
        Real widget is Toolbar.widget
    """
    def __init__(self, app):
        """
            Init toolbar
            @param app as Gtk.Application
        """
        Gtk.HeaderBar.__init__(self)

        self._toolbar_playback = ToolbarPlayback()
        self._toolbar_playback.show()
        self._toolbar_infos = ToolbarInfos()
        self._toolbar_infos.show()
        self._toolbar_title = ToolbarTitle()
        self._toolbar_title.show()
        self._toolbar_end = ToolbarEnd(app)
        self._toolbar_end.show()
        self.pack_start(self._toolbar_playback)
        self.pack_start(self._toolbar_infos)
        self.set_custom_title(self._toolbar_title)
        self.pack_end(self._toolbar_end)

        Lp.player.connect('status-changed', self._on_status_changed)
        Lp.player.connect('current-changed', self._on_current_changed)

    def do_get_preferred_height(self):
        """
            Here, we calculate height based on left widget
            We want to ignore titlebox height, like in original Gtk+ code
            Simplified version here
        """
        style = self.get_style_context()
        padding = style.get_padding(style.get_state())
        toolbar_height = self._toolbar_playback.get_preferred_height()
        return (toolbar_height[0] + padding.top + padding.bottom,
                toolbar_height[1] + padding.top + padding.bottom)

    def update_position(self, value=None):
        """
            Update progress bar position
            @param value as int
        """
        self._toolbar_title.update_position(value)

    def set_progress_width(self, width):
        """
            Set Gtk.Scale progress width
            @param width as int
        """
        self._toolbar_title.set_progress_width(width)

    def setup_menu_btn(self, menu):
        """
            Add an application menu to menu button
            @parma: menu as Gio.Menu
        """
        self._toolbar_end.setup_menu_btn(menu)

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

    def _on_current_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_current_changed(player)
        self._toolbar_infos.on_current_changed(player)
        self._toolbar_title.on_current_changed(player)
        self._toolbar_end.on_current_changed(player)

    def _on_status_changed(self, player):
        """
            Update buttons and progress bar
            @param player as Player
        """
        self._toolbar_playback.on_status_changed(player)
        self._toolbar_infos.on_status_changed(player)
        self._toolbar_title.on_status_changed(player)
        self._toolbar_end.on_status_changed(player)
Example #15
0
class Toolbar(Gtk.HeaderBar):
    """
        Lollypop toolbar
    """

    def __init__(self, app):
        """
            Init toolbar
            @param app as Gtk.Application
        """
        Gtk.HeaderBar.__init__(self)
        self._width = 700

        self._toolbar_playback = ToolbarPlayback()
        self._toolbar_playback.show()
        self._toolbar_infos = ToolbarInfos()
        self._toolbar_infos.show()
        self._toolbar_title = ToolbarTitle()
        self._toolbar_title.show()
        self._toolbar_end = ToolbarEnd(app)
        self._toolbar_end.show()
        self.pack_start(self._toolbar_playback)
        self.pack_start(self._toolbar_infos)
        self.set_custom_title(self._toolbar_title)
        self.pack_end(self._toolbar_end)

        Lp().player.connect('status-changed', self._on_status_changed)
        Lp().player.connect('current-changed', self._on_current_changed)
        Lp().player.connect('next-changed', self._on_next_changed)
        Lp().player.connect('prev-changed', self._on_prev_changed)

    def do_get_preferred_height(self):
        """
            Here, we calculate height based on:
            - playback toolbar if bigger
            - infos toolbar to adapt to font size then
        """
        style = self.get_style_context()
        padding = style.get_padding(style.get_state())
        info_height = self._toolbar_infos.get_preferred_height()
        if info_height[0]+padding.top+padding.bottom > 47:
            height = info_height[0]+padding.top+padding.bottom
        else:
            height = 47
        return (height, height)

    def do_get_preferred_width(self):
        """
            Allow snapping for screen with width > 1400
            @return (int, int)
        """
        return (700, self._width)

    def set_content_width(self):
        """
            Calculate infos/title width
        """
        width = self._toolbar_playback.get_preferred_width()[1] + \
            self._toolbar_end.get_preferred_width()[1]
        window = self.get_window()
        if window is not None:
            available = window.get_width() - width
            if available > 0:
                title = available/2
                self._toolbar_title.set_width(title)
                self._toolbar_infos.set_width((available-title)/2)
            self._width = window.get_width()

    def update_position(self, value=None):
        """
            Update progress bar position
            @param value as int
        """
        self._toolbar_title._update_position(value)

    def setup_menu_btn(self, menu):
        """
            Add an application menu to menu button
            @parma: menu as Gio.Menu
        """
        self._toolbar_end.setup_menu_btn(menu)

#######################
# PRIVATE             #
#######################
    def _on_current_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_current_changed(player)
        self._toolbar_infos.on_current_changed(player)
        self._toolbar_title.on_current_changed(player)

    def _on_prev_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_prev_changed(player)

    def _on_next_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_next_changed(player)
        self._toolbar_end.on_next_changed(player)

    def _on_status_changed(self, player):
        """
            Update buttons and progress bar
            @param player as Player
        """
        self._toolbar_playback.on_status_changed(player)
        self._toolbar_infos.on_status_changed(player)
        self._toolbar_title.on_status_changed(player)
        self._toolbar_end.on_status_changed(player)
Example #16
0
class Toolbar(Gtk.HeaderBar):
    """
        Lollypop toolbar
    """
    def __init__(self, app):
        """
            Init toolbar
            @param app as Gtk.Application
        """
        Gtk.HeaderBar.__init__(self)

        self._toolbar_playback = ToolbarPlayback()
        self._toolbar_playback.show()
        self._toolbar_infos = ToolbarInfos()
        self._toolbar_infos.show()
        self._toolbar_title = ToolbarTitle()
        self._toolbar_title.show()
        self._toolbar_end = ToolbarEnd(app)
        self._toolbar_end.show()
        self.pack_start(self._toolbar_playback)
        self.pack_start(self._toolbar_infos)
        self.set_custom_title(self._toolbar_title)
        self.pack_end(self._toolbar_end)

        Lp().player.connect('status-changed', self._on_status_changed)
        Lp().player.connect('current-changed', self._on_current_changed)
        Lp().player.connect('next-changed', self._on_next_changed)

    def do_get_preferred_height(self):
        """
            Here, we calculate height based on:
            - playback toolbar if bigger
            - infos toolbar to adapt to font size then
        """
        style = self.get_style_context()
        padding = style.get_padding(style.get_state())
        info_height = self._toolbar_infos.get_preferred_height()
        return (info_height[0] + padding.top + padding.bottom,
                info_height[1] + padding.top + padding.bottom)

    def update_position(self, value=None):
        """
            Update progress bar position
            @param value as int
        """
        self._toolbar_title._update_position(value)

    def set_progress_width(self, width):
        """
            Set Gtk.Scale progress width
            @param width as int
        """
        self._toolbar_title.set_progress_width(width)

    def setup_menu_btn(self, menu):
        """
            Add an application menu to menu button
            @parma: menu as Gio.Menu
        """
        self._toolbar_end.setup_menu_btn(menu)

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

    def _on_current_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_current_changed(player)
        self._toolbar_infos.on_current_changed(player)
        self._toolbar_title.on_current_changed(player)

    def _on_next_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_next_changed(player)
        self._toolbar_end.on_next_changed(player)

    def _on_status_changed(self, player):
        """
            Update buttons and progress bar
            @param player as Player
        """
        self._toolbar_playback.on_status_changed(player)
        self._toolbar_infos.on_status_changed(player)
        self._toolbar_title.on_status_changed(player)
        self._toolbar_end.on_status_changed(player)
Example #17
0
class Toolbar(Gtk.HeaderBar):
    """
        Lollypop toolbar
    """
    def __init__(self, app):
        """
            Init toolbar
            @param app as Gtk.Application
        """
        Gtk.HeaderBar.__init__(self)
        self._width = WindowSize.SMALL
        self.set_title("Lollypop")
        self._toolbar_playback = ToolbarPlayback()
        self._toolbar_playback.show()
        self._toolbar_info = ToolbarInfo()
        self._toolbar_info.show()
        self._toolbar_title = ToolbarTitle()
        self._toolbar_title.show()
        self._toolbar_end = ToolbarEnd(app)
        self._toolbar_end.show()
        self.pack_start(self._toolbar_playback)
        self.pack_start(self._toolbar_info)
        self.set_custom_title(self._toolbar_title)
        self.pack_end(self._toolbar_end)

        Lp().player.connect('status-changed', self._on_status_changed)
        Lp().player.connect('current-changed', self._on_current_changed)
        Lp().player.connect('next-changed', self._on_next_changed)
        Lp().player.connect('prev-changed', self._on_prev_changed)

    def do_get_preferred_height(self):
        """
            Here, we calculate height based on:
            - playback toolbar if bigger
            - infos toolbar to adapt to font size then
        """
        style = self.get_style_context()
        padding = style.get_padding(style.get_state())
        info_height = self._toolbar_info.get_preferred_height()
        if info_height[0] + padding.top + padding.bottom > 47:
            height = info_height[0] + padding.top + padding.bottom
        else:
            height = 47
        return (height, height)

    def do_get_preferred_width(self):
        """
            Allow snapping for screen with width > 1400
            @return (int, int)
        """
        return (WindowSize.SMALL, self._width)

    def set_content_width(self, window_width):
        """
            Calculate infos/title width
            @param window width as int
        """
        width = self._toolbar_playback.get_preferred_width()[1]
        if window_width < WindowSize.MONSTER:
            self._toolbar_info.hide()
        else:
            self._toolbar_info.show()
        if window_width < WindowSize.BIG:
            self._toolbar_end.hide()
        else:
            width += self._toolbar_end.get_preferred_width()[1]
            self._toolbar_end.show()
        window = self.get_window()
        if window is not None:
            available = window.get_width() - width
            if available > 0:
                if window_width >= WindowSize.MONSTER:
                    title = available / 2
                else:
                    title = available
                self._toolbar_title.set_width(title)
                if window_width >= WindowSize.MEDIUM:
                    self._toolbar_info.set_width((available - title) / 2)
            self._width = window.get_width()

    def update_position(self, value=None):
        """
            Update progress bar position
            @param value as int
        """
        self._toolbar_title._update_position(value)

    def setup_menu(self, menu):
        """
            Add an application menu to menu button
            @parma: menu as Gio.Menu
        """
        self._toolbar_end.setup_menu(menu)

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

    def _on_current_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_current_changed(player)
        self._toolbar_info.on_current_changed(player)
        self._toolbar_title.on_current_changed(player)

    def _on_prev_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_prev_changed(player)

    def _on_next_changed(self, player):
        """
            Update toolbar
            @param player as Player
        """
        self._toolbar_playback.on_next_changed(player)
        self._toolbar_end.on_next_changed(player)

    def _on_status_changed(self, player):
        """
            Update buttons and progress bar
            @param player as Player
        """
        self._toolbar_playback.on_status_changed(player)
        self._toolbar_title.on_status_changed(player)
        self._toolbar_end.on_status_changed(player)