32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""An OSD to show when tracks are selected."""
|
|
from gi.repository import GObject
|
|
from gi.repository import Gtk
|
|
from .. import playlist
|
|
|
|
|
|
class OSD(Gtk.Overlay):
|
|
"""An Overlay with extra controls for the Tracklist."""
|
|
|
|
playlist = GObject.Property(type=playlist.playlist.Playlist)
|
|
selection = GObject.Property(type=Gtk.SelectionModel)
|
|
|
|
have_selected = GObject.Property(type=bool, default=False)
|
|
n_selected = GObject.Property(type=int)
|
|
|
|
def __init__(self, selection: Gtk.SelectionModel, **kwargs):
|
|
"""Initialize an OSD."""
|
|
super().__init__(selection=selection, **kwargs)
|
|
|
|
self.selection.connect("selection-changed", self.__selection_changed)
|
|
|
|
def __selection_changed(self, selection: Gtk.SelectionModel,
|
|
position: int, n_items: int) -> None:
|
|
self.n_selected = selection.get_selection().get_size()
|
|
self.have_selected = self.n_selected > 0
|
|
|
|
def clear_selection(self, *args) -> None:
|
|
"""Clear the current selection."""
|
|
self.selection.unselect_all()
|
|
self.__selection_changed(self.selection, 0, 0)
|