-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
126 lines (91 loc) · 4.02 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import os, subprocess
import PySimpleGUIQt as sg
import configurator, authentication, qr
log = configurator.LOG.get()
cfg = configurator.CFG().load("settings.json")
lang = configurator.CFG().load("language.json")
text = configurator.CFG().load("language.json")[cfg["language"].lower()]
for key, value in lang["common"].items():
text[key] = value
class GUI():
def __init__(self):
self.WINDOW_TITLE = "MobilePayAlerts"
self.event_combiner = {
"_BTN_GENQR_": qr.generate
}
tab_1 = sg.Tab(text["tab_1"]["text"],
[[sg.HorizontalSeparator()],
[sg.Button("Start", key="_BTN_START_", size=(250, 40), visible=True)],
[sg.HorizontalSeparator()],
[sg.Button("Stop", key="_BTN_STOP_", size=(250, 40), visible=False)],
[sg.HorizontalSeparator()],
[sg.Button("Test", key="_BTN_TEST_", size=(250, 40), visible=True)],
[sg.HorizontalSeparator()]
])
tab_2 = sg.Tab(text["tab_2"]["text"],
[[sg.Text(text["label_settings"]["text"], font=("def", "def", "bold"))],
[sg.Text(text["label_name"]["text"], size=(11, 0.6)), sg.InputText(default_text=cfg["default_name"], key=text["input_name"]["key"], do_not_clear=True, tooltip=text["input_name"]["tt"])],
[sg.Text(text["label_msg"]["text"], size=(11, 0.6)), sg.InputText(default_text=cfg["default_msg"], key=text["input_msg"]["key"], do_not_clear=True, tooltip=text["input_msg"]["tt"])],
[sg.Text(text["label_lang"]["text"], size=(11, 0.6)), sg.InputCombo(text["languages"], key=text["combobox"]["key"], default_value=cfg["language"].capitalize())],
[sg.Button(text["btn_save"]["text"], key=text["btn_save"]["key"], tooltip=text["btn_save"]["tt"])],
[sg.HorizontalSeparator()],
[sg.Button(text["btn_generate"]["text"], key=text["btn_generate"]["key"], tooltip=text["btn_generate"]["tt"])],
[sg.HorizontalSeparator()],
[sg.Text(text["label_other_settings"]["text"], font=("def", "def", "bold"))],
[sg.Button(text["btn_reset"]["text"], key=text["btn_reset"]["key"]), sg.Button(text["btn_setup"]["text"], key=text["btn_setup"]["text"])],
])
self.layout = [[sg.TabGroup([[tab_1, tab_2]])]]
def main(self):
window = sg.Window(self.WINDOW_TITLE, size=(250, 250)).Layout(self.layout)
print(window)
while True:
event, values = window.Read()
if event is None or event == "Exit":
break
# Main Tab
if event == "_BTN_START_":
window.FindElement(event).Update(visible=False)
# self.receive_alerts = subprocess.Popen(["alerts.exe", "startReceiving"])
self.receive_alerts = subprocess.Popen(["python", "alerts.py", "startReceiving"])
window.FindElement("_BTN_STOP_").Update(visible=True)
elif event == "_BTN_STOP_":
window.FindElement(event).Update(visible=False)
self.receive_alerts.kill()
window.FindElement("_BTN_START_").Update(visible=True)
elif event == "_BTN_TEST_":
window.FindElement(event).Update(visible=False)
result = subprocess.run(["alerts.exe", "testAlert"])
window.FindElement(event).Update(visible=True)
# Settings Tab
elif event == "_BTN_SAVE_":
self.save(values)
elif event == "_BTN_SETUP_":
Main().setup()
elif event == "_BTN_RESET_":
Main().resetConfig()
elif event in self.event_combiner:
self.event_combiner[event]()
print(event, values)
window.Close()
def save(self, values):
cfg["language"] = values["_COMBO_LANG_"]
cfg["default_name"] = values["_INPUT_NAME_"]
cfg["default_msg"] = values["_INPUT_MSG_"]
configurator.CFG().save("settings.json", cfg)
class Main():
def __init__(self):
log.info("\n")
log.info("Checking for Pushbullet and Streamlabs token")
if cfg["pb_token"] == "" or cfg["sl_token"] == "":
sg.PopupOK("Opsætning", "Opsætning er krævet")
self.setup()
log.info("Pushbullet and Streamlabs tokens exist!")
GUI().main()
def setup(self):
log.info("Starting setup!")
authentication.runServer()
log.info("Setup done!")
def resetConfig(self):
log.info("Resetting config!")
configurator.CFG().reset("settings.json")
Main()