[QGIS-Developer] Understanding plugin management in QGIS - exposing QgsPluginRegistry to Python?

Matthias Kuhn matthias at opengis.ch
Sat Mar 14 16:17:51 PDT 2020


Hi Sebastian, Borys,

What about the opposite way: moving things to C++ and leaving only a 
very thing wrapper for interacting with the plugins in place?

That should get rid of duplicated code and be compatible with everything.

Best regards

Matthias

On 3/14/20 10:52 PM, Borys Jurgiel wrote:
> Hi Sebastian,
>
> The reason the whole infrastructure is split between Plugin Manager and Python
> Plugin Installer (and Python utils) is Python support is optional in QGIS.
>
> If QGIS is compiled without Python Support, the Plugin Manager still displays
> all C++ plugins, it just lacks Python ones (and of course install/deinstall
> funcions).
>
> I admit the the infrastructure became a bit complicated ;) However, porting
> the Plugin Manager to Python would require making Python a hard dependency of
> QGIS GUI (or we should drop C++ plugins by porting them all to core, what is
> discussed from time to time and doesn't seem to may happen).
>
> Regards,
>
> Borys
>
>
> Dnia sobota, 14 marca 2020 21:10:24 CET Sebastian M. Ernst pisze:
>> Hi folks,
>>
>> out of curiosity I have started poking around in QGIS' code related to
>> plugin management. It's an interesting mix of C++ and Python code. Even
>> the plugin management GUI itself is partially C++ (the main window,
>> QgsPluginManager[Interface], and part of its logic) and partially Python
>> (all further dialogs and their logic). As an experiment for now, I am
>> looking into how I could port at least the entire GUI to Python and
>> disentangle some of the knots. The rational is that plugin management is
>> not performance-critical and could become much more easy to maintain,
>> among a lot of other interesting benefits that a potentially fully
>> Python-based solution could offer. But that's a different story. For
>> now, I think I have hit a roadblock and was wondering whether anyone
>> could enlighten me. I'd greatly appreciate any help.
>>
>> I *believe* I have a fairly good understanding of what happens
>> underneath `/python/pyplugin_installer/`. The class `QgsPluginInstaller`
>> from `installer.py` appears to be a Python API that is called from the
>> C++-interface (`QgsPluginManagerInterface`) through `QgsPythonRunner`.
>> Most of the C++ appears to be located underneath
>> `/src/app/pluginmanager/` (with a single ui-file elsewhere,
>> `/src/ui/qgspluginmanagerbase.ui`). Having analyzed the C++ class
>> `QgsPluginManager` I believe most of the interface can easily ported to
>> Python.
>>
>> The tricky bit appears to be `/src/app/qgspluginregistry.cpp`. It offers
>> a class named `QgsPluginRegistry` (which is being used by
>> `QgsPluginManager`). I have not found a way to access this class (or
>> an/the instance of it) from Python. I figure it is required to handle
>> both Python *and* C++ plugins. `QgsPluginRegistry` makes heavy use of
>> `mPythonUtils`, which appears to be a C++ wrapper around
>> `/python/utils.py` (through `/src/python/qgspythonutilsimpl.cpp`). So
>> this portion of `QgsPluginRegistry` (about 50%) can be rewritten in
>> Python rather quickly. Methods such as `loadCppPlugin` or
>> `unloadCppPlugin` are a lot more problematic. As far as I can tell,
>> those would need to remain in C++ and they would need to be exposed to
>> Python somehow (if they are not already).
>>
>> Have I found all relevant components of QGIS responsible for plugin
>> management? Does my analysis contain any major flaws? Is there a way to
>> manage C++ plugins (i.e. to call `loadCppPlugin` and `unloadCppPlugin`)
>> from Python?
>>
>> Best regards,
>> Sebastian
>> _______________________________________________
>> QGIS-Developer mailing list
>> QGIS-Developer at lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 	
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>


More information about the QGIS-Developer mailing list