QGIS-3 – Avoiding Plugin Window from Opening at Start

qgis-3qgis-plugins

I have written a few QGIS plugins based on dockwidget (Spectre Viewer and Stripchart viewer). When opened, the plugin window is expected to stay open and react to interactions with opened layers. This works fine, but an annoyance is that when the plugin is installed and active, its window will open as soon as I start QGIS. I do not want them to appear until I open the plugin from the menu or toolbar. How can I do this?

The problem seems to be the opposite of QGIS plugins open automatically when starting QGIS, but I cannot see how the answer to this could help me (I do not have any startup.py in my plugins)

Best Answer

I made the following edits to your plugin's qgisSpectre.py file in my local installation which seem to have fixed the problem. You can make the same changes in your local installation to test, then update your plugin.

Move the line which creates the dialog instance from the initGui() method to the __init__() method and add the following lines like so:

self.dlg=qgisSpectreDockWidget(self.iface.mainWindow())
if self.dlg.isVisible():
    self.dlg.close()

enter image description here

Also in the __init__() method, change:

self.pluginIsActive = False

to:

self.pluginIsActive = None

Then set the self.pluginIsActive attribute to False in the initGui() method.

enter image description here

Related Question