Skip to content

Commit

Permalink
Add float support to UISliderWidget value getter and setter
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornall committed Jan 3, 2025
1 parent c4c9faf commit a767b0d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
14 changes: 6 additions & 8 deletions eqt/ui/UIFormWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@ def getWidgetState(self, widget, role=None):
widget_state['value'] = widget.isChecked()
elif isinstance(widget, QtWidgets.QComboBox):
widget_state['value'] = widget.currentIndex()
elif isinstance(widget, UISliderWidget) or isinstance(widget, QtWidgets.QSlider):
elif isinstance(widget, UISliderWidget):
widget_state['value'] = widget.getValue()
elif isinstance(widget, UISliderEditWidget):
widget_state['value'] = widget.getValue()
elif isinstance(widget, QtWidgets.QSlider):
widget_state['value'] = widget.value()
elif isinstance(widget, (QtWidgets.QDoubleSpinBox, QtWidgets.QSpinBox)):
widget_state['value'] = widget.value()
Expand All @@ -336,9 +340,6 @@ def getWidgetState(self, widget, role=None):
widget_state['value'] = widget.isChecked()
elif isinstance(widget, (QtWidgets.QTextEdit, QtWidgets.QPlainTextEdit)):
widget_state['value'] = widget.toPlainText()
elif isinstance(widget, UISliderEditWidget) or isinstance(widget, QtWidgets.QWidget):
widget_state['value'] = widget.getValue()
# isinstance(QWidget) must be last due to other QtWidgets inheriting from it
widget_state['enabled'] = widget.isEnabled()
widget_state['visible'] = widget.isVisible()
widget_state['widget_row'] = self.getWidgetRow(name, role)
Expand Down Expand Up @@ -412,7 +413,7 @@ def applyWidgetState(self, name, state, role=None):
widget.setChecked(value)
elif isinstance(widget, QtWidgets.QComboBox):
widget.setCurrentIndex(value)
elif isinstance(widget, (UISliderWidget, QtWidgets.QSlider)):
elif isinstance(widget, (UISliderWidget, UISliderEditWidget, QtWidgets.QSlider)):
widget.setValue(value)
elif isinstance(widget, (QtWidgets.QDoubleSpinBox, QtWidgets.QSpinBox)):
widget.setValue(value)
Expand All @@ -424,9 +425,6 @@ def applyWidgetState(self, name, state, role=None):
widget.setChecked(value)
elif isinstance(widget, (QtWidgets.QTextEdit, QtWidgets.QPlainTextEdit)):
widget.setPlainText(value)
elif isinstance(widget, (UISliderEditWidget, QtWidgets.QWidget)):
widget.setValue(value)
# isinstance(QWidget) must be last due to other QtWidgets inheriting from it

def applyWidgetStates(self, states):
'''
Expand Down
6 changes: 6 additions & 0 deletions eqt/ui/UISliderWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def __init__(self, line_edit, max_label, minimum=0.0, maximum=10.0, scale_factor
self.max_label.setAlignment(QtCore.Qt.AlignRight)
self.max_label.setText(str(self.maximum))

def getValue(self):
return self.getLineEditValue()

def setValue(self, value):
self.line_edit.setText(str(value))

def getSliderValue(self):
return self.value()

Expand Down
4 changes: 4 additions & 0 deletions test/test_UISliderEditWidget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import unittest

# from PySide2 import QtWidgets

# from eqt.ui import FormDialog, UISliderEditWidget, UISliderWidget


class UISliderEditWidget(unittest.TestCase):
def setUp(self):
Expand Down
4 changes: 2 additions & 2 deletions test/test__formUI_status_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def exampleState(self):
state = [{
'label_value': 'Test label state 0', 'checkBox_value': False, 'comboBox_value': 0,
'doubleSpinBox_value': 10.0, 'spinBox_value': 10, 'slider_value': 10,
'uiSliderWidget_value': 10, 'uiSliderEditWidget_value': 10.0,
'uiSliderWidget_value': 10.0, 'uiSliderEditWidget_value': 10.0,
'radioButton_value': False, 'textEdit_value': 'test edit 0',
'plainTextEdit_value': 'test plain 0', 'lineEdit_value': 'test line 0',
'button_value': False}, {
'label_value': 'Test label state 1', 'checkBox_value': True, 'comboBox_value': 1,
'doubleSpinBox_value': 1.0, 'spinBox_value': 1, 'slider_value': 1,
'uiSliderWidget_value': 1, 'uiSliderEditWidget_value': 1.0,
'uiSliderWidget_value': 1.0, 'uiSliderEditWidget_value': 1.0,
'radioButton_value': True, 'textEdit_value': 'test edit 1',
'plainTextEdit_value': 'test plain 1', 'lineEdit_value': 'test line 1',
'button_value': True}]
Expand Down

0 comments on commit a767b0d

Please sign in to comment.