AIdeaText commited on
Commit
75e2703
·
verified ·
1 Parent(s): 0ca21c6

Update modules/ui/ui.py

Browse files
Files changed (1) hide show
  1. modules/ui/ui.py +44 -28
modules/ui/ui.py CHANGED
@@ -75,50 +75,66 @@ eventos = [
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
 
 
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