Skip to content

Commit 4511ea1

Browse files
committedAug 22, 2017
Add a file selector for file parameters in model algorithms
Makes it more obvious to users that a fixed filename can be used here
1 parent 451a3fa commit 4511ea1

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed
 

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

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,24 +483,59 @@ def createWidget(self):
483483
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
484484
return FileSelectionPanel(self.param.behavior() == QgsProcessingParameterFile.Folder, self.param.extension())
485485
else:
486-
widget = QComboBox()
487-
widget.setEditable(True)
486+
self.combo = QComboBox()
487+
self.combo.setEditable(True)
488488
files = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFile, OutputFile)
489489
for f in files:
490-
widget.addItem(self.dialog.resolveValueDescription(f), f)
490+
self.combo.addItem(self.dialog.resolveValueDescription(f), f)
491+
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
492+
self.combo.setEditText("")
493+
widget = QWidget()
494+
layout = QHBoxLayout()
495+
layout.setMargin(0)
496+
layout.setContentsMargins(0, 0, 0, 0)
497+
layout.setSpacing(2)
498+
layout.addWidget(self.combo)
499+
btn = QToolButton()
500+
btn.setText('…')
501+
btn.setToolTip(self.tr("Select file"))
502+
btn.clicked.connect(self.selectFile)
503+
layout.addWidget(btn)
504+
widget.setLayout(layout)
491505
return widget
492506

507+
def selectFile(self):
508+
settings = QgsSettings()
509+
if os.path.isdir(os.path.dirname(self.combo.currentText())):
510+
path = os.path.dirname(self.combo.currentText())
511+
if settings.contains('/Processing/LastInputPath'):
512+
path = settings.value('/Processing/LastInputPath')
513+
else:
514+
path = ''
515+
516+
if self.param.extension():
517+
filter = self.tr('{} files').format(self.param.extension().upper()) + ' (*.' + self.param.extension() + self.tr(
518+
');;All files (*.*)')
519+
else:
520+
filter = self.tr('All files (*.*)')
521+
522+
filename, selected_filter = QFileDialog.getOpenFileName(self.widget,
523+
self.tr('Select file'), path,
524+
filter)
525+
if filename:
526+
self.combo.setEditText(filename)
527+
493528
def setValue(self, value):
494529
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
495530
self.widget.setText(value)
496531
else:
497-
self.setComboValue(value)
532+
self.setComboValue(value, combobox=self.combo)
498533

499534
def value(self):
500535
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
501536
return self.widget.getValue()
502537
else:
503-
return self.comboValue()
538+
return self.comboValue(combobox=self.combo)
504539

505540

506541
class FixedTableWidgetWrapper(WidgetWrapper):

0 commit comments

Comments
 (0)
Please sign in to comment.