-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtray.py
61 lines (48 loc) · 1.49 KB
/
tray.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
#!/bin/python3
import wx.adv
import wx
import webbrowser
import subprocess
from os import popen
TRAY_TOOLTIP = 'mdTeXerPad'
TRAY_ICON = 'static/favicon.svg'
def create_menu_item(menu, label, func):
item = wx.MenuItem(menu, -1, label)
menu.Bind(wx.EVT_MENU, func, id=item.GetId())
menu.Append(item)
return item
class TaskBarIcon(wx.adv.TaskBarIcon):
def __init__(self, frame):
self.frame = frame
super(TaskBarIcon, self).__init__()
self.set_icon(TRAY_ICON)
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
def CreatePopupMenu(self):
menu = wx.Menu()
create_menu_item(menu, 'Start', self.on_start)
menu.AppendSeparator()
create_menu_item(menu, 'Exit', self.on_exit)
return menu
def set_icon(self, path):
icon = wx.Icon(path)
self.SetIcon(icon, TRAY_TOOLTIP)
def on_start(self, event):
webbrowser.open('http://localhost:5000')
def on_left_down(self, event):
print('This is the mdTeXerPad Taskbar server')
def on_exit(self, event):
wx.CallAfter(self.Destroy)
self.frame.Close()
class App(wx.App):
def OnInit(self):
frame=wx.Frame(None)
self.SetTopWindow(frame)
TaskBarIcon(frame)
return True
def main():
server = App(False)
#flask = popen('gunicorn --bind 0.0.0.0:5000 app:app')
subprocess.Popen(['python3', 'app.py'])
server.MainLoop()
if __name__ == '__main__':
main()