Skip to content

Commit 1507f0d

Browse files
committed
[processing] add new output type - directory
1 parent 4d5b7d3 commit 1507f0d

7 files changed

Lines changed: 173 additions & 89 deletions

File tree

‎python/plugins/processing/gui/NumberInputPanel.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
class NumberInputPanel(QWidget, Ui_widgetNumberInput):
3434

3535
def __init__(self, number, minimum, maximum, isInteger):
36-
QDialog.__init__(self)
36+
QWidget.__init__(self)
3737
self.setupUi(self)
3838

3939
self.isInteger = isInteger

‎python/plugins/processing/gui/OutputSelectionPanel.py‎

Lines changed: 73 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,99 +27,114 @@
2727

2828
import os.path
2929
import re
30+
3031
from PyQt4.QtCore import *
3132
from PyQt4.QtGui import *
32-
from qgis.gui import *
33+
3334
from processing.core.ProcessingConfig import ProcessingConfig
3435
from processing.outputs.OutputVector import OutputVector
36+
from processing.outputs.OutputDirectory import OutputDirectory
3537

38+
from processing.ui.ui_widgetOutputSelect import Ui_widgetOutputSelect
3639

37-
class OutputSelectionPanel(QWidget):
40+
class OutputSelectionPanel(QWidget, Ui_widgetOutputSelect):
3841

39-
lastOutputFolder = None
40-
SAVE_TO_TEMP_FILE = '[Save to temporary file]'
42+
SAVE_TO_TEMP_FILE = QCoreApplication.translate(
43+
'OutputSelectionPanel', '[Save to temporary file]')
4144

4245
def __init__(self, output, alg):
46+
QWidget.__init__(self)
47+
self.setupUi(self)
48+
4349
self.output = output
4450
self.alg = alg
45-
super(OutputSelectionPanel, self).__init__(None)
46-
self.horizontalLayout = QHBoxLayout(self)
47-
self.horizontalLayout.setSpacing(2)
48-
self.horizontalLayout.setMargin(0)
49-
self.text = QLineEdit()
51+
5052
if hasattr(self.text, 'setPlaceholderText'):
51-
self.text.setPlaceholderText(
52-
OutputSelectionPanel.SAVE_TO_TEMP_FILE)
53-
self.text.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
54-
self.horizontalLayout.addWidget(self.text)
55-
self.pushButton = QPushButton()
56-
self.pushButton.setText('...')
57-
self.pushButton.clicked.connect(self.buttonPushed)
58-
self.horizontalLayout.addWidget(self.pushButton)
59-
self.setLayout(self.horizontalLayout)
60-
61-
def buttonPushed(self):
62-
popupmenu = QMenu()
63-
saveToTemporaryFileAction = QAction('Save to a temporary file',
64-
self.pushButton)
65-
saveToTemporaryFileAction.triggered.connect(self.saveToTemporaryFile)
66-
popupmenu.addAction(saveToTemporaryFileAction)
67-
if isinstance(self.output, OutputVector) \
68-
and self.alg.provider.supportsNonFileBasedOutput():
69-
saveToMemoryAction = QAction('Save to a memory layer',
70-
self.pushButton)
71-
saveToMemoryAction.triggered.connect(self.saveToMemory)
72-
popupmenu.addAction(saveToMemoryAction)
73-
saveToFileAction = QAction('Save to file...', self.pushButton)
74-
saveToFileAction.triggered.connect(self.saveToFile)
75-
popupmenu.addAction(saveToFileAction)
76-
77-
popupmenu.exec_(QCursor.pos())
53+
self.text.setPlaceholderText(self.SAVE_TO_TEMP_FILE)
54+
55+
self.btnBrowse.clicked.connect(self.selectOutput)
56+
57+
def selectOutput(self):
58+
if isinstance(self.output, OutputDirectory):
59+
self.selectDirectory()
60+
else:
61+
popupMenu = QMenu()
62+
63+
actionSaveToTempFile = QAction(
64+
self.tr('Save to a temporary file'), self.btnBrowse)
65+
actionSaveToTempFile.triggered.connect(self.saveToTemporaryFile)
66+
popupMenu.addAction(actionSaveToTempFile)
67+
68+
actionSaveToFile = QAction(
69+
self.tr('Save to file...'), self.btnBrowse)
70+
actionSaveToFile.triggered.connect(self.selectFile)
71+
popupMenu.addAction(actionSaveToFile)
72+
73+
if isinstance(self.output, OutputVector) \
74+
and self.alg.provider.supportsNonFileBasedOutput():
75+
actionSaveToMemory = QAction(
76+
self.tr('Save to memory layer'), self.btnBrowse)
77+
actionSaveToMemory.triggered.connect(self.saveToMemory)
78+
popupMenu.addAction(actionSaveToMemory)
79+
80+
popupMenu.exec_(QCursor.pos())
7881

