Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add ParameterMultipleExternalInput parameter type
- Loading branch information
Showing
6 changed files
with
326 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
python/plugins/processing/gui/MultipleExternalInputDialog.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
*************************************************************************** | ||
MultipleExternalInputDialog.py | ||
--------------------- | ||
Date : August 2012 | ||
Copyright : (C) 2012 by Victor Olaya | ||
(C) 2013 by CS Systemes d'information (CS SI) | ||
Email : volayaf at gmail dot com | ||
otb at c-s dot fr (CS SI) | ||
Contributors : Victor Olaya - basis from MultipleInputDialog | ||
Alexia Mondot (CS SI) - new parameter | ||
*************************************************************************** | ||
* * | ||
* 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. * | ||
* * | ||
*************************************************************************** | ||
""" | ||
|
||
__author__ = 'Victor Olaya' | ||
__date__ = 'August 2012' | ||
__copyright__ = '(C) 2012, Victor Olaya' | ||
# This will get replaced with a git SHA1 when you do a git archive | ||
__revision__ = '$Format:%H$' | ||
|
||
from PyQt4 import QtCore, QtGui | ||
import os | ||
|
||
class MultipleExternalInputDialog(QtGui.QDialog): | ||
def __init__(self, selectedoptions): | ||
self.selectedoptions = selectedoptions | ||
self.options=selectedoptions | ||
QtGui.QDialog.__init__(self) | ||
self.setModal(True) | ||
self.setupUi() | ||
self.selectedoptions = None | ||
|
||
def setupUi(self): | ||
self.resize(381, 320) | ||
self.setWindowTitle("Multiple selection") | ||
self.horizontalLayout = QtGui.QHBoxLayout(self) | ||
self.horizontalLayout.setSpacing(2) | ||
self.horizontalLayout.setMargin(0) | ||
self.buttonBox = QtGui.QDialogButtonBox() | ||
self.buttonBox.setOrientation(QtCore.Qt.Vertical) | ||
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) | ||
self.buttonPlus = QtGui.QPushButton("+") | ||
self.buttonBox.addButton(self.buttonPlus, QtGui.QDialogButtonBox.ActionRole) | ||
self.buttonMoins = QtGui.QPushButton("-") | ||
self.buttonBox.addButton(self.buttonMoins, QtGui.QDialogButtonBox.ActionRole) | ||
self.table = QtGui.QTableWidget() | ||
self.table.setColumnCount(1) | ||
self.table.setColumnWidth(0,270) | ||
self.table.verticalHeader().setVisible(False) | ||
self.table.horizontalHeader().setVisible(False) | ||
self.table.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch) | ||
self.horizontalLayout.addWidget(self.table) | ||
self.horizontalLayout.addWidget(self.buttonBox) | ||
self.setLayout(self.horizontalLayout) | ||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.okPressed) | ||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.cancelPressed) | ||
QtCore.QObject.connect(self.buttonPlus, QtCore.SIGNAL("clicked()"), self.addFile) | ||
QtCore.QObject.connect(self.buttonMoins, QtCore.SIGNAL("clicked()"), self.removeFile) | ||
QtCore.QMetaObject.connectSlotsByName(self) | ||
|
||
def setTableContent(self): | ||
# "self.options :", ['/temp/confmat1-1.csv', '/temp/confmat2-1.csv'] | ||
self.table.setRowCount(len(self.options)) | ||
for i in range(len(self.options)): | ||
item = QtGui.QLabel() | ||
item.setText(self.options[i]) | ||
self.table.setCellWidget(i,0, item) | ||
|
||
def okPressed(self): | ||
self.selectedoptions = [] | ||
self.selectedoptions = self.options | ||
# "self.selectedoptions :", ['/temp/confmat1-1.csv', '/temp/confmat2-1.csv'] | ||
self.close() | ||
|
||
def cancelPressed(self): | ||
self.selectedoptions = None | ||
self.close() | ||
|
||
def addFile(self): | ||
settings = QtCore.QSettings() | ||
lastfolder = settings.value("processingFilesLastFolder") | ||
if lastfolder : | ||
path = lastfolder | ||
else : | ||
path = QtCore.QDir.currentPath() | ||
|
||
filesOpened = QtGui.QFileDialog.getOpenFileNames( None, "Select the file(s) to use", path, "All files (*.*)" ) | ||
|
||
lastfile = "" | ||
for item in filesOpened: | ||
self.options.append( str(item) ) | ||
lastfile=item | ||
|
||
self.setTableContent() | ||
folder = os.path.dirname( str( lastfile ) ) | ||
settings.setValue("processingFilesLastFolder", folder) | ||
|
||
def removeFile(self): | ||
indexRow = self.table.currentRow() | ||
itemToRemove = self.options[indexRow] | ||
self.options.remove(itemToRemove) | ||
self.setTableContent() |
75 changes: 75 additions & 0 deletions
75
python/plugins/processing/gui/MultipleExternalInputPanel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
*************************************************************************** | ||
MultipleExternalInputPanel.py | ||
--------------------- | ||
Date : August 2012 | ||
Copyright : (C) 2012 by Victor Olaya | ||
(C) 2013 by CS Systemes d'information (CS SI) | ||
Email : volayaf at gmail dot com | ||
otb at c-s dot fr (CS SI) | ||
Contributors : Victor Olaya - basis from MultipleInputPanel | ||
Alexia Mondot (CS SI) - adapt for a new parameter | ||
*************************************************************************** | ||
* * | ||
* 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. * | ||
* * | ||
*************************************************************************** | ||
""" | ||
|
||
__author__ = 'Victor Olaya' | ||
__date__ = 'August 2012' | ||
__copyright__ = '(C) 2012, Victor Olaya' | ||
# This will get replaced with a git SHA1 when you do a git archive | ||
__revision__ = '$Format:%H$' | ||
|
||
from PyQt4 import QtCore, QtGui | ||
from processing.gui.MultipleExternalInputDialog import MultipleExternalInputDialog | ||
|
||
class MultipleExternalInputPanel(QtGui.QWidget): | ||
|
||
def __init__(self, parent = None): | ||
super(MultipleExternalInputPanel, self).__init__(parent) | ||
self.selectedoptions = [] | ||
self.horizontalLayout = QtGui.QHBoxLayout(self) | ||
self.horizontalLayout.setSpacing(2) | ||
self.horizontalLayout.setMargin(0) | ||
self.label = QtGui.QLabel() | ||
self.label.setText("0 elements selected") | ||
self.label.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) | ||
self.horizontalLayout.addWidget(self.label) | ||
self.pushButton = QtGui.QPushButton() | ||
self.pushButton.setText("...") | ||
self.pushButton.clicked.connect(self.showSelectionDialog) | ||
self.horizontalLayout.addWidget(self.pushButton) | ||
self.setLayout(self.horizontalLayout) | ||
|
||
def setSelectedItems(self, selected): | ||
#no checking is performed! | ||
self.selectedoptions = selected | ||
self.label.setText(str(len(self.selectedoptions)) + " elements selected") | ||
|
||
def showSelectionDialog(self): | ||
#======================================================================= | ||
# #If there is a datatype, we use it to create the list of options | ||
# if self.datatype is not None: | ||
# if self.datatype == ParameterMultipleInput.TYPE_RASTER: | ||
# options = QGisLayers.getRasterLayers() | ||
# elif self.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY: | ||
# options = QGisLayers.getVectorLayers() | ||
# else: | ||
# options = QGisLayers.getVectorLayers(self.datatype) | ||
# opts = [] | ||
# for opt in options: | ||
# opts.append(opt.name()) | ||
# self.options = opts | ||
#======================================================================= | ||
dlg = MultipleExternalInputDialog(self.selectedoptions) | ||
dlg.exec_() | ||
if dlg.selectedoptions != None: | ||
self.selectedoptions = dlg.selectedoptions | ||
self.label.setText(str(len(self.selectedoptions)) + " elements selected") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.