Skip to content

Commit 5464c45

Browse files
committedOct 5, 2016
[processing] use QgsMessage bar in algorithm dialogs
1 parent 56225c4 commit 5464c45

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed
 

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929

3030
from qgis.PyQt.QtCore import Qt
3131
from qgis.PyQt.QtWidgets import QMessageBox, QApplication, QPushButton, QWidget, QVBoxLayout
32-
from qgis.PyQt.QtGui import QCursor, QColor, QPalette
32+
from qgis.PyQt.QtGui import QCursor, QColor, QPalette, QSizePolicy
3333

3434
from qgis.core import QgsMapLayerRegistry
35+
from qgis.gui import QgsMessageBar
3536

3637
from processing.core.ProcessingLog import ProcessingLog
3738
from processing.core.ProcessingConfig import ProcessingConfig
@@ -71,6 +72,10 @@ def __init__(self, alg):
7172

7273
self.setMainWidget(ParametersPanel(self, alg))
7374

75+
self.bar = QgsMessageBar()
76+
self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
77+
self.layout().insertWidget(0, self.bar)
78+
7479
self.cornerWidget = QWidget()
7580
layout = QVBoxLayout()
7681
layout.setContentsMargins(0, 0, 0, 5)
@@ -179,13 +184,11 @@ def accept(self):
179184
palette = e.widget.palette()
180185
palette.setColor(QPalette.Base, QColor(255, 255, 0))
181186
e.widget.setPalette(palette)
182-
self.lblProgress.setText(
183-
self.tr('<b>Missing parameter value: %s</b>') % e.parameter.description)
184-
return
185187
except:
186-
QMessageBox.critical(self,
187-
self.tr('Unable to execute algorithm'),
188-
self.tr('Wrong or missing parameter values'))
188+
pass
189+
self.bar.clearWidgets()
190+
self.bar.pushMessage("", "Wrong or missing parameter value: %s" % e.parameter.description,
191+
level=QgsMessageBar.WARNING, duration=5)
189192

190193
def finish(self):
191194
keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from qgis.PyQt.QtWidgets import QTableWidgetItem, QComboBox, QLineEdit, QHeaderView, QFileDialog, QMessageBox
3636

3737
from qgis.core import QgsApplication
38+
from qgis.gui import QgsMessageBar
3839

3940
from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
4041
from processing.gui.GeometryPredicateSelectionPanel import GeometryPredicateSelectionPanel
@@ -88,8 +89,8 @@ def __init__(self, parent, alg):
8889
self.fillParameterValues)
8990

9091
self.initWidgets()
91-
92-
92+
93+
9394
def layerRegistryChanged(self):
9495
pass
9596

@@ -192,8 +193,9 @@ def save(self):
192193
continue
193194
wrapper = self.wrappers[row][col]
194195
if not self.setParamValue(param, wrapper, alg):
195-
self.parent.lblProgress.setText(
196-
self.tr('<b>Missing parameter value: %s (row %d)</b>') % (param.description, row + 1))
196+
self.parent.bar.pushMessage("", self.tr('Wrong or missing parameter value: %s (row %d)')
197+
% (param.description, row + 1),
198+
level=QgsMessageBar.WARNING, duration=5)
197199
return
198200
algParams[param.name] = param.getValueAsCommandLineParameter()
199201
col += 1
@@ -206,8 +208,9 @@ def save(self):
206208
algOutputs[out.name] = text.strip()
207209
col += 1
208210
else:
209-
self.parent.lblProgress.setText(
210-
self.tr('<b>Wrong or missing parameter value: %s (row %d)</b>') % (out.description, row + 1))
211+
self.parent.bar.pushMessage("", self.tr('Wrong or missing output value: %s (row %d)')
212+
% (out.description, row + 1),
213+
level=QgsMessageBar.WARNING, duration=5)
211214
return
212215
toSave.append({self.PARAMETERS: algParams, self.OUTPUTS: algOutputs})
213216

@@ -267,7 +270,7 @@ def fillParameterValues(self, column):
267270
wrapper = self.wrappers[0][column]
268271
for row in range(1, self.tblParameters.rowCount()):
269272
self.wrappers[row][column].setValue(wrapper.value())
270-
273+
271274
def toggleAdvancedMode(self, checked):
272275
for column, param in enumerate(self.alg.parameters):
273276
if param.isAdvanced:

‎python/plugins/processing/preconfigured/PreconfiguredAlgorithmDialog.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
from qgis.PyQt.QtWidgets import QMessageBox, QVBoxLayout, QLabel, QLineEdit, QWidget
3939
from qgis.PyQt.QtGui import QPalette, QColor
4040

41+
from qgis.gui import QgsMessageBar
42+
4143

4244
class PreconfiguredAlgorithmDialog(AlgorithmDialog):
4345

@@ -77,8 +79,9 @@ def accept(self):
7779
palette = e.widget.palette()
7880
palette.setColor(QPalette.Base, QColor(255, 255, 0))
7981
e.widget.setPalette(palette)
80-
self.lblProgress.setText(
81-
self.tr('<b>Missing parameter value: %s</b>') % e.parameter.description)
82+
self.parent.bar.pushMessage("", self.tr('Missing parameter value: %s')
83+
% e.parameter.description,
84+
level=QgsMessageBar.WARNING, duration=5)
8285
return
8386
except:
8487
QMessageBox.critical(self,

0 commit comments

Comments
 (0)
Please sign in to comment.