factory: Give ListRows an "active" property
And style them so the row is highlighted and the text is bold. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
9d7763a730
commit
710f3fba80
|
@ -20,3 +20,28 @@ box.emmental-splitbutton>menubutton>button {
|
|||
margin-left: -1px;
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
listview > row:checked {
|
||||
font-weight: bold;
|
||||
background-color: alpha(@accent_color, 0.2);
|
||||
}
|
||||
|
||||
listview > row:checked:hover {
|
||||
background-color: alpha(@accent_color, 0.27);
|
||||
}
|
||||
|
||||
listview > row:checked:active {
|
||||
background-color: alpha(@accent_color, 0.36);
|
||||
}
|
||||
|
||||
listview > row:checked:selected {
|
||||
background-color: alpha(@accent_color, 0.3);
|
||||
}
|
||||
|
||||
listview > row:checked:selected:hover {
|
||||
background-color: alpha(@accent_color, 0.33);
|
||||
}
|
||||
|
||||
listview > row:checked:selected:active {
|
||||
background-color: alpha(@accent_color, 0.39);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,10 @@ class ListRow(GObject.GObject):
|
|||
def do_unbind(self) -> None:
|
||||
"""Unbind the list item from the child widget."""
|
||||
|
||||
def bind_active(self, item_prop: str) -> None:
|
||||
"""Bind a property to the Row's active property."""
|
||||
self.bind_and_set(self.item, item_prop, self, "active")
|
||||
|
||||
def bind_and_set(self, src: GObject.GObject, src_prop: str,
|
||||
dst: GObject.GObject, dst_prop: str,
|
||||
bidirectional: bool = False,
|
||||
|
@ -54,6 +58,21 @@ class ListRow(GObject.GObject):
|
|||
self.bindings.clear()
|
||||
self.do_unbind()
|
||||
|
||||
@GObject.Property(type=bool, default=False)
|
||||
def active(self) -> bool:
|
||||
"""Get the active state of this Row."""
|
||||
if parent := self.listitem.get_child().get_parent():
|
||||
return parent.get_state_flags() & Gtk.StateFlags.CHECKED
|
||||
return False
|
||||
|
||||
@active.setter
|
||||
def active(self, newval: bool) -> None:
|
||||
if parent := self.listitem.get_child().get_parent():
|
||||
if newval:
|
||||
parent.set_state_flags(Gtk.StateFlags.CHECKED, False)
|
||||
else:
|
||||
parent.unset_state_flags(Gtk.StateFlags.CHECKED)
|
||||
|
||||
@GObject.Property(type=Gtk.Widget)
|
||||
def child(self) -> Gtk.Widget | None:
|
||||
"""Get the child widget displayed by this Row."""
|
||||
|
|
|
@ -30,12 +30,27 @@ class TestListRow(unittest.TestCase):
|
|||
self.assertEqual(self.row.listitem, self.listitem)
|
||||
self.assertEqual(self.row.child, self.listitem.get_child())
|
||||
self.assertEqual(self.row.item, self.item)
|
||||
self.assertFalse(self.row.active)
|
||||
|
||||
def test_bind(self):
|
||||
"""Test calling bind() on the ListRow."""
|
||||
self.row.bind()
|
||||
self.row.do_bind.assert_called()
|
||||
|
||||
def test_bind_active(self):
|
||||
"""Test binding a property to the Row's active property."""
|
||||
parent = Gtk.Box()
|
||||
parent.append(self.row.child)
|
||||
|
||||
self.row.bind_active("sensitive")
|
||||
self.assertEqual(len(self.row.bindings), 1)
|
||||
self.assertTrue(parent.get_state_flags() & Gtk.StateFlags.CHECKED)
|
||||
self.assertTrue(self.row.active)
|
||||
|
||||
self.item.set_sensitive(False)
|
||||
self.assertFalse(parent.get_state_flags() & Gtk.StateFlags.CHECKED)
|
||||
self.assertFalse(self.row.active)
|
||||
|
||||
def test_bind_and_set_property(self):
|
||||
"""Test the ListRow bind_property() function."""
|
||||
self.row.bind_and_set_property("label", "label")
|
||||
|
|
Loading…
Reference in New Issue