Daniel Brötzmann pushed to branch gtk4 at gajim / gajim


Commits:
a977f34e by wurstsalat at 2024-11-07T20:27:33+01:00
refactor: ResourceSelector: Fix resource item icon size; add test

- - - - -


2 changed files:

- gajim/gtk/resource_selector.py
- + test/gtk/ui_test_resource_selector.py


Changes:

=====================================
gajim/gtk/resource_selector.py
=====================================
@@ -106,9 +106,7 @@ def __init__(
                     icon_name = "phone-symbolic"
                     tooltip_text = _("Phone")
 
-        image = Gtk.Image()
-        image.set_from_icon_name(icon_name)
-        image.set_tooltip_text(tooltip_text)
+        image = Gtk.Image(icon_name=icon_name, tooltip_text=tooltip_text, 
pixel_size=32)
 
         name_label = Gtk.Label()
         name_label.set_text(self.device_text)


=====================================
test/gtk/ui_test_resource_selector.py
=====================================
@@ -0,0 +1,88 @@
+# This file is part of Gajim.
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+from collections.abc import Iterator
+from unittest.mock import MagicMock
+
+from gi.repository import Gtk
+from nbxmpp.protocol import JID
+
+from gajim.common import app
+from gajim.common.modules.contacts import BareContact
+from gajim.common.modules.contacts import ResourceContact
+from gajim.common.storage.cache import CacheStorage
+
+from gajim.gtk.resource_selector import ResourceSelector
+from gajim.gtk.widgets import GajimAppWindow
+
+from . import util
+
+ACCOUNT = 'testacc1'
+FROM_JID = '[email protected]'
+
+
+class TestResourceSelector(GajimAppWindow):
+    def __init__(self):
+        GajimAppWindow.__init__(
+            self,
+            name='',
+            title=__class__.__name__,
+            default_width=600,
+            default_height=600,
+        )
+
+        box = Gtk.Box(
+            halign=Gtk.Align.CENTER,
+            valign=Gtk.Align.CENTER,
+            hexpand=True,
+            width_request=500,
+            height_request=700
+        )
+        self.set_child(box)
+
+        contact = self._get_contact()
+
+        self._resources = self._generate_resources()
+
+        self._resource_selector = ResourceSelector(contact)
+        self._resource_selector.set_hexpand(True)
+        self._resource_selector.connect('selection-changed', 
self._on_selection_changed)
+        box.append(self._resource_selector)
+
+    def _on_selection_changed(
+        self,
+        _resource_selector: ResourceSelector,
+        state: bool
+    ) -> None:
+        print('Selection available:', state)
+
+    def _get_contact(self) -> BareContact:
+        contact = MagicMock(spec_set=BareContact)
+        contact.account = ACCOUNT
+        contact.jid = JID.from_string(FROM_JID)
+        contact.name = 'Test Contact'
+        contact.is_groupchat = False
+        contact.iter_resources = MagicMock(side_effect=self._iter_resources)
+        return contact
+
+    def _generate_resources(self) -> list[ResourceContact]:
+        resources: list[ResourceContact] = []
+        for index in range(5):
+            resource_contact = MagicMock(spec_set=ResourceContact)
+            resource_contact.jid = 
JID.from_string(f'{FROM_JID}/Resource.{index}')
+            resources.append(resource_contact)
+
+        return resources
+
+    def _iter_resources(self) -> Iterator[ResourceContact]:
+        yield from self._resources
+
+
+app.storage.cache = CacheStorage(in_memory=True)
+app.storage.cache.init()
+
+window = TestResourceSelector()
+window.show()
+
+util.run_app()



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

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/a977f34effa3c6241b2e38f4daadf3b0c431cf98
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