[acronyms] Type annotations, linting
This commit is contained in:
@@ -1 +1 @@
|
|||||||
from .acronyms_expander import AcronymsExpanderPlugin
|
from .acronyms_expander import AcronymsExpanderPlugin # type: ignore
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Acronyms Expander. If not, see <http://www.gnu.org/licenses/>.
|
# along with Acronyms Expander. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|||||||
@@ -14,6 +14,11 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Acronyms Expander. If not, see <http://www.gnu.org/licenses/>.
|
# along with Acronyms Expander. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
@@ -24,9 +29,16 @@ from gajim.common import app
|
|||||||
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
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from ..acronyms_expander import AcronymsExpanderPlugin
|
||||||
|
|
||||||
|
|
||||||
class ConfigDialog(Gtk.ApplicationWindow):
|
class ConfigDialog(Gtk.ApplicationWindow):
|
||||||
def __init__(self, plugin, transient):
|
def __init__(self,
|
||||||
|
plugin: AcronymsExpanderPlugin,
|
||||||
|
transient: Gtk.Window
|
||||||
|
) -> None:
|
||||||
|
|
||||||
Gtk.ApplicationWindow.__init__(self)
|
Gtk.ApplicationWindow.__init__(self)
|
||||||
self.set_application(app.app)
|
self.set_application(app.app)
|
||||||
self.set_show_menubar(False)
|
self.set_show_menubar(False)
|
||||||
@@ -38,7 +50,7 @@ class ConfigDialog(Gtk.ApplicationWindow):
|
|||||||
self.set_destroy_with_parent(True)
|
self.set_destroy_with_parent(True)
|
||||||
|
|
||||||
ui_path = Path(__file__).parent
|
ui_path = Path(__file__).parent
|
||||||
self._ui = get_builder(ui_path.resolve() / 'config.ui')
|
self._ui = get_builder(str(ui_path.resolve() / 'config.ui'))
|
||||||
|
|
||||||
self._plugin = plugin
|
self._plugin = plugin
|
||||||
|
|
||||||
@@ -50,19 +62,29 @@ class ConfigDialog(Gtk.ApplicationWindow):
|
|||||||
self._ui.connect_signals(self)
|
self._ui.connect_signals(self)
|
||||||
self.connect('destroy', self._on_destroy)
|
self.connect('destroy', self._on_destroy)
|
||||||
|
|
||||||
def _fill_list(self):
|
def _fill_list(self) -> None:
|
||||||
for acronym, substitute in self._plugin.acronyms.items():
|
for acronym, substitute in self._plugin.acronyms.items():
|
||||||
self._ui.acronyms_store.append([acronym, substitute])
|
self._ui.acronyms_store.append([acronym, substitute])
|
||||||
|
|
||||||
def _on_acronym_edited(self, _renderer, path, new_text):
|
def _on_acronym_edited(self,
|
||||||
|
_renderer: Gtk.CellRendererText,
|
||||||
|
path: str,
|
||||||
|
new_text: str
|
||||||
|
) -> None:
|
||||||
|
|
||||||
iter_ = self._ui.acronyms_store.get_iter(path)
|
iter_ = self._ui.acronyms_store.get_iter(path)
|
||||||
self._ui.acronyms_store.set_value(iter_, 0, new_text)
|
self._ui.acronyms_store.set_value(iter_, 0, new_text)
|
||||||
|
|
||||||
def _on_substitute_edited(self, _renderer, path, new_text):
|
def _on_substitute_edited(self,
|
||||||
|
_renderer: Gtk.CellRendererText,
|
||||||
|
path: str,
|
||||||
|
new_text: str
|
||||||
|
) -> None:
|
||||||
|
|
||||||
iter_ = self._ui.acronyms_store.get_iter(path)
|
iter_ = self._ui.acronyms_store.get_iter(path)
|
||||||
self._ui.acronyms_store.set_value(iter_, 1, new_text)
|
self._ui.acronyms_store.set_value(iter_, 1, new_text)
|
||||||
|
|
||||||
def _on_add_clicked(self, _button):
|
def _on_add_clicked(self, _button: Gtk.Button) -> None:
|
||||||
self._ui.acronyms_store.append(['', ''])
|
self._ui.acronyms_store.append(['', ''])
|
||||||
row = self._ui.acronyms_store[-1]
|
row = self._ui.acronyms_store[-1]
|
||||||
self._ui.acronyms_treeview.scroll_to_cell(
|
self._ui.acronyms_treeview.scroll_to_cell(
|
||||||
@@ -70,9 +92,9 @@ class ConfigDialog(Gtk.ApplicationWindow):
|
|||||||
self._ui.selection.unselect_all()
|
self._ui.selection.unselect_all()
|
||||||
self._ui.selection.select_path(row.path)
|
self._ui.selection.select_path(row.path)
|
||||||
|
|
||||||
def _on_remove_clicked(self, _button):
|
def _on_remove_clicked(self, _button: Gtk.Button) -> None:
|
||||||
model, paths = self._ui.selection.get_selected_rows()
|
model, paths = self._ui.selection.get_selected_rows()
|
||||||
references = []
|
references: list[Gtk.TreeRowReference] = []
|
||||||
for path in paths:
|
for path in paths:
|
||||||
references.append(Gtk.TreeRowReference.new(model, path))
|
references.append(Gtk.TreeRowReference.new(model, path))
|
||||||
|
|
||||||
@@ -80,7 +102,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):
|
def _on_destroy(self, *args: Any) -> None:
|
||||||
acronyms = {}
|
acronyms = {}
|
||||||
for row in self._ui.acronyms_store:
|
for row in self._ui.acronyms_store:
|
||||||
acronym, substitute = row
|
acronym, substitute = row
|
||||||
|
|||||||
Reference in New Issue
Block a user