Skip to content

Commit

Permalink
Merge pull request #45025 from gacarrillor/patch-2
Browse files Browse the repository at this point in the history
Set wait cursor while installing plugin from ZIP
  • Loading branch information
m-kuhn committed Sep 11, 2021
2 parents eef9176 + a0b7f14 commit 6d5d8e8
Showing 1 changed file with 34 additions and 37 deletions.
71 changes: 34 additions & 37 deletions python/pyplugin_installer/installer.py
Expand Up @@ -34,7 +34,7 @@
import qgis
from qgis.core import Qgis, QgsApplication, QgsNetworkAccessManager, QgsSettings, QgsNetworkRequestParameters
from qgis.gui import QgsMessageBar, QgsPasswordLineEdit, QgsHelp
from qgis.utils import (iface, startPlugin, unloadPlugin, loadPlugin,
from qgis.utils import (iface, startPlugin, unloadPlugin, loadPlugin, OverrideCursor,
reloadPlugin, updateAvailablePlugins, plugins_metadata_parser)
from .installer_data import (repositories, plugins, officialRepo,
settingsGroup, reposGroup, removeDir)
Expand Down Expand Up @@ -112,25 +112,22 @@ def fetchAvailablePlugins(self, reloadMode):
""" Fetch plugins from all enabled repositories."""
""" reloadMode = true: Fully refresh data from QgsSettings to mRepositories """
""" reloadMode = false: Fetch unready repositories only """
QApplication.setOverrideCursor(Qt.WaitCursor)

if reloadMode:
repositories.load()
plugins.clearRepoCache()
plugins.getAllInstalled()
with OverrideCursor(Qt.WaitCursor):
if reloadMode:
repositories.load()
plugins.clearRepoCache()
plugins.getAllInstalled()

for key in repositories.allEnabled():
if reloadMode or repositories.all()[key]["state"] == 3: # if state = 3 (error or not fetched yet), try to fetch once again
repositories.requestFetching(key, force_reload=reloadMode)

if repositories.fetchingInProgress():
fetchDlg = QgsPluginInstallerFetchingDialog(iface.mainWindow())
fetchDlg.exec_()
del fetchDlg
for key in repositories.all():
repositories.killConnection(key)
for key in repositories.allEnabled():
if reloadMode or repositories.all()[key]["state"] == 3: # if state = 3 (error or not fetched yet), try to fetch once again
repositories.requestFetching(key, force_reload=reloadMode)

QApplication.restoreOverrideCursor()
if repositories.fetchingInProgress():
fetchDlg = QgsPluginInstallerFetchingDialog(iface.mainWindow())
fetchDlg.exec_()
del fetchDlg
for key in repositories.all():
repositories.killConnection(key)

# display error messages for every unavailable repository, unless Shift pressed nor all repositories are unavailable
keepQuiet = QgsApplication.keyboardModifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier)
Expand Down Expand Up @@ -325,11 +322,10 @@ def installPlugin(self, key, quiet=False, stable=True):
"the list of installed plugins. You should find the plugin there, but it's not possible to "
"determine which of them it is and it's also not possible to inform you about available updates. "
"Please contact the plugin author and submit this issue.").format(plugin_path))
QApplication.setOverrideCursor(Qt.WaitCursor)
plugins.getAllInstalled()
plugins.rebuild()
self.exportPluginsToManager()
QApplication.restoreOverrideCursor()
with OverrideCursor(Qt.WaitCursor):
plugins.getAllInstalled()
plugins.rebuild()
self.exportPluginsToManager()
else:
QApplication.setOverrideCursor(Qt.WaitCursor)
# update the list of plugins in plugin handling routines
Expand Down Expand Up @@ -649,21 +645,22 @@ def installFromZipFile(self, filePath):
keepTrying = False

if success:
updateAvailablePlugins()
self.processDependencies(pluginName)
loadPlugin(pluginName)
plugins.getAllInstalled()
plugins.rebuild()

if settings.contains('/PythonPlugins/' + pluginName): # Plugin was available?
if settings.value('/PythonPlugins/' + pluginName, False, bool): # Plugin was also active?
reloadPlugin(pluginName) # unloadPlugin + loadPlugin + startPlugin
with OverrideCursor(Qt.WaitCursor):
updateAvailablePlugins()
self.processDependencies(pluginName)
loadPlugin(pluginName)
plugins.getAllInstalled()
plugins.rebuild()

if settings.contains('/PythonPlugins/' + pluginName): # Plugin was available?
if settings.value('/PythonPlugins/' + pluginName, False, bool): # Plugin was also active?
reloadPlugin(pluginName) # unloadPlugin + loadPlugin + startPlugin
else:
unloadPlugin(pluginName)
loadPlugin(pluginName)
else:
unloadPlugin(pluginName)
loadPlugin(pluginName)
else:
if startPlugin(pluginName):
settings.setValue('/PythonPlugins/' + pluginName, True)
if startPlugin(pluginName):
settings.setValue('/PythonPlugins/' + pluginName, True)

self.exportPluginsToManager()
msg = "<b>%s</b>" % self.tr("Plugin installed successfully")
Expand Down

0 comments on commit 6d5d8e8

Please sign in to comment.