Saturday, 20 August 2016

Is there a way to locate plugins in the QGIS gui programatically from pyqgis?


I've let my love of shiny new QGIS plugins get the better of me, and I'm finding it difficult to remember which menu / submenu / panel that a given plugin is in. I'm using well over 100 now, and going on a purge usually means I find another use for the plugin I just removed...


So I thought I'd try to write a plugin to get that info so I could search for it. Things that the Plugin manager knows, plus (most importantly) how to locate it in the GUI.



Processing is great for finding a lot of the built-in qgis functionality, but it doesn't find plugins which weren't written to make use of its framework.


Looking at the answer to listing installed plugins via pyqgis I was able to get a list of plugin names.


There seems to be a class, QgsPluginRegistry, which looks promising in the C++ code, but I can't find a SIP defintion file for that, so I don't think this class is exposed to python.


Using a bit of tracing through the QGIS source, I was able to write a short snippet to sniff the configuration files for the plugins


for x in qgis.utils.findPlugins("/home/steven/.qgis2/python/plugins"): 
# gets a (name,ConfigParser) tuple
print "_"*80
print x[0] # plugin name
for key in x[1].options('general'):
print "\t%s = %s" % (key, x[1].get('general',key))


This gives me access to the same info as the qgis plugin manager... changelogs, authorship, category and so on.


qgsAffine
name = Affine Transformations
qgisminimumversion = 2.0
description = Apply affine transformations to selected geometries.
version = 1.0.2
author = Mauricio de Paulo and Erik Timmers
email = [redacted]
changelog = [snipped]

experimental = False
deprecated = False
tags =
homepage = [redacted]
repository = [redacted]
tracker = [redacted]
icon = icon.svg
category = Vector

What it doesn't tell me is where, exactly, is it in the menu structure? Can this be got from pyqgis in a clean way?



Or to find this, do I need to start sniffing round the Qt GUI classes or writing python parsers (doable, but seems a bit over the top?) The category value (vector, raster etc) helps narrow the search, but there are plenty of plugins (e.g. MMqgis) which create their own menus.



Answer



Only an uninformed guess, but since plugins are only added to menus/toolbars when loaded - ie part of their classFactory instantiation process, and removed in the same way, there is probably no need to have any record of which menus plugins are in. You'd have to look at lower-level querying of the full QGIS menu options, not just plugins. No idea if that is possible.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...