Update modules/ui/ui.py
Browse files- modules/ui/ui.py +41 -38
modules/ui/ui.py
CHANGED
|
@@ -75,17 +75,50 @@ eventos = [
|
|
| 75 |
}
|
| 76 |
]
|
| 77 |
|
| 78 |
-
#
|
| 79 |
-
|
| 80 |
-
st.session_state
|
|
|
|
| 81 |
|
| 82 |
-
# Función para navegación
|
| 83 |
def update_event(delta):
|
|
|
|
| 84 |
st.session_state.current_event = (st.session_state.current_event + delta) % len(eventos)
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
#########################################################
|
| 91 |
|
|
@@ -388,37 +421,7 @@ def display_videos_and_info(lang_code, landing_t):
|
|
| 388 |
|
| 389 |
# Tab de Galería
|
| 390 |
with tab_gallery:
|
| 391 |
-
|
| 392 |
-
with st.container():
|
| 393 |
-
st.markdown("<h2 style='text-align: center;'>Eventos Relevantes</h2>", unsafe_allow_html=True)
|
| 394 |
-
|
| 395 |
-
with st.container():
|
| 396 |
-
col1, col2, col3 = st.columns([1, 6, 1])
|
| 397 |
-
|
| 398 |
-
with col1:
|
| 399 |
-
st.button("◀", on_click=update_event, args=(-1,), key="prev_btn")
|
| 400 |
-
|
| 401 |
-
with col2:
|
| 402 |
-
# Mostrar imagen actual
|
| 403 |
-
event = eventos[st.session_state.current_event]
|
| 404 |
-
st.image(
|
| 405 |
-
event["imagen"],
|
| 406 |
-
use_column_width=True,
|
| 407 |
-
caption=f"{event['titulo']} - {event['descripcion']}"
|
| 408 |
-
)
|
| 409 |
-
|
| 410 |
-
with col3:
|
| 411 |
-
st.button("▶", on_click=update_event, args=(1,), key="next_btn")
|
| 412 |
-
|
| 413 |
-
# Indicadores de posición (puntos)
|
| 414 |
-
st.markdown("<div class='carousel-nav'>", unsafe_allow_html=True)
|
| 415 |
-
for i in range(len(eventos)):
|
| 416 |
-
dot_class = "active" if i == st.session_state.current_event else ""
|
| 417 |
-
st.markdown(
|
| 418 |
-
f"<span class='carousel-dot {dot_class}' onclick='window.parent.streamlit.setComponentValue({i})'></span>",
|
| 419 |
-
unsafe_allow_html=True
|
| 420 |
-
)
|
| 421 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
| 422 |
|
| 423 |
#############################################################
|
| 424 |
#############################################################
|
|
|
|
| 75 |
}
|
| 76 |
]
|
| 77 |
|
| 78 |
+
# Inicialización robusta del session state
|
| 79 |
+
def initialize_session_state():
|
| 80 |
+
if 'current_event' not in st.session_state:
|
| 81 |
+
st.session_state.current_event = 0
|
| 82 |
|
| 83 |
+
# Función para navegación con verificación de estado
|
| 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 |
+
initialize_session_state() # Inicializar al mostrar el carrusel
|
| 91 |
+
|
| 92 |
+
with st.container():
|
| 93 |
+
st.markdown("<h2 style='text-align: center;'>Eventos Relevantes</h2>", unsafe_allow_html=True)
|
| 94 |
+
|
| 95 |
+
with st.container():
|
| 96 |
+
col1, col2, col3 = st.columns([1, 6, 1])
|
| 97 |
+
|
| 98 |
+
with col1:
|
| 99 |
+
st.button("◀", on_click=update_event, args=(-1,), key="prev_btn")
|
| 100 |
+
|
| 101 |
+
with col2:
|
| 102 |
+
# Mostrar imagen actual
|
| 103 |
+
event = eventos[st.session_state.current_event]
|
| 104 |
+
st.image(
|
| 105 |
+
event["imagen"],
|
| 106 |
+
use_column_width=True,
|
| 107 |
+
caption=f"{event['titulo']} - {event['descripcion']}"
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
with col3:
|
| 111 |
+
st.button("▶", on_click=update_event, args=(1,), key="next_btn")
|
| 112 |
+
|
| 113 |
+
# Indicadores de posición (puntos)
|
| 114 |
+
st.markdown("<div class='carousel-nav'>", unsafe_allow_html=True)
|
| 115 |
+
for i in range(len(eventos)):
|
| 116 |
+
dot_class = "active" if i == st.session_state.current_event else ""
|
| 117 |
+
st.markdown(
|
| 118 |
+
f"<span class='carousel-dot {dot_class}' onclick='st.session_state.current_event = {i}; st.rerun()'></span>",
|
| 119 |
+
unsafe_allow_html=True
|
| 120 |
+
)
|
| 121 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 122 |
|
| 123 |
#########################################################
|
| 124 |
|
|
|
|
| 421 |
|
| 422 |
# Tab de Galería
|
| 423 |
with tab_gallery:
|
| 424 |
+
show_carousel()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
|
| 426 |
#############################################################
|
| 427 |
#############################################################
|