from dash import Dash, Input, Output,State, callback, dcc, html,ALL,ctx
import dash_mantine_components as dmc
app = Dash(__name__)
app.layout = dmc.MantineProvider([
# Botones tipo A (triggers)
dmc.Button("Botón A 11", id={'type': 'A', 'index': "11"}),
dmc.Button("Botón A 23", id={'type': 'A', 'index': "23"}),
dmc.Button("Botón RESET", id={'type': 'A', 'index': "1111"}),
dmc.Divider(color="red"),
# Botones tipo B (targets)
dmc.Button("Botón B 111", id={'type': 'B', 'index': "111"},disabled=False,color="red"),
dmc.Button("Botón B 211", id={'type': 'B', 'index': "211"},disabled=True),
dmc.Button("Botón B 311", id={'type': 'B', 'index': "311"},disabled=True),
dmc.Button("Botón B 123", id={'type': 'B', 'index': "123"},disabled=True),
dmc.Button("Botón B 523", id={'type': 'B', 'index': "523"},disabled=True),
])
@callback(
Output("markdown", "style"),
Input("dropdown", "value"),
)
def update_markdown_style(color):
return {"color": color}
# from dash import Dash, html
@callback(
Output({'type': 'B', 'index': ALL}, 'disabled'),
Input({'type': 'A', 'index': ALL}, 'n_clicks'),
State({'type': 'B', 'index': ALL}, 'disabled'),
prevent_initial_call=True
)
def disable_buttons(n_clicks_list,n_disble):
if not any(n_clicks_list):
return [False] * len(ctx.outputs_list)
# Obtener el ID del botón que fue clickeado
trigger_index = list(ctx.triggered_id['index']) # [y, z] desempaquetar
# Lista para almacenar el estado disabled de cada botón tipo B
disabled_states = []
for n in range(len(ctx.outputs_list)):
button_index = list(ctx.outputs_list[n]['id']['index']) # [x, y, z] desempaquetar
# Verificar si el index del botón contiene los valores [y, z] al final
if len(button_index) >= len(trigger_index):
# Comprobar si los últimos elementos coinciden
if button_index[-len(trigger_index):] == trigger_index: #Comaparar y-y z-z
disabled_states.append(True) # Deshabilitar
else:
disabled_states.append(n_disble[n]) # Mantener actual
else:
disabled_states.append(False)
return disabled_states