Skip to content

Commit

Permalink
Merge pull request #43 from YvoElling/feature/update-kivy
Browse files Browse the repository at this point in the history
Update kivy and kivyMD to latest version
  • Loading branch information
Staartvin authored Apr 3, 2023
2 parents 13bcddb + 623b4b2 commit 235d5a7
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 52 deletions.
1 change: 1 addition & 0 deletions StellaPay.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def build(self):
Window.show_cursor = self.get_config_option(config.ConfigurationOption.DEVICE_SHOW_CURSOR) == "True"

# Load .kv file
Builder.load_file("kvs/VerticalButtonWithIcon.kv")
Builder.load_file("kvs/DefaultScreen.kv")

Logger.debug("StellaPayUI: Starting event loop")
Expand Down
66 changes: 28 additions & 38 deletions kvs/DefaultScreen.kv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

MDIconButton:
icon: 'img/STEmediumnobg.png'
user_font_size: "450sp"
icon_size: "450dp"
size_hint: None, None
pos_hint: {"center_x":0.27,"center_y":0.63}
on_release: root.to_credits()
Expand All @@ -14,17 +14,20 @@
text: "[b]STELLA PAY[/b]"
font_size: '53sp'
pos_hint: {"center_x":0.27,"center_y":0.2}
size_hint_x: 0.4
size_hint_y: 0.2
font_name: 'fonts/orbitron/Orbitron-Bold.ttf'
markup: True

MDIconButton:
id: connection_state
user_font_size: "25sp"
icon_size: "25dp"
md_bg_color: app.theme_cls.purple_button
icon: "wifi-off"
pos_hint: {"center_x": 0.13,"center_y":0.79}

MDFillRoundFlatButton:
id: button_select_user
text: "Selecteer gebruiker"
font_size: '32sp'
pos_hint: {"center_x":0.7,"center_y":0.78}
Expand Down Expand Up @@ -71,42 +74,29 @@
on_press: root.select_recent_user(recent_user_two.text)
halign: "center"

MDIconButton:
icon: "account-clock"
text: "test"
user_font_size: "64sp"
pos_hint: {"center_x":0.58,"center_y":0.24}
on_press: root.on_select_guest()

MDLabel:
text: "Gasten"
pos_hint: {"x":0.55,"center_y":0.165}
font_style: "H6"
theme_text_color: "Primary"

MDIconButton:
icon: "tools"
user_font_size: "64sp"
pos_hint: {"center_x":0.7,"center_y":0.24}
on_press: root.on_select_onderhoud()

MDLabel:
text: "Onderhoud"
pos_hint: {"x":0.665,"center_y":0.165}
font_style: "H6"
theme_text_color: "Primary"

MDIconButton:
icon: "account-supervisor-circle"
user_font_size: "64sp"
pos_hint: {"center_x":0.82,"center_y":0.24}
on_press: root.on_select_beheer()

MDLabel:
text: "Beheer"
pos_hint: {"x":0.795,"center_y":0.165}
font_style: "H6"
theme_text_color: "Primary"
BoxLayout:
orientation: "horizontal"
size_hint_x: 0.4
size_hint_y: 0.25
pos_hint: {"center_x": (button_select_user.center_x / root.width), "center_y": (stella_pay.center_y / root.height)}

VerticalButtonWithIcon:
id: guest_button
pos_hint: {"center_y": 0.5}
icon: "account-clock"
label_text: "Gasten"

VerticalButtonWithIcon:
id: maintenance_button
pos_hint: {"center_y": 0.5}
icon: "tools"
label_text: "Onderhoud"

VerticalButtonWithIcon:
id: admin_button
pos_hint: {"center_y": 0.5}
icon: "account-supervisor-circle"
label_text: "Beheer"

MDSpinner:
id: spinner
Expand Down
3 changes: 1 addition & 2 deletions kvs/ProductScreen.kv
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BoxLayout:
orientation: "vertical"

MDToolbar:
MDTopAppBar:
id: toolbar
title: 'Stella Pay'
font_name: 'fonts/orbitron/Orbitron-Bold.ttf'
Expand All @@ -14,7 +14,6 @@
id: android_tabs
tab_bar_height: '50dp'
lock_swiping: True
# anim_duration: 0.0
text_color_normal: (0,0,0,1)
text_color_active: (1,1,1,1)
color_indicator: (0,0,0,1)
Expand Down
2 changes: 1 addition & 1 deletion kvs/ProfileScreen.kv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
anchor_x: 'center'
anchor_y: 'top'

MDToolbar:
MDTopAppBar:
title: 'STELLA PAY'
font_name: 'fonts/orbitron/Orbitron-Bold.ttf'
# md_bg_color: 0.078, 0.537, 0.882, 1
Expand Down
23 changes: 23 additions & 0 deletions kvs/VerticalButtonWithIcon.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<VerticalButtonWithIcon@BoxLayout>:
# Custom variables
icon: ""
label_text: ""
pos_x: 0.0
pos_y: 0.0

orientation: "vertical"
pos_hint: {"x": root.pos_x, "y": root.pos_y}
size_hint_y: 0.15
size_hint_x: 0.1

MDIconButton:
id: icon_of_button
icon: root.icon
icon_size: "64dp"
pos_hint: {"center_x": .5}

