2012-10-05 23:28:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
BatchOutputSelectionPanel.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* 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$'
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
from PyQt4 import QtGui, QtCore
|
|
|
|
from sextante.gui.AutofillDialog import AutofillDialog
|
|
|
|
from sextante.parameters.ParameterMultipleInput import ParameterMultipleInput
|
|
|
|
from sextante.parameters.ParameterRaster import ParameterRaster
|
|
|
|
from sextante.parameters.ParameterTable import ParameterTable
|
|
|
|
from sextante.parameters.ParameterVector import ParameterVector
|
|
|
|
from sextante.parameters.ParameterBoolean import ParameterBoolean
|
|
|
|
from sextante.parameters.ParameterSelection import ParameterSelection
|
|
|
|
from sextante.parameters.ParameterFixedTable import ParameterFixedTable
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
|
|
|
|
class BatchOutputSelectionPanel(QtGui.QWidget):
|
|
|
|
|
|
|
|
def __init__(self, output, alg, row, col, batchDialog):
|
|
|
|
super(BatchOutputSelectionPanel, self).__init__(None)
|
|
|
|
self.alg = alg
|
|
|
|
self.row = row
|
|
|
|
self.col = col
|
|
|
|
self.output = output
|
|
|
|
self.batchDialog = batchDialog
|
|
|
|
self.table = batchDialog.table
|
|
|
|
self.horizontalLayout = QtGui.QHBoxLayout(self)
|
|
|
|
self.horizontalLayout.setSpacing(2)
|
|
|
|
self.horizontalLayout.setMargin(0)
|
|
|
|
self.text = QtGui.QLineEdit()
|
|
|
|
self.text.setText("")
|
|
|
|
self.text.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
|
|
|
|
self.horizontalLayout.addWidget(self.text)
|
|
|
|
self.pushButton = QtGui.QPushButton()
|
|
|
|
self.pushButton.setText("...")
|
|
|
|
self.pushButton.clicked.connect(self.showSelectionDialog)
|
|
|
|
self.horizontalLayout.addWidget(self.pushButton)
|
|
|
|
self.setLayout(self.horizontalLayout)
|
|
|
|
|
|
|
|
def showSelectionDialog(self):
|
|
|
|
filefilter = self.output.getFileFilter(self.alg)
|
|
|
|
filename = QtGui.QFileDialog.getSaveFileName(self, "Save file", QtCore.QString(), filefilter)
|
|
|
|
if filename:
|
2013-06-06 17:29:52 +02:00
|
|
|
filename = unicode(filename)
|
2012-09-15 18:25:25 +03:00
|
|
|
dlg = AutofillDialog(self.alg)
|
|
|
|
dlg.exec_()
|
|
|
|
if dlg.mode != None:
|
|
|
|
try:
|
|
|
|
if dlg.mode == AutofillDialog.DO_NOT_AUTOFILL:
|
2013-02-21 22:12:01 +01:00
|
|
|
#self.text.setValue(filename)
|
|
|
|
self.table.cellWidget(self.row, self.col).setValue(filename)
|
2012-09-15 18:25:25 +03:00
|
|
|
elif dlg.mode == AutofillDialog.FILL_WITH_NUMBERS:
|
|
|
|
n = self.table.rowCount() - self.row
|
|
|
|
for i in range(n):
|
|
|
|
name = filename[:filename.rfind(".")] + str(i+1) + filename[filename.rfind("."):]
|
|
|
|
self.table.cellWidget(i + self.row, self.col).setValue(name)
|
|
|
|
elif dlg.mode == AutofillDialog.FILL_WITH_PARAMETER:
|
|
|
|
n = self.table.rowCount() - self.row
|
|
|
|
for i in range(n):
|
|
|
|
widget = self.table.cellWidget(i+self.row, dlg.param)
|
|
|
|
param = self.alg.parameters[dlg.param]
|
|
|
|
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable, ParameterMultipleInput)):
|
2013-06-06 17:29:52 +02:00
|
|
|
s = unicode(widget.getText())
|
2012-09-15 18:25:25 +03:00
|
|
|
s = os.path.basename(s)
|
|
|
|
s= s[:s.rfind(".")]
|
|
|
|
elif isinstance(param, ParameterBoolean):
|
|
|
|
s = str(widget.currentIndex() == 0)
|
|
|
|
elif isinstance(param, ParameterSelection):
|
2013-06-03 21:25:22 +02:00
|
|
|
s = unicode(widget.currentText())
|
2012-09-15 18:25:25 +03:00
|
|
|
elif isinstance(param, ParameterFixedTable):
|
2013-06-03 21:25:22 +02:00
|
|
|
s = unicode(widget.table)
|
2012-09-15 18:25:25 +03:00
|
|
|
else:
|
2013-06-03 21:25:22 +02:00
|
|
|
s = unicode(widget.text())
|
2012-09-15 18:25:25 +03:00
|
|
|
name = filename[:filename.rfind(".")] + s + filename[filename.rfind("."):]
|
|
|
|
self.table.cellWidget(i + self.row, self.col).setValue(name)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
def setValue(self, text):
|
|
|
|
return self.text.setText(text)
|
|
|
|
|
|
|
|
def getValue(self):
|
2013-06-03 21:25:22 +02:00
|
|
|
return unicode(self.text.text())
|
2012-09-15 18:25:25 +03:00
|
|
|
|