-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainScreen.py
More file actions
166 lines (130 loc) · 6.23 KB
/
MainScreen.py
File metadata and controls
166 lines (130 loc) · 6.23 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
from kivy.uix.boxlayout import BoxLayout
from kivymd.uix.label import MDLabel
from kivymd.uix.button import MDRaisedButton
from kivymd.uix.list import OneLineListItem, MDList
from kivymd.uix.toolbar import MDTopAppBar
from kivy.uix.screenmanager import Screen
from kivy.uix.scrollview import ScrollView
from kivymd.uix.dialog import MDDialog
from GuardsScreen import GuardsScreen
from PositionsScreen import PositionsScreen
from ShavtzakScreen import ShavtzakScreen
class PositionDetailScreen(Screen):
def __init__(self, position, **kwargs):
super(PositionDetailScreen, self).__init__(**kwargs)
self.position = position
self.dialog = MDDialog(
title=f"Position: {position.name}",
text=f"Amount of Guards: {position.numOfGuards}\nGuarding Time: {position.guardingTime} minutes",
buttons=[
MDRaisedButton(text="Close", on_release=self.close_dialog)
]
)
self.dialog.get_normal_height()
def show_dialog(self):
self.dialog.open()
def close_dialog(self, instance):
self.dialog.dismiss()
class MainScreen(Screen):
def __init__(self, screen_manager, shavtzak_instance, **kwargs):
super(MainScreen, self).__init__(**kwargs)
self.shavtzak_instance = shavtzak_instance
# Create a toolbar for the screen
self.toolbar = MDTopAppBar(
title="Main Screen",
md_bg_color=(0.2, 0.7, 0.5, 1)
)
self.toolbar.pos_hint = {"top": 1}
self.add_widget(self.toolbar)
# Create a layout to hold the information
self.layout = BoxLayout(orientation="vertical", spacing=10, padding=10)
# Add the layout to the screen
self.add_widget(self.layout)
# Custom colors for the buttons
button_color = (0.2, 0.7, 0.5, 1)
text_color = (0, 0, 0, 1)
# "Guards" button
guards_button = MDRaisedButton(
text="Guards",
theme_text_color="Custom",
text_color=text_color,
md_bg_color=button_color,
pos_hint={"center_x": 0.35, "center_y": 0.84},
)
guards_button.bind(on_press=lambda x: self.switch_to_guards_screen(x, screen_manager))
self.add_widget(guards_button)
# "Positions" button
positions_button = MDRaisedButton(
text="Positions",
theme_text_color="Custom",
text_color=text_color,
md_bg_color=button_color,
pos_hint={"center_x": 0.48, "center_y": 0.84},
)
positions_button.bind(on_press=lambda x: self.switch_to_positions_screen(x, screen_manager))
self.add_widget(positions_button)
# "Make A Shavtzak" button
shavtzak_button = MDRaisedButton(
text="Make A Shavtzak",
theme_text_color="Custom",
text_color=text_color,
md_bg_color=button_color,
pos_hint={"center_x": 0.65, "center_y": 0.84},
)
shavtzak_button.bind(on_press=lambda x: self.switch_to_result_screen(x, screen_manager))
self.add_widget(shavtzak_button)
# Update information when the screen is shown
self.bind(on_enter=self.update_info)
def update_info(self, *args):
# Clear existing widgets from the layout
self.layout.clear_widgets()
# Create horizontal layout for guards list and positions list
horizontal_layout = BoxLayout(orientation="horizontal", spacing=10)
# Create vertical layout for guards list on the left
guards_scroll_view = ScrollView(size_hint=(0.5, 0.8))
guards_list = MDList()
guards_label = OneLineListItem(text="Guards List:", theme_text_color="Secondary")
guards_list.add_widget(guards_label)
index = 1
for guard in self.shavtzak_instance.guardList:
guard = str(index) + ". " + guard
item = OneLineListItem(text=guard)
guards_list.add_widget(item)
index += 1
guards_scroll_view.add_widget(guards_list)
horizontal_layout.add_widget(guards_scroll_view)
# Create vertical layout for positions list on the right
positions_scroll_view = ScrollView(size_hint=(0.5, 0.8))
positions_list = MDList()
positions_label = OneLineListItem(text="Positions List:", theme_text_color="Secondary")
positions_list.add_widget(positions_label)
for position in self.shavtzak_instance.positionList:
item = OneLineListItem(text=position.name, on_release=lambda x, p=position: self.show_position_details(p))
positions_list.add_widget(item)
positions_scroll_view.add_widget(positions_list)
horizontal_layout.add_widget(positions_scroll_view)
self.layout.add_widget(horizontal_layout)
def switch_to_guards_screen(self, instance, screen_manager):
# Switch to the Guards screen
if not any(isinstance(screen, GuardsScreen) for screen in screen_manager.screens):
guards_screen = GuardsScreen(self.shavtzak_instance, name="guards_screen")
screen_manager.add_widget(guards_screen)
self.switch_screen(screen_manager, "guards_screen")
def switch_to_positions_screen(self, instance, screen_manager):
# Switch to the Positions screen
if not any(isinstance(screen, PositionsScreen) for screen in screen_manager.screens):
positions_screen = PositionsScreen(self.shavtzak_instance, name="positions_screen")
screen_manager.add_widget(positions_screen)
self.switch_screen(screen_manager, "positions_screen")
def switch_to_result_screen(self, instance, screen_manager):
# Switch to the Result screen
if not any(isinstance(screen, ShavtzakScreen) for screen in screen_manager.screens):
result_screen = ShavtzakScreen(self.shavtzak_instance, name="result_screen")
screen_manager.add_widget(result_screen)
self.switch_screen(screen_manager, "result_screen")
def switch_screen(self, screen_manager, screen_name):
# Helper method to switch screens
screen_manager.current = screen_name
def show_position_details(self, position):
position_detail_screen = PositionDetailScreen(position)
position_detail_screen.show_dialog()