File indexing completed on 2024-05-12 04:58:40
0001 # ============================================================ 0002 # HelloPython plugin for Falkon 0003 # Copyright (C) 2018 David Rosca <nowrep@gmail.com> 0004 # 0005 # This program is free software: you can redistribute it and/or modify 0006 # it under the terms of the GNU General Public License as published by 0007 # the Free Software Foundation, either version 3 of the License, or 0008 # (at your option) any later version. 0009 # 0010 # This program is distributed in the hope that it will be useful, 0011 # but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 # GNU General Public License for more details. 0014 # 0015 # You should have received a copy of the GNU General Public License 0016 # along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 # ============================================================ 0018 import Falkon 0019 from PySide6 import QtCore, QtGui, QtWidgets 0020 from hellopython import sidebar, button 0021 from hellopython.i18n import i18n 0022 0023 class HelloPlugin(Falkon.PluginInterface, QtCore.QObject): 0024 buttons = {} 0025 0026 def init(self, state, settingsPath): 0027 print("{} {}".format(state, settingsPath)) 0028 0029 plugins = Falkon.MainApplication.instance().plugins() 0030 plugins.registerAppEventHandler(Falkon.PluginProxy.MousePressHandler, self) 0031 0032 plugins.mainWindowCreated.connect(self.mainWindowCreated) 0033 plugins.mainWindowDeleted.connect(self.mainWindowDeleted) 0034 0035 self.sidebar = sidebar.HelloSidebar() 0036 Falkon.SideBarManager.addSidebar("hellopython-sidebar", self.sidebar) 0037 0038 self.schemeHandler = HelloSchemeHandler() 0039 Falkon.MainApplication.instance().networkManager().registerExtensionSchemeHandler("hello", self.schemeHandler) 0040 0041 if state == Falkon.PluginInterface.LateInitState: 0042 for window in Falkon.MainApplication.instance().windows(): 0043 self.mainWindowCreated(window) 0044 0045 def unload(self): 0046 print("unload") 0047 0048 Falkon.SideBarManager.removeSidebar(self.sidebar) 0049 0050 for window in Falkon.MainApplication.instance().windows(): 0051 self.mainWindowDeleted(window) 0052 0053 def testPlugin(self): 0054 return True 0055 0056 def populateWebViewMenu(self, menu, view, r): 0057 self.view = view 0058 0059 title = "" 0060 if not r.imageUrl().isEmpty(): 0061 title += " on image" 0062 0063 if not r.linkUrl().isEmpty(): 0064 title += " on link" 0065 0066 if r.isContentEditable(): 0067 title += " on input" 0068 0069 menu.addAction(i18n("My first plugin action") + title, self.actionSlot) 0070 0071 def mousePress(self, type, obj, event): 0072 print("mousePress {} {} {}".format(type, obj, event)) 0073 return False 0074 0075 def actionSlot(self): 0076 QtWidgets.QMessageBox.information(self.view, i18n("Hello"), i18n("First plugin action works :-)")) 0077 0078 def showSettings(self, parent): 0079 self.settings = QtWidgets.QDialog(parent) 0080 b = QtWidgets.QPushButton("Hello Python v0.0.1") 0081 closeButton = QtWidgets.QPushButton(i18n("Close")) 0082 label = QtWidgets.QLabel() 0083 label.setPixmap(QtGui.QPixmap(":icons/other/about.svg")) 0084 0085 l = QtWidgets.QVBoxLayout(self.settings) 0086 l.addWidget(label) 0087 l.addWidget(b) 0088 l.addWidget(closeButton) 0089 0090 self.settings.setAttribute(QtCore.Qt.WA_DeleteOnClose) 0091 self.settings.setWindowTitle(i18n("Hello Python Settings")) 0092 self.settings.setWindowIcon(QtGui.QIcon(":icons/falkon.svg")) 0093 closeButton.clicked.connect(self.settings.close) 0094 0095 self.settings.show() 0096 0097 def mainWindowCreated(self, window): 0098 b = button.HelloButton() 0099 window.statusBar().addButton(b) 0100 window.navigationBar().addToolButton(b) 0101 self.buttons[window] = b 0102 0103 def mainWindowDeleted(self, window): 0104 if not window in self.buttons: return 0105 b = self.buttons[window] 0106 window.statusBar().removeButton(b) 0107 window.navigationBar().removeToolButton(b) 0108 del self.buttons[window] 0109 0110 Falkon.registerPlugin(HelloPlugin()) 0111 0112 class HelloSchemeHandler(Falkon.ExtensionSchemeHandler): 0113 def requestStarted(self, job): 0114 print("req {}".format(job.requestUrl())) 0115 self.setReply(job, "text/html", "<h1>TEST</h1>{}".format(job.requestUrl()))