From e6e71d82bfe39512f0eef2fa6aaaf58cbdd42448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sat, 25 Jan 2025 19:06:32 +0100 Subject: [PATCH] [acronyms] Port to Gtk4 --- acronyms_expander/gtk/config.py | 41 +++++++------ acronyms_expander/gtk/config.ui | 103 ++++++++++---------------------- 2 files changed, 56 insertions(+), 88 deletions(-) diff --git a/acronyms_expander/gtk/config.py b/acronyms_expander/gtk/config.py index 090bed0..e01ecd7 100644 --- a/acronyms_expander/gtk/config.py +++ b/acronyms_expander/gtk/config.py @@ -16,15 +16,13 @@ from __future__ import annotations -from typing import Any from typing import TYPE_CHECKING from pathlib import Path from gi.repository import Gtk -from gi.repository import Gdk -from gajim.common import app +from gajim.gtk.widgets import GajimAppWindow from gajim.plugins.plugins_i18n import _ from gajim.plugins.helpers import get_builder @@ -33,34 +31,41 @@ if TYPE_CHECKING: from ..acronyms_expander import AcronymsExpanderPlugin -class ConfigDialog(Gtk.ApplicationWindow): +class ConfigDialog(GajimAppWindow): def __init__(self, plugin: AcronymsExpanderPlugin, transient: Gtk.Window ) -> None: - Gtk.ApplicationWindow.__init__(self) - self.set_application(app.app) - self.set_show_menubar(False) - self.set_title(_('Acronyms Configuration')) - self.set_transient_for(transient) - self.set_default_size(400, 400) - self.set_type_hint(Gdk.WindowTypeHint.DIALOG) - self.set_modal(True) - self.set_destroy_with_parent(True) + GajimAppWindow.__init__( + self, + name="AcronymsConfigDialog", + title=_('Acronyms Configuration'), + default_width=400, + default_height=400, + transient_for=transient, + modal=True, + ) ui_path = Path(__file__).parent self._ui = get_builder(str(ui_path.resolve() / 'config.ui')) self._plugin = plugin - self.add(self._ui.box) + self.set_child(self._ui.box) self._fill_list() - self.show_all() - self._ui.connect_signals(self) - self.connect('destroy', self._on_destroy) + self._connect(self._ui.acronym_renderer, "edited", self._on_acronym_edited) + self._connect(self._ui.sub_renderer, "edited", self._on_substitute_edited) + self._connect(self._ui.add_button, "clicked", self._on_add_clicked) + self._connect(self._ui.remove_button, "clicked", self._on_remove_clicked) + self._connect(self.window, "close-request", self._on_close_request) + + self.show() + + def _cleanup(self) -> None: + del self._plugin def _fill_list(self) -> None: for acronym, substitute in self._plugin.acronyms.items(): @@ -102,7 +107,7 @@ class ConfigDialog(Gtk.ApplicationWindow): iter_ = model.get_iter(ref.get_path()) self._ui.acronyms_store.remove(iter_) - def _on_destroy(self, *args: Any) -> None: + def _on_close_request(self, win: Gtk.ApplicationWindow) -> None: acronyms = {} for row in self._ui.acronyms_store: acronym, substitute = row diff --git a/acronyms_expander/gtk/config.ui b/acronyms_expander/gtk/config.ui index 009bc61..330a405 100644 --- a/acronyms_expander/gtk/config.ui +++ b/acronyms_expander/gtk/config.ui @@ -1,30 +1,22 @@ - - + - - - True - False - 18 vertical - True - True - True - in - + 1 + 1 + 1 + - True - True + 1 acronyms_store 1 @@ -34,15 +26,14 @@ - True - Acronym - True - True + 1 + Acronym + 1 + 1 0 - - True - + + 1 0 @@ -52,15 +43,14 @@ - True - Substitute - True - True + 1 + Substitute + 1 + 1 0 - - True - + + 1 1 @@ -69,55 +59,28 @@ - + - - False - True - 0 - - - True - False - icons - 4 - - - True - False - Add - list-add-symbolic - - - - False - True - - - - - True - False - Remove - list-remove-symbolic - - - - False - True - - + + toolbar + + + Add + list-add-symbolic + + + + + Remove + list-remove-symbolic + + - - False - True - 1 -