7982
def saveToTemporaryFile(self):
8083
self.text.setText('')
8184

8285
def saveToMemory(self):
8386
self.text.setText('memory:')
8487

85-
def saveToFile(self):
86-
filefilter = self.output.getFileFilter(self.alg)
88+
def selectFile(self):
89+
fileFilter = self.output.getFileFilter(self.alg)
90+
8791
settings = QSettings()
8892
if settings.contains('/Processing/LastOutputPath'):
8993
path = settings.value('/Processing/LastOutputPath')
9094
else:
9195
path = ProcessingConfig.getSetting(ProcessingConfig.OUTPUT_FOLDER)
92-
lastEncoding = settings.value('/Processing/encoding', 'System')
93-
fileDialog = QgsEncodingFileDialog(self, 'Save file', path,
94-
filefilter, lastEncoding)
96+
97+
encoding = settings.value('/Processing/encoding', 'System')
98+
fileDialog = QgsEncodingFileDialog(
99+
self, self.tr('Save file'), path, fileFilter, encoding)
95100
fileDialog.setFileMode(QFileDialog.AnyFile)
96101
fileDialog.setAcceptMode(QFileDialog.AcceptSave)
97102
fileDialog.setConfirmOverwrite(True)
103+
98104
if fileDialog.exec_() == QDialog.Accepted:
99105
files = fileDialog.selectedFiles()
100106
encoding = unicode(fileDialog.encoding())
101107
self.output.encoding = encoding
102-
filename = unicode(files[0])
103-
selectedFilefilter = unicode(fileDialog.selectedNameFilter())
104-
if not filename.lower().endswith(
105-
tuple(re.findall("\*(\.[a-z]{1,5})", filefilter))):
108+
fileName = unicode(files[0])
109+
selectedFileFilter = unicode(fileDialog.selectedNameFilter())
110+
if not fileName.lower().endswith(
111+
tuple(re.findall("\*(\.[a-z]{1,5})", fileFilter))):
106112
ext = re.search("\*(\.[a-z]{1,5})", selectedFilefilter)
107113
if ext:
108-
filename = filename + ext.group(1)
109-
self.text.setText(filename)
114+
fileName += ext.group(1)
115+
self.text.setText(fileName)
110116
settings.setValue('/Processing/LastOutputPath',
111-
os.path.dirname(filename))
117+
os.path.dirname(fileName))
112118
settings.setValue('/Processing/encoding', encoding)
113119

120+
def selectDirectory(self):
121+
lastDir = ''
122+
123+
dirName = QFileDialog.getExistingDirectory(self,
124+
self.tr('Select directory'), lastDir, QFileDialog.ShowDirsOnly)
125+
126+
self.text.setText(dirName)
127+
114128
def getValue(self):
115-
filename = unicode(self.text.text())
116-
if filename.strip() == '' or filename \
117-
== OutputSelectionPanel.SAVE_TO_TEMP_FILE:
118-
return None
119-
if filename.startswith('memory:'):
120-
return filename
129+
fileName = unicode(self.text.text())
130+
if fileName.strip() in ['', self.SAVE_TO_TEMP_FILE]:
131+
value = None
132+
elif fileName.startswith('memory:'):
133+
value = fileName
134+
elif not os.path.isabs(fileName):
135+
value = ProcessingConfig.getSetting(
136+
ProcessingConfig.OUTPUT_FOLDER) + os.sep + fileName
121137
else:
122-
if not os.path.isabs(filename):
123-
filename = ProcessingConfig.getSetting(
124-
ProcessingConfig.OUTPUT_FOLDER) + os.sep + filename
125-
return filename
138+
value = fileName
139+
140+
return value

‎python/plugins/processing/modeler/ModelerParametersDialog.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from processing.outputs.OutputNumber import OutputNumber
5959
from processing.outputs.OutputHTML import OutputHTML
6060
from processing.outputs.OutputFile import OutputFile
61+
from processing.outputs.OutputDirectory import OutputDirectory
6162

6263

