-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrun.py
More file actions
67 lines (53 loc) · 1.42 KB
/
run.py
File metadata and controls
67 lines (53 loc) · 1.42 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
import webbrowser
import time
import signal
from utils import logger
import os
from pathlib import Path
from pystray import Icon as icon, Menu as menu, MenuItem as item
from PIL import Image
import sys
import subprocess
ROOT = Path(os.path.dirname(os.path.abspath(__file__)))
p = subprocess.Popen(['python', 'braindoor.py'])
running = True
time.sleep(2)
run_icon = Image.open('doc/nao.png')
stop_icon = Image.open('doc/zzz.png')
logger.info('Launch service')
def run_open():
url = "http://127.0.0.1:7860"
webbrowser.open(url)
def run_quit(icon):
p.terminate()
icon.stop()
sys.exit()
def run_switch(icon):
global running
global p
if running:
p.terminate()
running = False
icon.icon = stop_icon
icon.update_menu()
logger.info('Stop service')
else:
p = subprocess.Popen(['python', 'app.py'])
time.sleep(2)
running = True
icon.icon = run_icon
icon.update_menu()
logger.info('Restart service')
def switch_title(_):
if running:
return "Stop"
else:
return "Run"
def handler(signum,_):
if signum == signal.SIGINT:
p.terminate()
item_open = item("Open", run_open, visible=lambda _:running)
item_switch = item(switch_title, run_switch)
item_quit = item('Quit',run_quit)
signal.signal(signal.SIGINT, handler)
icon('braindoor', icon=run_icon, menu=menu(item_open,item_switch,item_quit)).run()