Skip to content

Commit

Permalink
Improvements to plugin installer:
Browse files Browse the repository at this point in the history
- ability to support custom repositories
- better error handling


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7909 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jan 10, 2008
1 parent 401ea62 commit b330657
Show file tree
Hide file tree
Showing 11 changed files with 611 additions and 206 deletions.
2 changes: 2 additions & 0 deletions python/plugins/plugin_installer/CMakeLists.txt
Expand Up @@ -8,5 +8,7 @@ __init__.py
installer_plugin.py
qgis_plugins.py
resources.py
repository_ui.py
repository_dialog.py
)
INSTALL(FILES ${INSTALLER_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/qgis/python/plugins/plugin_installer)
6 changes: 4 additions & 2 deletions python/plugins/plugin_installer/Makefile
Expand Up @@ -6,14 +6,14 @@ PYUIC = /usr/bin/pyuic4
RC_PY_FILE = resources.py
UI_PY_FILE = gui.py

all: $(RC_PY_FILE) $(UI_PY_FILE)
all: $(RC_PY_FILE) $(UI_PY_FILE) repository_ui.py

install: all
mkdir -p $(INST_DIR)
cp *.py $(INST_DIR)/

clean:
rm -f $(RC_PY_FILE) $(UI_PY_FILE)
rm -f $(RC_PY_FILE) $(UI_PY_FILE) repository_ui.py
rm -f *.pyc

zip:
Expand All @@ -25,3 +25,5 @@ $(RC_PY_FILE): resources.qrc
$(UI_PY_FILE): gui.ui
$(PYUIC) -o $(UI_PY_FILE) gui.ui

repository_ui.py: repository.ui
$(PYUIC) -o repository_ui.py repository.ui
4 changes: 2 additions & 2 deletions python/plugins/plugin_installer/__init__.py
@@ -1,5 +1,3 @@
# load TestPlugin class from file testplugin.py
from installer_plugin import InstallerPlugin

def name():
return "Plugin installer"
Expand All @@ -11,4 +9,6 @@ def version():
return "Version 0.02"

def classFactory(iface):
# load TestPlugin class from file testplugin.py
from installer_plugin import InstallerPlugin
return InstallerPlugin(iface)
205 changes: 195 additions & 10 deletions python/plugins/plugin_installer/dialog.py
@@ -1,26 +1,211 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qgis.core import QgsContextHelp
from qgis.core import QgsApplication, QgsContextHelp

from gui import Ui_Dialog
import resources

from repository_dialog import RepositoryDialog


class InstallerPluginGui(QDialog, Ui_Dialog):
def __init__(self, parent, fl):
QDialog.__init__(self, parent, fl)

self.default_repository_name = "Official QGIS repository"
self.default_repository = "http://spatialserver.net/cgi-bin/pyqgis_plugin.rb"

self.setupUi(self)

def on_buttonBrowse_released(self):
self.emit(SIGNAL("retrieveList(QString )"),"test" )
print "browse"

def on_pbnOK_released(self):
#self.hide()
self.emit(SIGNAL("installPlugin(QString )"), self.linePlugin.text() )
return
#self.done(1)
self.connect(self.buttonBrowse, SIGNAL("clicked()"), self.getAvailablePlugins)
self.connect(self.pbnOK, SIGNAL("clicked()"), self.installPlugin)

# grab the click on the treelist
self.connect(self.treePlugins, SIGNAL("itemClicked(QTreeWidgetItem *,int)"), self.treeClicked)

# repositories handling
self.connect(self.buttonAddRep, SIGNAL("clicked()"), self.addRepository)
self.connect(self.buttonEditRep, SIGNAL("clicked()"), self.editRepository)
self.connect(self.buttonDeleteRep, SIGNAL("clicked()"), self.deleteRepository)

self.populateRepositories()


def on_pbnCancel_clicked(self):
self.close()


def getAvailablePlugins(self):
print "getting list of plugins"
repository = self.getRepository()
if not repository:
return
repository_url = str(repository[1])

from qgis_plugins import retrieve_list
QApplication.setOverrideCursor(Qt.WaitCursor)

try:
pluginlist = retrieve_list(repository_url)
except IOError:
QApplication.restoreOverrideCursor()
QMessageBox.warning(self, "Error", "Couldn't connect to the repository.")
return
except Exception:
QApplication.restoreOverrideCursor()
QMessageBox.warning(self, "Error", "Couldn't parse output from repository.")
return

#output = "QGIS python plugins avialable from \n%s\n" % self.repository
#for p in pluginlist:
# output += "\n%s ( version %s )" % (p["name"], p["version"])
# output += "\n\t%s by %s" % (p["desc"],p["author"])
#self.gui.txtAvailable.setText(output)
self.treePlugins.clear()
for p in pluginlist:
a = QTreeWidgetItem(self.treePlugins)
a.setText(0,p["name"])
a.setText(1,p["version"])
a.setText(2,p["desc"])
a.setText(3,p["author"])

QApplication.restoreOverrideCursor()

# resize the columns
# plugin name
self.treePlugins.resizeColumnToContents(0);
# version
self.treePlugins.resizeColumnToContents(1);
# author/contributor
self.treePlugins.resizeColumnToContents(3);
# description
self.treePlugins.setColumnWidth(2, 560);


def installPlugin(self):
""" installs currently selected plugin """
plugin = self.linePlugin.text()
repository = self.getRepository()
if not repository:
return
repository_url = str(repository[1])
plugindir = str(QgsApplication.qgisSettingsDirPath()) + "/python/plugins"

QApplication.setOverrideCursor(Qt.WaitCursor)
from qgis_plugins import retrieve_list, install_plugin
print "install_plugin",plugin,plugindir,repository_url
result = install_plugin(plugin, plugindir, repository_url)
QApplication.restoreOverrideCursor()

if result[0]:
QMessageBox.information(self, "Plugin installed successfully", result[1])
else:
QMessageBox.warning(self, "Plugin installation failed", result[1])


def treeClicked(self, item, col):
self.linePlugin.setText(item.text(0))


def getRepository(self):
""" returns Name and URL of the current repository as a tuple or None if no repository is selected """
if self.comboRepositories.currentIndex() == -1:
return None

settings = QSettings()
reposGroup = "/Qgis/plugin-repos"
reposName = self.comboRepositories.currentText()
reposURL = settings.value(reposGroup+"/"+reposName+"/url", QVariant()).toString()
return (reposName, reposURL)


def populateRepositories(self):
""" populate repository combo box from the settings """
self.comboRepositories.clear()

settings = QSettings()
reposGroup = "/Qgis/plugin-repos"
settings.beginGroup(reposGroup)

# add the default repository when there isn't any...
if len(settings.childGroups()) == 0:
settings.setValue(self.default_repository_name+"/url", QVariant(self.default_repository))

for key in settings.childGroups():
self.comboRepositories.addItem(key)

settings.endGroup()


def addRepository(self):
""" add repository button has been clicked """
print "add"
dlg = RepositoryDialog(self)
if not dlg.exec_():
return

settings = QSettings()
reposGroup = "/Qgis/plugin-repos"
settings.beginGroup(reposGroup)

reposName = dlg.editName.text()
reposURL = dlg.editURL.text()
print "name: "+reposName
print "url: "+reposURL

# add to settings
settings.setValue(reposName+"/url", QVariant(reposURL))

# add to combobox
self.comboRepositories.addItem(reposName)


def editRepository(self):
""" edit repository button has been clicked """
print "edit"

current = self.comboRepositories.currentIndex()
if current == -1:
return

(reposName, reposURL) = self.getRepository()

dlg = RepositoryDialog(self)
dlg.editName.setText(reposName)
dlg.editURL.setText(reposURL)
if not dlg.exec_():
return

settings = QSettings()
reposGroup = "/Qgis/plugin-repos"
settings.beginGroup(reposGroup)

# first delete old setting
settings.remove(reposName)

# and create new one
settings.setValue(dlg.editName.text()+"/url", QVariant(dlg.editURL.text()))

# update the name if it has been changed
self.comboRepositories.setItemText(current, dlg.editName.text())


def deleteRepository(self):
""" delete repository button has been clicked """
print "delete"

current = self.comboRepositories.currentIndex()
if current == -1:
return

settings = QSettings()
reposGroup = "/Qgis/plugin-repos"
settings.beginGroup(reposGroup)

# delete from settings
reposName = self.comboRepositories.currentText()
settings.remove(reposName)

# delete from combo box
self.comboRepositories.removeItem(current)

0 comments on commit b330657

Please sign in to comment.