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

Move the color selection dialog from the "Recoil Element Info" window to the matplotlib window / widget #234

Closed
wants to merge 21 commits into from

Conversation

jkpnen
Copy link
Contributor

@jkpnen jkpnen commented Nov 30, 2021

Fix: #228:

  • Create new RecoilChangeColor class which removes color features from the older RecoilInfoDialog class
  • Move the color selection dialog from the "Recoil Element Info" window to the matplotlib window / widget
  • Simplify the code in a way that the buttons (in the GUI) are created in a loop

 - Create new RecoilChangeColor class which removes color features from the older RecoilInfoDialog class
 - Move the color selection dialog from the "Recoil Element Info" window to the matplotlib window / widget
 - Simplify the code in a way that the buttons (in the GUI) are created in a loop
- element.py: Rename method calls and refactor code
- energy_spectrum.py: Add a color change button
- recoil_atom_distribution.py: Separate open_reference_density_dialog and change_recoil_element_info methods
- reference_density_dialog.py: Rename the py-file, add properties to the class and remove unnecessary code
@jkpnen jkpnen marked this pull request as draft December 3, 2021 13:32
Copy link
Member

@tpitkanen tpitkanen left a comment

Choose a reason for hiding this comment

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

This PR is still a draft so I didn't look too in-depth.

Big issue: recoil_info_dialog.py is still refered to in the code (in recoil_atom_distribution.py). When renaming anything, always Ctrl+Shift+F the original name, no exceptions. (Also make sure that the Find in Files dialog is set to In Project, it seems to revert to Directory every now and then.)

dialogs/global_settings.py Outdated Show resolved Hide resolved
dialogs/simulation/reference_density_dialog.py Outdated Show resolved Hide resolved
dialogs/simulation/reference_density_dialog.py Outdated Show resolved Hide resolved
widgets/matplotlib/simulation/element.py Outdated Show resolved Hide resolved
widgets/matplotlib/simulation/element.py Outdated Show resolved Hide resolved
widgets/matplotlib/simulation/recoil_atom_distribution.py Outdated Show resolved Hide resolved
 - Fix the order of target and recoil atom distribution tabs
 - Rollback the previous button creation in a loop
@jkpnen
Copy link
Contributor Author

jkpnen commented Dec 10, 2021

This PR is still a draft so I didn't look too in-depth.

Big issue: recoil_info_dialog.py is still refered to in the code (in recoil_atom_distribution.py). When renaming anything, always Ctrl+Shift+F the original name, no exceptions. (Also make sure that the Find in Files dialog is set to In Project, it seems to revert to Directory every now and then.)

The pull-request was missing reqoil_info_dialog.py, which caused problems.

 - element.py: Add a check / an if statement for the recoil info dialog on the measurement tab
 - energy_spectrum.py: Fix tool tip messages
 - element.py: Add self to variables
 - recoil_atom_distribution.py: Gray out inactive bullet point rows
 - target.py: Share the reference density edit button between the both tabs
@jkpnen
Copy link
Contributor Author

jkpnen commented Dec 15, 2021

3838b78 does these:

  1. target.py
  2. UI modification
  3. recoil_atom_distribution.py

moving_color_selection

@jkpnen
Copy link
Contributor Author

jkpnen commented Dec 15, 2021

3520048

It would be better if the dialog remembered the state of the checkbox. Now if the user choose the user selection, then he/she/they have to check it again when the dialog is opened.

@tpitkanen , any idea how to do this?

reference_density_user_selection

@jkpnen
Copy link
Contributor Author

jkpnen commented Dec 15, 2021

da23afa: Add a warning text

The commit shares the same issue/feature as 3520048

using_user_selection

@tpitkanen
Copy link
Member

It would be better if the dialog remembered the state of the checkbox. Now if the user choose the user selection, then he/she/they have to check it again when the dialog is opened.

@tpitkanen , any idea how to do this?

Save the User selection value as a member variable in the RecoilElement object. Then look up that value when creating the Recoil element info dialog. I think most of the dialogs in Potku work like that.

Also, keep in mind that previous versions of Potku do not have this variable, so you'll have to do a sensible default value for old requests (if you haven't already done so). This change will also break backwards compatibility, but it can't really be avoided for this feature.

Finally, I would change to text to something like Manual reference density, or maybe invert the whole thing and call it Automatic reference density. The current wording is not immediately obvious (what selection?), and selection is a term used for element selections, which are not related to this.

@jkpnen
Copy link
Contributor Author

jkpnen commented Dec 16, 2021

It would be better if the dialog remembered the state of the checkbox. Now if the user choose the user selection, then he/she/they have to check it again when the dialog is opened.
@tpitkanen , any idea how to do this?

