-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathmain.py
More file actions
53 lines (41 loc) · 1.23 KB
/
main.py
File metadata and controls
53 lines (41 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import src
import multiprocessing
import signal
import sys
import os
import asyncio
from qasync import run, QEventLoop
from functools import partial
os.environ["QT_API"] = "PyQt6"
async def main(event_loop):
def close_future(future, loop):
loop.call_later(10, future.cancel)
future.cancel()
future = asyncio.Future()
window = src.Window(event_loop)
if hasattr(src.App, "aboutToQuit"):
getattr(src.App, "aboutToQuit").connect(
partial(close_future, future, event_loop))
try:
event_loop.add_signal_handler(signal.SIGINT, lambda: window.close())
event_loop.add_signal_handler(signal.SIGTERM, lambda: window.close())
except NotImplementedError: # windows...
pass
await future
if isinstance(future.result(), int):
return future.result()
return 0
if __name__ == '__main__':
# Pyinstaller fix
multiprocessing.freeze_support()
try:
try:
loop = QEventLoop()
asyncio.set_event_loop(loop)
sys.exit(loop.run_until_complete(main(loop)))
except asyncio.exceptions.CancelledError:
sys.exit(0)
except RuntimeError:
sys.exit(0)