Skip to content

Commit 231f4e8

Browse files
committedOct 12, 2013
[processing] homogenize widgets used for ParameterNumber (fix 8807)
1 parent 0f1a272 commit 231f4e8

File tree

5 files changed

+148
-36
lines changed

5 files changed

+148
-36
lines changed
 

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
class NumberInputDialog(QDialog, Ui_DlgNumberInput):
3939

40-
def __init__(self):
40+
def __init__(self, isInteger):
4141
QDialog.__init__(self)
4242
self.setupUi(self)
4343

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

5050
self.value = None
51+
self.isInteger = isInteger
52+
53+
if not self.isInteger:
54+
self.lblWarning.hide()
5155

5256
self.fillTree()
5357

@@ -123,6 +127,8 @@ def addValue(self):
123127
def accept(self):
124128
try:
125129
self.value = float(eval(str(self.leFormula.text())))
130+
if self.isInteger:
131+
self.value = int(round(self.value))
126132
QDialog.accept(self)
127133
except:
128134
QMessageBox.critical(self, self.tr('Wrong expression'),

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

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,38 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from PyQt4 import QtGui
28+
from PyQt4.QtGui import *
2929
from processing.gui.NumberInputDialog import NumberInputDialog
3030

31+
from processing.ui.ui_widgetNumberInput import Ui_widgetNumberInput
3132

32-
class NumberInputPanel(QtGui.QWidget):
33+
class NumberInputPanel(QWidget, Ui_widgetNumberInput):
3334

3435
def __init__(self, number, minimum, maximum, isInteger):
35-
super(NumberInputPanel, self).__init__(None)
36-
self.horizontalLayout = QtGui.QHBoxLayout(self)
37-
self.horizontalLayout.setSpacing(2)
38-
self.horizontalLayout.setMargin(0)
36+
QDialog.__init__(self)
37+
self.setupUi(self)
38+
3939
self.isInteger = isInteger
40-
if isInteger:
41-
self.spin = QtGui.QSpinBox()
40+
if self.isInteger:
41+
self.spnValue.setDecimals(0)
4242
if maximum:
43-
self.spin.setMaximum(maximum)
43+
self.spnValue.setMaximum(maximum)
4444
else:
45-
self.spin.setMaximum(99999999)
45+
self.spnValue.setMaximum(99999999)
4646
if minimum:
47-
self.spin.setMinimum(minimum)
47+
self.spnValue.setMinimum(minimum)
4848
else:
49-
self.spin.setMinimum(-99999999)
50-
self.spin.setValue(number)
51-
self.horizontalLayout.addWidget(self.spin)
52-
self.setLayout(self.horizontalLayout)
53-
else:
54-
self.text = QtGui.QLineEdit()
55-
self.text.setText(str(number))
56-
self.text.setSizePolicy(QtGui.QSizePolicy.Expanding,
57-
QtGui.QSizePolicy.Expanding)
58-
self.horizontalLayout.addWidget(self.text)
59-
self.pushButton = QtGui.QPushButton()
60-
self.pushButton.setText('...')
61-
self.pushButton.clicked.connect(self.showNumberInputDialog)
62-
self.horizontalLayout.addWidget(self.pushButton)
63-
self.setLayout(self.horizontalLayout)
49+
self.spnValue.setMinimum(-99999999)
50+
51+
self.spnValue.setValue(float(number))
52+
53+
self.btnCalc.clicked.connect(self.showNumberInputDialog)
6454

6555
def showNumberInputDialog(self):
66-
pass
67-
dlg = NumberInputDialog()
56+
dlg = NumberInputDialog(self.isInteger)
6857
dlg.exec_()
6958
if dlg.value is not None:
70-
self.text.setText(str(dlg.value))
59+
self.spnValue.setValue(dlg.value)
7160

7261
def getValue(self):
73-
if self.isInteger:
74-
return self.spin.value()
75-
else:
76-
return self.text.text()
62+
return self.spnValue.value()

‎python/plugins/processing/ui/DlgNumberInput.ui

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,20 @@
3232
<item>
3333
<widget class="QLabel" name="label">
3434
<property name="text">
35-
<string>Enter expression in the text field.
36-
Double click on elements in the tree to add their values to the expression.</string>
35+
<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>
36+
</property>
37+
<property name="wordWrap">
38+
<bool>true</bool>
39+
</property>
40+
</widget>
41+
</item>
42+
<item>
43+
<widget class="QLabel" name="lblWarning">
44+
<property name="text">
45+
<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>
46+
</property>
47+
<property name="wordWrap">
48+
<bool>true</bool>
3749
</property>
3850
</widget>
3951
</item>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Form implementation generated from reading ui file 'python/plugins/processing/ui/widgetNumberInput.ui'
4+
#
5+
# Created: Wed Oct 9 19:20:54 2013
6+
# by: PyQt4 UI code generator 4.9.1
7+
#
8+
# WARNING! All changes made in this file will be lost!
9+
10+
from PyQt4 import QtCore, QtGui
11+
12+
try:
13+
_fromUtf8 = QtCore.QString.fromUtf8
14+
except AttributeError:
15+
_fromUtf8 = lambda s: s
16+
17+
class Ui_widgetNumberInput(object):
18+
def setupUi(self, widgetNumberInput):
19+
widgetNumberInput.setObjectName(_fromUtf8("widgetNumberInput"))
20+
widgetNumberInput.resize(189, 28)
21+
self.horizontalLayout_2 = QtGui.QHBoxLayout(widgetNumberInput)
22+
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 2)
23+
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
24+
self.horizontalLayout = QtGui.QHBoxLayout()
25+
self.horizontalLayout.setSpacing(2)
26+
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
27+
self.spnValue = QtGui.QDoubleSpinBox(widgetNumberInput)
28+
self.spnValue.setDecimals(6)
29+
self.spnValue.setMinimum(-100000000.0)
30+
self.spnValue.setMaximum(100000000.0)
31+
self.spnValue.setObjectName(_fromUtf8("spnValue"))
32+
self.horizontalLayout.addWidget(self.spnValue)
33+
self.btnCalc = QtGui.QToolButton(widgetNumberInput)
34+
self.btnCalc.setObjectName(_fromUtf8("btnCalc"))
35+
self.horizontalLayout.addWidget(self.btnCalc)
36+
self.horizontalLayout_2.addLayout(self.horizontalLayout)
37+
38+
self.retranslateUi(widgetNumberInput)
39+
QtCore.QMetaObject.connectSlotsByName(widgetNumberInput)
40+
41+
def retranslateUi(self, widgetNumberInput):
42+
widgetNumberInput.setWindowTitle(QtGui.QApplication.translate("widgetNumberInput", "Form", None, QtGui.QApplication.UnicodeUTF8))
43+
self.btnCalc.setToolTip(QtGui.QApplication.translate("widgetNumberInput", "Open number input dialog", None, QtGui.QApplication.UnicodeUTF8))
44+
self.btnCalc.setText(QtGui.QApplication.translate("widgetNumberInput", "...", None, QtGui.QApplication.UnicodeUTF8))
45+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>widgetNumberInput</class>
4+
<widget class="QWidget" name="widgetNumberInput">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>189</width>
10+
<height>28</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Form</string>
15+
</property>
16+
<layout class="QHBoxLayout" name="horizontalLayout_2">
17+
<property name="leftMargin">
18+
<number>0</number>
19+
</property>
20+
<property name="topMargin">
21+
<number>0</number>
22+
</property>
23+
<property name="rightMargin">
24+
<number>0</number>
25+
</property>
26+
<property name="bottomMargin">
27+
<number>2</number>
28+
</property>
29+
<item>
30+
<layout class="QHBoxLayout" name="horizontalLayout">
31+
<property name="spacing">
32+
<number>2</number>
33+
</property>
34+
<item>
35+
<widget class="QDoubleSpinBox" name="spnValue">
36+
<property name="decimals">
37+
<number>6</number>
38+
</property>
39+
<property name="minimum">
40+
<double>-99999999.999999001622200</double>
41+
</property>
42+
<property name="maximum">
43+
<double>99999999.999999001622200</double>
44+
</property>
45+
</widget>
46+
</item>
47+
<item>
48+
<widget class="QToolButton" name="btnCalc">
49+
<property name="toolTip">
50+
<string>Open number input dialog</string>
51+
</property>
52+
<property name="text">
53+
<string>...</string>
54+
</property>
55+
</widget>
56+
</item>
57+
</layout>
58+
</item>
59+
</layout>
60+
</widget>
61+
<resources/>
62+
<connections/>
63+
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.