[Qgis-developer] Plugin snippets & cookbook

Larry Shaffer larrys at dakotacarto.com
Fri Mar 30 07:52:04 EDT 2012

Hi Denis,

On Fri, Mar 30, 2012 at 3:57 AM, Denis Rouzaud <denis.rouzaud at gmail.com> wrote:
> ...
> First, I propose to add these three lines in the code snippets. It is to
> include help link in thew plugin menu:
> def initGui(self):
>  # This initiates the action
>  self.helpAction = QAction(QIcon(":/plugins/myplugin/icons/help.png"),
> "Help", self.iface.mainWindow())
>  # This will open the website url using user's defined browser
>  QObject.connect(self.helpAction, SIGNAL("triggered()"), lambda:
> QDesktopServices.openUrl(QUrl("http://my.help.site/formyplugin")))
>  # This will add the help link in the plugin menu, under the entry "My
> Plugin"
>  self.iface.addPluginToMenu("&My plugin", self.helpAction)
> ...

Nifty snippet.

For connecting your signal to the lambda slot, how about new style instead?

    lambda: QDesktopServices.openUrl(QUrl("http://my.help.site/formyplugin")))

Also, you may want to note adding the removal call to the 'def
unload(self)' method as well:

self.iface.removePluginMenu("&My plugin", self.helpAction)

btw: Your snippet seems to be appearing 3 times in the listing. Maybe
a glitch with the site?


Larry Shaffer
Dakota Cartography
Black Hills, South Dakota

More information about the Qgis-developer mailing list