From 33ea49db00466d7126c7f44b56638d06412818d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Mon, 15 Oct 2018 01:06:34 +0200 Subject: [acronyms] Add config dialog --- acronyms_expander/gtk/config.py | 90 ++++++++++++++++++++++++++ acronyms_expander/gtk/config.ui | 139 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 acronyms_expander/gtk/config.py create mode 100644 acronyms_expander/gtk/config.ui (limited to 'acronyms_expander/gtk') diff --git a/acronyms_expander/gtk/config.py b/acronyms_expander/gtk/config.py new file mode 100644 index 0000000..706551a --- /dev/null +++ b/acronyms_expander/gtk/config.py @@ -0,0 +1,90 @@ +# Copyright (C) 2018 Philipp Hörist +# +# This file is part of Acronyms Expander. +# +# Acronyms Expander 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; version 3 only. +# +# Acronyms Expander 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 Acronyms Expander. If not, see . + +from pathlib import Path + +from gi.repository import Gtk +from gi.repository import Gdk + +from gajim.common import app + +from gajim.plugins.plugins_i18n import _ +from gajim.plugins.helpers import get_builder + + +class ConfigDialog(Gtk.ApplicationWindow): + def __init__(self, plugin, transient): + 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) + + ui_path = Path(__file__).parent + self._ui = get_builder(ui_path / 'config.ui') + + self._plugin = plugin + + self.add(self._ui.grid) + + self._fill_list() + self.show_all() + + self._ui.connect_signals(self) + self.connect('destroy', self._on_destroy) + + def _fill_list(self): + for acronym, substitute in self._plugin.acronyms.items(): + self._ui.acronyms_store.append([acronym, substitute]) + + def _on_acronym_edited(self, _renderer, path, new_text): + iter_ = self._ui.acronyms_store.get_iter(path) + self._ui.acronyms_store.set_value(iter_, 0, new_text) + + def _on_substitute_edited(self, _renderer, path, new_text): + iter_ = self._ui.acronyms_store.get_iter(path) + self._ui.acronyms_store.set_value(iter_, 1, new_text) + + def _on_add_clicked(self, _button): + self._ui.acronyms_store.append(['', '']) + row = self._ui.acronyms_store[-1] + self._ui.acronyms_treeview.scroll_to_cell( + row.path, None, False, 0, 0) + self._ui.selection.unselect_all() + self._ui.selection.select_path(row.path) + + def _on_remove_clicked(self, _button): + model, paths = self._ui.selection.get_selected_rows() + references = [] + for path in paths: + references.append(Gtk.TreeRowReference.new(model, path)) + + for ref in references: + iter_ = model.get_iter(ref.get_path()) + self._ui.acronyms_store.remove(iter_) + + def _on_destroy(self, *args): + acronyms = {} + for row in self._ui.acronyms_store: + acronym, substitute = row + if not acronym or not substitute: + continue + acronyms[acronym] = substitute + self._plugin.set_acronyms(acronyms) diff --git a/acronyms_expander/gtk/config.ui b/acronyms_expander/gtk/config.ui new file mode 100644 index 0000000..9c2a03b --- /dev/null +++ b/acronyms_expander/gtk/config.ui @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + True + False + 12 + 12 + 12 + 12 + 6 + + + True + True + True + True + in + + + True + True + True + True + acronyms_store + 1 + + + multiple + + + + + True + Acronym + True + True + 0 + + + True + + + + 0 + + + + + + + True + Substitute + True + True + 0 + + + True + + + + 1 + + + + + + + + + 0 + 0 + + + + + True + False + + + True + True + True + start + + + + True + False + list-add-symbolic + + + + + + False + True + 0 + + + + + Remove + True + True + True + end + + + + + True + True + end + 1 + + + + + 0 + 1 + + + + -- cgit v1.2.3