Skip to content

Commit

Permalink
Update examples and tests to include UISliderLEditWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornall committed Jan 3, 2025
1 parent 5c595bf commit 1545425
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 20 deletions.
11 changes: 4 additions & 7 deletions eqt/ui/UIFormWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ 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) or isinstance(widget, UISliderLEditWidget):
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,8 +338,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, UISliderLEditWidget) or isinstance(widget, QtWidgets.QWidget):
widget_state['value'] = widget.getValue()
widget_state['enabled'] = widget.isEnabled()
widget_state['visible'] = widget.isVisible()
widget_state['widget_row'] = self.getWidgetRow(name, role)
Expand Down Expand Up @@ -411,7 +411,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, UISliderLEditWidget, QtWidgets.QSlider)):
widget.setValue(value)
elif isinstance(widget, (QtWidgets.QDoubleSpinBox, QtWidgets.QSpinBox)):
widget.setValue(value)
Expand All @@ -423,9 +423,6 @@ def applyWidgetState(self, name, state, role=None):
widget.setChecked(value)
elif isinstance(widget, (QtWidgets.QTextEdit, QtWidgets.QPlainTextEdit)):
widget.setPlainText(value)
elif isinstance(widget, UISliderLEditWidget) or isinstance(
widget, QtWidgets.QWidget):
widget.setValue(value)

