From d2e3ca50d2dacefeccd8c92290ea54f82f47c3bf Mon Sep 17 00:00:00 2001 From: Danica Sugic Date: Thu, 22 Feb 2024 17:59:11 +0000 Subject: [PATCH] changes from review - partial --- CHANGELOG.md | 3 ++- eqt/ui/FormDialog.py | 23 ++++++++++++----------- eqt/ui/UIFormWidget.py | 11 +++++++++++ examples/advanced_dialog_example.py | 4 ++-- test/test__formUI_status_test.py | 2 +- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cacd5c5..b10eaaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/eqt/ui/FormDialog.py b/eqt/ui/FormDialog.py index 4eb7c59..f095e79 100644 --- a/eqt/ui/FormDialog.py +++ b/eqt/ui/FormDialog.py @@ -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() @@ -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 @@ -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): """ @@ -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() @@ -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. diff --git a/eqt/ui/UIFormWidget.py b/eqt/ui/UIFormWidget.py index e504f8e..902a539 100644 --- a/eqt/ui/UIFormWidget.py +++ b/eqt/ui/UIFormWidget.py @@ -2,6 +2,8 @@ from .UISliderWidget import UISliderWidget +from warnings import warn + class UIFormWidget: ''' @@ -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.''' @@ -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() diff --git a/examples/advanced_dialog_example.py b/examples/advanced_dialog_example.py index 32500ed..dc44ef5 100644 --- a/examples/advanced_dialog_example.py +++ b/examples/advanced_dialog_example.py @@ -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) @@ -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 diff --git a/test/test__formUI_status_test.py b/test/test__formUI_status_test.py index 537e57f..3a8e18f 100644 --- a/test/test__formUI_status_test.py +++ b/test/test__formUI_status_test.py @@ -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()