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

Window closing event fired after closing confirmation #1178

Closed
p4bl0- opened this issue Jul 23, 2023 · 4 comments
Closed

Window closing event fired after closing confirmation #1178

p4bl0- opened this issue Jul 23, 2023 · 4 comments

Comments

@p4bl0-
Copy link
Contributor

p4bl0- commented Jul 23, 2023

Specification

  • pywebview version: 4.2.2
  • python: 3.11.2
  • operating system: Linux Debian 12.0
  • web renderer: GTK (Qt is not working and can only display a blank window — note that I'm using KDE)

Description

The events.closing documentation says :

Event fired when pywebview window is about to be closed. If confirm_quit is set, then this event is fired before the close confirmation is displayed. If event handler returns False, the close operation will be cancelled.

This does not seem to be the case:

import webview
def bug ():
    print("hey")
window = webview.create_window('events.closing bug', confirm_close=True)
window.events.closing += bug
webview.start()

Expected behavior: when closing the window, see hey printed on stdout then see the confirmation dialog.

Actual behavior: when closing the window, the confirmation dialog appears and if canceled, nothing happens, if confirmed, the window gets closed and hey is printed on stdout.

The behavior is the same with events.closed.

Note that if the bug function returns False however, the behavior does not change using the closed event but it prevents the window from being closed using the closing event, so at least this works as expected.

However, if confirm_close is not set then returning False from the closing-event handler does not prevent the window from being closed, and that's probably a bug too.

@p4bl0-
Copy link
Contributor Author

p4bl0- commented Jul 23, 2023

I'd like to add that I found this bug while doing some tests because I wanted to be able to issue a specific confirmation dialog (something like "you have unsaved work, do you wish to save it before you quit?"), but trying to create a confirmation dialog while the window is closing does not work and makes the program hang indefinitely.


I tried create a new window to open the confirmation dialog from it but it still has the same behavior (even without the confirmation dialog, just creating a new window dring the closing event makes the whole program hand indefinitely).


I also tried to change the confirmation dialog's text using the localization parameter. This does work, but I cannot dynamically change the state of the confirm_close property of my window to issue the confirmation dialog only if the user did not save their work yet.

UPDATE: Okay I cannot do that because I use GTK and that the choice is made at init time, it would have worked is I was using Qt because the check is done at event time. I guess this is because their is no equivalent of event.ignore() in GTK? (new UPDATE: just returning True cancels the delete-event)

@p4bl0-
Copy link
Contributor Author

p4bl0- commented Jul 23, 2023

However, if confirm_close is not set then returning False from the closing-event handler does not prevent the window from being closed, and that's probably a bug too.

Fixed this part in #1179 for GTK (I don't know if other GUI lib are affected).

@p4bl0-
Copy link
Contributor Author

p4bl0- commented Jul 23, 2023

#1180 fixes this issue.

@p4bl0-
Copy link
Contributor Author

p4bl0- commented Aug 8, 2023

With #1181 merged I believe this issue can be closed.

@p4bl0- p4bl0- closed this as completed Aug 8, 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

No branches or pull requests

1 participant