Philipp Hörist pushed to branch gtk4 at gajim / gajim


Commits:
db43197f by Philipp Hörist at 2024-10-02T22:19:39+02:00
refactor: SideBarSwitcher: Fix

- - - - -


2 changed files:

- gajim/gtk/sidebar_switcher.py
- gajim/gtk/util.py


Changes:

=====================================
gajim/gtk/sidebar_switcher.py
=====================================
@@ -9,6 +9,7 @@
 from gi.repository import Gtk
 
 from gajim.common import app
+from gajim.gtk.util import iterate_children
 
 
 class SideBarSwitcher(Gtk.ListBox):
@@ -26,18 +27,19 @@ def __init__(self, width: int | None = None) -> None:
 
     def set_stack(self, stack: Gtk.Stack, rows_visible: bool = True) -> None:
         self._stack = stack
-        for page in self._stack.get_children():
-            name = self._stack.child_get_property(page, 'name')
+        for page in iterate_children(self._stack):
+            page = cast(Gtk.StackPage, page)
+            name = page.get_name()
             if name is None:
                 raise ValueError('unnamed child')
-            title = self._stack.child_get_property(page, 'title')
+            title = page.get_title()
             if title is None:
                 raise ValueError('no title on child')
-            icon_name = self._stack.child_get_property(page, 'icon-name')
+            icon_name = page.get_icon_name()
 
             row = Row(name, title, icon_name, rows_visible)
 
-            self.add(row)
+            self.append(row)
             self._rows[name] = row
 
         self._select_first_row()
@@ -63,7 +65,7 @@ def _select_first_row(self):
 
     def _destroy(self, _widget: SideBarSwitcher) -> None:
         for row in self._rows.values():
-            row.destroy()
+            self.remove(row)
         self._rows.clear()
         del self._stack
         app.check_finalize(self)
@@ -82,15 +84,12 @@ def __init__(self,
 
         box = Gtk.Box()
         if icon_name is not None:
-            image = Gtk.Image.new_from_icon_name(icon_name, Gtk.IconSize.MENU)
+            image = Gtk.Image.new_from_icon_name(icon_name)
             image.get_style_context().add_class('dim-label')
-            box.add(image)
+            box.append(image)
 
         label = Gtk.Label(label=title)
         label.set_xalign(0)
-        box.add(label)
-        self.add(box)
-
-        self.show_all()
-        self.set_visible(False)
+        box.append(label)
+        self.set_child(box)
         self.set_visible(visible)


=====================================
gajim/gtk/util.py
=====================================
@@ -992,3 +992,13 @@ def iterate_listbox_children(listbox: Gtk.ListBox) -> 
Iterator[Gtk.Widget]:
 
 def get_listbox_row_count(listbox: Gtk.ListBox) -> int:
     return len(list(iterate_listbox_children(listbox)))
+
+
+def iterate_children(widget: Gtk.Widget) -> Iterator[Gtk.Widget]:
+    child = widget.get_first_child()
+    if child is None:
+        return
+    yield child
+
+    while child := child.get_next_sibling():
+        yield child



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/db43197f631c1e64d0a2b542bfcf0cb0bd76d879

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/db43197f631c1e64d0a2b542bfcf0cb0bd76d879
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to