Skip to content
Permalink
Browse files

[processing] Add class ExpressionEnabledWidgetWrapper

  • Loading branch information
arnaud-morvan committed Feb 9, 2017
1 parent 482aadc commit dda667023a6cdedb813b1926f0c3d79276255ba3
Showing with 58 additions and 10 deletions.
  1. +58 −10 python/plugins/processing/gui/wrappers.py
@@ -32,16 +32,34 @@
import os
from functools import cmp_to_key

from qgis.core import QgsCoordinateReferenceSystem, QgsApplication, QgsWkbTypes, QgsMapLayerProxyModel
from qgis.PyQt.QtWidgets import QCheckBox, QComboBox, QLineEdit, QPlainTextEdit, QWidget, QHBoxLayout, QToolButton, QFileDialog
from qgis.gui import (QgsFieldExpressionWidget,
QgsExpressionLineEdit,
QgsProjectionSelectionWidget,
QgsGenericProjectionSelector,
QgsFieldComboBox,
QgsFieldProxyModel,
QgsMapLayerComboBox
)
from qgis.core import (
QgsApplication,
QgsCoordinateReferenceSystem,
QgsExpression,
QgsMapLayerProxyModel,
QgsWkbTypes,
)
from qgis.PyQt.QtWidgets import (
QCheckBox,
QComboBox,
QDialog,
QFileDialog,
QHBoxLayout,
QLineEdit,
QPlainTextEdit,
QToolButton,
QWidget,
)
from qgis.gui import (
QgsExpressionLineEdit,
QgsExpressionBuilderDialog,
QgsFieldComboBox,
QgsFieldExpressionWidget,
QgsFieldProxyModel,
QgsGenericProjectionSelector,
QgsMapLayerComboBox,
QgsProjectionSelectionWidget,
)
from qgis.PyQt.QtCore import pyqtSignal, QObject, QVariant, QSettings

from processing.gui.NumberInputPanel import NumberInputPanel, ModellerNumberInputPanel
@@ -175,6 +193,36 @@ def getFileName(self, initial_value=''):
return filename, selected_filter


class ExpressionEnabledWidgetWrapper(WidgetWrapper):

def createWidget(self, basewidget):
expr_button = QToolButton()
expr_button.clicked.connect(self.showExpressionsBuilder)
expr_button.setText('...')

layout = QHBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(basewidget)
layout.addWidget(expr_button)

widget = QWidget()
widget.setLayout(layout)

return widget

def showExpressionsBuilder(self):
context = self.param.expressionContext()
value = self.value()
if not isinstance(value, str):
value = ''
dlg = QgsExpressionBuilderDialog(None, value, self.widget, 'generic', context)
dlg.setWindowTitle(self.tr('Expression based input'))
if dlg.exec_() == QDialog.Accepted:
exp = QgsExpression(dlg.expressionText())
if not exp.hasParserError():
self.setValue(dlg.expressionText())


class BasicWidgetWrapper(WidgetWrapper):

def createWidget(self):

0 comments on commit dda6670

Please sign in to comment.
You can’t perform that action at this time.