borysiasty / plugin_reloader

QGIS plugin: Reloads a chosen plugin in one click (only useful for Python Plugin Developers)
GNU General Public License v3.0
19 stars 16 forks source link

Doesn't reload imported libraries #37

Closed geraldo closed 1 week ago

geraldo commented 9 months ago

Thanks for your great plugin, really a essential tool for developing QGIS plugins.

Would it be possible to reload also loaded libraries when reloading a plugin? Sometimes I have to test changes in related libraries and right now I have to reload QGIS in order to reload a library.

Example: GeoCat Bridge uses not core library bridge-style, which doesn´t get reloaded on reloading the plugin.

borysiasty commented 6 months ago

Hi,

I apologize for the late reply, I was a bit off last years.

I'll look at it in a few weeks. I know know this problem very well from my own work, so It's time to to sort it out finally ;)

borysiasty commented 1 month ago

@geraldo Could you please check if the problem still occurs in Reloader 0.10?

If so, could you please provide steps for reproduce? I mean an actual modification I can do to bridge-style that won't be reloaded. After some random test it seems to work, but maybe I didn't make it deep enough.

borysiasty commented 3 weeks ago

Closing because of no feedback.

geraldo commented 2 weeks ago

Thanks @borysiasty for your efforts and your great plugin. Sorry for the late response, I was off for some time.

I just checked this issue with your latest plugin version 0.10 and see that the issue is still happening. Here the steps to reproduce with Geocatbride plugin:

  1. Install plugin from https://plugins.qgis.org/plugins/geocatbridge/
  2. Open a QGIS project, open Style Viewer (Web -> Geocat Bridge -> StyleViewer), select Tab Panel Mapbox and select a layer in Layers Panel to show the style code.
  3. Edit and save file python/plugins/geocatbridge/libs/bridgestyle/bridgestyle/mapboxgl/fromgeostyler.py, for example line 178 putting: lay["source-layer"] = "SOURCE:" + source
  4. Reload plugin geocatbridge and check layer style code in Style Viewer

The code should have changed from "source-layer": "layername" to "source-layer": "SOURCE:layername", but actually this doesn't happen till you restart QGIS.

borysiasty commented 1 week ago

Hi @geraldo!

The problem is in your unload() function, where the dock widget is not effectively removed from QGIS window and it keeps running, detached from the plugin (like a zombie process).

So every time you run the reloader it works fine: the modified plugin is loaded and a new dock is created, but the new dock is hidden:

Plugin.py:89:        self.iface.addDockWidget(Qt.RightDockWidgetArea, self.widget_styleviewer)
Plugin.py:90:        self.widget_styleviewer.hide()

The dock you still see is the zombie one. Now if you right-click on the toolbar area to list available docks, you will see multiple StyleViewers. Only one of them is the current one, controlled by the current instance of the plugin.

The reloader is helpless if you don't properly remove widgets from GUI, so you need to fix in the unload() function. Instead of calling:

        self.closeDialog(self.widget_styleviewer)  # noqa

remove it from GUI, destroy the underlying C++ object, and then the Python one:

        self.iface.removeDockWidget(self.widget_styleviewer)
        self.widget_styleviewer.deleteLater()
        del self.widget_styleviewer

I put the following code at the end of the function, after removeProvider, as it seems to need the dock.

So I'm closing the issue again ;) Hopefully it solves the problem.