sidebar: Convert the section Group into a View
I change it to inherit from Gtk.Box, and append Sections as they are added. I also add some stand-alone styling to set it apart as its own widget. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
a8e7078308
commit
7e99fd1ba0
|
@ -29,25 +29,23 @@ class Card(Gtk.Box):
|
|||
self._genres = genre.Section(self.sql.genres)
|
||||
self._decades = decade.Section(self.sql.decades, self.sql.years)
|
||||
self._libraries = library.Section(self.sql.libraries)
|
||||
self._group = section.Group(sql)
|
||||
self._view = section.View(sql)
|
||||
|
||||
self.append(self._filter)
|
||||
|
||||
for sect in [self._playlists, self._artists, self._genres,
|
||||
self._decades, self._libraries]:
|
||||
self.append(sect)
|
||||
self._group.add(sect)
|
||||
self._view.add(sect)
|
||||
self.append(self._view)
|
||||
|
||||
self._group.bind_property("selected-playlist",
|
||||
self, "selected-playlist")
|
||||
self._view.bind_property("selected-playlist",
|
||||
self, "selected-playlist")
|
||||
self.bind_property("show-all-artists", self._artists, "show-all",
|
||||
GObject.BindingFlags.BIDIRECTIONAL)
|
||||
|
||||
self._filter.connect("search-changed", self.__search_changed)
|
||||
self.sql.connect("table-loaded", self.__table_loaded)
|
||||
|
||||
self.add_css_class("background")
|
||||
self.add_css_class("linked")
|
||||
self.add_css_class("card")
|
||||
|
||||
def __search_changed(self, entry: entry.Filter) -> None:
|
||||
|
|
|
@ -99,8 +99,8 @@ class Section(header.Header):
|
|||
"""Signal that the selected playlist has changed."""
|
||||
|
||||
|
||||
class Group(GObject.GObject):
|
||||
"""A group of sections."""
|
||||
class View(Gtk.Box):
|
||||
"""A widget for displaying a group of sections."""
|
||||
|
||||
sql = GObject.Property(type=db.Connection)
|
||||
current = GObject.Property(type=Section)
|
||||
|
@ -108,8 +108,8 @@ class Group(GObject.GObject):
|
|||
selected_playlist = GObject.Property(type=db.playlist.Playlist)
|
||||
|
||||
def __init__(self, sql: db.Connection):
|
||||
"""Initialize a Section Group."""
|
||||
super().__init__(sql=sql)
|
||||
"""Initialize a Section View."""
|
||||
super().__init__(sql=sql, orientation=Gtk.Orientation.VERTICAL)
|
||||
self._sections = []
|
||||
|
||||
def __on_active(self, section: Section, param: GObject.ParamSpec) -> None:
|
||||
|
@ -145,6 +145,7 @@ class Group(GObject.GObject):
|
|||
def add(self, section: Section) -> None:
|
||||
"""Add a section to the group."""
|
||||
self._sections.append(section)
|
||||
self.append(section)
|
||||
section.connect("notify::active", self.__on_active)
|
||||
section.connect("playlist-activated", self.__playlist_activated)
|
||||
section.connect("playlist-selected", self.__playlist_selected)
|
||||
|
|
|
@ -4,7 +4,6 @@ import emmental.db
|
|||
import emmental.sidebar.section
|
||||
import tests.util
|
||||
import unittest.mock
|
||||
from gi.repository import GObject
|
||||
from gi.repository import GLib
|
||||
from gi.repository import Gtk
|
||||
|
||||
|
@ -150,7 +149,7 @@ class TestGroup(tests.util.TestCase):
|
|||
def setUp(self):
|
||||
"""Set up common variables."""
|
||||
super().setUp()
|
||||
self.group = emmental.sidebar.section.Group(self.sql)
|
||||
self.view = emmental.sidebar.section.View(self.sql)
|
||||
self.row_type = emmental.sidebar.row.TreeRow
|
||||
self.section1 = emmental.sidebar.section.Section(self.sql.playlists,
|
||||
self.row_type)
|
||||
|
@ -161,35 +160,40 @@ class TestGroup(tests.util.TestCase):
|
|||
|
||||
def test_init(self):
|
||||
"""Test that the Group is set up properly."""
|
||||
self.assertIsInstance(self.group, GObject.GObject)
|
||||
self.assertListEqual(self.group._sections, [])
|
||||
self.assertEqual(self.group.sql, self.sql)
|
||||
self.assertIsInstance(self.view, Gtk.Box)
|
||||
self.assertListEqual(self.view._sections, [])
|
||||
self.assertEqual(self.view.sql, self.sql)
|
||||
self.assertEqual(self.view.get_orientation(),
|
||||
Gtk.Orientation.VERTICAL)
|
||||
|
||||
def test_add(self):
|
||||
"""Test adding sections to the Group."""
|
||||
self.group.add(self.section1)
|
||||
self.assertListEqual(self.group._sections, [self.section1])
|
||||
self.group.add(self.section2)
|
||||
self.assertListEqual(self.group._sections,
|
||||
self.view.add(self.section1)
|
||||
self.assertListEqual(self.view._sections, [self.section1])
|
||||
self.assertEqual(self.view.get_first_child(), self.section1)
|
||||
|
||||
self.view.add(self.section2)
|
||||
self.assertListEqual(self.view._sections,
|
||||
[self.section1, self.section2])
|
||||
self.assertEqual(self.section1.get_next_sibling(), self.section2)
|
||||
|
||||
def test_current(self):
|
||||
"""Test the current section property."""
|
||||
self.group.add(self.section1)
|
||||
self.group.add(self.section2)
|
||||
self.assertIsNone(self.group.current)
|
||||
self.view.add(self.section1)
|
||||
self.view.add(self.section2)
|
||||
self.assertIsNone(self.view.current)
|
||||
|
||||
self.section1.active = True
|
||||
self.assertEqual(self.group.current, self.section1)
|
||||
self.assertEqual(self.view.current, self.section1)
|
||||
|
||||
self.section2.active = True
|
||||
self.assertEqual(self.group.current, self.section2)
|
||||
self.assertEqual(self.view.current, self.section2)
|
||||
self.assertFalse(self.section1.active)
|
||||
|
||||
def test_animation(self):
|
||||
"""Test setting the section animation style."""
|
||||
self.group.add(self.section1)
|
||||
self.group.add(self.section2)
|
||||
self.view.add(self.section1)
|
||||
self.view.add(self.section2)
|
||||
|
||||
self.section1.active = True
|
||||
self.assertEqual(self.section1.animation,
|
||||
|
@ -201,8 +205,8 @@ class TestGroup(tests.util.TestCase):
|
|||
|
||||
def test_playlist_activated(self):
|
||||
"""Test responding to the section playlist-activated signal."""
|
||||
self.group.add(self.section1)
|
||||
self.group.add(self.section2)
|
||||
self.view.add(self.section1)
|
||||
self.view.add(self.section2)
|
||||
self.assertIsNone(self.sql.active_playlist)
|
||||
|
||||
playlist = self.sql.playlists.create("Test Playlist")
|
||||
|
@ -215,16 +219,16 @@ class TestGroup(tests.util.TestCase):
|
|||
|
||||
def test_selections(self):
|
||||
"""Test the selected section & playlist properties."""
|
||||
self.group.add(self.section1)
|
||||
self.group.add(self.section2)
|
||||
self.view.add(self.section1)
|
||||
self.view.add(self.section2)
|
||||
|
||||
self.assertIsNone(self.group.selected_section)
|
||||
self.assertIsNone(self.group.selected_playlist)
|
||||
self.assertIsNone(self.view.selected_section)
|
||||
self.assertIsNone(self.view.selected_playlist)
|
||||
|
||||
genre = self.sql.genres.create("Test Genre")
|
||||
self.section2.emit("playlist-selected", genre)
|
||||
self.assertEqual(self.group.selected_section, self.section2)
|
||||
self.assertEqual(self.group.selected_playlist, genre)
|
||||
self.assertEqual(self.view.selected_section, self.section2)
|
||||
self.assertEqual(self.view.selected_playlist, genre)
|
||||
|
||||
self.section2.active = True
|
||||
treerow = self.section2._selection.get_selected_item()
|
||||
|
|
|
@ -23,8 +23,6 @@ class TestSidebar(tests.util.TestCase):
|
|||
Gtk.Orientation.VERTICAL)
|
||||
self.assertFalse(self.sidebar.get_sensitive())
|
||||
|
||||
self.assertTrue(self.sidebar.has_css_class("background"))
|
||||
self.assertTrue(self.sidebar.has_css_class("linked"))
|
||||
self.assertTrue(self.sidebar.has_css_class("card"))
|
||||
|
||||
def test_filter(self):
|
||||
|
@ -73,15 +71,17 @@ class TestSidebar(tests.util.TestCase):
|
|||
self.assertIsNone(self.sidebar.selected_playlist)
|
||||
|
||||
playlist1 = self.sql.playlists.create("Playlist 1")
|
||||
self.sidebar._group.selected_playlist = playlist1
|
||||
self.sidebar._view.selected_playlist = playlist1
|
||||
self.assertEqual(self.sidebar.selected_playlist, playlist1)
|
||||
|
||||
def test_group(self):
|
||||
"""Test that sidebar sections are part of the same Group."""
|
||||
self.assertIsInstance(self.sidebar._group,
|
||||
emmental.sidebar.section.Group)
|
||||
def test_view(self):
|
||||
"""Test that sidebar sections are in the View."""
|
||||
self.assertIsInstance(self.sidebar._view,
|
||||
emmental.sidebar.section.View)
|
||||
self.assertEqual(self.sidebar._filter.get_next_sibling(),
|
||||
self.sidebar._view)
|
||||
|
||||
self.assertListEqual(self.sidebar._group._sections,
|
||||
self.assertListEqual(self.sidebar._view._sections,
|
||||
[self.sidebar._playlists,
|
||||
self.sidebar._artists,
|
||||
self.sidebar._genres,
|
||||
|
@ -101,7 +101,7 @@ class TestSidebar(tests.util.TestCase):
|
|||
self.assertIsInstance(self.sidebar._libraries,
|
||||
emmental.sidebar.library.Section)
|
||||
|
||||
self.assertEqual(self.sidebar._filter.get_next_sibling(),
|
||||
self.assertEqual(self.sidebar._view.get_first_child(),
|
||||
self.sidebar._playlists)
|
||||
self.assertEqual(self.sidebar._playlists.get_next_sibling(),
|
||||
self.sidebar._artists)
|
||||
|
|
Loading…
Reference in New Issue