Add SettingsDialog, aloow change of icon
closes GH-2 Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
parent
b9306987e6
commit
844eb00abe
@ -1,12 +1,20 @@
|
||||
import Falkon
|
||||
import os
|
||||
from PySide2 import QtCore, QtGui
|
||||
from readability.settingsDialog import SettingsDialog
|
||||
|
||||
|
||||
class Readability(Falkon.PluginInterface, QtCore.QObject):
|
||||
view = None
|
||||
config = None
|
||||
|
||||
def init(self, state, settingsPath):
|
||||
self.config = {
|
||||
"settingsFile": os.path.join(settingsPath, "readability", "settings.ini"),
|
||||
"icon": "dark"
|
||||
}
|
||||
self.loadSettings()
|
||||
|
||||
plugins = Falkon.MainApplication.instance().plugins()
|
||||
|
||||
plugins.mainWindowCreated.connect(self.onMainWindowCreated)
|
||||
@ -37,8 +45,9 @@ class Readability(Falkon.PluginInterface, QtCore.QObject):
|
||||
and hitTestResult.mediaUrl().isEmpty()
|
||||
and not hitTestResult.isContentEditable()
|
||||
and not hitTestResult.isContentSelected()):
|
||||
icon = "icon-light.png" if self.config["icon"] == "light" else "icon-dark.png"
|
||||
menu.addAction(
|
||||
QtGui.QIcon(os.path.join(os.path.dirname(__file__), "data", "icon.png")),
|
||||
QtGui.QIcon(os.path.join(os.path.dirname(__file__), "data", icon)),
|
||||
"Readability",
|
||||
self.makeReadability
|
||||
)
|
||||
@ -94,5 +103,26 @@ class Readability(Falkon.PluginInterface, QtCore.QObject):
|
||||
|
||||
self.view.page().runJavaScript(call)
|
||||
|
||||
def showSettings(self, parent):
|
||||
settings = SettingsDialog(self.config, parent)
|
||||
settings.accepted.connect(self.saveSettings)
|
||||
settings.exec_()
|
||||
|
||||
def saveSettings(self):
|
||||
settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat)
|
||||
|
||||
settings.beginGroup("Readability")
|
||||
settings.setValue("icon", self.config["icon"])
|
||||
settings.endGroup()
|
||||
|
||||
settings.sync()
|
||||
|
||||
def loadSettings(self):
|
||||
settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat)
|
||||
|
||||
settings.beginGroup("Readability")
|
||||
self.config["icon"] = str(settings.value("icon", self.config["icon"]))
|
||||
settings.endGroup()
|
||||
|
||||
|
||||
Falkon.registerPlugin(Readability())
|
||||
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
BIN
readability/data/icon-light.png
Normal file
BIN
readability/data/icon-light.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
40
readability/i18n.py
Normal file
40
readability/i18n.py
Normal 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
|
@ -2,11 +2,11 @@
|
||||
Name=Readability
|
||||
Comment=Transform webpage to easy reading.
|
||||
|
||||
Icon=data/icon.png
|
||||
Icon=data/icon-dark.png
|
||||
Type=Service
|
||||
X-Falkon-Type=Extension/Python
|
||||
|
||||
X-Falkon-Author=Juraj Oravec
|
||||
X-Falkon-Email=sgd.orava@gmail.com
|
||||
X-Falkon-Version=1.0.0
|
||||
X-Falkon-Settings=false
|
||||
X-Falkon-Settings=true
|
||||
|
62
readability/settingsDialog.py
Normal file
62
readability/settingsDialog.py
Normal file
@ -0,0 +1,62 @@
|
||||
# ============================================================
|
||||
# Auto Zoomer - 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 Falkon
|
||||
import os
|
||||
from PySide2 import QtCore, QtWidgets, QtUiTools
|
||||
from readability.i18n import i18n
|
||||
|
||||
|
||||
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__), "settingsDialog.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.radioButtonLight.setChecked(self.config["icon"] == "light")
|
||||
self.ui.radioButtonDark.setChecked(self.config["icon"] == "dark")
|
||||
|
||||
self.ui.buttonBoxConfirm.accepted.connect(self.accept)
|
||||
self.ui.buttonBoxConfirm.rejected.connect(self.reject)
|
||||
|
||||
def translations(self):
|
||||
self.setWindowTitle(i18n("Readability Settings"))
|
||||
self.ui.radioButtonLight.setText(i18n("Light"))
|
||||
self.ui.radioButtonDark.setText(i18n("Dark"))
|
||||
|
||||
def updateData(self):
|
||||
self.config["icon"] = "light" if self.ui.radioButtonLight.isChecked() else "dark"
|
||||
|
||||
def accept(self):
|
||||
self.updateData()
|
||||
|
||||
super().accept()
|
58
readability/settingsDialog.ui
Normal file
58
readability/settingsDialog.ui
Normal file
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>399</width>
|
||||
<height>180</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Readability Settings</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBoxIcon">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Menu icon:</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButtonLight">
|
||||
<property name="text">
|
||||
<string>Light</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButtonDark">
|
||||
<property name="text">
|
||||
<string>Dark</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBoxConfirm">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user