# Copyright 2021 (c) Anna Schumaker. import db import lib from gi.repository import Gtk from . import model from . import view class FilterEntry(lib.filter.Entry): def __init__(self): lib.filter.Entry.__init__(self, model.PlaylistFilter) self.set_margin_start(200) self.set_margin_end(200) self.set_hexpand(True) class PropertyToggle(Gtk.ToggleButton): def __init__(self, prop, icon): Gtk.ToggleButton.__init__(self) self.set_icon_name(icon) self.set_sensitive(False) self.property = prop self.playlist = None def set_playlist(self, plist): self.playlist = plist self.set_active(plist.get_property(self.property)) def do_toggled(self): if self.playlist: self.playlist.set_property(self.property, self.get_active()) class RandomToggle(PropertyToggle): def __init__(self): PropertyToggle.__init__(self, "random", "media-playlist-shuffle") def set_playlist(self, plist): super().set_playlist(plist) self.set_sensitive(plist != db.user.Table.find("Previous")) class LoopToggle(PropertyToggle): def __init__(self): PropertyToggle.__init__(self, "loop", "media-playlist-repeat") def set_playlist(self, plist): super().set_playlist(plist) self.set_sensitive(plist != db.user.Table.find("Collection") and plist != db.user.Table.find("Previous") and plist != db.user.Table.find("Queued Tracks")) class SortButton(Gtk.MenuButton): def __init__(self): Gtk.MenuButton.__init__(self) self.set_icon_name("view-sort-ascending") self.set_popover(view.SortOrderPopover()) self.set_sensitive(False) def set_playlist(self, plist): self.get_popover().set_playlist(plist) self.set_sensitive(plist != db.user.Table.find("Previous")) class JumpButton(Gtk.Button): def __init__(self): Gtk.Button.__init__(self) self.set_icon_name("go-jump") self.set_sensitive(False) def set_playlist(self, plist): self.set_sensitive(plist is not None) class ControlBox(Gtk.Box): def __init__(self): Gtk.Box.__init__(self, margin_top=5, margin_bottom=5, margin_end=5, margin_start=5) self.add_css_class("linked") def set_playlist(self, plist): child = self.get_first_child() while child: child.set_playlist(plist) child = child.get_next_sibling() class PlaylistBox(ControlBox): def __init__(self): ControlBox.__init__(self) self.append(RandomToggle()) self.append(LoopToggle()) self.append(SortButton()) self.append(JumpButton()) def get_jump_button(self): return self.get_last_child() class Header(Gtk.Box): def __init__(self): Gtk.Box.__init__(self) self.append(FilterEntry()) self.append(PlaylistBox()) def get_jump_button(self): return self.get_last_child().get_jump_button() def set_playlist(self, plist): self.get_last_child().set_playlist(plist)