From 588b290b00362a97cf8093af579fb3147813946c Mon Sep 17 00:00:00 2001 From: Zhengyu Peng Date: Thu, 11 Jul 2024 10:39:38 -0400 Subject: [PATCH] adjust GUI --- app.py | 26 +++++++------- app_layout.py | 99 ++++++++++++++++++++++++++------------------------- config.json | 1 - utils.py | 12 +++++++ 4 files changed, 74 insertions(+), 64 deletions(-) delete mode 100644 config.json diff --git a/app.py b/app.py index 9e498b2..6b34e14 100644 --- a/app.py +++ b/app.py @@ -39,7 +39,7 @@ from dash.dependencies import Input, Output, State from dash.exceptions import PreventUpdate -from utils import load_config +from utils import load_config, save_config from view_callbacks.test_case_view import get_test_case_view_callbacks from view_callbacks.control_view import get_control_view_callbacks @@ -82,7 +82,7 @@ def on_modal_open(modal_open): data_path = config.get("DATA_PATH", DATA_PATH) config["DATA_PATH"] = data_path - json.dump(config, open("./config.json", "w+")) + save_config(config, "./config.json") return { "data_path": data_path, @@ -130,7 +130,7 @@ def on_path_change(data_path, refresh): config["DATA_PATH"] = data_path config["CASE"] = case_val - json.dump(config, open("./config.json", "w+")) + save_config(config, "./config.json") return { "case_options": options, @@ -209,7 +209,7 @@ def on_case_change(case_val, data_path): config["DATA_PATH"] = data_path config["CASE"] = case_val config["FILE"] = file_value - json.dump(config, open("./config.json", "w+")) + save_config(config, "./config.json") return { "file_value": file_value, @@ -255,7 +255,7 @@ def on_modal_close( config["DATA_PATH"] = data_path config["CASE"] = case_val config["FILE"] = file_value - json.dump(config, open("./config.json", "w+")) + save_config(config, "./config.json") if current_file == file_value: return { @@ -296,14 +296,12 @@ def open_modal(select_modal): return {"modal_is_open": True} -""" -This clientside callback function disables the interval component based on -the number of clicks on the play button and stop button. If the play button -is clicked and the number of play clicks is greater than 0, the interval -component is disabled. If the stop button is clicked and the number of stop -clicks is greater than 0, the interval component is enabled. If neither button -is clicked, the interval component remains unchanged. -""" +# This clientside callback function disables the interval component based on +# the number of clicks on the play button and stop button. If the play button +# is clicked and the number of play clicks is greater than 0, the interval +# component is disabled. If the stop button is clicked and the number of stop +# clicks is greater than 0, the interval component is enabled. If neither button +# is clicked, the interval component remains unchanged. app.clientside_callback( """ function(play_clicks, stop_clicks) { @@ -353,5 +351,5 @@ def open_modal(select_modal): # serve(app.server, listen="*:8000") FlaskUI( - app=app.server, server="flask", port=46754, profile_dir_prefix="sensorview" + app=app.server, server="flask", port=45678, profile_dir_prefix="sensorview" ).run() diff --git a/app_layout.py b/app_layout.py index 036f21c..8dc15f3 100644 --- a/app_layout.py +++ b/app_layout.py @@ -163,7 +163,8 @@ target="c-picker-3d", placement="top", ), - ] + ], + size="sm", ), width=3, ), @@ -184,7 +185,8 @@ target="colormap-3d", placement="top", ), - ] + ], + size="sm", ), width=3, ), @@ -225,7 +227,7 @@ "uirevision": "no_change", }, }, - style={"height": "85vh"}, + style={"height": "80vh"}, ), className="mt-2", ), @@ -267,11 +269,14 @@ ), dbc.Row( [ - dcc.Interval( - id="interval-component", - interval=2 * 100, # in milliseconds - disabled=True, - n_intervals=0, + dbc.Col( + dcc.Interval( + id="interval-component", + interval=2 * 100, # in milliseconds + disabled=True, + n_intervals=0, + ), + width=4, ), dbc.Col( dbc.ButtonGroup( @@ -308,9 +313,35 @@ color="secondary", n_clicks=0, ), - ] + ], + className="w-100 mx-auto", + ), + width=4, + ), + dbc.Col( + dbc.DropdownMenu( + [ + dbc.DropdownMenuItem( + "Export all frames as an HTML video", + id="export-scatter3d", + n_clicks=0, + ), + dbc.DropdownMenuItem( + "Filtered Data (Current Frame)", + id="export-data-current", + n_clicks=0, + ), + dbc.DropdownMenuItem( + "Filtered Data (All Frames)", + id="export-data-all", + n_clicks=0, + ), + ], + label="Export", + right=True, + style={"float": "right"}, ), - width=2, + width=4, ), dbc.Tooltip( "Previous frame", @@ -332,38 +363,11 @@ target="next-button", placement="top", ), - ], - justify="center", - ), - html.Div( - [ - dbc.DropdownMenu( - [ - dbc.DropdownMenuItem( - "Export all frames as an HTML video", - id="export-scatter3d", - n_clicks=0, - ), - dbc.DropdownMenuItem( - "Filtered Data (Current Frame)", - id="export-data-current", - n_clicks=0, - ), - dbc.DropdownMenuItem( - "Filtered Data (All Frames)", - id="export-data-all", - n_clicks=0, - ), - ], - label="Export", - right=True, - style={"float": "right"}, - ), html.Div( id="hidden-scatter3d", style={"display": "none"}, ), - ] + ], ), ] ), @@ -444,7 +448,7 @@ ), ] ), - style={"overflow-y": "scroll", "height": "110vh"}, + style={"overflow-y": "scroll", "height": "100vh"}, ), ] ) @@ -1316,16 +1320,13 @@ def get_app_layout(): width=1, ), dbc.Col( - html.Div( - [ - dbc.Button( - html.I(className="bi bi-link-45deg"), - id="button-add", - n_clicks=0, - size="sm", - ) - ], - className="d-grid", + dbc.Button( + html.I(className="bi bi-link-45deg"), + id="button-add", + n_clicks=0, + color="secondary", + size="sm", + className="w-100", ), width=12, className="my-2", diff --git a/config.json b/config.json deleted file mode 100644 index 230c332..0000000 --- a/config.json +++ /dev/null @@ -1 +0,0 @@ -{"CASE": "arbe_vs_flr7hd", "FILE": "{\"path\": \"C:\\\\Users\\\\zjx8rj\\\\OneDrive - Aptiv\\\\radarviz\\\\arbe_vs_flr7hd\\\\cr\", \"name\": \"no_target.csv\", \"feather_name\": \"no_target.feather\"}", "DATA_PATH": "C:\\Users\\zjx8rj\\OneDrive - Aptiv\\radarviz"} \ No newline at end of file diff --git a/utils.py b/utils.py index fb59ebd..bef60e8 100644 --- a/utils.py +++ b/utils.py @@ -53,6 +53,18 @@ def load_config(json_file): return json.load(read_file) +def save_config(json_dict, json_file): + """ + Save configuration file. + + Parameters: + - json_dict (dict): Python dict + - json_file (str): The path to the JSON configuration file. + """ + with open(json_file, "w+", encoding="utf-8") as write_file: + json.dump(json_dict, write_file, indent=4) + + def load_data(file, file_list): """ Load data from file(s).