1
FalkonTutorials/articles/4. Adding entry to the extension menu.md
Juraj Oravec c3a07f2402
Add 4. Adding entry to the extension menu
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-05-23 22:48:56 +02:00

32 lines
1.2 KiB
Markdown

# Falkon Python Tutorial - 4. Adding entry to the extension menu
To add an entry to extension menu the `populateExtensionsMenu(self, menu)` method has to be implemented in plugin class.
The reason can be faound in the [source code](https://github.com/KDE/falkon/blob/master/src/lib/plugins/plugininterface.h)
The parameter menu is the menu into which the new entry / action will be added.
```python
def populateExtensionsMenu(self, menu):
action = Falkon.Action(
"Tutorial 4 - Extension menu entry",
menu
)
action.triggered.connect(self.onExtensionMenuTriggered)
menu.addAction(action)
def onExtensionMenuTriggered(self):
msgBox = QtWidgets.QMessageBox()
msgBox.setText('Tutorial 4 - Message from extension menu')
msgBox.exec_()
```
In this example the action will show messagebox[1] with 'Tutorial 4 - Message from extension menu'.
The full code can be found at [extensions/Tutorial4](../extensions/Tutorial4)
**Note:** Always create an instance of Action in `populateExtensionsMenu`.
It will be deleted / destroyed when the menu is hidden.
[1]: https://doc.qt.io/qtforpython/PySide2/QtWidgets/QMessageBox.html