[quick_replies] Type annotations, linting
This commit is contained in:
@@ -1 +1 @@
|
|||||||
from .plugin import QuickRepliesPlugin
|
from .plugin import QuickRepliesPlugin # type: ignore
|
||||||
|
|||||||
@@ -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 Quick Replies. If not, see <http://www.gnu.org/licenses/>.
|
# along with Quick Replies. 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 ..plugin import QuickRepliesPlugin
|
||||||
|
|
||||||
|
|
||||||
class ConfigDialog(Gtk.ApplicationWindow):
|
class ConfigDialog(Gtk.ApplicationWindow):
|
||||||
def __init__(self, plugin, transient):
|
def __init__(self,
|
||||||
|
plugin: QuickRepliesPlugin,
|
||||||
|
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,15 +62,20 @@ 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 reply in self._plugin.quick_replies:
|
for reply in self._plugin.quick_replies:
|
||||||
self._ui.replies_store.append([reply])
|
self._ui.replies_store.append([reply])
|
||||||
|
|
||||||
def _on_reply_edited(self, _renderer, path, new_text):
|
def _on_reply_edited(self,
|
||||||
|
_renderer: Gtk.CellRendererText,
|
||||||
|
path: str,
|
||||||
|
new_text: str
|
||||||
|
) -> None:
|
||||||
|
|
||||||
iter_ = self._ui.replies_store.get_iter(path)
|
iter_ = self._ui.replies_store.get_iter(path)
|
||||||
self._ui.replies_store.set_value(iter_, 0, new_text)
|
self._ui.replies_store.set_value(iter_, 0, new_text)
|
||||||
|
|
||||||
def _on_add_clicked(self, _button):
|
def _on_add_clicked(self, _button: Gtk.Button) -> None:
|
||||||
self._ui.replies_store.append([_('New Quick Reply')])
|
self._ui.replies_store.append([_('New Quick Reply')])
|
||||||
row = self._ui.replies_store[-1]
|
row = self._ui.replies_store[-1]
|
||||||
self._ui.replies_treeview.scroll_to_cell(
|
self._ui.replies_treeview.scroll_to_cell(
|
||||||
@@ -66,9 +83,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))
|
||||||
|
|
||||||
@@ -76,8 +93,8 @@ class ConfigDialog(Gtk.ApplicationWindow):
|
|||||||
iter_ = model.get_iter(ref.get_path())
|
iter_ = model.get_iter(ref.get_path())
|
||||||
self._ui.replies_store.remove(iter_)
|
self._ui.replies_store.remove(iter_)
|
||||||
|
|
||||||
def _on_destroy(self, *args):
|
def _on_destroy(self, *args: Any) -> None:
|
||||||
replies = []
|
replies: list[str] = []
|
||||||
for row in self._ui.replies_store:
|
for row in self._ui.replies_store:
|
||||||
if row[0] == '':
|
if row[0] == '':
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -1,3 +1,18 @@
|
|||||||
|
# This file is part of Gajim.
|
||||||
|
#
|
||||||
|
# Gajim is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Gajim is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import cast
|
from typing import cast
|
||||||
@@ -24,7 +39,7 @@ from quick_replies.gtk.config import ConfigDialog
|
|||||||
|
|
||||||
|
|
||||||
class QuickRepliesPlugin(GajimPlugin):
|
class QuickRepliesPlugin(GajimPlugin):
|
||||||
def init(self):
|
def init(self) -> None:
|
||||||
self.description = _('Adds a menu with customizable quick replies')
|
self.description = _('Adds a menu with customizable quick replies')
|
||||||
self.config_dialog = partial(ConfigDialog, self)
|
self.config_dialog = partial(ConfigDialog, self)
|
||||||
self.gui_extension_points = {
|
self.gui_extension_points = {
|
||||||
@@ -50,7 +65,7 @@ class QuickRepliesPlugin(GajimPlugin):
|
|||||||
self._button.show()
|
self._button.show()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _load_quick_replies():
|
def _load_quick_replies() -> list[str]:
|
||||||
try:
|
try:
|
||||||
data_path = Path(configpaths.get('PLUGINS_DATA'))
|
data_path = Path(configpaths.get('PLUGINS_DATA'))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|||||||
Reference in New Issue
Block a user