2021-06-29 11:44:10 -04:00
|
|
|
# Copyright 2021 (c) Anna Schumaker.
|
2021-07-17 21:27:26 -04:00
|
|
|
import audio
|
2021-11-03 13:11:31 -04:00
|
|
|
import lib
|
|
|
|
from gi.repository import Gtk, GLib
|
|
|
|
from lib import settings
|
2021-06-29 11:44:10 -04:00
|
|
|
|
2021-11-03 12:54:58 -04:00
|
|
|
|
|
|
|
class LabelFactory(Gtk.SignalListItemFactory):
|
|
|
|
def __init__(self, xalign):
|
|
|
|
Gtk.SignalListItemFactory.__init__(self)
|
|
|
|
self.connect("setup", self.on_setup)
|
|
|
|
self.connect("bind", self.on_bind)
|
|
|
|
self.connect("unbind", self.on_unbind)
|
|
|
|
self.connect("teardown", self.on_teardown)
|
|
|
|
self.xalign = xalign
|
|
|
|
|
|
|
|
def get_track_text(self, track):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def on_setup(self, factory, listitem):
|
|
|
|
listitem.set_child(Gtk.Label(xalign=self.xalign))
|
|
|
|
|
|
|
|
def on_bind(self, factory, listitem):
|
|
|
|
text = self.get_track_text(listitem.get_item())
|
|
|
|
listitem.get_child().set_text(text)
|
|
|
|
|
|
|
|
def on_unbind(self, factory, listitem):
|
|
|
|
listitem.get_child().set_text("")
|
|
|
|
|
|
|
|
def on_teardown(self, factory, listitem):
|
|
|
|
listitem.set_child(None)
|
|
|
|
|
|
|
|
|
2021-11-03 13:54:47 -04:00
|
|
|
class TracknoFactory(LabelFactory):
|
|
|
|
def __init__(self): LabelFactory.__init__(self, xalign=1)
|
|
|
|
def get_track_text(self, track): return f"{track.disc.number}-{track.number:02}"
|
|
|
|
|
|
|
|
|
2021-11-03 14:38:12 -04:00
|
|
|
class TitleFactory(LabelFactory):
|
|
|
|
def __init__(self): LabelFactory.__init__(self, xalign=0)
|
|
|
|
def get_track_text(self, track): return track.title
|
|
|
|
|
|
|
|
|
2021-06-29 11:44:10 -04:00
|
|
|
class Column(Gtk.ColumnViewColumn):
|
2021-11-03 13:11:31 -04:00
|
|
|
def __init__(self, title, factory, width=-1, **kwargs):
|
|
|
|
Gtk.ColumnViewColumn.__init__(self, title=title, **kwargs)
|
|
|
|
self.set_factory(factory)
|
|
|
|
self.set_resizable(True)
|
|
|
|
|
|
|
|
lib.settings.initialize(f"column.{title}", width)
|
|
|
|
self.set_fixed_width(settings.get_int(f"column.{title}"))
|
|
|
|
self.connect("notify::fixed-width", self.width_changed)
|
|
|
|
|
|
|
|
def width_changed(self, col, param):
|
|
|
|
lib.settings.set(f"column.{self.get_title()}", self.get_fixed_width())
|
|
|
|
|
|
|
|
|
2021-11-03 13:54:47 -04:00
|
|
|
def TracknoColumn(): return Column("#", TracknoFactory())
|
2021-11-03 14:38:12 -04:00
|
|
|
def TitleColumn(): return Column("Title", TitleFactory(), width=250, expand=True)
|
2021-11-03 13:54:47 -04:00
|
|
|
|
|
|
|
|
2021-11-03 13:11:31 -04:00
|
|
|
class OldColumn(Gtk.ColumnViewColumn):
|
2021-06-29 17:01:30 -04:00
|
|
|
def __init__(self, title, field, width=-1, expand=False, align=0):
|
2021-06-29 11:44:10 -04:00
|
|
|
Gtk.ColumnViewColumn.__init__(self)
|
2021-06-29 17:01:30 -04:00
|
|
|
self.field = field
|
|
|
|
self.align = align
|
|
|
|
|
|
|
|
self.factory = Gtk.SignalListItemFactory()
|
|
|
|
self.factory.connect("bind", self.on_bind)
|
|
|
|
self.factory.connect("setup", self.on_setup)
|
|
|
|
self.factory.connect("teardown", self.on_teardown)
|
|
|
|
self.factory.connect("unbind", self.on_unbind)
|
2021-06-29 11:44:10 -04:00
|
|
|
|
2021-06-29 11:55:29 -04:00
|
|
|
settings.initialize(f"column.{title}", width)
|
|
|
|
|
2021-06-29 17:01:30 -04:00
|
|
|
self.set_factory(self.factory)
|
2021-06-29 11:55:29 -04:00
|
|
|
self.set_fixed_width(settings.get_int(f"column.{title}"))
|
2021-06-29 12:52:09 -04:00
|
|
|
self.set_expand(expand)
|
2021-06-29 11:44:10 -04:00
|
|
|
self.set_resizable(True)
|
|
|
|
self.set_title(title)
|
2021-06-29 11:55:29 -04:00
|
|
|
self.connect("notify::fixed-width", self.on_width_changed)
|
|
|
|
|
|
|
|
def on_width_changed(self, col, param):
|
|
|
|
settings.set(f"column.{self.get_title()}", self.get_fixed_width())
|
2021-06-29 17:01:30 -04:00
|
|
|
|
|
|
|
def on_bind(self, factory, listitem):
|
|
|
|
track = listitem.get_item()
|
2021-07-17 21:27:26 -04:00
|
|
|
text = GLib.markup_escape_text(track[self.field])
|
|
|
|
if track == audio.Player.track:
|
|
|
|
text = f"<b>{text}</b>"
|
|
|
|
listitem.get_child().set_markup(text)
|
2021-06-29 17:01:30 -04:00
|
|
|
listitem.get_child().set_xalign(self.align)
|
|
|
|
|
|
|
|
def on_setup(self, factory, listitem):
|
|
|
|
listitem.set_child(Gtk.Label())
|
|
|
|
|
|
|
|
def on_teardown(self, factory, listitem):
|
|
|
|
listitem.set_child(None)
|
|
|
|
|
|
|
|
def on_unbind(self, factory, listitem):
|
|
|
|
pass
|