Save the User selection value as a member variable in the RecoilElement object. Then look up that value when creating the Recoil element info dialog. I think most of the dialogs in Potku work like that.

Also, keep in mind that previous versions of Potku do not have this variable, so you'll have to do a sensible default value for old requests (if you haven't already done so). This change will also break backwards compatibility, but it can't really be avoided for this feature.

Finally, I would change to text to something like Manual reference density, or maybe invert the whole thing and call it Automatic reference density. The current wording is not immediately obvious (what selection?), and selection is a term used for element selections, which are not related to this.

Where is that Recoil element info dialog?

Edit: You probably meant Reference density dialog or RecoilAtomDistributionWidget or TargetWidget

 - recoil_atom_distribution.py: Check if the user selection i.e. the manual reference density checkbox is checked
 - recoil_element.py: Save the user selection value as a member variable in the RecoilElement object
 - reference_density_dialog.py: Add a checker for the user selection
@tpitkanen
Copy link
Member

Recoil element info is the title of the ReferenceDensityDialog window, as seen in the middle screenshot. That's what I'm referring to.

@jkpnen
Copy link
Contributor Author

jkpnen commented Dec 17, 2021

Recoil element info is the title of the ReferenceDensityDialog window, as seen in the middle screenshot. That's what I'm referring to.

Okay. Actually it should be Target composition info without an element name (Cl in this case). I'll change that.

 - Change "Recoil element info" to "Reference density"
 - Remove an element name from the reference density dialog
@jkpnen jkpnen marked this pull request as ready for review December 20, 2021 13:04
@jkpnen
Copy link
Contributor Author

jkpnen commented Dec 21, 2021

Crashes if the user tries to add a new recoil element.

 - element.py: Add a new button
 - recoil_atom_distribution.py: Remove buttons activation feature
 - target.py: Add new buttons
@jkpnen
Copy link
Contributor Author

jkpnen commented Jan 11, 2022

Crashes if the user tries to add a new recoil element.

7eb99e7 fix this.

@jkpnen
Copy link
Contributor Author

jkpnen commented Jan 11, 2022

@tpitkanen, there is now this disabled "draw energy spectra" button. Do you know how to make it work like the wrench button? Or should we just remove it?

jakoavain

@tpitkanen
Copy link
Member

@tpitkanen, there is now this disabled "draw energy spectra" button. Do you know how to make it work like the wrench button? Or should we just remove it?

jakoavain

I don't think it's particularly useful, feel free to remove it.

@jkpnen
Copy link
Contributor Author

jkpnen commented Jan 11, 2022

@tpitkanen, there is now this disabled "draw energy spectra" button. Do you know how to make it work like the wrench button? Or should we just remove it?
jakoavain

I don't think it's particularly useful, feel free to remove it.

OK: 1738dbd

@tpitkanen
Copy link
Member

…ements):

 - recoil_atom_distribution.py: Add a warning box and remove a "missing button" feature
 - reference_density_dialog.py: Remove unused properties and add a warning box
@jkpnen
Copy link
Contributor Author

jkpnen commented Jan 13, 2022

a23bb7b fix these:

In my opinion a warning box is better than a missing button. Previously the reference density button disappeared (from the recoil atom distribution tab) if there were no elements in the simulation.

warning_no_elements_1
warning_no_elements_2

Comment on lines +137 to +139
if (self.element_simulation.is_simulation_running() or
self.element_simulation.is_optimization_running()) and \
self.name != self.recoil_element.name:
Copy link
Member

@tpitkanen tpitkanen Jan 17, 2022

Choose a reason for hiding this comment

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

There's no self.name anymore, so this will throw an exception if self.element_simulation.is_optimization_running() is True.

