Daniel Brötzmann pushed to branch gtk4 at gajim / gajim
Commits:
b920d302 by wurstsalat at 2024-10-11T23:32:23+02:00
refactor: NickChooser: Add missing signal, use SignalHandler, correctly finalize
- - - - -
2 changed files:
- gajim/gtk/groupchat_nick.py
- + test/gtk/test_groupchat_nick.py
Changes:
=====================================
gajim/gtk/groupchat_nick.py
=====================================
@@ -6,22 +6,31 @@
from nbxmpp.protocol import InvalidJid
from nbxmpp.protocol import validate_resourcepart
+from gajim.common import app
+
from gajim.gtk.builder import get_builder
+from gajim.gtk.util import SignalManager
-class NickChooser(Gtk.MenuButton):
+class NickChooser(Gtk.MenuButton, SignalManager):
def __init__(self) -> None:
Gtk.MenuButton.__init__(self)
- self._ui = get_builder('groupchat_nick_chooser.ui', self)
+ SignalManager.__init__(self)
+
+ self._ui = get_builder('groupchat_nick_chooser.ui')
self.set_child(self._ui.button_content)
self.set_receives_default(False)
self.set_popover(self._ui.popover)
- self._ui.popover.set_default_widget(
- self._ui.apply_button)
- # self.connect('toggled', self._on_nickname_button_toggled) TODO GTK4
- self._ui.entry.connect('changed', self._on_nickname_changed)
- self._ui.apply_button.connect('clicked', self._on_apply_nickname)
+ self._ui.popover.set_default_widget(self._ui.apply_button)
+ self._connect(self, 'notify::active', self._on_nickname_button_toggled)
+ self._connect(self._ui.entry, 'changed', self._on_nickname_changed)
+ self._connect(self._ui.apply_button, 'clicked',
self._on_apply_nickname)
+
+ def do_unroot(self) -> None:
+ Gtk.MenuButton.do_unroot(self)
+ self._disconnect_all()
+ app.check_finalize(self)
def get_text(self) -> str:
return self._ui.entry.get_text()
@@ -30,7 +39,9 @@ def set_text(self, text: str) -> None:
self._ui.entry.set_text(text)
self._ui.label.set_text(text)
- def _on_nickname_button_toggled(self, _widget: Gtk.MenuButton) -> None:
+ def _on_nickname_button_toggled(
+ self, _widget: Gtk.MenuButton, _active: bool
+ ) -> None:
self._ui.entry.grab_focus()
def _on_nickname_changed(self, entry: Gtk.Entry) -> None:
=====================================
test/gtk/test_groupchat_nick.py
=====================================
@@ -0,0 +1,41 @@
+# This file is part of Gajim.
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+from gi.repository import Gtk
+
+from gajim.gtk.groupchat_nick import NickChooser
+from gajim.gtk.widgets import GajimAppWindow
+
+from . import util
+
+
+class TestNickChooser(GajimAppWindow):
+ def __init__(self):
+ GajimAppWindow.__init__(
+ self,
+ name='',
+ title='Test NickChooser',
+ default_width=700,
+ default_height=700,
+ )
+
+ self._main_box = Gtk.Box(
+ hexpand=True, halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER
+ )
+
+ self._nick_chooser = NickChooser()
+ self._nick_chooser.set_text('Fancy Nickname')
+
+ self._main_box.append(self._nick_chooser)
+
+ self.set_child(self._main_box)
+
+ def _cleanup(self) -> None:
+ pass
+
+
+window = TestNickChooser()
+window.show()
+
+util.run_app()
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/b920d30246f719ae6b75fb5f911384172a849f48
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/b920d30246f719ae6b75fb5f911384172a849f48
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]