-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtui.py
72 lines (54 loc) · 2.31 KB
/
tui.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
import main
import npyscreen
class MainForm(npyscreen.ActionFormV2):
def create(self):
self.addChannel = self.add(npyscreen.ButtonPress, name="Add", when_pressed_function=self.goToAdd)
self.deleteChannel = self.add(npyscreen.ButtonPress, name="Delete", when_pressed_function=self.goToDel)
self.webhook = self.add(npyscreen.ButtonPress, name="Edit webhook", when_pressed_function=self.goToWebhook)
def goToAdd(self):
self.parentApp.switchForm('ADD')
def goToDel(self):
self.parentApp.switchForm('DEL')
def goToWebhook(self):
self.parentApp.switchForm('WEBHOOK')
def on_cancel(self):
self.parentApp.switchForm(None)
class AddForm(npyscreen.ActionForm):
def create(self):
self.channelName = self.add(npyscreen.TitleText, name="Name:")
self.channelId= self.add(npyscreen.TitleText, name="Id:")
def on_cancel(self):
self.channelName.value = ""
self.channelId.value = ""
self.parentApp.setNextForm('MAIN')
def on_ok(self):
main.add(self.channelName.value, self.channelId.value)
self.on_cancel()
class DelForm(npyscreen.ActionForm):
def create(self):
self.channelName = self.add(npyscreen.TitleText, name="Name:")
for channel in list(main.getDict().keys())[1:]:
self.add(npyscreen.ButtonPress, name=channel)
def on_cancel(self):
self.channelName.value = ""
self.parentApp.setNextForm('MAIN')
def on_ok(self):
main.remove(self.channelName.value)
self.on_cancel()
class WebhookForm(npyscreen.ActionForm):
def create(self):
self.webhook = self.add(npyscreen.TitleText, name="Webhook url:")
def on_cancel(self):
self.webhook.value = ""
self.parentApp.setNextForm('MAIN')
def on_ok(self):
main.changeWebhook(self.webhook.value)
self.on_cancel()
class App(npyscreen.NPSAppManaged):
def onStart(self):
self.addForm('MAIN', MainForm, name="Ungoogled Youtube Subscriptions")
self.addForm('ADD', AddForm, name="Ungoogled Youtube Subscriptions")
self.addForm('DEL', DelForm, name="Ungoogled Youtube Subscriptions")
self.addForm('WEBHOOK', WebhookForm, name="Ungoogled Youtube Subscriptions")
if __name__ == '__main__':
mainApp = App().run()