Skip to content

Commit

Permalink
[processing] use QgsMessage bar in algorithm dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Oct 5, 2016
1 parent 56225c4 commit 5464c45
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
17 changes: 10 additions & 7 deletions python/plugins/processing/gui/AlgorithmDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@

from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QMessageBox, QApplication, QPushButton, QWidget, QVBoxLayout
from qgis.PyQt.QtGui import QCursor, QColor, QPalette
from qgis.PyQt.QtGui import QCursor, QColor, QPalette, QSizePolicy

from qgis.core import QgsMapLayerRegistry
from qgis.gui import QgsMessageBar

from processing.core.ProcessingLog import ProcessingLog
from processing.core.ProcessingConfig import ProcessingConfig
Expand Down Expand Up @@ -71,6 +72,10 @@ def __init__(self, alg):

self.setMainWidget(ParametersPanel(self, alg))

self.bar = QgsMessageBar()
self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
self.layout().insertWidget(0, self.bar)

self.cornerWidget = QWidget()
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 5)
Expand Down Expand Up @@ -179,13 +184,11 @@ def accept(self):
palette = e.widget.palette()
palette.setColor(QPalette.Base, QColor(255, 255, 0))
e.widget.setPalette(palette)
self.lblProgress.setText(
self.tr('<b>Missing parameter value: %s</b>') % e.parameter.description)
return
except:
QMessageBox.critical(self,
self.tr('Unable to execute algorithm'),
self.tr('Wrong or missing parameter values'))
pass
self.bar.clearWidgets()
self.bar.pushMessage("", "Wrong or missing parameter value: %s" % e.parameter.description,
level=QgsMessageBar.WARNING, duration=5)

def finish(self):
keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)
Expand Down
17 changes: 10 additions & 7 deletions python/plugins/processing/gui/BatchPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from qgis.PyQt.QtWidgets import QTableWidgetItem, QComboBox, QLineEdit, QHeaderView, QFileDialog, QMessageBox

from qgis.core import QgsApplication
from qgis.gui import QgsMessageBar

from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
from processing.gui.GeometryPredicateSelectionPanel import GeometryPredicateSelectionPanel
Expand Down Expand Up @@ -88,8 +89,8 @@ def __init__(self, parent, alg):
self.fillParameterValues)

self.initWidgets()


def layerRegistryChanged(self):
pass

Expand Down Expand Up @@ -192,8 +193,9 @@ def save(self):
continue
wrapper = self.wrappers[row][col]
if not self.setParamValue(param, wrapper, alg):
self.parent.lblProgress.setText(
self.tr('<b>Missing parameter value: %s (row %d)</b>') % (param.description, row + 1))
self.parent.bar.pushMessage("", self.tr('Wrong or missing parameter value: %s (row %d)')
% (param.description, row + 1),
level=QgsMessageBar.WARNING, duration=5)
return
algParams[param.name] = param.getValueAsCommandLineParameter()
col += 1
Expand All @@ -206,8 +208,9 @@ def save(self):
algOutputs[out.name] = text.strip()
col += 1
else:
self.parent.lblProgress.setText(
self.tr('<b>Wrong or missing parameter value: %s (row %d)</b>') % (out.description, row + 1))
self.parent.bar.pushMessage("", self.tr('Wrong or missing output value: %s (row %d)')
% (out.description, row + 1),
level=QgsMessageBar.WARNING, duration=5)
return
toSave.append({self.PARAMETERS: algParams, self.OUTPUTS: algOutputs})

Expand Down Expand Up @@ -267,7 +270,7 @@ def fillParameterValues(self, column):
wrapper = self.wrappers[0][column]
for row in range(1, self.tblParameters.rowCount()):
self.wrappers[row][column].setValue(wrapper.value())

def toggleAdvancedMode(self, checked):
for column, param in enumerate(self.alg.parameters):
if param.isAdvanced:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
from qgis.PyQt.QtWidgets import QMessageBox, QVBoxLayout, QLabel, QLineEdit, QWidget
from qgis.PyQt.QtGui import QPalette, QColor

from qgis.gui import QgsMessageBar


class PreconfiguredAlgorithmDialog(AlgorithmDialog):

Expand Down Expand Up @@ -77,8 +79,9 @@ def accept(self):
palette = e.widget.palette()
palette.setColor(QPalette.Base, QColor(255, 255, 0))
e.widget.setPalette(palette)
self.lblProgress.setText(
self.tr('<b>Missing parameter value: %s</b>') % e.parameter.description)
self.parent.bar.pushMessage("", self.tr('Missing parameter value: %s')
% e.parameter.description,
level=QgsMessageBar.WARNING, duration=5)
return
except:
QMessageBox.critical(self,
Expand Down

0 comments on commit 5464c45

Please sign in to comment.