-
-
Notifications
You must be signed in to change notification settings - Fork 690
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
Add polling based window waiting for testbed #3047
Changes from 5 commits
081ac8f
dfbe752
03d2bfc
b0de666
8bb7443
bf48d6a
4f0bb3d
f403967
e528998
3a1a9ed
c44667c
a936bd2
1b12681
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The `wait_for_window()` window probe method, now has a polling based waiting mechanism. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import asyncio | ||
|
||
from rubicon.objc import objc_id, send_message | ||
|
||
from toga.constants import WindowState | ||
from toga_cocoa.libs import NSWindow, NSWindowStyleMask | ||
|
||
from .dialogs import DialogsMixin | ||
|
@@ -27,16 +30,34 @@ async def wait_for_window( | |
message, | ||
minimize=False, | ||
full_screen=False, | ||
state_switch_not_from_normal=False, | ||
expected_state=None, | ||
): | ||
await self.redraw( | ||
message, | ||
delay=( | ||
1.75 | ||
if state_switch_not_from_normal | ||
else 0.75 if full_screen else 0.5 if minimize else 0.1 | ||
), | ||
) | ||
await self.redraw(message, delay=0.1) | ||
if expected_state: | ||
timeout = 5 | ||
polling_interval = 0.1 | ||
exception = None | ||
loop = asyncio.get_running_loop() | ||
start_time = loop.time() | ||
while (loop.time() - start_time) < timeout: | ||
try: | ||
assert self.instantaneous_state == expected_state | ||
assert self.window._impl._pending_state_transition is None | ||
return | ||
except AssertionError as e: | ||
exception = e | ||
await asyncio.sleep(polling_interval) | ||
continue | ||
raise exception | ||
|
||
async def wait_for_window_close(self, pre_close_window_state): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I change wait_for_window_close() to close_and_wait_for_window(), so that we could determine the pre_close_window_state and close the window at the window probe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you start proposing method names like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the subject of naming, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a |
||
if pre_close_window_state == WindowState.FULLSCREEN: | ||
delay = 1 | ||
elif pre_close_window_state == WindowState.MINIMIZED: | ||
delay = 0.5 | ||
else: | ||
delay = 0.1 | ||
await self.redraw("Closing window", delay=delay) | ||
|
||
def close(self): | ||
self.native.performClose(None) | ||
|
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.
Are we still using the
minimize
andfull_screen
arguments? If so... why? My original question about this was "What's the difference betweenfull_screen=True
andexpected_state=FULL_SCREEN
" - if the answer is "nothing", then why do we need the other arguments?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.
Looks like, I had missed cleanup of unused parameters. I have removed them now.