diff --git a/main.py b/main.py index 1da11b3f59f687c1cc3046c9d3e55977d2a04f25..54e4bb31165feeefec1ef2efc9e2ccd4f124534e 100644 --- a/main.py +++ b/main.py @@ -36,6 +36,13 @@ max_topic = utils.MaxTopicLength() # buffer for mqtt log message_queue = queue.Queue() +# buttons to show only in expert-view (additionally to coordinator-div and arm/object divs) +expert_view_buttons = [ + 'send-place-a-model-details', + 'send-place-b-model-details', + 'send-place-b-demo-initial_scene' +] + # button-id: (topic, payload) commands = { 'send-place-a-model': ('place-a/model', '1'), @@ -120,7 +127,13 @@ topics_enabled_once_seen = [ svg_image_topic = 'place-b/model/svg/path' button_style_normal = {"marginRight": "15px", "padding": "2px", "height": "20px", "line-height": "0", "marginTop": "5px"} +button_style_normal_invisible = {"marginRight": "15px", "padding": "2px", "height": "20px", "line-height": "0", "marginTop": "5px", 'display': 'none'} + button_style_exit = {**button_style_normal, "backgroundColor": "red", "color": "white"} +button_style_exit_invisible = {**button_style_normal_invisible, "backgroundColor": "red", "color": "white"} + +buttons_style = {"display":"none", "border": "1px black solid", "border-radius": "5px", "marginTop": "5px"} + textarea_style_normal = {'width': '100%', 'height': '200px', 'resize': 'vertical'} tab_height = '3vh' tabs_style = {'line-height': tab_height} @@ -195,11 +208,11 @@ app.layout = html.Div([ html.Button('RAG B Ready', id='send-place-b-rag-ready', style=button_style_normal), html.Button('Dummy Ready', id='send-dummy-ready', style=button_style_normal), # ], className='row'), - ], className="four columns"), + ], className="four columns", id='coordinator-div', style={'display': 'none'}), html.Div([ # Column for commands of place a html.H3("Commands Place A"), html.Button('Model', id='send-place-a-model', style=button_style_normal), - html.Button('Model (Details)', id='send-place-a-model-details', style=button_style_normal), + html.Button('Model (Details)', id='send-place-a-model-details', style=button_style_normal_invisible), html.Button('Rewind', id='send-place-a-rewind', style=button_style_normal), html.Button('Start', id='send-place-a-start', style=button_style_normal), html.Button('Exit', id='send-place-a-exit', style=button_style_exit), @@ -209,12 +222,12 @@ app.layout = html.Div([ html.Div([ # Column for commands of place b html.H3("Commands Place B"), html.Button('Model', id='send-place-b-model', style=button_style_normal), - html.Button('Model (Details)', id='send-place-b-model-details', style=button_style_normal), + html.Button('Model (Details)', id='send-place-b-model-details', style=button_style_normal_invisible), html.Button('Rewind', id='send-place-b-rewind', style=button_style_normal), html.Button('Start', id='send-place-b-start', style=button_style_normal), html.Button('Exit', id='send-place-b-exit', style=button_style_exit), # html.Button('obj-Red -> Red', id='send-place-b-demo-objRed-red', style=button_style_normal), - html.Button('initial_scene', id='send-place-b-demo-initial_scene', style=button_style_normal), + html.Button('initial_scene', id='send-place-b-demo-initial_scene', style=button_style_normal_invisible), # html.Button('arm1-moving', id='send-place-b-demo-arm1-moving', style=button_style_normal), # html.Button('arm1-idle', id='send-place-b-demo-arm1-idle', style=button_style_normal), # html.Button('arm2-moving', id='send-place-b-demo-arm2-moving', style=button_style_normal), @@ -229,14 +242,14 @@ app.layout = html.Div([ {'label': 'Moving', 'value': 'moving'}] , 'moving', id='send-arm-state-state', inline=True, style={"marginRight": "10px", "marginTop": "5px"}), html.Button('Send', id='send-arm-state', style=button_style_normal) - ], className='row', style={"display":"flex", "border": "1px black solid", "border-radius": "5px", "marginTop": "5px"}), + ], className='row', style=buttons_style, id='arm-buttons'), html.Div([ dcc.RadioItems(['blue1', 'blue2', 'green1', 'green2'], 'blue1', id='send-obj-pos-obj', inline=True, style={"marginRight": "10px", "marginTop": "5px"}), dcc.RadioItems(['cz1', 'G1', 'G2', 'B1', 'B2'], 'cz1', id='send-obj-pos-pos', inline=True, style={"marginRight": "10px", "marginTop": "5px"}), html.Button('Send', id='send-obj-pos', style=button_style_normal) - ], className='row', style={"display":"flex", "border": "1px black solid", "border-radius": "5px", "marginTop": "5px"}) + ], className='row', style=buttons_style, id='object-buttons') ], className="four columns"), ], className='row'), # dcc.Markdown("---"), @@ -266,6 +279,12 @@ app.layout = html.Div([ value=["Auto-Scroll"], labelStyle={"display": "inline-block"}, ), + dcc.Checklist( + id="expert-view", + options=[{"label": "Expert View", "value": "expert-view"}], + value=[], + labelStyle={"display": "inline-block"}, + ), dcc.Checklist( id="mqtt-connected", options=[{"label": "MQTT connected?", "value": "yes", "disabled": True}], @@ -343,40 +362,24 @@ def send_json_for_object_to_topic(json_content: str, obj, topic: str): mqttc.publish(topic=topic, payload=obj.SerializeToString()) -# @app.callback( -# Output('hidden-div-scene-a', 'children'), -# Input('send-place-a-update', 'n_clicks'), -# State('place-a-input-json', 'value') -# ) -# def send_scene_a(n_clicks, json_content): -# """ -# Send scene in place a -# :param n_clicks: button.clicks -# :param json_content: state of place-a-input-json -# :return: no_update -# """ -# if n_clicks: -# scene = cgv_connector_pb2.Scene() -# send_json_for_object_to_topic(json_content, scene, 'place-a/scene/update') -# return dash.no_update -# -# -# @app.callback( -# Output('hidden-div-scene-b', 'children'), -# Input('send-place-b-update', 'n_clicks'), -# State('place-b-input-json', 'value') -# ) -# def send_scene_a(n_clicks, json_content): -# """ -# Send scene in place b -# :param n_clicks: button.clicks -# :param json_content:state of place-b-input-json -# :return:no_update -# """ -# if n_clicks: -# scene = cgv_connector_pb2.Scene() -# send_json_for_object_to_topic(json_content, scene, 'place-b/scene/update') -# return dash.no_update +@app.callback( + [Output(button_id, 'style') for button_id in expert_view_buttons], + Output('coordinator-div', 'style'), + Output('arm-buttons', 'style'), + Output('object-buttons', 'style'), + Input('expert-view', 'value') +) +def toggle_expert_view(visibility_state): + local_buttons_style = dict(buttons_style) + local_buttons_style['display'] = 'flex' if visibility_state else 'none' + result = [button_style_normal if visibility_state else button_style_normal_invisible for _ in expert_view_buttons] + result.append({'display': 'block' if visibility_state else 'none'}) + result.append(local_buttons_style) + result.append(local_buttons_style) + print(result) + return result + + @app.callback( Output('hidden-div-scene-b', 'children'), [Input(button_id, 'n_clicks') for button_id in complex_commands],