Skip to content

Commit d7e49f5

Browse files
authored
Merge pull request #38 from gacarrillor/check_deps_on_plugin_install
Add support for dependency check while installing a plugin
2 parents e272291 + ee0ddbc commit d7e49f5

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

a00_qpip/plugin.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
import pkg_resources
1010
import qgis
1111
from pkg_resources import DistributionNotFound, VersionConflict
12+
from pyplugin_installer import installer
1213
from qgis.core import QgsApplication, QgsSettings
13-
from qgis.PyQt.QtWidgets import QAction
14+
from qgis.PyQt.QtWidgets import QAction, QApplication
1415

1516
from .ui import MainDialog
1617
from .utils import Lib, Req, icon, log, run_cmd
@@ -54,10 +55,11 @@ def __init__(self, iface, plugin_path=None):
5455

5556
sys.path_importer_cache.clear()
5657

57-
# Monkey patch qgis.utils
58-
log("Applying monkey patch to qgis.utils")
58+
# Monkey patch qgis.utils and installer
59+
log("Applying monkey patch to qgis.utils and installer")
5960
self._original_loadPlugin = qgis.utils.loadPlugin
6061
qgis.utils.loadPlugin = self.patched_load_plugin
62+
installer.loadPlugin = self.patched_load_plugin
6163

6264
self.iface.initializationCompleted.connect(self.initComplete)
6365

@@ -87,8 +89,9 @@ def unload(self):
8789
self.iface.removePluginMenu("QPIP", self.show_folder_action)
8890

8991
# Remove monkey patch
90-
log("Unapplying monkey patch to qgis.utils")
92+
log("Unapplying monkey patch to qgis.utils and installer")
9193
qgis.utils.loadPlugin = self._original_loadPlugin
94+
installer.loadPlugin = self._original_loadPlugin
9295

9396
# Remove path alterations
9497
if self.site_packages_path in sys.path:
@@ -104,33 +107,48 @@ def patched_load_plugin(self, packageName):
104107
"""
105108
This replaces qgis.utils.loadPlugin
106109
"""
110+
res = False
111+
112+
# Get override cursor if any, to restore it later
113+
cursor_shape = None
114+
cursor = QApplication.overrideCursor()
115+
if cursor:
116+
cursor_shape = cursor.shape()
117+
QApplication.restoreOverrideCursor()
118+
107119
if not self._is_qgis_loaded():
108120
# During QGIS startup
109121
log(f"Loading {packageName} (GUI is no yet ready).")
110122
if not self._check_on_startup():
111123
# With initial loading disabled, we simply load the plugin
112124
log(f"Check on startup disabled. Normal loading of {packageName}.")
113-
return self._original_loadPlugin(packageName)
125+
res = self._original_loadPlugin(packageName)
114126
else:
115127
# With initial loading enabled, we defer loading
116128
log(f"Check on startup enabled, we defer loading of {packageName}.")
117129
self._defered_packages.append(packageName)
118-
return False
130+
res = False
119131
else:
120132
# QGIS ready, a plugin probably was just enabled in the manager
121133
log(f"Loading {packageName} (GUI is ready).")
122134
if not self._check_on_install():
123135
# With loading on install disabled, we simply load the plugin
124136
log(f"Check on install disabled. Normal loading of {packageName}.")
125-
return self._original_loadPlugin(packageName)
137+
res = self._original_loadPlugin(packageName)
126138
else:
127139
log(f"Check on install enabled, we check {packageName}.")
128140
dialog, run_gui = self.check_deps(additional_plugins=[packageName])
129141
if run_gui:
130142
self.promt_install(dialog)
131143
self.save_settings(dialog)
132144
self.start_packages([packageName])
133-
return True
145+
res = True
146+
147+
# Restore original cursor
148+
if cursor_shape:
149+
QApplication.setOverrideCursor(cursor_shape)
150+
151+
return res
134152

135153
def check_deps(self, additional_plugins=[]) -> Union[MainDialog, bool]:
136154
"""

0 commit comments

Comments
 (0)