This repository has been archived by the owner on Nov 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcostscreen.py
81 lines (59 loc) · 2.52 KB
/
costscreen.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
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import Screen
from kivy.properties import BooleanProperty, NumericProperty
from mainwidgets import MainButton, MessagePopup, SelectionPopup
from guest import *
class ReceiptCancelButton(MainButton):
unavailable = BooleanProperty()
def on_release(self):
if self.unavailable:
MessagePopup(message="You can not cancel this activity!").open()
else:
self.parent.parent.cancel()
class ReceiptBlock(BoxLayout):
def __init__(self, **kwargs):
# initiate with given activity information
self.name = kwargs.pop("name")
self.day = kwargs.pop("day")
self.price = kwargs.pop("price")
self.finished = self.day < get_day() + Activity.BOOK_AHEAD
super().__init__(**kwargs)
def _cancel(self):
Guest.book_activity("activities", self.day, Activity.no_activity().name)
self.parent.remove_widget(self)
ReceiptLayout.single.total -= self.price
MessagePopup(message="This activity is cancelled!")
def cancel(self):
popup = SelectionPopup(title="Warning",
message="After cancelling this activity, you'll have to rebook it in the main menu.\n"
"Are you sure you want to cancel this event?")
popup.add_choice(text="Cancel Activity",
on_release=lambda _: self._cancel())
popup.add_choice(text="Do Not Cancel")
popup.open()
class TotalBlock(BoxLayout):
def __init__(self, **kwargs):
self.total = kwargs.pop("total")
super().__init__(**kwargs)
class ReceiptLayout(BoxLayout):
single = None
total = NumericProperty()
def __init__(self, **kwargs):
super().__init__(**kwargs)
ReceiptLayout.single = self
def refresh(self):
layout = self.ids.receipt_blocks
layout.clear_widgets()
receipt, total = Guest.costs()
if receipt:
for activity in receipt:
# instantiate rows using activity objects
layout.add_widget(ReceiptBlock(name=activity.name,
day=activity.day,
price=activity.price))
else:
MessagePopup(message="You haven't booked any activity yet.").open()
self.total = total
class CostScreen(Screen):
def on_pre_enter(self, *args):
self.ids.receipt_layout.refresh()