Also, because the automatic reference density update (#236) is simulation-wide (or at least I hope it is), manually setting it should apply for each RecoilElement. So, the checks in this if statement should be run for each RecoilElement in the simulation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no self.name anymore, so this will throw an exception if self.element_simulation.is_optimization_running() is True.

That is not my change. What should we do with it?

Copy link
Member

@tpitkanen tpitkanen Jan 19, 2022

Choose a reason for hiding this comment

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

It is:

Even if it wasn't, it still needs to be fixed.

I don't know what that inequality check does in practice. Run an optimization on the master branch version and figure out how it works. There's probably some other way to get that name.

Edit: in the future, changing the reference density should apply for all RecoilElements, so this check will change too. But before that happens, this should still be fixed some way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should there be own PR for this?

Copy link
Member

Choose a reason for hiding this comment

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

Should there be own PR for this?

It would be simpler to do the change here. After all, this is the PR that introduces the changes that can cause a crash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know how to fix this?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know how to fix this?

As I said, run an optimization on the master branch version and figure out how it works.

If it looks like the and name != self.recoil_element.name: part can be safely removed, do that. But before you do that, find out what the check actually does and why it's needed.

@tpitkanen
Copy link
Member

In my opinion a warning box is better than a missing button. Previously the reference density button disappeared (from the recoil atom distribution tab) if there were no elements in the simulation.

An always usable dialog would be even better, though that'll require moving the reference density to Simulation or similar.

 - recoil_atom_distribution.py: Add a new method call
 - recoil_element.py: Fix a crashing bug
 - target.py: Add a separate method for removing labels from the GUI
 - Return the initial reference density from the simulation element when the reference density is set by default
 - Add a critical warning box because the dynamic reference density is an unstable feature at the moment
 - Fix button state hassle
Comment on lines +118 to +126
reply = QtWidgets.QMessageBox.critical(
self, "Critical warning",
"This is an unstable feature. "
"It only changes the reference density of the selected "
"element %s.\n"
"\nDo not continue unless you are sure what you are doing!" %
self.recoil_element.element.symbol,
QtWidgets.QMessageBox.Ok,
QtWidgets.QMessageBox.Cancel)
Copy link
Member

Choose a reason for hiding this comment

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

This is more of a warning than a critical: https://en.wikipedia.org/wiki/Syslog#Severity_level

Also, f-strings (alongside the legacy .format()) are the main way to format strings in Potku.

Suggested change
reply = QtWidgets.QMessageBox.critical(
self, "Critical warning",
"This is an unstable feature. "
"It only changes the reference density of the selected "
"element %s.\n"
"\nDo not continue unless you are sure what you are doing!" %
self.recoil_element.element.symbol,
QtWidgets.QMessageBox.Ok,
QtWidgets.QMessageBox.Cancel)
reply = QtWidgets.QMessageBox.warning(
self, "Warning",
f"This is an experimental feature. "
f"It only changes the reference density of the selected "
f"element {self.recoil_element.element.symbol}.\n\n"
f"Do not continue unless you are sure what you are doing!",
QtWidgets.QMessageBox.Ok,
QtWidgets.QMessageBox.Cancel)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is more of a warning than a critical: https://en.wikipedia.org/wiki/Syslog#Severity_level

Yes, it's a critical warning.

Copy link
Member

Choose a reason for hiding this comment

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

A critical warning would be two separate severity levels in one, which is not possible.

As we can see in the Qt documentation, critical is reserved for critical errors (the most severe kind). Now if we look up "critical error" online, we can see that it's really severe.

A critical error is a serious computer error that forces the program to stop and it becomes impossible for the running program, operating system or software to continue working normally. This error might cause the computer to reboot or freeze.

Meanwhile, the thing here isn't even an error (because it's expected and normal), so according to the Qt documentation, it should be information at most. However, I think we can go with warning to catch the user's attention.

