r0x0r / pywebview

Build GUI for your Python program with JavaScript, HTML, and CSS
https://pywebview.flowrl.com
BSD 3-Clause "New" or "Revised" License
4.62k stars 537 forks source link

Access window size on closing #573

Closed mrzv closed 4 years ago

mrzv commented 4 years ago

Specification

Description

I'm new to pywebview, and I'm trying to figure out the right way to do the following. I'd like to save the shape of the window (width and height), when the window is closed or closing. The problem is that when I try to do this from a callback (added to window.closing), everything hangs. I think there is a deadlock somewhere, but I don't quite understand the design.

What's the right way to do this?

I can access width and height from the function f I pass to webview.start(f, window), but that doesn't solve the issue of how to trigger this logic when the window is closing.

r0x0r commented 4 years ago

This is clearly a bug. The code invoked by on_closing is executed in a separate thread and is invoked after window is already closed. I think this can be resolved with an additional lock just to handle the closing case.

mrzv commented 4 years ago

Good to know. Thanks for looking into it. I wasn't sure if I was misunderstanding something, or if it was a bug.

Is there a good way to save the window shape on closing until this is fixed, or am I better off just waiting?

r0x0r commented 4 years ago

I will try to fix this asap. Meanwhile the best course solution would be periodically save window dimensions somewhere and read the final value on window closing. Stupid, but it should work.

r0x0r commented 4 years ago

@mrzv I pushed a fix for Cocoa to the closing-fix branch. Window dimensions and position should be accessible during window.closing event. Invoking other methods might still result in a deadlock though. Other platforms are not checked yet

mrzv commented 4 years ago

Thanks!

r0x0r commented 4 years ago

PR here https://github.com/r0x0r/pywebview/pull/575

mrzv commented 4 years ago

I should probably mention that I had the same deadlock, when I tried to read the shape of the window from window.closed. I don't know if it's relevant and the PR fixes both cases, but just FYI.

mrzv commented 4 years ago

c0ba525 fixed window.closing event, but not window.closed. That one still causes a deadlock.

r0x0r commented 4 years ago

Getting window properties on window.closed doesn’t make any sense, as the window does not longer exist. It should not cause a deadlock though.