From 517678bd5be2aa5e4113a3d423b2d2b1704fd3d8 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Sat, 29 Feb 2020 21:56:08 +0100 Subject: [PATCH] Add settings dialog Signed-off-by: Juraj Oravec --- tabcounter/__init__.py | 7 ++++ tabcounter/i18n.py | 40 +++++++++++++++++++++ tabcounter/metadata.desktop | 2 +- tabcounter/settings.ui | 70 ++++++++++++++++++++++++++++++++++++ tabcounter/settingsDialog.py | 60 +++++++++++++++++++++++++++++++ 5 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 tabcounter/i18n.py create mode 100644 tabcounter/settings.ui create mode 100644 tabcounter/settingsDialog.py diff --git a/tabcounter/__init__.py b/tabcounter/__init__.py index 07474e6..9ed1ceb 100644 --- a/tabcounter/__init__.py +++ b/tabcounter/__init__.py @@ -24,6 +24,7 @@ from PySide2 import QtCore from tabcounter.label import Label from tabcounter.config import Config from tabcounter.constants import DISPLAY_TYPE +from tabcounter.settingsDialog import SettingsDialog class tabCounter(Falkon.PluginInterface, QtCore.QObject): @@ -53,6 +54,12 @@ class tabCounter(Falkon.PluginInterface, QtCore.QObject): def testPlugin(self): return True + def showSettings(self, parent): + settings = SettingsDialog(self.config, parent) + settings.accepted.connect(self.config.save) + settings.exec_() + + def onMainWindowCreated(self, window): labelWidget = Label(window, self.config.displayType) self.config.displayTypeChanged.connect(labelWidget.displayTypeChanged) diff --git a/tabcounter/i18n.py b/tabcounter/i18n.py new file mode 100644 index 0000000..3db8440 --- /dev/null +++ b/tabcounter/i18n.py @@ -0,0 +1,40 @@ +# ============================================================ +# Falkon - Qt web browser +# Copyright (C) 2018 David Rosca +# Copyright (C) 2019 Juraj Oravec +# +# This program 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. +# +# This program 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 this program. If not, see . +# ============================================================ +import gettext +import os +from PySide2 import QtCore + +locale = QtCore.QLocale.system() +languages = [ + locale.name(), + locale.bcp47Name() +] +i = locale.name().find('_') +if i > 0: + languages.append(locale.name()[:i]) + +localedir = QtCore.QStandardPaths.locate( + QtCore.QStandardPaths.GenericDataLocation, + os.path.join(os.path.dirname(__file__), "locale"), + QtCore.QStandardPaths.LocateDirectory +) + +t = gettext.translation(__package__, localedir, languages, fallback=True) +i18n = t.gettext +i18np = t.ngettext diff --git a/tabcounter/metadata.desktop b/tabcounter/metadata.desktop index 91e974c..8295368 100644 --- a/tabcounter/metadata.desktop +++ b/tabcounter/metadata.desktop @@ -8,4 +8,4 @@ X-Falkon-Type=Extension/Python X-Falkon-Author=Juraj Oravec X-Falkon-Email=sgd.orava@gmail.com X-Falkon-Version=0.1.0 -X-Falkon-Settings=false +X-Falkon-Settings=true diff --git a/tabcounter/settings.ui b/tabcounter/settings.ui new file mode 100644 index 0000000..4e1e29d --- /dev/null +++ b/tabcounter/settings.ui @@ -0,0 +1,70 @@ + + + SettingsDialog + + + + 0 + 0 + 298 + 96 + + + + Tab Counter Settings + + + + + + + + + + Show count of tabs: + + + + + + + + All + + + + + Loaded + + + + + Unloaded + + + + + Loaded/All + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + diff --git a/tabcounter/settingsDialog.py b/tabcounter/settingsDialog.py new file mode 100644 index 0000000..30acddc --- /dev/null +++ b/tabcounter/settingsDialog.py @@ -0,0 +1,60 @@ +# ============================================================ +# Unloader - plugin for Falkon +# Copyright (C) 2019 Juraj Oravec +# +# This program 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. +# +# This program 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 this program. If not, see . +# ============================================================ + +import os +from PySide2 import QtCore, QtWidgets, QtUiTools +from tabcounter.i18n import i18n +from tabcounter.constants import DISPLAY_TYPE + + +class SettingsDialog(QtWidgets.QDialog): + ui = None + config = None + + def __init__(self, config, parent=None): + super().__init__(parent) + + self.config = config + + file = QtCore.QFile(os.path.join(os.path.dirname(__file__), "settings.ui")) + file.open(QtCore.QFile.ReadOnly) + self.ui = QtUiTools.QUiLoader().load(file, self) + file.close() + + layout = QtWidgets.QVBoxLayout(self) + layout.addWidget(self.ui) + self.setLayout(layout) + + self.translations() + + self.ui.displayTypeComboBox.setCurrentIndex(self.config.displayType - 1) + + self.ui.buttonBoxConfirm.accepted.connect(self.accept) + self.ui.buttonBoxConfirm.rejected.connect(self.reject) + + def translations(self): + self.setWindowTitle(i18n("Tab Counter Settings")) + self.ui.displayTypeLabel.setText(i18n("Show count of tabs:")) + + def updateData(self): + self.config.displayType = self.ui.displayTypeComboBox.currentIndex() + 1 + + def accept(self): + self.updateData() + + super().accept()