-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
- 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
There was a problem hiding this 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.)
- Fix the order of target and recoil atom distribution tabs - Rollback the previous button creation in a loop
The pull-request was missing |
- 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
3838b78 does these:
|
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 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
Recoil element info is the title of the |
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
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
7eb99e7 fix this. |
@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? |
I don't think it's particularly useful, feel free to remove it. |
OK: 1738dbd |
|
…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
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. |
if (self.element_simulation.is_simulation_running() or | ||
self.element_simulation.is_optimization_running()) and \ | ||
self.name != self.recoil_element.name: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ifself.element_simulation.is_optimization_running()
is True.
That is not my change. What should we do with it?
There was a problem hiding this comment.
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 RecoilElement
s, so this check will change too. But before that happens, this should still be fixed some way.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
An always usable dialog would be even better, though that'll require moving the reference density to |
- 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
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) |
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 Simulation
s 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
if reference_density == self.reference_density: | ||
self.reference_density_element_default = reference_density |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
I can't merge this, the Edit the recoil element info cancel button doesn't work properly. Steps to reproduce:
Also, this needs to be fixed first. |
Closing pull request as outdated/redundant, the recoil element color features are ok in their current location. |
Fix: #228: