File: MultipleFileInputDialog.py

package info (click to toggle)
qgis 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 374,696 kB
  • ctags: 66,263
  • sloc: cpp: 396,139; ansic: 241,070; python: 130,609; xml: 14,884; perl: 1,290; sh: 1,287; sql: 500; yacc: 268; lex: 242; makefile: 168
file content (110 lines) | stat: -rw-r--r-- 4,613 bytes parent folder | download
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
# -*- 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 MultipleFileInputDialog(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.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.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()