@@ -86,6 +86,8 @@ def __init__(self, directory: Path, name: str,
# e.g. Sample-01, Sample-02.optional_name,...
self._running_int = 1 # TODO: Maybe be saved into .request file?

self.manual_reference_density_checked = False
Copy link
Member

Choose a reason for hiding this comment

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

This is not a Request-wide setting, because there can be multiple Simulations in a single Request. Ideally, it would be stored in Simulation (I think), but right now it should be stored in RecoilElement because the reference_density is RecoilElement-specific too.


self.exec_()

def _state_changed(self):
if self.userSelectionCheckBox.isChecked():
self.scientific_spinbox.setDisabled(False)
# When the reference density is set by manually and the user
Copy link
Member

Choose a reason for hiding this comment

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

The cancel button doesn't work right. If I click Set the reference density manually, Ok (critical dialog) and then Cancel (reference density dialog), the checkbox stays enabled, but the numerical value doesn't persist. The yellow warning label doesn't show up either.

The correct behavior would be to cancel everything, including the checkbox.

I would remove the critical dialog completely, and just draw a red warning text in the Reference density dialog itself.

Alternatively, the critical dialog's Cancel button could be completely removed. Then only the Reference density dialog's Cancel and Ok buttons need to be checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The cancel button doesn't work right. If I click Set the reference density manually, Ok (critical dialog) and then Cancel (reference density dialog), the checkbox stays enabled, but the numerical value doesn't persist. The yellow warning label doesn't show up either.

A good catch. I tried to be sharp.

I would remove the critical dialog completely, and just draw a red warning text in the Reference density dialog itself.

Why?

Copy link
Member

Choose a reason for hiding this comment

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

I would remove the critical dialog completely, and just draw a red warning text in the Reference density dialog itself.

Why?

Because with another dialog that has Ok and Cancel buttons, there's more stuff to keep track of. If the new dialog were removed, or at least it had its Cancel button removed, the code would get simpler.

@@ -97,14 +99,41 @@ def __init__(self, recoil_element: RecoilElement,
self.formLayout.removeRow(self.widget)

self.isOk = False
self.isCancelled = False # Cancel-button's state
Copy link
Member

Choose a reason for hiding this comment

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

This seems to make everything more complicated, I'd suggest removing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do you know its state otherwise?

Copy link
Member

Choose a reason for hiding this comment

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

As discussed in our meeting, if the inner dialog's Cancel button is removed, this and related logic is not needed anymore. Another discussed alternative was to remove the warning dialog completely, and just add a red warning text (when the checkbox is checked / maybe always?).

I'll elaborate on the red warning text's advantage here: the dialog is fine the first time, but it'll get annoying if the user wants to set reference density for multiple elements.

An always present warning text is the simplest to implement, and I don't think there are any major drawbacks.

Comment on lines +84 to +85
if reference_density == self.reference_density:
self.reference_density_element_default = reference_density
Copy link
Member

Choose a reason for hiding this comment

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

This is dangerous because the member variable is only sometimes present. It should be always present (if needed at all), otherwise this can cause crashes when checking the value.

I would try to get rid of this new variable if possible.

It'll also cause issues when serializing/deserializing objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be always present (if needed at all), otherwise this can cause crashes when checking the value.

Where for example? And how to restore the original / default reference density value?

It'll also cause issues when serializing/deserializing objects.

Where for example?

Copy link
Member

Choose a reason for hiding this comment

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

It should be always present (if needed at all), otherwise this can cause crashes when checking the value.

Where for example? And how to restore the original / default reference density value?

As discussed in our meeting, just get the default reference density value that's used for all elements. It's currently defined as Profile.REFERENCE_DENSITY (which isn't really right but that'll have to wait for now, #241). Then there's no need to other save the value.

It'll also cause issues when serializing/deserializing objects.

Where for example?

Here for example

.manual_reference_density_checked:
density = self.current_recoil_element.reference_density
else:
density = self.current_recoil_element.reference_density_element_default
Copy link
Member

Choose a reason for hiding this comment

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

Crashes if a new sub-element is added in Recoil atom distribution:

Traceback (most recent call last):
  File "<potku>\widgets\matplotlib\simulation\recoil_atom_distribution.py", line 1034, in choose_element
    self.update_recoil_element_info_labels()
  File "<potku>\widgets\matplotlib\simulation\recoil_atom_distribution.py", line 1261, in update_recoil_element_info_labels
    density = self.current_recoil_element.reference_density_element_default
AttributeError: 'RecoilElement' object has no attribute 'reference_density_element_default'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A good catch.


self.manual_reference_density_checked = False
if reference_density == self.reference_density:
self.reference_density_element_default = reference_density
Copy link
Member

Choose a reason for hiding this comment

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

Unit test TestRecoilElement.test_serialization() fails due to the new member variable.

@jkpnen jkpnen closed this Jan 26, 2022
@jkpnen jkpnen reopened this Jan 26, 2022
@jkpnen
Copy link
Contributor Author

jkpnen commented Jan 26, 2022

The latest commit 2b35520 should be in its own branch and this pull-request should be closed / finished BEFORE it. Besides, 2b35520 can't be applied before this pull-request is closed. I will make a separate issue for 2b35520

@tpitkanen
Copy link
Member

The latest commit 2b35520 should be in its own branch and this pull-request should be closed / finished BEFORE it. Besides, 2b35520 can't be applied before this pull-request is closed. I will make a separate issue for 2b35520

I can't merge this, the Edit the recoil element info cancel button doesn't work properly. Steps to reproduce:

  1. Open a request > simulation > recoil atom distribution
  2. Click Edit the recoil element info (wrench icon)
  3. Click the color field, select a new color, press OK
  4. Press Cancel in the Recoil element info dialog
  5. The element's color doesn't change (good, works like it used to)
  6. Close Potku
  7. Reopen the request > simulation
  8. The element's color has changed to the selected one (bug)

Also, this needs to be fixed first.

@mlaitin mlaitin requested a review from tleppala March 8, 2023 13:21
@samivout
Copy link
Collaborator

Closing pull request as outdated/redundant, the recoil element color features are ok in their current location.

@samivout samivout closed this Jul 14, 2023
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.

Color selection dialog in the "Recoil Element Info" window is wrongly located
3 participants