Add settings dialog

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
Juraj Oravec 2020-02-29 21:56:08 +01:00
parent 3e95e04610
commit 517678bd5b
No known key found for this signature in database
GPG Key ID: 63ACB65056BC8D07
5 changed files with 178 additions and 1 deletions

View File

@ -24,6 +24,7 @@ from PySide2 import QtCore
from tabcounter.label import Label from tabcounter.label import Label
from tabcounter.config import Config from tabcounter.config import Config
from tabcounter.constants import DISPLAY_TYPE from tabcounter.constants import DISPLAY_TYPE
from tabcounter.settingsDialog import SettingsDialog
class tabCounter(Falkon.PluginInterface, QtCore.QObject): class tabCounter(Falkon.PluginInterface, QtCore.QObject):
@ -53,6 +54,12 @@ class tabCounter(Falkon.PluginInterface, QtCore.QObject):
def testPlugin(self): def testPlugin(self):
return True return True
def showSettings(self, parent):
settings = SettingsDialog(self.config, parent)
settings.accepted.connect(self.config.save)
settings.exec_()
def onMainWindowCreated(self, window): def onMainWindowCreated(self, window):
labelWidget = Label(window, self.config.displayType) labelWidget = Label(window, self.config.displayType)
self.config.displayTypeChanged.connect(labelWidget.displayTypeChanged) self.config.displayTypeChanged.connect(labelWidget.displayTypeChanged)

40
tabcounter/i18n.py Normal file
View File

@ -0,0 +1,40 @@
# ============================================================
# Falkon - Qt web browser
# Copyright (C) 2018 David Rosca <nowrep@gmail.com>
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
#
# 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 <http://www.gnu.org/licenses/>.
# ============================================================
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

View File

@ -8,4 +8,4 @@ X-Falkon-Type=Extension/Python
X-Falkon-Author=Juraj Oravec X-Falkon-Author=Juraj Oravec
X-Falkon-Email=sgd.orava@gmail.com X-Falkon-Email=sgd.orava@gmail.com
X-Falkon-Version=0.1.0 X-Falkon-Version=0.1.0
X-Falkon-Settings=false X-Falkon-Settings=true

70
tabcounter/settings.ui Normal file
View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SettingsDialog</class>
<widget class="QWidget" name="SettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>298</width>
<height>96</height>
</rect>
</property>
<property name="windowTitle">
<string>Tab Counter Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="displayTypeLabel">
<property name="text">
<string>Show count of tabs:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="displayTypeComboBox">
<item>
<property name="text">
<string>All</string>
</property>
</item>
<item>
<property name="text">
<string>Loaded</string>
</property>
</item>
<item>
<property name="text">
<string>Unloaded</string>
</property>
</item>
<item>
<property name="text">
<string>Loaded/All</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBoxConfirm">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,60 @@
# ============================================================
# Unloader - plugin for Falkon
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
#
# 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 <http://www.gnu.org/licenses/>.
# ============================================================
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()