1
FalkonTutorials/python/articles/4.Adding_entry_to_the_extension_menu.md
Juraj Oravec 77a28db48e
Rename image and extension subfolders by category
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
2022-04-27 22:49:06 +02:00

1.6 KiB

Falkon Python Tutorial - 4. Adding entry to the extension menu

Hello, in this chapter I will show you how to add an entry to the extension menu. The extension menu is located at Tools: Extensions.

Extension menu

In this example extension you will see popup message box with 'Tutorial 4 - Message from extension menu' after you click on the menu entry.

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 found in the source code

The parameter menu is the menu into which the new entry / action will be added.

    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_()

The full code can be found at extensions/Tutorial4

Note: Always create an instance of Action in populateExtensionsMenu. It will be deleted / destroyed when the menu is hidden.
Do not try to add keyboard shortcut to the action used to construct the menu, it will not work properly.