Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save entries by default in the Form Dialog #97

Merged
merged 32 commits into from
Dec 7, 2023
Merged

Conversation

DanicaSTFC
Copy link
Collaborator

@DanicaSTFC DanicaSTFC commented Oct 26, 2023

Closes #87

  • Adds a method to UIFormWidget to populate the default widget states dictionary and one to make default widget states visible.
  • Form dialog saves states by default when Ok is clicked and restores the previously saved states or the default states when Cancel is clicked.
  • Add example file "dialog_example_3_save_default" to demonstrate the new features.
  • Add example file "utilitiesForExample" for methods recurring in the examples.
  • Add exampleState, set_state and test_dialog_buttons_default_behaviour to the unit tests.

Copy link
Member

@lauramurgatroyd lauramurgatroyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, here are some initial comments before I look more in depth at the unit tests (so I would say hold off on actioning my comments on the unit tests so far). Just wanted to submit this first review as is because of the bug I found in the behaviour, and I will review again later today with more detailed suggestions for the unit tests targeting the removal of opening the dialog etc.

Unfortunately, I found the dialog_example_3_save_default example didn't work as I expected. I opened the dialog, changed some content of the dialog and pressed cancel. Then found that the content I changed was still there. I think this only happens if you press cancel before you have ever pressed Ok.

I was also surprised to find that when I ran the dialog_example_2 it didn't now save the states - do you have any insight as to why? It may be the case that we only need one example - I don't think that this example and dialog_example_2 should in theory really be showing different behaviour unless there's something that I have missed.

test/test__formUI_status_test.py Outdated Show resolved Hide resolved
examples/dialog_example_3_save_default.py Outdated Show resolved Hide resolved
examples/dialog_example_3_save_default.py Outdated Show resolved Hide resolved
examples/dialog_example_3_save_default.py Outdated Show resolved Hide resolved
eqt/ui/FormDialog.py Show resolved Hide resolved
examples/dialog_example_3_save_default.py Outdated Show resolved Hide resolved
test/test__formUI_status_test.py Outdated Show resolved Hide resolved
test/test__formUI_status_test.py Outdated Show resolved Hide resolved
test/test__formUI_status_test.py Outdated Show resolved Hide resolved
Copy link
Member

@lauramurgatroyd lauramurgatroyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't get time to review properly but here are some initial comments as discussed today

eqt/ui/UIFormWidget.py Outdated Show resolved Hide resolved
eqt/ui/UIFormWidget.py Outdated Show resolved Hide resolved
eqt/ui/UIFormWidget.py Outdated Show resolved Hide resolved
@DanicaSTFC
Copy link
Collaborator Author

@lauramurgatroyd when you are happy with the PR changes I will resolve the merge conflicts locally.

eqt/ui/UIFormWidget.py Outdated Show resolved Hide resolved
eqt/ui/UIFormWidget.py Outdated Show resolved Hide resolved
eqt/ui/UIFormWidget.py Outdated Show resolved Hide resolved
test/test__formUI_status_test.py Show resolved Hide resolved
test/test__formUI_status_test.py Outdated Show resolved Hide resolved
test/test__formUI_status_test.py Outdated Show resolved Hide resolved
test/test__formUI_status_test.py Outdated Show resolved Hide resolved
test/test__formUI_status_test.py Outdated Show resolved Hide resolved
test/test__formUI_status_test.py Outdated Show resolved Hide resolved
self.assertEqual(states0, self.form.getAllWidgetStates())
self.click_Cancel()
self.assertEqual(states1, self.form.getAllWidgetStates())

def test_getWidgetState_returns_QLabel_value(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have decided on the method for applying the default widget values, please add a test for this.

Copy link
Collaborator Author

@DanicaSTFC DanicaSTFC Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After our discussion from yesterday, I do not think it is worth adding a test as I just invoked your methods. What do you think? (see new commits from today)

@DanicaSTFC DanicaSTFC added this to the v1.0.0 milestone Nov 22, 2023
@DanicaSTFC
Copy link
Collaborator Author

DanicaSTFC commented Nov 24, 2023

I merged the code with main (remove widget PR already included). The remove widget is not compatible with the default states because it deletes the widgets and the default cannot be restored. In particular, when we remove widgets and we press cancel, there is no way to restore the default widgets. The remove widget method needs to be changed for this PR to be merged with main.

Week 27 Nov - 1 Dec

After discussions with @paskino, we decided that we will save the removed widgets in a new dictionary. Thus, the remove widgets method will only hide the widgets rather than deleting them completely.

In order to finalise this PR, we need to use the insert widget method (PR #109) and widget number to reinstate the widgets in the correct location in the layout (issue #105 and issue #95).

Week 04 Dec - 08 Dec

We decided to merge this PR and leave the remove widget example returning errors when cancel is clicked. We will fix the problem in the other PRs.

@DanicaSTFC DanicaSTFC marked this pull request as draft November 30, 2023 15:01
@DanicaSTFC
Copy link
Collaborator Author

@lauramurgatroyd

The remove widget example is currently returning an error when cancel is clicked. This will be fixed once PR #109 is merged and issues #95 and #105 are solved. As discussed in today's group meeting, can we please merge this PR so the whole process becomes easier? Thanks.

@DanicaSTFC DanicaSTFC marked this pull request as ready for review December 4, 2023 12:23
Copy link
Collaborator

@paskino paskino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the method name. For the rest it seems good to me.

eqt/ui/UIFormWidget.py Outdated Show resolved Hide resolved
eqt/ui/UIFormWidget.py Outdated Show resolved Hide resolved
@DanicaSTFC DanicaSTFC requested a review from paskino December 4, 2023 18:21
Copy link
Member

@lauramurgatroyd lauramurgatroyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good except I had a question about the visibility of the default states

'''
if hasattr(self, 'widget_states'):
if not hasattr(self, 'widget_states'):
self.set_default_widget_states_visible_true()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we do this? What if the default state of a widget is that it is invisible and we want to re-apply that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it because the default states are added when the widgets are added which could be when the form is closed?

If so, should it be instead that the default state is saved upon first opening the form?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this is a later problem and we may need to open an issue about rethinking how the visibility is saved.

Copy link
Collaborator Author

@DanicaSTFC DanicaSTFC Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy with the way I saved the visibility: they are "not visible" in the default states because when we created the widgets they were, indeed, non visible.

If I want to apply default states which are not visible to a visible form, the restoration step should inherit the visibility of the form. I tried to change the visibility after the cancel button was clicked and the form was closed hoping the widgets would inherit the visibility from the opened form but I was not successful. I do agree with you and this was not done optimally here.

I cannot think of an example where we would want to restore non visible default states to a visible form.

I have addressed some problems with saving default states in my next PR. Hopefully once this and the next PR are merged, we could optimise these procedures before the milestone?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I think when we click the cancel button the form is open so it is not wrong to set the visibility true in that step.

Copy link
Member

@lauramurgatroyd lauramurgatroyd Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example I was thinking of would be a case where the default case has some advanced widgets that are by default hidden and could be shown using a checkbox or similar.

But I can see the docstring explains what is happening with the visibility being restored as True so I am happy to approve

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thank you, I will open an issue with this. #113

@DanicaSTFC DanicaSTFC merged commit 05bc80d into main Dec 7, 2023
6 checks passed
@DanicaSTFC DanicaSTFC deleted the save-entries-by-default branch December 7, 2023 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FormDialog should save all entries by default when 'OK' is pressed
3 participants