rind: Set the row height of PlaylitNodes

If the node is a playlist, then we can use their natural height.
Otherwise, we set a height based on the first playlist in the model.
This way every row has the same height.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-04-19 11:08:24 -04:00
parent 14851e0c59
commit bfe7e3550b
3 changed files with 34 additions and 13 deletions

View File

@ -466,9 +466,7 @@ audio-volume-medium-symbolic</property>
<property name="fixed_width">50</property>
<property name="title" translatable="yes">column</property>
<child>
<object class="GtkCellRendererPixbuf">
<property name="stock_size">1</property>
</object>
<object class="GtkCellRendererPixbuf"/>
<attributes>
<attribute name="icon-name">0</attribute>
</attributes>
@ -482,6 +480,7 @@ audio-volume-medium-symbolic</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="height">2</attribute>
<attribute name="markup">1</attribute>
</attributes>
</child>

View File

@ -23,6 +23,8 @@ class ManagerModel(GObject.GObject, Gtk.TreeModel):
return isinstance(plist, curds.Playlist)
def do_get_column_type(self, col):
if col == 2:
return int
return str
def do_get_iter(self, path):
@ -32,7 +34,7 @@ class ManagerModel(GObject.GObject, Gtk.TreeModel):
return self.iter_valid(iter)
def do_get_n_columns(self):
return 2
return 3
def do_get_path(self, iter):
path = Gtk.TreePath(iter.user_data - 1)
@ -40,17 +42,29 @@ class ManagerModel(GObject.GObject, Gtk.TreeModel):
path.append_index(iter.user_data2 - 1)
return path
def do_get_node_value(self, plist, column):
if column == 1:
return str(plist)
elif column == 2:
col = Treeview.get_column(1)
return Treeview.get_cell_area(Gtk.TreePath(0), col).height
def do_get_playlist_value(self, plist, column):
if column == 1:
text = GLib.markup_escape_text(str(plist))
if plist == curds.PlaylistManager.current[0]:
return f"<b>{text}</b>"
return text
elif column == 2:
return -1
def do_get_value(self, iter, column):
plist = self.iter_playlist(iter)
if column == 0:
return plist.icon
if isinstance(plist, curds.Playlist):
cur = curds.PlaylistManager.current[0]
text = GLib.markup_escape_text(str(plist))
if plist == cur:
return f"<b>{text}</b>"
return text
return str(plist)
return self.do_get_playlist_value(plist, column)
return self.do_get_node_value(plist, column)
def do_iter_children(self, parent):
return self.do_iter_nth_child(parent, 0)

View File

@ -47,10 +47,12 @@ class TestManager(unittest.TestCase):
self.assertEqual(manager.MgrModel.filter.get_model(), manager.MgrModel)
def test_model_init(self):
self.assertEqual(self.model.get_n_columns(), 2)
self.assertEqual(self.model.get_n_columns(), 3)
self.assertEqual(self.model.get_flags(), 0)
for col in range(self.model.get_n_columns()):
self.assertEqual(self.model.get_column_type(col), GObject.GType(str))
self.assertEqual(self.model.get_column_type(0), GObject.GType(str))
self.assertEqual(self.model.get_column_type(1), GObject.GType(str))
self.assertEqual(self.model.get_column_type(2), GObject.GType(int))
def test_model_get_iter(self):
for i, node in enumerate(plist_mgr.children):
@ -82,6 +84,8 @@ class TestManager(unittest.TestCase):
self.assertEqual(path.get_indices(), [ iter.user_data - 1, i ])
def test_model_get_value(self):
col = manager.Treeview.get_column(1)
rect = manager.Treeview.get_cell_area(Gtk.TreePath(0), col)
iter = Gtk.TreeIter()
for i, node in enumerate(plist_mgr.children):
@ -89,6 +93,10 @@ class TestManager(unittest.TestCase):
iter.user_data = i + 1
self.assertEqual(self.model.get_value(iter, 0), node.icon)
self.assertEqual(self.model.get_value(iter, 1), text)
if isinstance(node, curds.Playlist):
self.assertEqual(self.model.get_value(iter, 2), -1)
else:
self.assertEqual(self.model.get_value(iter, 2), rect.height)
def test_model_iter_children(self):
iter = self.model.iter_children(None)