From 06f995316e9674c62929f8277841d16b6ae2e754 Mon Sep 17 00:00:00 2001 From: "Juergen E. Fischer" Date: Mon, 21 Mar 2016 05:04:29 +0100 Subject: [PATCH] plugin installer: switch to pyqt wrappers --- python/pyplugin_installer/__init__.py | 4 +-- python/pyplugin_installer/installer.py | 36 +++++++++---------- python/pyplugin_installer/installer_data.py | 26 +++++++------- .../qgsplugininstallerfetchingdialog.py | 6 ++-- .../qgsplugininstallerinstallingdialog.py | 18 +++++----- .../qgsplugininstallerpluginerrordialog.py | 4 +-- .../qgsplugininstallerrepositorydialog.py | 6 ++-- 7 files changed, 50 insertions(+), 50 deletions(-) diff --git a/python/pyplugin_installer/__init__.py b/python/pyplugin_installer/__init__.py index 8813c15d6fc..909360ee4d4 100644 --- a/python/pyplugin_installer/__init__.py +++ b/python/pyplugin_installer/__init__.py @@ -30,8 +30,8 @@ __revision__ = '$Format:%H$' # import functions for easier access -import installer -from installer import initPluginInstaller +from . import installer +from .installer import initPluginInstaller # NOQA def instance(): diff --git a/python/pyplugin_installer/installer.py b/python/pyplugin_installer/installer.py index 3588a13740b..a3ab8dcadcf 100644 --- a/python/pyplugin_installer/installer.py +++ b/python/pyplugin_installer/installer.py @@ -23,19 +23,19 @@ ***************************************************************************/ """ -from PyQt4.QtCore import Qt, QObject, QSettings, QDir, QUrl -from PyQt4.QtGui import QMessageBox, QLabel, QFrame, QApplication -from PyQt4.QtNetwork import QNetworkRequest +from PyQt.QtCore import Qt, QObject, QSettings, QDir, QUrl +from PyQt.QtWidgets import QMessageBox, QLabel, QFrame, QApplication +from PyQt.QtNetwork import QNetworkRequest import qgis from qgis.core import QgsApplication, QgsNetworkAccessManager from qgis.gui import QgsMessageBar from qgis.utils import iface, startPlugin, unloadPlugin, loadPlugin, reloadPlugin, updateAvailablePlugins -from installer_data import repositories, plugins, officialRepo, settingsGroup, reposGroup, removeDir -from qgsplugininstallerinstallingdialog import QgsPluginInstallerInstallingDialog -from qgsplugininstallerpluginerrordialog import QgsPluginInstallerPluginErrorDialog -from qgsplugininstallerfetchingdialog import QgsPluginInstallerFetchingDialog -from qgsplugininstallerrepositorydialog import QgsPluginInstallerRepositoryDialog +from .installer_data import repositories, plugins, officialRepo, settingsGroup, reposGroup, removeDir +from .qgsplugininstallerinstallingdialog import QgsPluginInstallerInstallingDialog +from .qgsplugininstallerpluginerrordialog import QgsPluginInstallerPluginErrorDialog +from .qgsplugininstallerfetchingdialog import QgsPluginInstallerFetchingDialog +from .qgsplugininstallerrepositorydialog import QgsPluginInstallerRepositoryDialog # public instances: @@ -58,7 +58,7 @@ class QgsPluginInstaller(QObject): def __init__(self): """ Initialize data objects, starts fetching if appropriate, and warn about/removes obsolete plugins """ - QObject.__init__(self) # initialize QObject in order to to use self.tr() + QObject.__init__(self) # initialize QObject in order to to use self.tr() repositories.load() plugins.getAllInstalled() @@ -109,7 +109,7 @@ class QgsPluginInstaller(QObject): 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 + if reloadMode or repositories.all()[key]["state"] == 3: # if state = 3 (error or not fetched yet), try to fetch once again repositories.requestFetching(key) if repositories.fetchingInProgress(): @@ -147,12 +147,12 @@ class QgsPluginInstaller(QObject): for key in plugins.all(): if plugins.all()[key]["status"] == "new": status = self.tr("There is a new plugin available") - tabIndex = 4 # PLUGMAN_TAB_NEW + tabIndex = 4 # PLUGMAN_TAB_NEW # then check for updates (and eventually overwrite status) for key in plugins.all(): if plugins.all()[key]["status"] == "upgradeable": status = self.tr("There is a plugin update available") - tabIndex = 3 # PLUGMAN_TAB_UPGRADEABLE + tabIndex = 3 # PLUGMAN_TAB_UPGRADEABLE # finally set the notify label if status: self.statusLabel.setText(u' %s ' % (tabIndex, status)) @@ -275,7 +275,7 @@ class QgsPluginInstaller(QObject): previousStatus = plugin["status"] if not plugin: return - if plugin["status"] == "newer" and not plugin["error"]: # ask for confirmation if user downgrades an usable plugin + if plugin["status"] == "newer" and not plugin["error"]: # ask for confirmation if user downgrades an usable plugin if QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), self.tr("Are you sure you want to downgrade the plugin to the latest available version? The installed one is newer!"), QMessageBox.Yes, QMessageBox.No) == QMessageBox.No: return @@ -310,11 +310,11 @@ class QgsPluginInstaller(QObject): settings.setValue("/PythonPlugins/" + plugin["id"], True) else: settings = QSettings() - if settings.value("/PythonPlugins/" + key, False, type=bool): # plugin will be reloaded on the fly only if currently loaded - reloadPlugin(key) # unloadPlugin + loadPlugin + startPlugin + if settings.value("/PythonPlugins/" + key, False, type=bool): # plugin will be reloaded on the fly only if currently loaded + reloadPlugin(key) # unloadPlugin + loadPlugin + startPlugin infoString = (self.tr("Plugin reinstalled successfully"), "") else: - unloadPlugin(key) # Just for a case. Will exit quietly if really not loaded + unloadPlugin(key) # Just for a case. Will exit quietly if really not loaded loadPlugin(key) infoString = (self.tr("Plugin reinstalled successfully"), self.tr("Python plugin reinstalled.\nYou need to restart QGIS in order to reload it.")) if quiet: @@ -456,7 +456,7 @@ class QgsPluginInstaller(QObject): dlg.labelInfo.setText(self.tr("This repository is blocked due to incompatibility with your QGIS version")) dlg.labelInfo.setFrameShape(QFrame.Box) if not dlg.exec_(): - return # nothing to do if cancelled + return # nothing to do if cancelled for i in repositories.all().values(): if dlg.editURL.text().strip() == i["url"] and dlg.editURL.text().strip() != repositories.all()[reposName]["url"]: iface.pluginManagerInterface().pushMessage(self.tr("Unable to add another repository with the same URL!"), QgsMessageBar.WARNING) @@ -476,7 +476,7 @@ class QgsPluginInstaller(QObject): if dlg.editURL.text().strip() == repositories.all()[reposName]["url"] and dlg.checkBoxEnabled.checkState() == checkState[repositories.all()[reposName]["enabled"]]: repositories.rename(reposName, newName) self.exportRepositoriesToManager() - return # nothing else to do if only repository name was changed + return # nothing else to do if only repository name was changed plugins.removeRepository(reposName) self.reloadAndExportData() diff --git a/python/pyplugin_installer/installer_data.py b/python/pyplugin_installer/installer_data.py index 5c9626bbe2e..93db60567cd 100644 --- a/python/pyplugin_installer/installer_data.py +++ b/python/pyplugin_installer/installer_data.py @@ -23,9 +23,9 @@ ***************************************************************************/ """ -from PyQt4.QtCore import pyqtSignal, QObject, QCoreApplication, QFile, QDir, QDirIterator, QSettings, QDate, QUrl, QFileInfo, QLocale, QByteArray -from PyQt4.QtXml import QDomDocument -from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply +from PyQt.QtCore import pyqtSignal, QObject, QCoreApplication, QFile, QDir, QDirIterator, QSettings, QDate, QUrl, QFileInfo, QLocale, QByteArray +from PyQt.QtXml import QDomDocument +from PyQt.QtNetwork import QNetworkRequest, QNetworkReply import sys import os import codecs @@ -34,7 +34,7 @@ import qgis.utils from qgis.core import QGis, QgsNetworkAccessManager, QgsAuthManager from qgis.gui import QgsMessageBar from qgis.utils import iface, plugin_paths -from version_compare import compareVersions, normalizeVersion, isCompatible +from .version_compare import compareVersions, normalizeVersion, isCompatible """ @@ -118,7 +118,7 @@ def removeDir(path): result = "" if not QFile(path).exists(): result = QCoreApplication.translate("QgsPluginInstaller", "Nothing to remove! Plugin directory doesn't exist:") + "\n" + path - elif QFile(path).remove(): # if it is only link, just remove it without resolving. + elif QFile(path).remove(): # if it is only link, just remove it without resolving. pass else: fltr = QDir.Dirs | QDir.Files | QDir.Hidden @@ -314,7 +314,7 @@ class Repositories(QObject): if url == officialRepo[1]: officialRepoPresent = True if url == officialRepo[2]: - settings.setValue(key + "/url", officialRepo[1]) # correct a depreciated url + settings.setValue(key + "/url", officialRepo[1]) # correct a depreciated url officialRepoPresent = True if not officialRepoPresent: settings.setValue(officialRepo[0] + "/url", officialRepo[1]) @@ -499,10 +499,10 @@ class Plugins(QObject): def __init__(self): QObject.__init__(self) - self.mPlugins = {} # the dict of plugins (dicts) - self.repoCache = {} # the dict of lists of plugins (dicts) - self.localCache = {} # the dict of plugins (dicts) - self.obsoletePlugins = [] # the list of outdated 'user' plugins masking newer 'system' ones + self.mPlugins = {} # the dict of plugins (dicts) + self.repoCache = {} # the dict of lists of plugins (dicts) + self.localCache = {} # the dict of plugins (dicts) + self.obsoletePlugins = [] # the list of outdated 'user' plugins masking newer 'system' ones # ----------------------------------------- # def all(self): @@ -566,7 +566,7 @@ class Plugins(QObject): return cp.get('general', fct) except Exception as e: if not errorDetails: - errorDetails = e.args[0] # set to the first problem + errorDetails = e.args[0] # set to the first problem return "" def pluginMetadata(fct): @@ -585,7 +585,7 @@ class Plugins(QObject): if not QDir(path).exists(): return - global errorDetails # to communicate with the metadataParser fn + global errorDetails # to communicate with the metadataParser fn plugin = dict() error = "" errorDetails = "" @@ -728,7 +728,7 @@ class Plugins(QObject): allowDeprecated = settings.value(settingsGroup + "/allowDeprecated", False, type=bool) for i in self.repoCache.values(): for j in i: - plugin = j.copy() # do not update repoCache elements! + plugin = j.copy() # do not update repoCache elements! key = plugin["id"] # check if the plugin is allowed and if there isn't any better one added already. if (allowExperimental or not plugin["experimental"]) \ diff --git a/python/pyplugin_installer/qgsplugininstallerfetchingdialog.py b/python/pyplugin_installer/qgsplugininstallerfetchingdialog.py index 215a81b740d..42c563848a4 100644 --- a/python/pyplugin_installer/qgsplugininstallerfetchingdialog.py +++ b/python/pyplugin_installer/qgsplugininstallerfetchingdialog.py @@ -24,10 +24,10 @@ ***************************************************************************/ """ -from PyQt4.QtGui import QDialog, QTreeWidgetItem +from PyQt.QtWidgets import QDialog, QTreeWidgetItem -from ui_qgsplugininstallerfetchingbase import Ui_QgsPluginInstallerFetchingDialogBase -from installer_data import repositories +from .ui_qgsplugininstallerfetchingbase import Ui_QgsPluginInstallerFetchingDialogBase +from .installer_data import repositories class QgsPluginInstallerFetchingDialog(QDialog, Ui_QgsPluginInstallerFetchingDialogBase): diff --git a/python/pyplugin_installer/qgsplugininstallerinstallingdialog.py b/python/pyplugin_installer/qgsplugininstallerinstallingdialog.py index f91afe19207..64a7f6e91a4 100644 --- a/python/pyplugin_installer/qgsplugininstallerinstallingdialog.py +++ b/python/pyplugin_installer/qgsplugininstallerinstallingdialog.py @@ -24,16 +24,16 @@ ***************************************************************************/ """ -from PyQt4.QtCore import QDir, QUrl, QFile, QCoreApplication -from PyQt4.QtGui import QDialog -from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply +from PyQt.QtCore import QDir, QUrl, QFile, QCoreApplication +from PyQt.QtWidgets import QDialog +from PyQt.QtNetwork import QNetworkRequest, QNetworkReply import qgis from qgis.core import QgsNetworkAccessManager, QgsAuthManager -from ui_qgsplugininstallerinstallingbase import Ui_QgsPluginInstallerInstallingDialogBase -from installer_data import removeDir, repositories -from unzip import unzip +from .ui_qgsplugininstallerinstallingbase import Ui_QgsPluginInstallerInstallingDialogBase +from .installer_data import removeDir, repositories +from .unzip import unzip class QgsPluginInstallerInstallingDialog(QDialog, Ui_QgsPluginInstallerInstallingDialogBase): @@ -118,10 +118,10 @@ class QgsPluginInstallerInstallingDialog(QDialog, Ui_QgsPluginInstallerInstallin # if the target directory already exists as a link, remove the link without resolving: QFile(pluginDir + unicode(QDir.separator()) + self.plugin["id"]).remove() try: - unzip(unicode(tmpPath), unicode(pluginDir)) # test extract. If fails, then exception will be raised and no removing occurs + unzip(unicode(tmpPath), unicode(pluginDir)) # test extract. If fails, then exception will be raised and no removing occurs # removing old plugin files if exist - removeDir(QDir.cleanPath(pluginDir + "/" + self.plugin["id"])) # remove old plugin if exists - unzip(unicode(tmpPath), unicode(pluginDir)) # final extract. + removeDir(QDir.cleanPath(pluginDir + "/" + self.plugin["id"])) # remove old plugin if exists + unzip(unicode(tmpPath), unicode(pluginDir)) # final extract. except: self.mResult = self.tr("Failed to unzip the plugin package. Probably it's broken or missing from the repository. You may also want to make sure that you have write permission to the plugin directory:") + "\n" + pluginDir self.reject() diff --git a/python/pyplugin_installer/qgsplugininstallerpluginerrordialog.py b/python/pyplugin_installer/qgsplugininstallerpluginerrordialog.py index e9fd268bbd8..b49d4b03880 100644 --- a/python/pyplugin_installer/qgsplugininstallerpluginerrordialog.py +++ b/python/pyplugin_installer/qgsplugininstallerpluginerrordialog.py @@ -24,9 +24,9 @@ ***************************************************************************/ """ -from PyQt4.QtGui import QDialog +from PyQt.QtWidgets import QDialog -from ui_qgsplugininstallerpluginerrorbase import Ui_QgsPluginInstallerPluginErrorDialogBase +from .ui_qgsplugininstallerpluginerrorbase import Ui_QgsPluginInstallerPluginErrorDialogBase class QgsPluginInstallerPluginErrorDialog(QDialog, Ui_QgsPluginInstallerPluginErrorDialogBase): diff --git a/python/pyplugin_installer/qgsplugininstallerrepositorydialog.py b/python/pyplugin_installer/qgsplugininstallerrepositorydialog.py index 5e5fe398c8e..66f735d0534 100644 --- a/python/pyplugin_installer/qgsplugininstallerrepositorydialog.py +++ b/python/pyplugin_installer/qgsplugininstallerrepositorydialog.py @@ -25,10 +25,10 @@ """ from qgis.gui import QgsAuthConfigSelect -from PyQt4.QtGui import QDialog, QDialogButtonBox, QVBoxLayout -from PyQt4.QtCore import Qt +from PyQt.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout +from PyQt.QtCore import Qt -from ui_qgsplugininstallerrepositorybase import Ui_QgsPluginInstallerRepositoryDetailsDialogBase +from .ui_qgsplugininstallerrepositorybase import Ui_QgsPluginInstallerRepositoryDetailsDialogBase class QgsPluginInstallerRepositoryDialog(QDialog, Ui_QgsPluginInstallerRepositoryDetailsDialogBase):