MDLabel:
text: root.label_text
font_style: "H6"
halign: "center"
theme_text_color: "Primary"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
smartcard~=0.3
Kivy~=2.1.0
requests==2.28.2
kivymd~=0.104.2
kivymd~=1.1.1
11 changes: 8 additions & 3 deletions scrs/DefaultScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def __init__(self, **kwargs):
# Register listener
App.get_running_app().data_controller.register_connection_listener(self.connection_change_listener)

# Listen to a user pressing the icon of a button
self.ids.admin_button.ids.icon_of_button.bind(on_press=self.on_select_beheer)
self.ids.guest_button.ids.icon_of_button.bind(on_press=self.on_select_guest)
self.ids.maintenance_button.ids.icon_of_button.bind(on_press=self.on_select_onderhoud)

def register_card_listener(self, card_connection_manager: "CardConnectionManager"):
card_connection_manager.register_listener(self.nfc_listener)

Expand Down Expand Up @@ -283,13 +288,13 @@ def move_to_register_card_screen(self, uid: str):
self.manager.get_screen(Screens.REGISTER_UID_SCREEN.value).nfc_id = uid
self.manager.current = Screens.REGISTER_UID_SCREEN.value

def on_select_guest(self):
def on_select_guest(self, _):
self.select_special_user("Gast Account")

def on_select_beheer(self):
def on_select_beheer(self, _):
self.select_special_user("Beheer Algemeen")

def on_select_onderhoud(self):
def on_select_onderhoud(self, _):
self.select_special_user("Beheer Onderhoud")

def select_special_user(self, user: str):
Expand Down
26 changes: 19 additions & 7 deletions scrs/ProductScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
from kivy.clock import Clock, mainthread
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, SlideTransition
from kivymd.material_resources import dp
from kivymd.uix.button import MDFlatButton, MDRaisedButton
from kivymd.uix.dialog import MDDialog
from kivymd.uix.spinner import MDSpinner

from ds.Product import Product
from ds.Purchase import Purchase
Expand Down Expand Up @@ -108,7 +110,7 @@ def show_products(self, products: Dict[str, List[Product]]):
Logger.debug(f"StellaPayUI: ({threading.current_thread().name}) Drawing tabs for the first time.")
self.tabs = []
for tab_name in products.keys():
tab = TabDisplay(text=tab_name)
tab = TabDisplay(title=tab_name)
self.ids.android_tabs.add_widget(tab)
self.tabs.append(tab)
else:
Expand All @@ -117,7 +119,7 @@ def show_products(self, products: Dict[str, List[Product]]):
start_time = time.time()

for tab in self.tabs:
for product in products[tab.text]:
for product in products[tab.title]:
# Get fun fact description of database
product_description = App.get_running_app().database_manager.get_random_fun_fact(product.get_name())

Expand All @@ -143,7 +145,7 @@ def show_products(self, products: Dict[str, List[Product]]):
)
)

Logger.debug(f"Loaded products of category {tab.text} (no skipping) in {time.time() - start_time} seconds")
Logger.debug(f"Loaded products of category {tab.title} (no skipping) in {time.time() - start_time} seconds")

Logger.debug(f"Loaded all products (no skipping) in {time.time() - start_time} seconds")

Expand Down Expand Up @@ -191,7 +193,7 @@ def on_timeout(self, dt):
#
# upon leaving the screen, cancel the timeout event
#
def on_leave(self, *args):
def on_pre_leave(self, *args):
self.timeout_event.cancel()

if self.final_dialog is not None:
Expand Down Expand Up @@ -245,7 +247,6 @@ def show_shopping_cart(self):
MDRaisedButton(text="Ja", on_release=self.on_confirm_payment),
],
)

# Open the dialog to display the shopping cart
self.shopping_cart_dialog.open()

Expand All @@ -270,6 +271,13 @@ def on_cancel_payment(self, dt):
def on_confirm_payment(self, dt=None):
Logger.info(f"StellaPayUI: Payment was confirmed by the user.")

spinner = MDSpinner(size_hint=(None, None), size=(dp(32), dp(32)), active=True)

# Show a spinner when user confirms the payment and hide the other buttons
self.shopping_cart_dialog.ids.button_box.add_widget(spinner)
self.shopping_cart_dialog.ids.button_box.children[1].opacity = 0.0
self.shopping_cart_dialog.ids.button_box.children[2].opacity = 0.0

asyncio.run_coroutine_threadsafe(self.submit_payment(), loop=App.get_running_app().loop)

async def submit_payment(self):
Expand All @@ -279,13 +287,17 @@ async def submit_payment(self):
self.shopping_cart
)

self.update_ui_after_payment(successfully_created_transactions)

@mainthread
def update_ui_after_payment(self, transaction_successful: bool):
# Reset instance variables
self.end_user_session()

if self.shopping_cart_dialog is not None:
self.shopping_cart_dialog.dismiss()

if successfully_created_transactions:
if transaction_successful:
self.show_thanks_dialog()
else:
self.show_failure_dialog()
Expand All @@ -296,7 +308,7 @@ def show_thanks_dialog(self):

self.final_dialog = MDDialog(
text="Gelukt! Je aankoop is geregistreerd!",
on_dismiss=self.on_thanks
on_dismiss=self.on_thanks,
)

self.timeout_event = Clock.schedule_once(self.on_thanks, 5)
Expand Down

0 comments on commit 235d5a7

Please sign in to comment.