1

After having built a QGIS 3 plugin, I'd like to know how could I call my plugin without clicking on the plugin bar of QGIS to launch it.

I've tried implement a first batch file for it :

REM changer OSGEO4W_ROOT pour aller sur le dossier du shell
SET OSGEO4W_ROOT=C:\Program Files\QGIS 3.4
SET QGISNAME=qgis
SET QGIS=%OSGEO4W_ROOT%\apps\%QGISNAME%
SET QGIS_PREFIX_PATH=%QGIS%
REM Gdal setup
SET PATH=%OSGEO4W_ROOT%\bin;%QGIS%\bin;%PATH%
SET PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37
SET PYTHONPATH=%QGIS%\python;%PYTHONPATH%

REM Launch python
REM python "C:\Users\(username)\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\tombarel\zoom_snap_dialog.py"
pause

The problem is I don't know how to launch the plugin from my batchfile once I've opened QGIS (version 3.4.4)

I've seen previous answers where fToolsmodule was still available for QGIS 2.X. but about the version 3 of QGIS I can't figure out how to do a standalone program which actions the plugin

I've tried to look at the run()method in the plugin main python file but I couldn't find a way either to call it from another python file

underdark
  • 84,148
  • 21
  • 231
  • 413
Brocolus
  • 303
  • 1
  • 2
  • 13
  • So, you want your plugin to automatically start once you open a QGIS-project? – Erik Feb 08 '19 at 14:30
  • Yes, once QGIS opened and the project loaded, I'd like a program (out of QGIS) to send a signal to QGIS to start and open the plugin – Brocolus Feb 08 '19 at 14:40
  • 2
    search for startup.py which is automatically run by qgis at startup and call your plugin in this script. – Snaileater Feb 08 '19 at 18:39
  • 2
    If you want to autostart your plugin once QGIS is started startup.py is the best way to go. Otherwise if you want to start it while QGIS is running from another application you need a mechanism to send and receive data between different processes. I would use startup.py to start a TCP socket server in a separate thread listening for incoming connections. From anywhere else a client may connect and send some data. If the server recognizes this data, it gets reference to QGIS instance and triggers some action associated with this kind of data. – Detlev Feb 09 '19 at 07:54
  • Thank you very much for you answers, I've looked at the startup.py file of QGIS 3 but it really does sound challenging at my level, If for example I wanted to launch the plugin once QGIS started, should I just call for the plugin.pyand plugin_dialog.pyfiles in startup.py ? Or am I missing a step ? I understand the process you've offered with the TCP server but isn't there a way to receive a signal from a PyQt5 GUI for instance ? – Brocolus Feb 09 '19 at 23:40
  • 1
    This question is about a similar problem. https://gis.stackexchange.com/q/287057/46073 – Andreas Müller Feb 10 '19 at 22:11
  • Thank you for your answer, I've see this post but I'm getting the same error at the call of plugin=[plugin_name].classFactory(iface) : It's doing the error : TypeError: 'NoneType' object is not subscriptable at the line of my plugin's script : locale = QSettings().value('locale/userLocale')[0:2] did you have this mistake too ? – Brocolus Feb 11 '19 at 00:15

0 Answers0