-
Notifications
You must be signed in to change notification settings - Fork 0
/
keypad_app.py
72 lines (55 loc) · 2.06 KB
/
keypad_app.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
63
64
65
66
67
68
69
70
71
72
# -- coding: utf-8 --
import rumps, objc
import os, os.path
cwd = os.path.abspath(os.getcwd())
print(cwd)
import sys
sys.path.append(cwd + '/share/pync')
import dateutil.parser
import pync
class StatusBarApp(rumps.App):
def __init__(self, *args, **kwargs):
self.enabled_icon=cwd+"/share/Keypad.icns"
self.disabled_icon=cwd+"/share/Disabled.icns"
kwargs['icon'] = self.disabled_icon
try:
self.server = kwargs.pop("server")
except KeyError:
print("server not supplied")
self.server = type('dummy_server', (object,),
{'start':lambda *args: 0,
'stop':lambda *args: 0,
'running':None})()
super(StatusBarApp, self).__init__(*args, **kwargs)
self.notifier = pync.Notifier
self.server_running = False
@rumps.clicked("Edit config file")
def prefs(self, _):
os.system("open -e "+cwd+"/share/config.json")
@rumps.clicked("Run server")
def onoff(self, sender):
sender.state = not sender.state
if sender.state:
self.icon=self.enabled_icon
address = self.server.start()
self.notify("Server started", "Navigate to {} on your device".format(address))
self.server_running = True
else:
self.icon=self.disabled_icon
self.notify("Server stopped", "Click run server to begin")
self.server.stop()
self.server_running = False
@rumps.clicked('Quit')
def clean_up_before_quit(self, _):
print('*** Quitting ***')
if self.server.running:
self.notify("Server stopped", "Application closed")
self.server.stop()
rumps.quit_application()
def notify(self, subtitle, message=None):
if message is not None:
self.notifier.notify(message, subtitle=subtitle, title=self.name,
sender="red-box-labs.keypad")
else:
self.notifier.notify(subtitle, title=self.name,
sender="red-box-labs.keypad")