68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
# Copyright 2021 (c) Anna Schumaker.
|
|
from gi.repository import Gtk, GLib, Pango
|
|
import tagdb
|
|
|
|
class TagRow(Gtk.ListBoxRow):
|
|
def __init__(self, tag, icon):
|
|
Gtk.ListBoxRow.__init__(self)
|
|
self.tag = tag
|
|
self.grid = Gtk.Grid()
|
|
self.image = Gtk.Image.new_from_icon_name(icon)
|
|
self.image.set_margin_start(5)
|
|
self.image.set_margin_end(5)
|
|
|
|
self.label = Gtk.Label()
|
|
self.label.set_halign(Gtk.Align.START)
|
|
self.label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
|
|
self.label.set_hexpand(True)
|
|
|
|
self.grid.attach(self.image, 0, 0, 1, 1)
|
|
self.grid.attach(self.label, 1, 0, 1, 1)
|
|
self.grid.set_margin_end(5)
|
|
self.set_child(self.grid)
|
|
self.set_label()
|
|
|
|
def set_label(self):
|
|
count = len(self.tag)
|
|
bold = tagdb.Stack.current() == self.tag
|
|
text = f"{self.tag.name}\n{count} Track{'s' if count != 1 else ''}"
|
|
self.label.set_markup(("<b>%s</b>" if bold else "%s") %
|
|
GLib.markup_escape_text(text))
|
|
|
|
|
|
class ParentTagRow(TagRow):
|
|
def __init__(self, tag, icon):
|
|
TagRow.__init__(self, tag, icon)
|
|
self.children = [ ]
|
|
self.expander = Gtk.ToggleButton()
|
|
self.expander.connect("toggled", self.on_toggle)
|
|
self.expander.set_icon_name("pan-end-symbolic")
|
|
self.expander.add_css_class("flat")
|
|
|
|
self.grid.insert_column(0)
|
|
self.grid.attach(self.expander, 0, 0, 1, 1)
|
|
|
|
def add_child(self, child):
|
|
self.children.append(child)
|
|
child.set_visible(self.expander.get_active())
|
|
|
|
def on_toggle(self, button):
|
|
direction = "down" if self.expander.get_active() else "end"
|
|
self.expander.set_icon_name(f"pan-{direction}-symbolic")
|
|
for child in self.children:
|
|
child.set_visible(self.expander.get_active())
|
|
|
|
|
|
class TagHeader(Gtk.Box):
|
|
def __init__(self, char):
|
|
Gtk.Box.__init__(self)
|
|
self.set_orientation(Gtk.Orientation.VERTICAL)
|
|
self.set_margin_top(5)
|
|
|
|
self.label = Gtk.Label()
|
|
self.label.set_markup(f"<small><b>{char}</b></small>")
|
|
self.separator = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL)
|
|
|
|
self.append(self.label)
|
|
self.append(self.separator)
|