-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
62 lines (42 loc) · 1.52 KB
/
main.py
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
from threading import Thread
from loguru import logger
from nicegui import app, ui
from PIL import Image
from pystray import Icon, Menu, MenuItem
from src.interface.gui import DaCapoUI
from src.utils import get_text
# from niceguiToolkit.layout import inject_layout_tool
# inject_layout_tool()
_ = get_text()
logger.add('dacapo.log', format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | "
"<level>{level: <7}</level> | "
"<level>{message}</level>"
)
def on_open():
app.native.main_window.show()
def on_hide():
app.native.main_window.hide()
def on_exit():
icon.stop()
app.shutdown()
def show_exception(e):
logger.exception(e)
ui.notify(str(e), position='top', type='negative')
def startup():
"""https://github.com/zauberzeug/nicegui/issues/3149"""
@ui.page('/')
def create_ui():
DaCapoUI().show()
# app.on_exception(lambda e: show_exception(e))
# if __name__ == "__mp_main__":
# DaCapoUI().show()
# ui.run(title='DaCapo', window_size=(1200, 800), reload=True)
if __name__ == "__main__":
image = Image.open('static/logo/logo.ico')
menu = Menu(MenuItem(_('打开'), on_open, default=True), MenuItem(_('隐藏'), on_hide), MenuItem(_('退出'), on_exit))
icon = Icon('DaCapo', image, menu=menu)
Thread(target=icon.run, daemon=True).start()
app.on_startup(startup)
app.on_exception(lambda e: show_exception(e))
ui.run(title='DaCapo', window_size=(1200, 800), reload=False)
icon.stop()