-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuardsScreen.py
99 lines (86 loc) · 3.53 KB
/
GuardsScreen.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
from kivy.clock import Clock
from kivy.uix.screenmanager import Screen
from kivymd.uix.label import MDLabel
from kivymd.uix.button import MDFlatButton
from kivymd.uix.textfield import MDTextField
from kivymd.uix.toolbar import MDTopAppBar
from Shavtzak import Shavtzak
class GuardsScreen(Screen):
def __init__(self, shavtzak_instance, **kwargs):
super(GuardsScreen, self).__init__(**kwargs)
self.shavtzak_instance = shavtzak_instance
# Create a toolbar for the screen
self.toolbar = MDTopAppBar(
title="Guards Screen",
md_bg_color=(0.2, 0.7, 0.5, 1),
right_action_items=[["arrow-right", lambda x: self.back()]]
)
self.toolbar.pos_hint = {"top": 1}
self.add_widget(self.toolbar)
# Add an entry for the guard's name
self.guard_entry = MDTextField(
hint_text="Enter Guard's Name To Add",
size_hint=(0.8, 1),
pos_hint={"center_x": 0.5, "center_y": 0.7},
font_size=22,
)
self.add_widget(self.guard_entry)
# Add a button to add the guard
add_guard_button = MDFlatButton(
text="Add Guard",
font_size=17,
text_color=(0, 0, 0, 1),
md_bg_color=(0.2, 0.7, 0.5, 1),
pos_hint={"center_x": 0.5, "center_y": 0.6},
)
add_guard_button.bind(on_press=self.add_guard)
self.add_widget(add_guard_button)
# Add a label for feedback
self.label = MDLabel(
halign="center",
pos_hint={"center_x": 0.5, "center_y": 0.5},
theme_text_color="Secondary"
)
self.add_widget(self.label)
# Add an entry for the guard's name to delete
self.guard_delete_entry = MDTextField(
hint_text="Enter Guard's Name To Delete",
size_hint=(0.8, 1),
pos_hint={"center_x": 0.5, "center_y": 0.4},
font_size=22,
)
self.add_widget(self.guard_delete_entry)
# Add a button to delete the guard
delete_guard_button = MDFlatButton(
text="Delete Guard",
font_size=17,
text_color=(0, 0, 0, 1),
md_bg_color=(0.2, 0.7, 0.5, 1),
pos_hint={"center_x": 0.5, "center_y": 0.3},
)
delete_guard_button.bind(on_press=self.delete_guard)
self.add_widget(delete_guard_button)
def back(self):
# Handle going back to the main screen
print("Going back to the main screen")
self.manager.current = "main_screen"
def add_guard(self, instance):
# Handle adding a guard
guard_name = self.guard_entry.text
if self.shavtzak_instance.addGuard(guard_name):
self.label.text = "Add Successfully"
Clock.schedule_once(lambda dt: setattr(self.label, 'text', ""), 3)
else:
self.label.text = "Existing Guard, Enter Other Guard's Name"
Clock.schedule_once(lambda dt: setattr(self.label, 'text', ""), 3)
self.guard_entry.text = ""
def delete_guard(self, instance):
# Handle deleting a guard
guard_name = self.guard_delete_entry.text
if self.shavtzak_instance.deleteGuard(guard_name):
self.label.text = "Delete Successfully"
Clock.schedule_once(lambda dt: setattr(self.label, 'text', ""), 3)
else:
self.label.text = "Not Existing Guard, Enter Other Guard's Name"
Clock.schedule_once(lambda dt: setattr(self.label, 'text', ""), 3)
self.guard_delete_entry.text = ""