This repository was archived by the owner on Apr 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (53 loc) · 2.04 KB
/
main.py
File metadata and controls
66 lines (53 loc) · 2.04 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from cefpython3 import cefpython as cef
import ctypes
import os
import platform
import sys
from threading import Thread
import uvicorn
import time
import app.server as server
def cef_settings():
if hasattr(sys, '_MEIPASS'):
# settings when packaged
settings = {'locales_dir_path': os.path.join(sys._MEIPASS, 'locales'),
'resources_dir_path': sys._MEIPASS,
'browser_subprocess_path': os.path.join(sys._MEIPASS, 'subprocess.exe')}
else:
# settings when unpackaged
settings = {}
return settings
def launch_cef():
check_versions()
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
cef.Initialize(settings=cef_settings())
browser = cef.CreateBrowserSync(url="http://localhost:8000/login",
window_title="Wikimedia Italia - Invio PEC")
if platform.system() == "Windows":
window_handle = browser.GetOuterWindowHandle()
insert_after_handle = 0
# X and Y parameters are ignored by setting the SWP_NOMOVE flag
SWP_NOMOVE = 0x0002
# noinspection PyUnresolvedReferences
ctypes.windll.user32.SetWindowPos(window_handle, insert_after_handle,
0, 0, 1600, 900, SWP_NOMOVE)
cef.MessageLoop()
del browser
cef.Shutdown()
def check_versions():
ver = cef.GetVersion()
print("[main.py] CEF Python {ver}".format(ver=ver["version"]))
print("[main.py] Chromium {ver}".format(ver=ver["chrome_version"]))
print("[main.py] CEF {ver}".format(ver=ver["cef_version"]))
print("[main.py] Python {ver} {arch}".format(
ver=platform.python_version(),
arch=platform.architecture()[0]))
assert cef.__version__ >= "57.0", "CEF Python v57.0+ required to run this"
def launch_unicorn():
uvicorn.run(server.app, host="127.0.0.1", port=8000, reload=False)
if __name__ == '__main__':
t1 = Thread(target=launch_unicorn)
t2 = Thread(target=launch_cef)
t1.start()
time.sleep(3)
t2.start()