-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python: Add support for invoke_from_event_loop
Fixes #420
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright © SixtyFPS GmbH <[email protected]> | ||
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial | ||
|
||
from slint import slint as native | ||
import threading | ||
from datetime import timedelta | ||
|
||
|
||
def test_threads(): | ||
global was_here | ||
was_here = False | ||
|
||
def invoked_from_event_loop(): | ||
global was_here | ||
was_here = True | ||
native.quit_event_loop() | ||
|
||
def quit(): | ||
native.invoke_from_event_loop(invoked_from_event_loop) | ||
|
||
thr = threading.Thread(target=quit) | ||
native.Timer.single_shot(timedelta(milliseconds=10), lambda: thr.start()) | ||
fallback_timer = native.Timer() | ||
fallback_timer.start(native.TimerMode.Repeated, timedelta( | ||
milliseconds=100), native.quit_event_loop) | ||
native.run_event_loop() | ||
thr.join() | ||
fallback_timer.stop() | ||
assert was_here == True |