sidebar: Create a Section for Genres

This section uses the default Row for displaying genre playlists. I use
the theater icon from the gnome icon-library as the section header.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2022-08-30 14:41:02 -04:00
parent c396839316
commit 0f2a5aee9d
3 changed files with 70 additions and 0 deletions

28
emmental/sidebar/genre.py Normal file
View File

@ -0,0 +1,28 @@
# Copyright 2022 (c) Anna Schumaker.
"""Displays our genre playlists."""
from .. import db
from . import row
from . import section
class GenreRow(row.TreeRow):
"""A TreeRow for displaying Genre playlists."""
def __init__(self, *args, **kwargs):
"""Initialize a GenreRow."""
super().__init__(*args, indented=False, **kwargs)
self.child = row.Row()
class Section(section.Section):
"""A sidebar Section for the genre list."""
def __init__(self, table: db.genres.Table):
"""Initialize our Genre section."""
super().__init__(table, GenreRow, icon_name="theater",
title="Genres", subtitle="0 genres")
def do_get_subtitle(self, n_genres: int) -> str:
"""Return a subtitle for this section."""
s_genres = "s" if n_genres != 1 else ""
return f"{n_genres} genre{s_genres}"

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" height="16px" viewBox="0 0 16 16" width="16px"><g fill="#222222"><path d="m 8 0 c -2 0 -2 2 -2 2 v 1 h 2 c 0.226562 0 0.4375 0.027344 0.640625 0.070312 c 0.113281 -0.046874 0.230469 -0.070312 0.359375 -0.070312 c 0.449219 0 0.828125 0.296875 0.957031 0.699219 c 0 0.003906 -0.003906 0.003906 0 0.003906 c 0.308594 0.257813 0.542969 0.558594 0.6875 0.851563 c 0.371094 0.738281 0.355469 1.445312 0.355469 1.445312 c 1.105469 0 2 0.894531 2 2 h -2 v 2 s 0.003906 0.867188 -0.261719 1.992188 c 0.085938 0.007812 0.171875 0.007812 0.261719 0.007812 c 5 0 5 -6 5 -6 v -4 s 0 -2 -2 -2 z m 5 3 c 0.550781 0 1 0.449219 1 1 s -0.449219 1 -1 1 s -1 -0.449219 -1 -1 s 0.449219 -1 1 -1 z m -7 2 v 1 s 0 0.097656 0.011719 0.269531 c 0.292969 -0.171875 0.628906 -0.269531 0.988281 -0.269531 c 1.09375 0 2 0.90625 2 2 v -2 s -0.015625 -0.292969 -0.144531 -0.550781 c -0.128907 -0.261719 -0.1875 -0.449219 -0.855469 -0.449219 z m 3 3 c 0 1.042969 -0.824219 1.914062 -1.851562 1.992188 c 0.011718 0.011718 0.015624 0.023437 0.023437 0.035156 c 0.457031 0.082031 0.800781 0.46875 0.824219 0.933594 c 0.238281 0.207031 0.5 0.390624 0.800781 0.542968 c 0.191406 -0.835937 0.203125 -1.503906 0.203125 -1.503906 z m 0 0"/><path d="m 8 4 h -6 c -2 0 -2 2 -2 2 v 4 s 0 6 5 6 s 5 -6 5 -6 v -4 s 0 -2 -2 -2 z m -5 3 c 0.550781 0 1 0.449219 1 1 s -0.449219 1 -1 1 s -1 -0.449219 -1 -1 s 0.449219 -1 1 -1 z m 4 0 c 0.550781 0 1 0.449219 1 1 s -0.449219 1 -1 1 s -1 -0.449219 -1 -1 s 0.449219 -1 1 -1 z m -4 4 h 4 c 0 1.105469 -0.894531 2 -2 2 s -2 -0.894531 -2 -2 z m 0 0"/></g></svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1,40 @@
# Copyright 2022 (c) Anna Schumaker.
"""Tests our genre section."""
import emmental.sidebar.genre
import tests.util
from gi.repository import Gtk
class TestGenre(tests.util.TestCase):
"""Test our Genre section."""
def setUp(self):
"""Set up common variables."""
super().setUp()
self.genres = emmental.sidebar.genre.Section(self.sql.genres)
def test_init(self):
"""Test that the genre section is set up correctly."""
self.assertIsInstance(self.genres, emmental.sidebar.section.Section)
self.assertEqual(self.genres._factory.row_type,
emmental.sidebar.genre.GenreRow)
self.assertEqual(self.genres.table, self.sql.genres)
self.assertEqual(self.genres.icon_name, "theater")
self.assertEqual(self.genres.title, "Genres")
def test_subtitle(self):
"""Test that the subtitle property is set properly."""
self.assertEqual(self.genres.subtitle, "0 genres")
self.sql.genres.create("Genre 1")
self.assertEqual(self.genres.subtitle, "1 genre")
self.sql.genres.create("Genre 2")
self.assertEqual(self.genres.subtitle, "2 genres")
def test_genre_row(self):
"""Test the GenreRow."""
listitem = Gtk.ListItem()
row = emmental.sidebar.genre.GenreRow(listitem)
self.assertIsInstance(row, emmental.sidebar.row.TreeRow)
self.assertIsInstance(row.child, emmental.sidebar.row.Row)
self.assertFalse(row.indented)