diff --git a/readability/__init__.py b/readability/__init__.py index 8d2a587..98a9d15 100644 --- a/readability/__init__.py +++ b/readability/__init__.py @@ -2,18 +2,22 @@ import Falkon import os from PySide2 import QtCore, QtGui from readability.settingsDialog import SettingsDialog +from readability.button import Button class Readability(Falkon.PluginInterface, QtCore.QObject): - view = None config = None + view = None + buttons = None def init(self, state, settingsPath): self.config = { "settingsFile": os.path.join(settingsPath, "readability", "settings.ini"), "icon": "dark" } + self.buttons = {} self.loadSettings() + self.onConfigUpdate() plugins = Falkon.MainApplication.instance().plugins() @@ -32,10 +36,15 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): return True def onMainWindowCreated(self, window): - pass + button = Button(self.config["icon"]) + button.clicked.connect(lambda: self.makeReadability(button.webView())) + + window.navigationBar().addToolButton(button) + self.buttons[window] = button def onMainWindowDeleted(self, window): - pass + if window in self.buttons: + del self.buttons[window] def populateWebViewMenu(self, menu, view, hitTestResult): self.view = view @@ -52,7 +61,10 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): self.makeReadability ) - def makeReadability(self): + def makeReadability(self, view=None): + if view: + self.view = view + dataDir = os.path.join(os.path.dirname(__file__), "data") iconClose = Falkon.QzTools.pixmapToDataUrl( @@ -106,6 +118,7 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): def showSettings(self, parent): settings = SettingsDialog(self.config, parent) settings.accepted.connect(self.saveSettings) + settings.accepted.connect(self.onConfigUpdate) settings.exec_() def saveSettings(self): @@ -124,5 +137,9 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): self.config["icon"] = str(settings.value("icon", self.config["icon"])) settings.endGroup() + def onConfigUpdate(self): + for _, button in self.buttons.items(): + button.updateIcon(self.config["icon"]) + Falkon.registerPlugin(Readability()) diff --git a/readability/button.py b/readability/button.py new file mode 100644 index 0000000..8ef82f6 --- /dev/null +++ b/readability/button.py @@ -0,0 +1,48 @@ +# Readability - 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 Falkon +import os +from PySide2 import QtGui + + +class Button(Falkon.AbstractButtonInterface): + def __init__(self, iconStyle): + super().__init__() + + icon = "icon-light.png" if iconStyle == "light" else "icon-dark.png" + self.setIcon(QtGui.QIcon( + os.path.join(os.path.dirname(__file__), "data", icon)) + ) + self.setTitle("Button") + self.setToolTip("Activate Readability") + + self.clicked.connect(self.onClicked) + + def id(self): + return "readability-button" + + def name(self): + return "Readability" + + def onClicked(self, controller): + pass + + def updateIcon(self, iconStyle): + icon = "icon-light.png" if iconStyle == "light" else "icon-dark.png" + self.setIcon(QtGui.QIcon( + os.path.join(os.path.dirname(__file__), "data", icon)) + )