Add more arguments for edit string popups#129
Conversation
5d0e5a5 to
c240f22
Compare
cmeyer
left a comment
There was a problem hiding this comment.
On macOS, it looks like this.
On Windows, it looks like this.
On both platforms, the Escape key no longer works - as expected since the self.__request_close_fn() was removed.
Tested from console with this script:
from nion.ui import Dialog
Dialog.pose_edit_string_pop_up("X", lambda x: None, window=_window)
I would recommend:
- switch back to the old style window that does not have close/min/max buttons.
- model it after .Net MessageBox function
- restore the escape handling.
I cannot reproduce the escape-triggering-console message problem - so let's try to reproduce that reliably and fix it separately before this PR.
The script you ran hadn't set the window_style so it was defaulting to a window vs if you pass in a "default" it will be the modeless style. The modeless style would throw the console error when return was pressed, while the window would behave properly. I updated the code to check that the window style is not "default" before running the close function which means the escape now should work again in your tests. If there are any other dialog options that cause that error, i.e. that don't make a window, then it should check those too, but I haven't done that yet. |
|
@cmeyer I removed the windows_style parameter so now it will be a popup by default. |
cmeyer
left a comment
There was a problem hiding this comment.
A few quick points...
The reject function in pose_confirmation_pop_up has the same bug that was fixed in this PR in pose_edit_string_pop_up: the extra call to __request_close_fn. The pose_select_item_pop_up is already correct. That also points to a quick change or follow-up maintenance PR: pull the common Handler base out of each of those functions so that the common code is only written once.
Also, the arguments to button text arguments to pose_confirmation_pop_up should be None rather than hard coded strings. Making that change will match how pose_edit_string_pop_up handles it.
|
The same |
There are many similar Handler code blocks throughout swift, but consolidating them should be a separate project. The handler in the pose_confirmation popup is intentionally different from pose_edit_string_popup. It allows for escape to trigger closing but does NOT allow enter to confirm. That limitation was made as I implemented it for removing a workspace and thought it shouldn't be able to click enter to do that, but maybe it should be consistent. |
Will do! |
Because it was a "popup" window it doesn't extra call. I removed the window_style from the arguments so it is always a "popup". |
cmeyer
left a comment
There was a problem hiding this comment.
I think we should change the name of all of the functions to use popup instead of pop_up. To maintain backwards compatibility, we can have lines at the bottom of the file (with a compatibility comment) like:
pose_edit_string_pop_up = pose_edit_string_popup
pose_select_item_pop_up = pose_select_item_popup
There is no need for a pose_confirmation_pop_up line as it is just being introduced with this PR.
|
The position is now defaults based off the arguments passed into the function: """
If the position is not None then the popup will be centered on that point.
Otherwise, the popup will use get_popup_position to be centered on the top third of the parent_rect parameter \
if it is not None or the window if parent_rect is None.
""" |
cmeyer
left a comment
There was a problem hiding this comment.
From @Ion-e
it changes the popup dialog used in the renaming of collections
I think we're going to need something more sophisticated for window positioning - or at least able to address the positioning requirements that the top-left of the dialog appears at a particular point (see CollectionsWidget in nionswift).
|
Merging with cleanup, ebb47f0 |


Fixes #132. Adds arguments for the window style and Cancel and Done buttons.
Remove unnecessary call to __request_close_fn in reject that caused a console error when clicking escape.
If either button is a string then it will display the buttons, otherwise it will have the existing behavior of not having buttons.