def applyWidgetStates(self, states):
'''
Expand Down
8 changes: 4 additions & 4 deletions eqt/ui/UISliderLEditWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, minimum=0.0, maximum=1.0, step_size=1.0, scale_factor=1.0,
self.show()

def getValue(self):
return float(self.line_edit.text())
return self.getLineEditValue()

def setValue(self, value):
self.line_edit.setText(str(value))
Expand All @@ -91,17 +91,17 @@ def getSliderValue(self):
return self.slider.value()

def getLineEditValue(self):
return self.line_edit.text()
return float(self.line_edit.text())

def updateSlider(self):
state = self.validator.validate(self.line_edit.text(), 0)
if state[0] == QtGui.QDoubleValidator.Acceptable:
line_edit_value = float(self.getLineEditValue())
line_edit_value = self.getLineEditValue()
self.slider.setValue(line_edit_value)
self.setValue(line_edit_value)
else:
self.line_edit.setText(str(self.minimum))
line_edit_value = float(self.getLineEditValue())
line_edit_value = self.getLineEditValue()
self.slider.setValue(line_edit_value)
self.setValue(line_edit_value)

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

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

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

Expand Down
17 changes: 15 additions & 2 deletions examples/utilitiesForExamples.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from PySide2 import QtWidgets

from eqt.ui.UISliderLEditWidget import UISliderLEditWidget
from eqt.ui.UISliderWidget import UISliderWidget


Expand All @@ -8,7 +9,8 @@ def list_all_widgets():
'label': QtWidgets.QLabel('test label'), 'checkBox': QtWidgets.QCheckBox('test checkbox'),
'comboBox': QtWidgets.QComboBox(), 'doubleSpinBox': QtWidgets.QDoubleSpinBox(),
'spinBox': QtWidgets.QSpinBox(), 'slider': QtWidgets.QSlider(),
'uiSliderWidget': UISliderWidget(QtWidgets.QLabel()),
'uiSliderWidget': UISliderWidget(QtWidgets.QLineEdit(), QtWidgets.QLabel()),
'uiSliderLEditWidget': UISliderLEditWidget(),
'radioButton': QtWidgets.QRadioButton('test radio button'),
'textEdit': QtWidgets.QTextEdit('test text edit'),
'plainTextEdit': QtWidgets.QPlainTextEdit('test plain text edit'),
Expand All @@ -33,7 +35,18 @@ def addWidgetsToExample(form):
form.addWidget(QtWidgets.QDoubleSpinBox(), 'DoubleSpinBox: ', 'doubleSpinBox')
form.addWidget(QtWidgets.QSpinBox(), 'SpinBox: ', 'spinBox')
form.addWidget(QtWidgets.QSlider(), 'Slider: ', 'slider')
form.addWidget(UISliderWidget(QtWidgets.QLabel()), 'UISlider: ', 'uiSliderWidget')

line_edit = QtWidgets.QLineEdit()
max_label = QtWidgets.QLabel()
form.addWidget(
UISliderWidget(line_edit, max_label, minimum=0.0, maximum=100.0, scale_factor=10.0),
'UISliderWidget: ', 'uiSliderWidget')
form.addWidget(max_label, '', 'uiSliderMaxLabel')
form.addWidget(line_edit, '', 'uiSliderLineEdit')

form.addWidget(UISliderLEditWidget(minimum=0.0, maximum=100.0, scale_factor=10.0),
'UISliderLEditWidget:', 'uiSliderLEditWidget')

form.addWidget(QtWidgets.QRadioButton('select me'), 'RadioButton: ', 'radioButton')
form.addWidget(QtWidgets.QTextEdit('write text here'), 'TextEdit: ', 'textEdit')
form.addWidget(QtWidgets.QPlainTextEdit('write text here'), 'PlainTextEdit: ', 'plainTextEdit')
Expand Down
37 changes: 30 additions & 7 deletions test/test__formUI_status_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from eqt.ui.FormDialog import AdvancedFormDialog, FormDialog
from eqt.ui.UIFormWidget import FormDockWidget, FormWidget
from eqt.ui.UISliderLEditWidget import UISliderLEditWidget
from eqt.ui.UISliderWidget import UISliderWidget

from . import is_ci, skip
Expand All @@ -33,14 +34,16 @@ 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, 'radioButton_value': False,
'textEdit_value': 'test edit 0', 'plainTextEdit_value': 'test plain 0',
'lineEdit_value': 'test line 0', 'button_value': False}, {
'uiSliderWidget_value': 10, 'uiSliderLEditWidget_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, 'radioButton_value': True,
'textEdit_value': 'test edit 1', 'plainTextEdit_value': 'test plain 1',
'lineEdit_value': 'test line 1', 'button_value': True}]
'uiSliderWidget_value': 1, 'uiSliderLEditWidget_value': 1.0,
'radioButton_value': True, 'textEdit_value': 'test edit 1',
'plainTextEdit_value': 'test plain 1', 'lineEdit_value': 'test line 1',
'button_value': True}]
return state

@property
Expand All @@ -52,7 +55,9 @@ def list_all_widgets(self):
'label': QtWidgets.QLabel('test label'),
'checkBox': QtWidgets.QCheckBox('test checkbox'), 'comboBox': combobox_widget,
'doubleSpinBox': QtWidgets.QDoubleSpinBox(), 'spinBox': QtWidgets.QSpinBox(),
'slider': QtWidgets.QSlider(), 'uiSliderWidget': UISliderWidget(QtWidgets.QLabel()),
'slider': QtWidgets.QSlider(), 'uiSliderWidget': UISliderWidget(
QtWidgets.QLineEdit(),
QtWidgets.QLabel()), 'uiSliderLEditWidget': UISliderLEditWidget(),
'radioButton': QtWidgets.QRadioButton('test radio button'),
'textEdit': QtWidgets.QTextEdit('test text edit'),
'plainTextEdit': QtWidgets.QPlainTextEdit('test plain text edit'),
Expand Down Expand Up @@ -106,6 +111,8 @@ def set_state(self, i: int):
self.form.getWidget('slider').setValue(state[i]['slider_value'])
# UISlider
self.form.getWidget('uiSliderWidget').setValue(state[i]['uiSliderWidget_value'])
# UISliderLEditWidget
self.form.getWidget('uiSliderLEditWidget').setValue(state[i]['uiSliderLEditWidget_value'])
# QRadioButton
self.form.getWidget('radioButton').setChecked(state[i]['radioButton_value'])
# QTextEdit
Expand Down Expand Up @@ -141,6 +148,9 @@ def set_spanning_state(self, i: int):
self.form.getWidget('slider_spanning').setValue(state[i]['slider_value'])
# UISlider
self.form.getWidget('uiSliderWidget_spanning').setValue(state[i]['uiSliderWidget_value'])
# UISliderLEditWidget
self.form.getWidget('uiSliderLEditWidget_spanning').setValue(
state[i]['uiSliderLEditWidget_value'])
# QRadioButton
self.form.getWidget('radioButton_spanning').setChecked(state[i]['radioButton_value'])
# QTextEdit
Expand Down Expand Up @@ -374,6 +384,19 @@ def test_getWidgetState_returns_UISliderWidget_value(self):
self.assertEqual(
self.form.getWidgetState('uiSliderWidget_field')['value'], final_slider_value)

def test_getWidgetState_returns_UISliderLEditWidget_value(self):
"""Check that the value of the UISliderLEditWidget is returned in the state"""
initial_slider_value = 0

self.assertEqual(
self.form.getWidgetState('uiSliderLEditWidget_field')['value'], initial_slider_value)

final_slider_value = 1
self.form.getWidget('UISliderLEditWidget').setValue(final_slider_value)

self.assertEqual(
self.form.getWidgetState('uiSliderLEditWidget_field')['value'], final_slider_value)

def test_getWidgetState_returns_QLineEdit_value(self):
"""Check that the value of the QLineEdit is saved to the state"""
initial_lineEdit_value = ''
Expand Down

0 comments on commit 1545425

Please sign in to comment.