Skip to content
Permalink
Browse files

[processing] homogenize widgets used for ParameterNumber (fix 8807)

  • Loading branch information
alexbruy committed Oct 12, 2013
1 parent 0f1a272 commit 231f4e844422c75bcfd3252a2e3de5d7a8c10ce4
@@ -37,7 +37,7 @@

class NumberInputDialog(QDialog, Ui_DlgNumberInput):

def __init__(self):
def __init__(self, isInteger):
QDialog.__init__(self)
self.setupUi(self)

@@ -48,6 +48,10 @@ def __init__(self):
self.treeValues.doubleClicked.connect(self.addValue)

self.value = None
self.isInteger = isInteger

if not self.isInteger:
self.lblWarning.hide()

self.fillTree()

@@ -123,6 +127,8 @@ def addValue(self):
def accept(self):
try:
self.value = float(eval(str(self.leFormula.text())))
if self.isInteger:
self.value = int(round(self.value))
QDialog.accept(self)
except:
QMessageBox.critical(self, self.tr('Wrong expression'),
@@ -25,52 +25,38 @@

__revision__ = '$Format:%H$'

from PyQt4 import QtGui
from PyQt4.QtGui import *
from processing.gui.NumberInputDialog import NumberInputDialog

from processing.ui.ui_widgetNumberInput import Ui_widgetNumberInput

class NumberInputPanel(QtGui.QWidget):
class NumberInputPanel(QWidget, Ui_widgetNumberInput):

def __init__(self, number, minimum, maximum, isInteger):
super(NumberInputPanel, self).__init__(None)
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
QDialog.__init__(self)
self.setupUi(self)

self.isInteger = isInteger
if isInteger:
self.spin = QtGui.QSpinBox()
if self.isInteger:
self.spnValue.setDecimals(0)
if maximum:
self.spin.setMaximum(maximum)
self.spnValue.setMaximum(maximum)
else:
self.spin.setMaximum(99999999)
self.spnValue.setMaximum(99999999)
if minimum:
self.spin.setMinimum(minimum)
self.spnValue.setMinimum(minimum)
else:
self.spin.setMinimum(-99999999)
self.spin.setValue(number)
self.horizontalLayout.addWidget(self.spin)
self.setLayout(self.horizontalLayout)
else:
self.text = QtGui.QLineEdit()
self.text.setText(str(number))
self.text.setSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
self.horizontalLayout.addWidget(self.text)
self.pushButton = QtGui.QPushButton()
self.pushButton.setText('...')
self.pushButton.clicked.connect(self.showNumberInputDialog)
self.horizontalLayout.addWidget(self.pushButton)
self.setLayout(self.horizontalLayout)
self.spnValue.setMinimum(-99999999)

self.spnValue.setValue(float(number))

self.btnCalc.clicked.connect(self.showNumberInputDialog)

def showNumberInputDialog(self):
pass
dlg = NumberInputDialog()
dlg = NumberInputDialog(self.isInteger)
dlg.exec_()
if dlg.value is not None:
self.text.setText(str(dlg.value))
self.spnValue.setValue(dlg.value)

def getValue(self):
if self.isInteger:
return self.spin.value()
else:
return self.text.text()
return self.spnValue.value()
@@ -32,8 +32,20 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Enter expression in the text field.
Double click on elements in the tree to add their values to the expression.</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enter expression in the text field. Double click on elements in the tree to add their values to the expression.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblWarning">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Warning&lt;/span&gt;: if expression result is float value, but integer required, result will be rounded to integer.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'python/plugins/processing/ui/widgetNumberInput.ui'
#
# Created: Wed Oct 9 19:20:54 2013
# by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class Ui_widgetNumberInput(object):
def setupUi(self, widgetNumberInput):
widgetNumberInput.setObjectName(_fromUtf8("widgetNumberInput"))
widgetNumberInput.resize(189, 28)
self.horizontalLayout_2 = QtGui.QHBoxLayout(widgetNumberInput)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 2)
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.spnValue = QtGui.QDoubleSpinBox(widgetNumberInput)
self.spnValue.setDecimals(6)
self.spnValue.setMinimum(-100000000.0)
self.spnValue.setMaximum(100000000.0)
self.spnValue.setObjectName(_fromUtf8("spnValue"))
self.horizontalLayout.addWidget(self.spnValue)
self.btnCalc = QtGui.QToolButton(widgetNumberInput)
self.btnCalc.setObjectName(_fromUtf8("btnCalc"))
self.horizontalLayout.addWidget(self.btnCalc)
self.horizontalLayout_2.addLayout(self.horizontalLayout)

self.retranslateUi(widgetNumberInput)
QtCore.QMetaObject.connectSlotsByName(widgetNumberInput)

def retranslateUi(self, widgetNumberInput):
widgetNumberInput.setWindowTitle(QtGui.QApplication.translate("widgetNumberInput", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.btnCalc.setToolTip(QtGui.QApplication.translate("widgetNumberInput", "Open number input dialog", None, QtGui.QApplication.UnicodeUTF8))
self.btnCalc.setText(QtGui.QApplication.translate("widgetNumberInput", "...", None, QtGui.QApplication.UnicodeUTF8))

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>widgetNumberInput</class>
<widget class="QWidget" name="widgetNumberInput">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>189</width>
<height>28</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QDoubleSpinBox" name="spnValue">
<property name="decimals">
<number>6</number>
</property>
<property name="minimum">
<double>-99999999.999999001622200</double>
</property>
<property name="maximum">
<double>99999999.999999001622200</double>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnCalc">
<property name="toolTip">
<string>Open number input dialog</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit 231f4e8

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