1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-19 18:26:34 +01:00

Add example hellopython Python extension

This commit is contained in:
David Rosca 2018-02-26 18:18:56 +01:00
parent 228e672254
commit 43e886a1b0
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
7 changed files with 220 additions and 0 deletions

View File

@ -1,3 +1,4 @@
add_subdirectory(lib)
add_subdirectory(main)
add_subdirectory(plugins)
add_subdirectory(scripts)

View File

@ -0,0 +1,5 @@
function(install_python_script name)
install(DIRECTORY ${name} DESTINATION "${FALKON_INSTALL_PLUGINDIR}/python")
endfunction()
install_python_script(hellopython)

View File

@ -0,0 +1,18 @@
# ============================================================
# HelloPython plugin for Falkon
# Copyright (C) 2018 David Rosca <nowrep@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/>.
# ============================================================
from .hellopython import *

View File

@ -0,0 +1,40 @@
# ============================================================
# HelloPython plugin for Falkon
# Copyright (C) 2018 David Rosca <nowrep@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
from PySide2 import QtGui, QtWidgets
class HelloButton(Falkon.AbstractButtonInterface):
def __init__(self):
super().__init__()
self.setIcon(QtGui.QIcon(":icons/other/about.svg"))
self.setTitle("HelloPython")
self.setToolTip("Hello Python")
self.clicked.connect(self.onClicked)
def id(self):
return "hellopython-button"
def name(self):
return "HelloPython button"
def onClicked(self, controller):
self.menu = QtWidgets.QMenu()
self.menu.addAction("Hello Python", lambda: print("clicked"))
self.menu.popup(controller.callPopupPosition(self.menu.sizeHint()))
self.menu.aboutToHide.connect(controller.callPopupClosed)

View File

@ -0,0 +1,106 @@
# ============================================================
# HelloPython plugin for Falkon
# Copyright (C) 2018 David Rosca <nowrep@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
from PySide2 import QtCore, QtGui, QtWidgets
from hellopython import sidebar, button
class HelloPlugin(Falkon.PluginInterface, QtCore.QObject):
buttons = {}
def init(self, state, settingsPath):
print("{} {}".format(state, settingsPath))
plugins = Falkon.MainApplication.instance().plugins()
plugins.registerAppEventHandler(Falkon.PluginProxy.MousePressHandler, self)
plugins.mainWindowCreated.connect(self.mainWindowCreated)
plugins.mainWindowDeleted.connect(self.mainWindowDeleted)
self.sidebar = sidebar.HelloSidebar()
Falkon.SideBarManager.addSidebar("hellopython-sidebar", self.sidebar)
if state == Falkon.PluginInterface.LateInitState:
for window in Falkon.MainApplication.instance().windows():
self.mainWindowCreated(window)
def unload(self):
print("unload")
Falkon.SideBarManager.removeSidebar("hellopython-sidebar")
for window in Falkon.MainApplication.instance().windows():
self.mainWindowDeleted(window)
def testPlugin(self):
return True
def populateWebViewMenu(self, menu, view, r):
self.view = view
title = ""
if not r.imageUrl().isEmpty():
title += " on image"
if not r.linkUrl().isEmpty():
title += " on link"
if r.isContentEditable():
title += " on input"
menu.addAction("My first plugin action" + title, self.actionSlot)
def mousePress(self, type, obj, event):
print("mousePress {} {} {}".format(type, obj, event))
return False
def actionSlot(self):
QtWidgets.QMessageBox.information(self.view, "Hello", "First plugin action works :-)")
def showSettings(self, parent):
self.settings = QtWidgets.QDialog(parent)
b = QtWidgets.QPushButton("Hello Python v0.0.1")
closeButton = QtWidgets.QPushButton("Close")
label = QtWidgets.QLabel()
label.setPixmap(QtGui.QPixmap(":icons/other/about.svg"))
l = QtWidgets.QVBoxLayout(self.settings)
l.addWidget(label)
l.addWidget(b)
l.addWidget(closeButton)
self.settings.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.settings.setWindowTitle("Hello Python Settings")
self.settings.setWindowIcon(QtGui.QIcon(":icons/falkon.svg"))
closeButton.clicked.connect(self.settings.close)
self.settings.show()
def mainWindowCreated(self, window):
b = button.HelloButton()
window.statusBar().addButton(b)
window.navigationBar().addToolButton(b)
self.buttons[window] = b
def mainWindowDeleted(self, window):
if not window in self.buttons: return
b = self.buttons[window]
window.statusBar().removeButton(b)
window.navigationBar().removeToolButton(b)
del self.buttons[window]
Falkon.registerPlugin(HelloPlugin())

View File

@ -0,0 +1,11 @@
[Desktop Entry]
Name=Hello Python
Comment=Example Python extension
Icon=
Type=Service
X-Falkon-Author=David Rosca
X-Falkon-Email=nowrep@gmail.com
X-Falkon-Version=0.1.0
X-Falkon-Settings=true

View File

@ -0,0 +1,39 @@
# ============================================================
# HelloPython plugin for Falkon
# Copyright (C) 2018 David Rosca <nowrep@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
from PySide2 import QtGui, QtWidgets
class HelloSidebar(Falkon.SideBarInterface):
def title(self):
return "HelloPython Sidebar"
def createMenuAction(self):
act = QtWidgets.QAction("Hello Python Sidebar")
act.setCheckable(True)
return act
def createSideBarWidget(self, window):
w = QtWidgets.QWidget()
b = QtWidgets.QPushButton("Hello Python v0.0.1");
label = QtWidgets.QLabel()
label.setPixmap(QtGui.QPixmap(":icons/other/about.svg"));
l = QtWidgets.QVBoxLayout(w);
l.addWidget(label);
l.addWidget(b);
w.setLayout(l);
return w