6364
class ModelerParametersDialog(QtGui.QDialog):
@@ -130,7 +131,7 @@ def setupUi(self):
130131
if output.hidden:
131132
continue
132133
if isinstance(output, (OutputRaster, OutputVector, OutputTable,
133-
OutputHTML, OutputFile)):
134+
OutputHTML, OutputFile, OutputDirectory)):
134135
label = QtGui.QLabel(output.description + '<'
135136
+ output.__module__.split('.')[-1] + '>')
136137
item = QLineEdit()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
OutputDirectory.py
6+
---------------------
7+
Date : May 2014
8+
Copyright : (C) 2014 by Alexander Bruy
9+
Email : alexander dot bruy at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Alexander Bruy'
21+
__date__ = 'May 2014'
22+
__copyright__ = '(C) 2014, Alexander Bruy'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
from processing.outputs.Output import Output
29+
30+
31+
class OutputDirectory(Output):
32+
pass

‎python/plugins/processing/outputs/OutputFactory.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from processing.outputs.OutputNumber import OutputNumber
3333
from processing.outputs.OutputFile import OutputFile
3434
from processing.outputs.OutputString import OutputString
35+
from processing.outputs.OutputDirectory import OutputDirectory
3536

3637

3738
class OutputFactory:
@@ -46,6 +47,7 @@ def getFromString(s):
4647
OutputNumber,
4748
OutputFile,
4849
OutputString,
50+
OutputDirectory
4951
]
5052
for clazz in classes:
5153
if s.startswith(clazz().outputTypeName()):

‎python/plugins/processing/ui/widgetNumberInput.ui‎

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,45 @@
77
<x>0</x>
88
<y>0</y>
99
<width>205</width>
10-
<height>49</height>
10+
<height>24</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
16-
<layout class="QHBoxLayout" name="horizontalLayout_2">
1716
<property name="spacing">
1817
<number>0</number>
1918
</property>
19+
20+
<layout class="QHBoxLayout" name="horizontalLayout">
21+
<property name="spacing">
22+
<number>2</number>
23+
</property>
2024
<property name="margin">
2125
<number>0</number>
2226
</property>
2327
<item>
24-
<layout class="QHBoxLayout" name="horizontalLayout">
25-
<property name="spacing">
26-
<number>2</number>
28+
<widget class="QDoubleSpinBox" name="spnValue">
29+
<property name="decimals">
30+
<number>6</number>
31+
</property>
32+
<property name="minimum">
33+
<double>-99999999.999999001622200</double>
34+
</property>
35+
<property name="maximum">
36+
<double>99999999.999999001622200</double>
37+
</property>
38+
</widget>
39+
</item>
40+
<item>
41+
<widget class="QToolButton" name="btnCalc">
42+
<property name="toolTip">
43+
<string>Open number input dialog</string>
44+
</property>
45+
<property name="text">
46+
<string>...</string>
2747
</property>
28-
<item>
29-
<widget class="QDoubleSpinBox" name="spnValue">
30-
<property name="decimals">
31-
<number>6</number>
32-
</property>
33-
<property name="minimum">
34-
<double>-99999999.999999001622200</double>
35-
</property>
36-
<property name="maximum">
37-
<double>99999999.999999001622200</double>
38-
</property>
39-
</widget>
40-
</item>
41-
<item>
42-
<widget class="QToolButton" name="btnCalc">
43-
<property name="toolTip">
44-
<string>Open number input dialog</string>
45-
</property>
46-
<property name="text">
47-
<string>...</string>
48-
</property>
49-
</widget>
50-
</item>
51-
</layout>
48+
</widget>
5249
</item>
5350
</layout>
5451
</widget>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>widgetOutputSelect</class>
4+
<widget class="QWidget" name="widgetOutputSelect">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>24</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Form</string>
15+
</property>
16+
<layout class="QHBoxLayout" name="horizontalLayout">
17+
<property name="spacing">
18+
<number>2</number>
19+
</property>
20+
<property name="margin">
21+
<number>0</number>
22+
</property>
23+
<item>
24+
<widget class="QLineEdit" name="text"/>
25+
</item>
26+
<item>
27+
<widget class="QToolButton" name="btnBrowse">
28+
<property name="text">
29+
<string>...</string>
30+
</property>
31+
</widget>
32+
</item>
33+
</layout>
34+
</widget>
35+
<resources/>
36+
<connections/>
37+
</ui>

0 commit comments

Comments
 (0)