Skip to content

Commit 484a932

Browse files
author
wonder
committed
Improvements to plugin installer:
- ability to support custom repositories - better error handling git-svn-id: http://svn.osgeo.org/qgis/trunk@7909 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 64f9254 commit 484a932

File tree

11 files changed

+611
-206
lines changed

11 files changed

+611
-206
lines changed

python/plugins/plugin_installer/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ __init__.py
88
installer_plugin.py
99
qgis_plugins.py
1010
resources.py
11+
repository_ui.py
12+
repository_dialog.py
1113
)
1214
INSTALL(FILES ${INSTALLER_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/qgis/python/plugins/plugin_installer)

python/plugins/plugin_installer/Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ PYUIC = /usr/bin/pyuic4
66
RC_PY_FILE = resources.py
77
UI_PY_FILE = gui.py
88

9-
all: $(RC_PY_FILE) $(UI_PY_FILE)
9+
all: $(RC_PY_FILE) $(UI_PY_FILE) repository_ui.py
1010

1111
install: all
1212
mkdir -p $(INST_DIR)
1313
cp *.py $(INST_DIR)/
1414

1515
clean:
16-
rm -f $(RC_PY_FILE) $(UI_PY_FILE)
16+
rm -f $(RC_PY_FILE) $(UI_PY_FILE) repository_ui.py
1717
rm -f *.pyc
1818

1919
zip:
@@ -25,3 +25,5 @@ $(RC_PY_FILE): resources.qrc
2525
$(UI_PY_FILE): gui.ui
2626
$(PYUIC) -o $(UI_PY_FILE) gui.ui
2727

28+
repository_ui.py: repository.ui
29+
$(PYUIC) -o repository_ui.py repository.ui

python/plugins/plugin_installer/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# load TestPlugin class from file testplugin.py
2-
from installer_plugin import InstallerPlugin
31

42
def name():
53
return "Plugin installer"
@@ -11,4 +9,6 @@ def version():
119
return "Version 0.02"
1210

1311
def classFactory(iface):
12+
# load TestPlugin class from file testplugin.py
13+
from installer_plugin import InstallerPlugin
1414
return InstallerPlugin(iface)
+195-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,211 @@
11
from PyQt4.QtCore import *
22
from PyQt4.QtGui import *
33

4-
from qgis.core import QgsContextHelp
4+
from qgis.core import QgsApplication, QgsContextHelp
55

66
from gui import Ui_Dialog
77
import resources
88

9+
from repository_dialog import RepositoryDialog
10+
11+
912
class InstallerPluginGui(QDialog, Ui_Dialog):
1013
def __init__(self, parent, fl):
1114
QDialog.__init__(self, parent, fl)
1215

16+
self.default_repository_name = "Official QGIS repository"
17+
self.default_repository = "http://spatialserver.net/cgi-bin/pyqgis_plugin.rb"
18+
1319
self.setupUi(self)
1420

15-
def on_buttonBrowse_released(self):
16-
self.emit(SIGNAL("retrieveList(QString )"),"test" )
17-
print "browse"
18-
19-
def on_pbnOK_released(self):
20-
#self.hide()
21-
self.emit(SIGNAL("installPlugin(QString )"), self.linePlugin.text() )
22-
return
23-
#self.done(1)
21+
self.connect(self.buttonBrowse, SIGNAL("clicked()"), self.getAvailablePlugins)
22+
self.connect(self.pbnOK, SIGNAL("clicked()"), self.installPlugin)
2423

24+
# grab the click on the treelist
25+
self.connect(self.treePlugins, SIGNAL("itemClicked(QTreeWidgetItem *,int)"), self.treeClicked)
26+
27+
# repositories handling
28+
self.connect(self.buttonAddRep, SIGNAL("clicked()"), self.addRepository)
29+
self.connect(self.buttonEditRep, SIGNAL("clicked()"), self.editRepository)
30+
self.connect(self.buttonDeleteRep, SIGNAL("clicked()"), self.deleteRepository)
31+
32+
self.populateRepositories()
33+
34+
2535
def on_pbnCancel_clicked(self):
2636
self.close()
37+
38+
39+
def getAvailablePlugins(self):
40+
print "getting list of plugins"
41+
repository = self.getRepository()
42+
if not repository:
43+
return
44+
repository_url = str(repository[1])
45+
46+
from qgis_plugins import retrieve_list
47+
QApplication.setOverrideCursor(Qt.WaitCursor)
48+
49+
try:
50+
pluginlist = retrieve_list(repository_url)
51+
except IOError:
52+
QApplication.restoreOverrideCursor()
53+
QMessageBox.warning(self, "Error", "Couldn't connect to the repository.")
54+
return
55+
except Exception:
56+
QApplication.restoreOverrideCursor()
57+
QMessageBox.warning(self, "Error", "Couldn't parse output from repository.")
58+
return
59+
60+
#output = "QGIS python plugins avialable from \n%s\n" % self.repository
61+
#for p in pluginlist:
62+
# output += "\n%s ( version %s )" % (p["name"], p["version"])
63+
# output += "\n\t%s by %s" % (p["desc"],p["author"])
64+
#self.gui.txtAvailable.setText(output)
65+
self.treePlugins.clear()
66+
for p in pluginlist:
67+
a = QTreeWidgetItem(self.treePlugins)
68+
a.setText(0,p["name"])
69+
a.setText(1,p["version"])
70+
a.setText(2,p["desc"])
71+
a.setText(3,p["author"])
72+
73+
QApplication.restoreOverrideCursor()
74+
75+
# resize the columns
76+
# plugin name
77+
self.treePlugins.resizeColumnToContents(0);
78+
# version
79+
self.treePlugins.resizeColumnToContents(1);
80+
# author/contributor
81+
self.treePlugins.resizeColumnToContents(3);
82+
# description
83+
self.treePlugins.setColumnWidth(2, 560);
84+
85+
86+
def installPlugin(self):
87+
""" installs currently selected plugin """
88+
plugin = self.linePlugin.text()
89+
repository = self.getRepository()
90+
if not repository:
91+
return
92+
repository_url = str(repository[1])
93+
plugindir = str(QgsApplication.qgisSettingsDirPath()) + "/python/plugins"
94+
95+
QApplication.setOverrideCursor(Qt.WaitCursor)
96+
from qgis_plugins import retrieve_list, install_plugin
97+
print "install_plugin",plugin,plugindir,repository_url
98+
result = install_plugin(plugin, plugindir, repository_url)
99+
QApplication.restoreOverrideCursor()
100+
101+
if result[0]:
102+
QMessageBox.information(self, "Plugin installed successfully", result[1])
103+
else:
104+
QMessageBox.warning(self, "Plugin installation failed", result[1])
105+
106+
107+
def treeClicked(self, item, col):
108+
self.linePlugin.setText(item.text(0))
109+
110+
111+
def getRepository(self):
112+
""" returns Name and URL of the current repository as a tuple or None if no repository is selected """
113+
if self.comboRepositories.currentIndex() == -1:
114+
return None
115+
116+
settings = QSettings()
117+
reposGroup = "/Qgis/plugin-repos"
118+
reposName = self.comboRepositories.currentText()
119+
reposURL = settings.value(reposGroup+"/"+reposName+"/url", QVariant()).toString()
120+
return (reposName, reposURL)
121+
122+
123+
def populateRepositories(self):
124+
""" populate repository combo box from the settings """
125+
self.comboRepositories.clear()
126+
127+
settings = QSettings()
128+
reposGroup = "/Qgis/plugin-repos"
129+
settings.beginGroup(reposGroup)
130+
131+
# add the default repository when there isn't any...
132+
if len(settings.childGroups()) == 0:
133+
settings.setValue(self.default_repository_name+"/url", QVariant(self.default_repository))
134+
135+
for key in settings.childGroups():
136+
self.comboRepositories.addItem(key)
137+
138+
settings.endGroup()
139+
140+
141+
def addRepository(self):
142+
""" add repository button has been clicked """
143+
print "add"
144+
dlg = RepositoryDialog(self)
145+
if not dlg.exec_():
146+
return
147+
148+
settings = QSettings()
149+
reposGroup = "/Qgis/plugin-repos"
150+
settings.beginGroup(reposGroup)
151+
152+
reposName = dlg.editName.text()
153+
reposURL = dlg.editURL.text()
154+
print "name: "+reposName
155+
print "url: "+reposURL
156+
157+
# add to settings
158+
settings.setValue(reposName+"/url", QVariant(reposURL))
159+
160+
# add to combobox
161+
self.comboRepositories.addItem(reposName)
162+
163+
164+
def editRepository(self):
165+
""" edit repository button has been clicked """
166+
print "edit"
167+
168+
current = self.comboRepositories.currentIndex()
169+
if current == -1:
170+
return
171+
172+
(reposName, reposURL) = self.getRepository()
173+
174+
dlg = RepositoryDialog(self)
175+
dlg.editName.setText(reposName)
176+
dlg.editURL.setText(reposURL)
177+
if not dlg.exec_():
178+
return
179+
180+
settings = QSettings()
181+
reposGroup = "/Qgis/plugin-repos"
182+
settings.beginGroup(reposGroup)
183+
184+
# first delete old setting
185+
settings.remove(reposName)
186+
187+
# and create new one
188+
settings.setValue(dlg.editName.text()+"/url", QVariant(dlg.editURL.text()))
189+
190+
# update the name if it has been changed
191+
self.comboRepositories.setItemText(current, dlg.editName.text())
192+
193+
194+
def deleteRepository(self):
195+
""" delete repository button has been clicked """
196+
print "delete"
197+
198+
current = self.comboRepositories.currentIndex()
199+
if current == -1:
200+
return
201+
202+
settings = QSettings()
203+
reposGroup = "/Qgis/plugin-repos"
204+
settings.beginGroup(reposGroup)
205+
206+
# delete from settings
207+
reposName = self.comboRepositories.currentText()
208+
settings.remove(reposName)
209+
210+
# delete from combo box
211+
self.comboRepositories.removeItem(current)

0 commit comments

Comments
 (0)