Skip to content

Commit

Permalink
changes from review - partial
Browse files Browse the repository at this point in the history
  • Loading branch information
DanicaSTFC committed Feb 22, 2024
1 parent 5536161 commit d2e3ca5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Version 1.0.0
- Adds the class `AdvancedDialogForm` & tests/example (#124)
- Adds the class `AdvancedDialogForm` & tests/example;
deprecates `getWidgetStates` to be `getSavedWidgetStates` (#124)
- Edits 'contributing.md' and 'README.md (#131, #133)
- Adds unit test for `addWidget` and `addSpanningWidget`; adds `getIndexFromVerticalLayout`
to `FormDialog` (#123)
Expand Down
23 changes: 12 additions & 11 deletions eqt/ui/FormDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ def saveAllWidgetStates(self):
'''
self.formWidget.saveAllWidgetStates()

def getWidgetStates(self):
'''Deprecated. Use `getSavedWidgetStates`.'''
return self.formWidget.getWidgetStates()

def getSavedWidgetStates(self):
'''Returns the saved widget states.'''
return self.formWidget.getSavedWidgetStates()
Expand Down Expand Up @@ -333,11 +337,11 @@ def __init__(self, parent=None, title=None, parent_button_name=None):
Creates a form dialog and adds a default button to the vertical layout.
The default button is located between the form layout and the buttons 'ok' and 'cancel'.
The default button is connected to the 'setDefaultValues' method.
The default button is connected to the '_setDefaultValues' method.
Parameters
----------
parent : QWidget or None, optional
parent : UIFormWidget or None, optional
The parent widget of the advanced form dialog.
If None, the dialog is created without a parent.
title : str or None, optional
Expand All @@ -362,7 +366,7 @@ def __init__(self, parent=None, title=None, parent_button_name=None):
# add default button to vertical layout
self.default_button = QtWidgets.QPushButton("Set default values")
self.insertWidgetToVerticalLayout(1, self.default_button)
self.default_button.clicked.connect(lambda: self.setDefaultValues())
self.default_button.clicked.connect(lambda: self._setDefaultValues())

def _onOk(self):
"""
Expand All @@ -372,11 +376,8 @@ def _onOk(self):
to visible and closes the dialog. Adds or updates or removes widgets from the
parent based on the values of the widgets in the advanced dialog.
"""
self.saveAllWidgetStates()
self.onOk()
super()._onOk()
self.formWidget.setDefaultWidgetStatesVisibleTrue()
self.close()

if self.display_on_parent_dict:
if self.getSavedWidgetStates() == self.getDefaultWidgetStates():
self._removeWidgetsFromParent()
Expand Down Expand Up @@ -411,17 +412,17 @@ def _removeWidgetsFromParent(self):
if f'{name}_field' in self.dialog_parent.getWidgets():
self.dialog_parent.removeWidget(name)

def setDefaultValues(self):
def _setDefaultValues(self):
"""
Sets the widgets in the advanced dialog to their default states.
Makes the default widget states visible and applies the widget states
to the widgets in the form.
Makes the default widget states visible, as often the default states are saved while the widgets are not visible.
Applies the widget states to the widgets in the form.
"""
self.formWidget.setDefaultWidgetStatesVisibleTrue()
self.applyWidgetStates(self.formWidget.default_widget_states)

def addToDictionaryDisplayOnParent(self, name):
def displayWidgetValueOnParent(self, name):
"""
Adds `name` in a dictionary. The order in which names are added to this
dictionary reflects the order in which the widgets are added to the parent.
Expand Down
11 changes: 11 additions & 0 deletions eqt/ui/UIFormWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from .UISliderWidget import UISliderWidget

from warnings import warn


class UIFormWidget:
'''
Expand Down Expand Up @@ -463,6 +465,11 @@ def saveAllWidgetStates(self):
To later restore the states, use `restoreAllSavedWidgetStates()`.
'''
self.widget_states = self.getAllWidgetStates()

def getWidgetStates(self):
'''Deprecated. Use `getSavedWidgetStates`.'''
warn('The method `getWidgetStates` is deprecated, use `getSavedWidgetStates`.', DeprecationWarning, stacklevel=2)
return self.getSavedWidgetStates()

def getSavedWidgetStates(self):
'''Returns the saved widget states.'''
Expand Down Expand Up @@ -622,6 +629,10 @@ def saveAllWidgetStates(self):
'''
self.widget().saveAllWidgetStates()

def getWidgetStates(self):
'''Deprecated. Use `getSavedWidgetStates`.'''
return self.widget().getWidgetStates()

def getSavedWidgetStates(self):
'''Returns the saved widget states.'''
return self.widget().getSavedWidgetStates()
Expand Down
4 changes: 2 additions & 2 deletions examples/advanced_dialog_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, parent=None):
# finally add to the form widget
dialog.insertWidget(0, 'input_title', QtWidgets.QLabel("Input Values: "))
dialog.insertWidget(1, 'input1', qwidget, qlabel)
dialog.addToDictionaryDisplayOnParent('input1')
dialog.displayWidgetValueOnParent('input1')

# add input 2 as QComboBox
qlabel = QtWidgets.QLabel(dialog.groupBox)
Expand All @@ -41,7 +41,7 @@ def __init__(self, parent=None):
qwidget.setEnabled(True)
# finally add to the form widget
dialog.addWidget(qwidget, qlabel, 'input2')
dialog.addToDictionaryDisplayOnParent('input2')
dialog.displayWidgetValueOnParent('input2')
dialog.addWidget(QtWidgets.QLabel("Example Vertical Layout Text"), layout="vertical")

# store a reference
Expand Down
2 changes: 1 addition & 1 deletion test/test__formUI_status_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def setUp(self):
self.vertical_layout = self.form.formWidget.uiElements['verticalLayout']
self.add_every_widget()
for key in self.list_all_widgets:
self.form.addToDictionaryDisplayOnParent(key)
self.form.displayWidgetValueOnParent(key)

self.form_without_parent = AdvancedFormDialog()

Expand Down

0 comments on commit d2e3ca5

Please sign in to comment.