Update modules/ui/ui.py
Browse files- modules/ui/ui.py +44 -28
modules/ui/ui.py
CHANGED
@@ -75,50 +75,66 @@ eventos = [
|
|
75 |
}
|
76 |
]
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
if
|
81 |
st.session_state.current_event = 0
|
|
|
|
|
82 |
|
83 |
-
|
84 |
-
def update_event(delta):
|
85 |
-
initialize_session_state() # Asegurar que el estado existe
|
86 |
-
st.session_state.current_event = (st.session_state.current_event + delta) % len(eventos)
|
87 |
-
|
88 |
-
# Contenedor del carrusel
|
89 |
def show_carousel():
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
with st.container():
|
|
|
|
|
|
|
|
|
96 |
col1, col2, col3 = st.columns([1, 6, 1])
|
97 |
|
98 |
with col1:
|
99 |
-
st.button("◀",
|
|
|
|
|
100 |
|
101 |
with col2:
|
102 |
-
|
103 |
-
|
104 |
st.image(
|
105 |
-
|
106 |
use_column_width=True,
|
107 |
caption=f"{event['titulo']} - {event['descripcion']}"
|
108 |
)
|
109 |
|
110 |
with col3:
|
111 |
-
st.button("▶",
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
st.
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
#########################################################
|
124 |
|
|
|
75 |
}
|
76 |
]
|
77 |
|
78 |
+
def initialize_carousel_state():
|
79 |
+
"""Inicializa todas las variables de estado necesarias para el carrusel"""
|
80 |
+
if not hasattr(st.session_state, 'current_event'):
|
81 |
st.session_state.current_event = 0
|
82 |
+
if not hasattr(st.session_state, 'carousel_initialized'):
|
83 |
+
st.session_state.carousel_initialized = True
|
84 |
|
85 |
+
#####################
|
|
|
|
|
|
|
|
|
|
|
86 |
def show_carousel():
|
87 |
+
"""Muestra el carrusel de imágenes con inicialización segura del estado"""
|
88 |
+
try:
|
89 |
+
# Inicialización segura del estado
|
90 |
+
initialize_carousel_state()
|
91 |
+
|
92 |
+
# Verificación adicional
|
93 |
+
if not hasattr(st.session_state, 'current_event'):
|
94 |
+
st.session_state.current_event = 0
|
95 |
+
st.rerun()
|
96 |
+
|
97 |
+
current_idx = st.session_state.current_event
|
98 |
|
99 |
with st.container():
|
100 |
+
st.markdown("<h2 style='text-align: center; margin-bottom: 30px;'>Eventos Relevantes</h2>",
|
101 |
+
unsafe_allow_html=True)
|
102 |
+
|
103 |
+
# Controles de navegación
|
104 |
col1, col2, col3 = st.columns([1, 6, 1])
|
105 |
|
106 |
with col1:
|
107 |
+
if st.button("◀", key="carousel_prev"):
|
108 |
+
st.session_state.current_event = (current_idx - 1) % len(eventos)
|
109 |
+
st.rerun()
|
110 |
|
111 |
with col2:
|
112 |
+
event = eventos[current_idx]
|
113 |
+
img = Image.open(event["imagen"]) if isinstance(event["imagen"], str) else event["imagen"]
|
114 |
st.image(
|
115 |
+
img,
|
116 |
use_column_width=True,
|
117 |
caption=f"{event['titulo']} - {event['descripcion']}"
|
118 |
)
|
119 |
|
120 |
with col3:
|
121 |
+
if st.button("▶", key="carousel_next"):
|
122 |
+
st.session_state.current_event = (current_idx + 1) % len(eventos)
|
123 |
+
st.rerun()
|
124 |
+
|
125 |
+
# Indicadores de posición
|
126 |
+
st.markdown("<div class='carousel-nav'>", unsafe_allow_html=True)
|
127 |
+
cols = st.columns(len(eventos))
|
128 |
+
for i, col in enumerate(cols):
|
129 |
+
with col:
|
130 |
+
if st.button("•", key=f"carousel_dot_{i}"):
|
131 |
+
st.session_state.current_event = i
|
132 |
+
st.rerun()
|
133 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
134 |
+
|
135 |
+
except Exception as e:
|
136 |
+
st.error(f"Error al mostrar el carrusel: {str(e)}")
|
137 |
+
logger.error(f"Error en show_carousel: {str(e)}")
|
138 |
|
139 |
#########################################################
|
140 |
|