Skip to content

Commit

Permalink
allow more granular values in spinboxes
Browse files Browse the repository at this point in the history
Some frequencies such as 1575,42M (GPS) are not representable
by four decimals with the higher suffix (1,57542G).
This commit adapts the number of decimals to the actual value.
The maximum number of decimals is capped at 10.
  • Loading branch information
jopohl committed Jan 27, 2020
1 parent 57436fb commit 53548c0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 29 deletions.
22 changes: 11 additions & 11 deletions data/ui/modulation.ui
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<width>373</width>
<height>330</height>
</rect>
</property>
Expand Down Expand Up @@ -485,7 +485,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>380</width>
<width>373</width>
<height>141</height>
</rect>
</property>
Expand All @@ -499,7 +499,7 @@
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
<number>10</number>
</property>
<property name="minimum">
<double>0.001000000000000</double>
Expand Down Expand Up @@ -594,7 +594,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>380</width>
<width>353</width>
<height>143</height>
</rect>
</property>
Expand Down Expand Up @@ -624,7 +624,7 @@
<string/>
</property>
<property name="decimals">
<number>3</number>
<number>10</number>
</property>
<property name="minimum">
<double>0.000000000000000</double>
Expand Down Expand Up @@ -831,7 +831,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<width>353</width>
<height>227</height>
</rect>
</property>
Expand Down Expand Up @@ -1084,16 +1084,16 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ZoomableGraphicView</class>
<extends>QGraphicsView</extends>
<header>urh.ui.views.ZoomableGraphicView.h</header>
</customwidget>
<customwidget>
<class>KillerDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>urh.ui.KillerDoubleSpinBox.h</header>
</customwidget>
<customwidget>
<class>ZoomableGraphicView</class>
<extends>QGraphicsView</extends>
<header>urh.ui.views.ZoomableGraphicView.h</header>
</customwidget>
<customwidget>
<class>ZoomAndDropableGraphicView</class>
<extends>QGraphicsView</extends>
Expand Down
11 changes: 7 additions & 4 deletions data/ui/send_recv_device_settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>860</width>
<height>711</height>
<height>754</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -230,14 +230,17 @@ QGroupBox::indicator:checked {
<item row="7" column="1">
<widget class="KillerDoubleSpinBox" name="spinBoxFreq">
<property name="decimals">
<number>3</number>
<number>10</number>
</property>
<property name="minimum">
<double>0.001000000000000</double>
</property>
<property name="maximum">
<double>1000000000000.000000000000000</double>
</property>
<property name="value">
<double>433920000.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="0">
Expand Down Expand Up @@ -483,7 +486,7 @@ QGroupBox::indicator:checked {
<item row="8" column="1">
<widget class="KillerDoubleSpinBox" name="spinBoxSampleRate">
<property name="decimals">
<number>3</number>
<number>10</number>
</property>
<property name="minimum">
<double>0.001000000000000</double>
Expand All @@ -496,7 +499,7 @@ QGroupBox::indicator:checked {
<item row="9" column="1">
<widget class="KillerDoubleSpinBox" name="spinBoxBandwidth">
<property name="decimals">
<number>3</number>
<number>10</number>
</property>
<property name="minimum">
<double>0.001000000000000</double>
Expand Down
19 changes: 15 additions & 4 deletions src/urh/ui/KillerDoubleSpinBox.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import string

from PyQt5.QtCore import QLocale
from PyQt5.QtCore import QRegExp
from PyQt5.QtGui import QValidator
Expand Down Expand Up @@ -40,13 +42,22 @@ def adjust_step(self):

def textFromValue(self, value: float):
if abs(value) >= 10 ** 9:
return super().textFromValue(value / 10 ** 9) + "G"
result, suffix = super().textFromValue(value / 10 ** 9), "G"
elif abs(value) >= 10 ** 6:
return super().textFromValue(value / 10 ** 6) + "M"
result, suffix = super().textFromValue(value / 10 ** 6), "M"
elif abs(value) >= 10 ** 3:
return super().textFromValue(value / 10 ** 3) + "K"
result, suffix = super().textFromValue(value / 10 ** 3), "K"
else:
return super().textFromValue(value)
result, suffix = super().textFromValue(value), ""

result = result.rstrip("0")
if len(result) == 0:
return result

if result[-1] not in string.digits:
result += "0"

return result + suffix

def valueFromText(self, text: str):
if text.endswith("G") or text.endswith("g"):
Expand Down
12 changes: 6 additions & 6 deletions src/urh/ui/ui_modulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def setupUi(self, DialogModulation):
self.scrollArea_5.setWidgetResizable(True)
self.scrollArea_5.setObjectName("scrollArea_5")
self.scrollAreaWidgetContents_5 = QtWidgets.QWidget()
self.scrollAreaWidgetContents_5.setGeometry(QtCore.QRect(0, 0, 400, 330))
self.scrollAreaWidgetContents_5.setGeometry(QtCore.QRect(0, 0, 373, 330))
self.scrollAreaWidgetContents_5.setObjectName("scrollAreaWidgetContents_5")
self.gridLayout_4 = QtWidgets.QGridLayout(self.scrollAreaWidgetContents_5)
self.gridLayout_4.setObjectName("gridLayout_4")
Expand Down Expand Up @@ -225,7 +225,7 @@ def setupUi(self, DialogModulation):
self.scrollArea_3.setWidgetResizable(True)
self.scrollArea_3.setObjectName("scrollArea_3")
self.scrollAreaWidgetContents_3 = QtWidgets.QWidget()
self.scrollAreaWidgetContents_3.setGeometry(QtCore.QRect(0, 0, 380, 141))
self.scrollAreaWidgetContents_3.setGeometry(QtCore.QRect(0, 0, 373, 141))
self.scrollAreaWidgetContents_3.setObjectName("scrollAreaWidgetContents_3")
self.gridLayout_2 = QtWidgets.QGridLayout(self.scrollAreaWidgetContents_3)
self.gridLayout_2.setObjectName("gridLayout_2")
Expand All @@ -235,7 +235,7 @@ def setupUi(self, DialogModulation):
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.spinBoxSampleRate.sizePolicy().hasHeightForWidth())
self.spinBoxSampleRate.setSizePolicy(sizePolicy)
self.spinBoxSampleRate.setDecimals(3)
self.spinBoxSampleRate.setDecimals(10)
self.spinBoxSampleRate.setMinimum(0.001)
self.spinBoxSampleRate.setMaximum(999999999.0)
self.spinBoxSampleRate.setObjectName("spinBoxSampleRate")
Expand Down Expand Up @@ -283,7 +283,7 @@ def setupUi(self, DialogModulation):
self.scrollArea_2.setWidgetResizable(True)
self.scrollArea_2.setObjectName("scrollArea_2")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 380, 143))
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 353, 143))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.gridLayout = QtWidgets.QGridLayout(self.scrollAreaWidgetContents)
self.gridLayout.setObjectName("gridLayout")
Expand All @@ -302,7 +302,7 @@ def setupUi(self, DialogModulation):
sizePolicy.setHeightForWidth(self.doubleSpinBoxCarrierFreq.sizePolicy().hasHeightForWidth())
self.doubleSpinBoxCarrierFreq.setSizePolicy(sizePolicy)
self.doubleSpinBoxCarrierFreq.setSuffix("")
self.doubleSpinBoxCarrierFreq.setDecimals(3)
self.doubleSpinBoxCarrierFreq.setDecimals(10)
self.doubleSpinBoxCarrierFreq.setMinimum(0.0)
self.doubleSpinBoxCarrierFreq.setMaximum(99999999999.0)
self.doubleSpinBoxCarrierFreq.setObjectName("doubleSpinBoxCarrierFreq")
Expand Down Expand Up @@ -397,7 +397,7 @@ def setupUi(self, DialogModulation):
self.scrollArea_4.setWidgetResizable(True)
self.scrollArea_4.setObjectName("scrollArea_4")
self.scrollAreaWidgetContents_4 = QtWidgets.QWidget()
self.scrollAreaWidgetContents_4.setGeometry(QtCore.QRect(0, 0, 400, 227))
self.scrollAreaWidgetContents_4.setGeometry(QtCore.QRect(0, 0, 353, 227))
self.scrollAreaWidgetContents_4.setObjectName("scrollAreaWidgetContents_4")
self.gridLayout_3 = QtWidgets.QGridLayout(self.scrollAreaWidgetContents_4)
self.gridLayout_3.setObjectName("gridLayout_3")
Expand Down
9 changes: 5 additions & 4 deletions src/urh/ui/ui_send_recv_device_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Ui_FormDeviceSettings(object):
def setupUi(self, FormDeviceSettings):
FormDeviceSettings.setObjectName("FormDeviceSettings")
FormDeviceSettings.resize(860, 711)
FormDeviceSettings.resize(860, 754)
self.verticalLayout = QtWidgets.QVBoxLayout(FormDeviceSettings)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
Expand Down Expand Up @@ -110,9 +110,10 @@ def setupUi(self, FormDeviceSettings):
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 0, 0, 1, 1)
self.spinBoxFreq = KillerDoubleSpinBox(self.frame_2)
self.spinBoxFreq.setDecimals(3)
self.spinBoxFreq.setDecimals(10)
self.spinBoxFreq.setMinimum(0.001)
self.spinBoxFreq.setMaximum(1000000000000.0)
self.spinBoxFreq.setProperty("value", 433920000.0)
self.spinBoxFreq.setObjectName("spinBoxFreq")
self.gridLayout.addWidget(self.spinBoxFreq, 7, 1, 1, 1)
self.labelAntenna = QtWidgets.QLabel(self.frame_2)
Expand Down Expand Up @@ -228,13 +229,13 @@ def setupUi(self, FormDeviceSettings):
self.spinBoxNRepeat.setObjectName("spinBoxNRepeat")
self.gridLayout.addWidget(self.spinBoxNRepeat, 15, 1, 1, 1)
self.spinBoxSampleRate = KillerDoubleSpinBox(self.frame_2)
self.spinBoxSampleRate.setDecimals(3)
self.spinBoxSampleRate.setDecimals(10)
self.spinBoxSampleRate.setMinimum(0.001)
self.spinBoxSampleRate.setMaximum(1000000000000.0)
self.spinBoxSampleRate.setObjectName("spinBoxSampleRate")
self.gridLayout.addWidget(self.spinBoxSampleRate, 8, 1, 1, 1)
self.spinBoxBandwidth = KillerDoubleSpinBox(self.frame_2)
self.spinBoxBandwidth.setDecimals(3)
self.spinBoxBandwidth.setDecimals(10)
self.spinBoxBandwidth.setMinimum(0.001)
self.spinBoxBandwidth.setMaximum(1000000000000.0)
self.spinBoxBandwidth.setObjectName("spinBoxBandwidth")
Expand Down

0 comments on commit 53548c0

Please sign in to comment.