45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
# Copyright 2022 (c) Anna Schumaker.
|
|
"""Extra buttons for the TrackList."""
|
|
from gi.repository import GObject
|
|
from gi.repository import Gio
|
|
from gi.repository import Gtk
|
|
from .. import buttons
|
|
from .. import factory
|
|
|
|
|
|
class VisibleSwitch(factory.ListRow):
|
|
"""A list row containing a Gtk.Switch."""
|
|
|
|
def __init__(self, listitem: Gtk.ListItem):
|
|
"""Initialize a VisibleSwitch ListRow."""
|
|
super().__init__(listitem=listitem, child=Gtk.Switch())
|
|
|
|
def do_bind(self) -> None:
|
|
"""Bind the visible property to the switch active property."""
|
|
self.bind_and_set_property("visible", "active", bidirectional=True)
|
|
|
|
|
|
class VisibleColumns(buttons.PopoverButton):
|
|
"""Shows a Popover Menu to select which columns are visible."""
|
|
|
|
columns = GObject.Property(type=Gio.ListModel)
|
|
|
|
def __init__(self, columns: Gio.ListModel, **kwargs):
|
|
"""Initialize the VisibleColumns button."""
|
|
super().__init__(columns=columns, icon_name="columns-symbolic",
|
|
has_frame=False, **kwargs)
|
|
self._selection = Gtk.NoSelection(model=self.columns)
|
|
self.popover_child = Gtk.ColumnView(model=self._selection,
|
|
show_row_separators=True)
|
|
self.__append_column(factory.InscriptionFactory("title"),
|
|
"Column", width=125)
|
|
self.__append_column(factory.Factory(row_type=VisibleSwitch),
|
|
"Visible")
|
|
self.popover_child.add_css_class("data-table")
|
|
|
|
def __append_column(self, factory: factory.Factory,
|
|
title: str, *, width: int = -1) -> None:
|
|
column = Gtk.ColumnViewColumn(factory=factory, title=title,
|
|
fixed_width=width)
|
|
self.popover_child.append_column(column)
|