|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + MultipleExternalInputDialog.py |
| 6 | + --------------------- |
| 7 | + Date : August 2012 |
| 8 | + Copyright : (C) 2012 by Victor Olaya |
| 9 | + (C) 2013 by CS Systemes d'information (CS SI) |
| 10 | + Email : volayaf at gmail dot com |
| 11 | + otb at c-s dot fr (CS SI) |
| 12 | + Contributors : Victor Olaya - basis from MultipleInputDialog |
| 13 | + Alexia Mondot (CS SI) - new parameter |
| 14 | +*************************************************************************** |
| 15 | +* * |
| 16 | +* This program is free software; you can redistribute it and/or modify * |
| 17 | +* it under the terms of the GNU General Public License as published by * |
| 18 | +* the Free Software Foundation; either version 2 of the License, or * |
| 19 | +* (at your option) any later version. * |
| 20 | +* * |
| 21 | +*************************************************************************** |
| 22 | +""" |
| 23 | + |
| 24 | +__author__ = 'Victor Olaya' |
| 25 | +__date__ = 'August 2012' |
| 26 | +__copyright__ = '(C) 2012, Victor Olaya' |
| 27 | +# This will get replaced with a git SHA1 when you do a git archive |
| 28 | +__revision__ = '$Format:%H$' |
| 29 | + |
| 30 | +from PyQt4 import QtCore, QtGui |
| 31 | +import os |
| 32 | + |
| 33 | +class MultipleExternalInputDialog(QtGui.QDialog): |
| 34 | + def __init__(self, selectedoptions): |
| 35 | + self.selectedoptions = selectedoptions |
| 36 | + self.options=selectedoptions |
| 37 | + QtGui.QDialog.__init__(self) |
| 38 | + self.setModal(True) |
| 39 | + self.setupUi() |
| 40 | + self.selectedoptions = None |
| 41 | + |
| 42 | + def setupUi(self): |
| 43 | + self.resize(381, 320) |
| 44 | + self.setWindowTitle("Multiple selection") |
| 45 | + self.horizontalLayout = QtGui.QHBoxLayout(self) |
| 46 | + self.horizontalLayout.setSpacing(2) |
| 47 | + self.horizontalLayout.setMargin(0) |
| 48 | + self.buttonBox = QtGui.QDialogButtonBox() |
| 49 | + self.buttonBox.setOrientation(QtCore.Qt.Vertical) |
| 50 | + self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) |
| 51 | + self.buttonPlus = QtGui.QPushButton("+") |
| 52 | + self.buttonBox.addButton(self.buttonPlus, QtGui.QDialogButtonBox.ActionRole) |
| 53 | + self.buttonMoins = QtGui.QPushButton("-") |
| 54 | + self.buttonBox.addButton(self.buttonMoins, QtGui.QDialogButtonBox.ActionRole) |
| 55 | + self.table = QtGui.QTableWidget() |
| 56 | + self.table.setColumnCount(1) |
| 57 | + self.table.setColumnWidth(0,270) |
| 58 | + self.table.verticalHeader().setVisible(False) |
| 59 | + self.table.horizontalHeader().setVisible(False) |
| 60 | + self.table.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch) |
| 61 | + self.horizontalLayout.addWidget(self.table) |
| 62 | + self.horizontalLayout.addWidget(self.buttonBox) |
| 63 | + self.setLayout(self.horizontalLayout) |
| 64 | + QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.okPressed) |
| 65 | + QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.cancelPressed) |
| 66 | + QtCore.QObject.connect(self.buttonPlus, QtCore.SIGNAL("clicked()"), self.addFile) |
| 67 | + QtCore.QObject.connect(self.buttonMoins, QtCore.SIGNAL("clicked()"), self.removeFile) |
| 68 | + QtCore.QMetaObject.connectSlotsByName(self) |
| 69 | + |
| 70 | + def setTableContent(self): |
| 71 | + # "self.options :", ['/temp/confmat1-1.csv', '/temp/confmat2-1.csv'] |
| 72 | + self.table.setRowCount(len(self.options)) |
| 73 | + for i in range(len(self.options)): |
| 74 | + item = QtGui.QLabel() |
| 75 | + item.setText(self.options[i]) |
| 76 | + self.table.setCellWidget(i,0, item) |
| 77 | + |
| 78 | + def okPressed(self): |
| 79 | + self.selectedoptions = [] |
| 80 | + self.selectedoptions = self.options |
| 81 | + # "self.selectedoptions :", ['/temp/confmat1-1.csv', '/temp/confmat2-1.csv'] |
| 82 | + self.close() |
| 83 | + |
| 84 | + def cancelPressed(self): |
| 85 | + self.selectedoptions = None |
| 86 | + self.close() |
| 87 | + |
| 88 | + def addFile(self): |
| 89 | + settings = QtCore.QSettings() |
| 90 | + lastfolder = settings.value("processingFilesLastFolder") |
| 91 | + if lastfolder : |
| 92 | + path = lastfolder |
| 93 | + else : |
| 94 | + path = QtCore.QDir.currentPath() |
| 95 | + |
| 96 | + filesOpened = QtGui.QFileDialog.getOpenFileNames( None, "Select the file(s) to use", path, "All files (*.*)" ) |
| 97 | + |
| 98 | + lastfile = "" |
| 99 | + for item in filesOpened: |
| 100 | + self.options.append( str(item) ) |
| 101 | + lastfile=item |
| 102 | + |
| 103 | + self.setTableContent() |
| 104 | + folder = os.path.dirname( str( lastfile ) ) |
| 105 | + settings.setValue("processingFilesLastFolder", folder) |
| 106 | + |
| 107 | + def removeFile(self): |
| 108 | + indexRow = self.table.currentRow() |
| 109 | + itemToRemove = self.options[indexRow] |
| 110 | + self.options.remove(itemToRemove) |
| 111 | + self.setTableContent() |
0 commit comments