[acronyms] Port to Gtk4
This commit is contained in:
@@ -16,15 +16,13 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from gi.repository import Gtk
|
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.plugins_i18n import _
|
||||||
from gajim.plugins.helpers import get_builder
|
from gajim.plugins.helpers import get_builder
|
||||||
@@ -33,34 +31,41 @@ if TYPE_CHECKING:
|
|||||||
from ..acronyms_expander import AcronymsExpanderPlugin
|
from ..acronyms_expander import AcronymsExpanderPlugin
|
||||||
|
|
||||||
|
|
||||||
class ConfigDialog(Gtk.ApplicationWindow):
|
class ConfigDialog(GajimAppWindow):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
plugin: AcronymsExpanderPlugin,
|
plugin: AcronymsExpanderPlugin,
|
||||||
transient: Gtk.Window
|
transient: Gtk.Window
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
Gtk.ApplicationWindow.__init__(self)
|
GajimAppWindow.__init__(
|
||||||
self.set_application(app.app)
|
self,
|
||||||
self.set_show_menubar(False)
|
name="AcronymsConfigDialog",
|
||||||
self.set_title(_('Acronyms Configuration'))
|
title=_('Acronyms Configuration'),
|
||||||
self.set_transient_for(transient)
|
default_width=400,
|
||||||
self.set_default_size(400, 400)
|
default_height=400,
|
||||||
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
|
transient_for=transient,
|
||||||
self.set_modal(True)
|
modal=True,
|
||||||
self.set_destroy_with_parent(True)
|
)
|
||||||
|
|
||||||
ui_path = Path(__file__).parent
|
ui_path = Path(__file__).parent
|
||||||
self._ui = get_builder(str(ui_path.resolve() / 'config.ui'))
|
self._ui = get_builder(str(ui_path.resolve() / 'config.ui'))
|
||||||
|
|
||||||
self._plugin = plugin
|
self._plugin = plugin
|
||||||
|
|
||||||
self.add(self._ui.box)
|
self.set_child(self._ui.box)
|
||||||
|
|
||||||
self._fill_list()
|
self._fill_list()
|
||||||
self.show_all()
|
|
||||||
|
|
||||||
self._ui.connect_signals(self)
|
self._connect(self._ui.acronym_renderer, "edited", self._on_acronym_edited)
|
||||||
self.connect('destroy', self._on_destroy)
|
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:
|
def _fill_list(self) -> None:
|
||||||
for acronym, substitute in self._plugin.acronyms.items():
|
for acronym, substitute in self._plugin.acronyms.items():
|
||||||
@@ -102,7 +107,7 @@ class ConfigDialog(Gtk.ApplicationWindow):
|
|||||||
iter_ = model.get_iter(ref.get_path())
|
iter_ = model.get_iter(ref.get_path())
|
||||||
self._ui.acronyms_store.remove(iter_)
|
self._ui.acronyms_store.remove(iter_)
|
||||||
|
|
||||||
def _on_destroy(self, *args: Any) -> None:
|
def _on_close_request(self, win: Gtk.ApplicationWindow) -> None:
|
||||||
acronyms = {}
|
acronyms = {}
|
||||||
for row in self._ui.acronyms_store:
|
for row in self._ui.acronyms_store:
|
||||||
acronym, substitute = row
|
acronym, substitute = row
|
||||||
|
|||||||
@@ -1,30 +1,22 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.22.1 -->
|
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk" version="4.0"/>
|
||||||
<object class="GtkListStore" id="acronyms_store">
|
<object class="GtkListStore" id="acronyms_store">
|
||||||
<columns>
|
<columns>
|
||||||
<!-- column-name acronym -->
|
|
||||||
<column type="gchararray"/>
|
<column type="gchararray"/>
|
||||||
<!-- column-name substitute -->
|
|
||||||
<column type="gchararray"/>
|
<column type="gchararray"/>
|
||||||
</columns>
|
</columns>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkBox" id="box">
|
<object class="GtkBox" id="box">
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="border_width">18</property>
|
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkScrolledWindow">
|
<object class="GtkScrolledWindow">
|
||||||
<property name="visible">True</property>
|
<property name="focusable">1</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="vexpand">1</property>
|
||||||
<property name="vexpand">True</property>
|
<property name="hexpand">1</property>
|
||||||
<property name="shadow_type">in</property>
|
<property name="child">
|
||||||
<child>
|
|
||||||
<object class="GtkTreeView" id="acronyms_treeview">
|
<object class="GtkTreeView" id="acronyms_treeview">
|
||||||
<property name="visible">True</property>
|
<property name="focusable">1</property>
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="model">acronyms_store</property>
|
<property name="model">acronyms_store</property>
|
||||||
<property name="search_column">1</property>
|
<property name="search_column">1</property>
|
||||||
<child internal-child="selection">
|
<child internal-child="selection">
|
||||||
@@ -34,15 +26,14 @@
|
|||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkTreeViewColumn">
|
<object class="GtkTreeViewColumn">
|
||||||
<property name="resizable">True</property>
|
<property name="resizable">1</property>
|
||||||
<property name="title" translatable="yes">Acronym</property>
|
<property name="title" translatable="1">Acronym</property>
|
||||||
<property name="clickable">True</property>
|
<property name="clickable">1</property>
|
||||||
<property name="sort_indicator">True</property>
|
<property name="sort_indicator">1</property>
|
||||||
<property name="sort_column_id">0</property>
|
<property name="sort_column_id">0</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkCellRendererText">
|
<object class="GtkCellRendererText" id="acronym_renderer">
|
||||||
<property name="editable">True</property>
|
<property name="editable">1</property>
|
||||||
<signal name="edited" handler="_on_acronym_edited" swapped="no"/>
|
|
||||||
</object>
|
</object>
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="text">0</attribute>
|
<attribute name="text">0</attribute>
|
||||||
@@ -52,15 +43,14 @@
|
|||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkTreeViewColumn">
|
<object class="GtkTreeViewColumn">
|
||||||
<property name="resizable">True</property>
|
<property name="resizable">1</property>
|
||||||
<property name="title" translatable="yes">Substitute</property>
|
<property name="title" translatable="1">Substitute</property>
|
||||||
<property name="clickable">True</property>
|
<property name="clickable">1</property>
|
||||||
<property name="sort_indicator">True</property>
|
<property name="sort_indicator">1</property>
|
||||||
<property name="sort_column_id">0</property>
|
<property name="sort_column_id">0</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkCellRendererText">
|
<object class="GtkCellRendererText" id="sub_renderer">
|
||||||
<property name="editable">True</property>
|
<property name="editable">1</property>
|
||||||
<signal name="edited" handler="_on_substitute_edited" swapped="no"/>
|
|
||||||
</object>
|
</object>
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="text">1</attribute>
|
<attribute name="text">1</attribute>
|
||||||
@@ -69,55 +59,28 @@
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">0</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkToolbar">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="css-classes">toolbar</property>
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="toolbar_style">icons</property>
|
|
||||||
<property name="icon_size">4</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkToolButton">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="tooltip_text" translatable="yes">Add</property>
|
|
||||||
<property name="icon_name">list-add-symbolic</property>
|
|
||||||
<signal name="clicked" handler="_on_add_clicked" swapped="no"/>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="homogeneous">True</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkToolButton">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="tooltip_text" translatable="yes">Remove</property>
|
|
||||||
<property name="icon_name">list-remove-symbolic</property>
|
|
||||||
<signal name="clicked" handler="_on_remove_clicked" swapped="no"/>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="homogeneous">True</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<style>
|
<style>
|
||||||
<class name="inline-toolbar"/>
|
<class name="inline-toolbar"/>
|
||||||
</style>
|
</style>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="add_button">
|
||||||
|
<property name="tooltip_text" translatable="1">Add</property>
|
||||||
|
<property name="icon_name">list-add-symbolic</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="remove_button">
|
||||||
|
<property name="tooltip_text" translatable="1">Remove</property>
|
||||||
|
<property name="icon_name">list-remove-symbolic</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">1</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</interface>
|
</interface>
|
||||||
|
|||||||
Reference in New Issue
Block a user