emmental/playlist/view.py

67 lines
2.3 KiB
Python

# Copyright 2021 (c) Anna Schumaker.
import audio
from gi.repository import Gtk
from . import column
from . import model
from . import sort
class PlaylistView(Gtk.ColumnView):
def __init__(self):
Gtk.ColumnView.__init__(self)
self.add_css_class("data-table")
self.set_model(model.PlaylistSelection())
self.set_enable_rubberband(True)
self.set_hexpand(True)
self.set_vexpand(True)
self.connect("activate", self.activated)
self.append_column(column.TracknoColumn())
self.append_column(column.TitleColumn())
self.append_column(column.LengthColumn())
self.append_column(column.ArtistColumn())
self.append_column(column.AlbumColumn())
self.append_column(column.SubtitleColumn())
self.append_column(column.YearColumn())
self.append_column(column.PlayCountColumn())
self.append_column(column.LastPlayedColumn())
def activated(self, view, position):
track = self.get_model().get_item(position)
if audio.play_track(track):
plist = self.get_playlist()
if index := plist.get_track_index(track):
plist.current = index
def get_filter_model(self): return self.get_model().get_filter_model()
def get_playlist(self): return self.get_model().get_playlist()
def set_playlist(self, plist): self.get_model().set_playlist(plist)
class PlaylistWindow(Gtk.ScrolledWindow):
def __init__(self):
Gtk.ScrolledWindow.__init__(self)
self.set_child(PlaylistView())
def get_filter_model(self): return self.get_child().get_filter_model()
def get_playlist(self): return self.get_child().get_playlist()
def set_playlist(self, plist): self.get_child().set_playlist(plist)
class SortOrderView(Gtk.ListView):
def __init__(self):
Gtk.ListView.__init__(self)
self.set_model(Gtk.NoSelection.new(model.FlatSortModel()))
self.set_factory(sort.Factory(self.get_model().get_model()))
def set_playlist(self, plist):
self.get_model().get_model().set_playlist(plist)
class SortOrderPopover(Gtk.Popover):
def __init__(self):
Gtk.Popover.__init__(self)
self.set_child(SortOrderView())
def set_playlist(self, plist):
self.get_child().set_playlist(plist)