/
installer_plugin.py
executable file
·201 lines (164 loc) · 8.56 KB
/
installer_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# -*- coding: utf-8 -*-
"""
Copyright (C) 2007-2008 Matthew Perry
Copyright (C) 2008-2010 Borys Jurgiel
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from installer_gui import *
from installer_data import *
import resources_rc
class InstallerPlugin():
# ----------------------------------------- #
def __init__(self, iface):
self.iface = iface
setIface(self.iface) #pass self.iface to installer_data module (needed for plugin loading & testing)
if QGIS_MAJOR_VER: # new plugin API
self.mainWindow = self.iface.mainWindow
else: # old plugin API
self.mainWindow = self.iface.getMainWindow
self.guiDlg = None
# ----------------------------------------- #
def setCurrentTheme(self, theThemeName):
""" Set icons to the current theme """
self.action.setIcon(self.getThemeIcon("plugin_installer.png"))
# ----------------------------------------- #
def getThemeIcon(self, theName):
""" get the icon from the best available theme """
if not QGIS_MAJOR_VER: # QGIS 0.x
return QIcon(":/plugins/installer/" + theName)
myCurThemePath = QgsApplication.activeThemePath() + "/plugins/" + theName;
myDefThemePath = QgsApplication.defaultThemePath() + "/plugins/" + theName;
myQrcPath = ":/plugins/installer/" + theName;
if QFile.exists(myCurThemePath):
return QIcon(myCurThemePath)
elif QFile.exists(myDefThemePath):
return QIcon(myDefThemePath)
elif QFile.exists(myQrcPath):
return QIcon(myQrcPath)
else:
return QIcon()
# ----------------------------------------- #
def initGui(self):
""" create action that will start plugin window and then add it to menu """
self.action = QAction(self.getThemeIcon("plugin_installer.png"), QCoreApplication.translate("QgsPluginInstaller","Fetch Python Plugins..."), self.mainWindow())
self.action.setWhatsThis(QCoreApplication.translate("QgsPluginInstaller","Install more plugins from remote repositories"))
self.action.setStatusTip(QCoreApplication.translate("QgsPluginInstaller","Install more plugins from remote repositories"))
if QGIS_MAJOR_VER: # new plugin API
nextAction = self.iface.actionManagePlugins()
self.iface.pluginMenu().insertAction(nextAction,self.action)
else: # old plugin API
nextAction = self.mainWindow().menuBar().actions()[4].menu().actions()[1]
self.mainWindow().menuBar().actions()[4].menu().insertAction(nextAction,self.action)
QObject.connect(self.action, SIGNAL("triggered()"), self.run)
QObject.connect(self.iface, SIGNAL("currentThemeChanged ( QString )"), self.setCurrentTheme)
self.statusLabel = None
repositories.load()
plugins.getAllInstalled()
if repositories.checkingOnStart() and repositories.timeForChecking() and repositories.allEnabled():
self.statusLabel = QLabel(QCoreApplication.translate("QgsPluginInstaller","Looking for new plugins..."), self.mainWindow().statusBar())
self.mainWindow().statusBar().insertPermanentWidget(0,self.statusLabel)
QObject.connect(self.statusLabel, SIGNAL("linkActivated (QString)"), self.preRun)
QObject.connect(repositories, SIGNAL("checkingDone()"), self.checkingDone)
for key in repositories.allEnabled():
repositories.requestFetching(key)
else:
for key in repositories.allEnabled():
repositories.setRepositoryData(key,"state",3)
for i in plugins.obsoletePlugins:
QMessageBox.warning(self.mainWindow(), QCoreApplication.translate("QgsPluginInstaller","QGIS Plugin Conflict:")+" "+plugins.localCache[i]["name"], QCoreApplication.translate("QgsPluginInstaller","The Plugin Installer has detected an obsolete plugin which masks a newer version shipped with this QGIS version. This is likely due to files associated with a previous installation of QGIS. Please use the Plugin Installer to remove that older plugin in order to unmask the newer version shipped with this copy of QGIS."))
# ----------------------------------------- #
def checkingDone(self):
""" display the notify label if any updates or news available """
if not self.statusLabel:
return
# look for news in the repositories
plugins.markNews()
status = ""
# first check for news
for key in plugins.all():
if plugins.all()[key]["status"] == "new":
status = QCoreApplication.translate("QgsPluginInstaller","There is a new plugin available")
# then check for updates (and eventually overwrite status)
for key in plugins.all():
if plugins.all()[key]["status"] == "upgradeable":
status = QCoreApplication.translate("QgsPluginInstaller","There is a plugin update available")
# finally set the notify label
if status:
self.statusLabel.setText(u' <a href="#">%s</a> ' % status)
else:
self.mainWindow().statusBar().removeWidget(self.statusLabel)
self.statusLabel = None
# ----------------------------------------- #
def unload(self):
""" remove the menu item and notify label """
# kill pending http requests
for key in repositories.all():
repositories.killConnection(key)
if QGIS_MAJOR_VER: # new plugin API
self.iface.pluginMenu().removeAction(self.action)
else: # old plugin API
self.mainWindow().menuBar().actions()[4].menu().removeAction(self.action)
if self.statusLabel:
self.mainWindow().statusBar().removeWidget(self.statusLabel)
if self.guiDlg:
self.guiDlg.close()
# ----------------------------------------- #
def preRun(self, * params):
""" stupid method to get rid of the string value """
self.run()
# ----------------------------------------- #
def run(self, parent = None):
""" create and show a configuration dialog """
QApplication.setOverrideCursor(Qt.WaitCursor)
if self.statusLabel:
self.mainWindow().statusBar().removeWidget(self.statusLabel)
self.statusLabel = None
if not parent:
parent = self.mainWindow()
for key in repositories.all():
if repositories.all()[key]["state"] == 3: # if state = 3 (error), try to fetch once again
repositories.requestFetching(key)
if repositories.fetchingInProgress():
self.fetchDlg = QgsPluginInstallerFetchingDialog(parent)
self.fetchDlg.exec_()
del self.fetchDlg
for key in repositories.all():
repositories.killConnection(key)
QApplication.restoreOverrideCursor()
# display error messages for every unavailable reposioty, unless Shift pressed nor all repositories are unavailable
keepQuiet = QgsApplication.keyboardModifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier)
if repositories.allUnavailable() and repositories.allUnavailable() != repositories.allEnabled():
for key in repositories.allUnavailable():
if not keepQuiet:
QMessageBox.warning(parent, QCoreApplication.translate("QgsPluginInstaller","QGIS Python Plugin Installer"), QCoreApplication.translate("QgsPluginInstaller","Error reading repository:") + QString(' %s\n%s' % (key,repositories.all()[key]["error"])))
if QgsApplication.keyboardModifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier):
keepQuiet = True
flags = Qt.WindowTitleHint | Qt.WindowSystemMenuHint | Qt.WindowMaximizeButtonHint
self.guiDlg = QgsPluginInstallerDialog(parent,flags)
self.guiDlg.show()
# ----------------------------------------- #
def newlyInstalledPlugins(self):
""" return the list of newly installed plugins for further loading """
return history.toList("A")
# ----------------------------------------- #
def newlyUninstalledPlugins(self):
""" return the list of newly uninstalled plugins for further unloading """
return history.toList("D")
# ----------------------------------------- #
def newlyReinstalledPlugins(self):
""" return the list of newly reinstalled plugins for further reloading """
return history.toList("R")
# ----------------------------------------- #
def resetNewlyProcessedPlugins(self):
""" clear the dict of newly processed plugins """
history.clear()