-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
239 lines (155 loc) · 8.11 KB
/
main.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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
########################################################################
## IMPORTS
########################################################################
from kivy.lang import Builder
from typing import Union, NoReturn
from kivy.clock import Clock
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.tools.hotreload.app import MDApp
from kivy.core.window import Window
from kivy.animation import Animation
import os
import scripts.mdb as mdb # Importar el archivo mdb.py
from scripts.mdb import g
import sys
import threading
import time
Window.fullscreen = False
########################################################################
## MAIN CLASS
########################################################################
class MainApp(MDApp):
# Global screen manager variable
global screen_manager
screen_manager = ScreenManager()
########################################################################
## Build Function
########################################################################
def restart_gif(self):
# Reinicia la animación del GIF
original_source = self.ids.progress.source
self.ids.progress.source = '' # Cambia temporalmente la fuente a vacío
self.ids.progress.source = original_source # Vuelve a la fuente original para reiniciar la animación
def change_recipiente(self):
screen_manager.current = "recipiente"
def change_cono(self):
screen_manager.current = "sabor_cono"
def change_vaso(self):
screen_manager.current = "sabor_vaso"
def change_cono_vainilla(self):
screen_manager.current = "topping_cono_vainilla"
def change_cono_megamix(self):
screen_manager.current = "topping_cono_megamix"
def change_cono_chocolate(self):
screen_manager.current = "topping_cono_chocolate"
def change_vaso_vainilla(self):
screen_manager.current = "topping_vaso_vainilla"
def change_vaso_megamix(self):
screen_manager.current = "topping_vaso_megamix"
def change_vaso_chocolate(self):
screen_manager.current = "topping_vaso_chocolate"
def change_orden_lista_vaso_chocolate(self):
screen_manager.current = "orden_lista_vaso_chocolate"
###################################################################
##### En esta funcion se crean las pantallas que se van ausar #####
###################################################################
def build(self):
# Set App Title
self.title="E-LEGANT"
# Set App Theme
self.theme_cls.primary_palette='BlueGray'
# Load kv screen files to builder
screen_manager.add_widget(Builder.load_file("screens/inicio.kv"))
screen_manager.add_widget(Builder.load_file("screens/recipiente.kv"))
screen_manager.add_widget(Builder.load_file("screens/sabor_vaso.kv"))
screen_manager.add_widget(Builder.load_file("screens/sabor_cono.kv"))
screen_manager.add_widget(Builder.load_file("screens/topping_cono_chocolate.kv"))
screen_manager.add_widget(Builder.load_file("screens/topping_cono_megamix.kv"))
screen_manager.add_widget(Builder.load_file("screens/topping_cono_vainilla.kv"))
screen_manager.add_widget(Builder.load_file("screens/topping_vaso_chocolate.kv"))
screen_manager.add_widget(Builder.load_file("screens/topping_vaso_megamix.kv"))
screen_manager.add_widget(Builder.load_file("screens/topping_vaso_vainilla.kv"))
screen_manager.add_widget(Builder.load_file("screens/orden_lista_vaso_chocolate.kv"))
# self.install_idle(timeout=30)
# Return screen manager
return screen_manager
########################################################################
## This function runs on app start
########################################################################
#def on_start(self):
# Delay time for splash screen before transitioning to main screen
#Clock.schedule_once(self.change_screen1, 5) # Delay for 10 seconds
def on_start(self) -> NoReturn:
#Clock.schedule_once(self.generate_application_screens, 1)
#Clock.schedule_once(self.schedule_update_total_money_label, 2) # Programa la actualización después de un pequeño retraso
# Clock.schedule_once(self.setup_mdb, 2)
Clock.schedule_once(self.schedule_update_total_money_label, 2) # Programa la actualización después de un pequeño retraso
########################################################################
## This function changes the current screen to main screen
########################################################################
def on_idle(self, *args):
screen_manager.current = "inicio"
######################################################################################################
## Logica de mdb
######################################################################################################
def setup_mdb(self, dt=None):
port = '/dev/ttyUSB0' # Cambia esto según tu sistema operativo
ser = mdb.connect_to_mdb_rs232(port)
if ser:
mdb.enable_coin_acceptor(ser)
mdb.enable_bill_acceptor(ser)
print("Iniciando hilo de lectura del puerto MDB")
mdb_thread = threading.Thread(target=mdb.mdb_read_and_parse)
mdb_thread.daemon = True
mdb_thread.start()
def cancelar_venta(self):
print("Cancelando venta")
mdb.mdb_coin_change(g.total_money)
mdb.mdb_bill_reject()
g.total_money = 0 # Llama a la función para cancelar la venta cashless
# self.root.current = 'recipiente'
def schedule_update_total_money_label(self, dt):
Clock.schedule_interval(self.update_total_money_label, 1) # Actualiza el label cada segundo
def update_total_money_label(self, dt):
try:
total_money_label = self.root.get_screen('orden_lista_vaso_chocolate').ids.total_money_label
total_money_label.text = f"${g.total_money}"
# amount_to_charge_label = self.root.get_screen('orden_lista_vaso_chocolate').ids.amount_to_charge_label
# precio_helado=self.precio_pedido[0].replace("$","")
# precio_topping=self.precio_pedido[1].replace("$","")
# precio_helado = float(precio_helado)
# precio_topping =float(precio_topping)
# amount_to_charge_label.text = f"Monto a cobrar: {precio_helado + precio_topping - g.total_money} pesos"
print("intento")
except KeyError:
print("No se pudo encontrar el ID total_money_label")
except Exception as e:
print(f"Error al actualizar el label: {e}")
######################################################################################################
## Animaciones
######################################################################################################
def total_money_label(self, widget,name_screen):
total_money_label = self.root.get_screen(name_screen).ids.total_money_label
total_money_label.opacity = 0
amount_to_charge_label = self.root.get_screen(name_screen).ids.amount_to_charge_label
amount_to_charge_label.opacity = 0
anim = Animation(opacity=0, duration=2.5)
anim += Animation(opacity=1, duration=1.5)
anim.start(widget)
def idle_off(self, *args):
# cancel the timer
if self.root.current != 'inicio' and self.root.current != 'orden_lista_vaso_chocolate':
self.timer.cancel()
self.timer = None
print('on_leave')
def idle_on(self, *args):
# start the timer for 30 seconds
self.timer = Clock.schedule_once(self.on_idle, 30)
print('on_enter')
########################################################################
## RUN APP
########################################################################
MainApp().run()
########################################################################
## END ==>
########################################################################