From e81b673e2b0b6e5ab3e868eebe41520369283349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20David=20M=C3=BCller?= Date: Thu, 16 May 2024 09:28:48 +0200 Subject: [PATCH] add subsection parameter --- src/workflow/StreamlitUI.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/workflow/StreamlitUI.py b/src/workflow/StreamlitUI.py index de26674..7b64b2b 100644 --- a/src/workflow/StreamlitUI.py +++ b/src/workflow/StreamlitUI.py @@ -363,6 +363,7 @@ def input_TOPP( exclude_parameters: List[str] = [], include_parameters: List[str] = [], display_full_parameter_names: bool = False, + display_subsections: bool = False, custom_defaults: dict = {}, ) -> None: """ @@ -375,7 +376,8 @@ def input_TOPP( num_cols (int, optional): Number of columns to use for the layout. Defaults to 3. exclude_parameters (List[str], optional): List of parameter names to exclude from the widget. Defaults to an empty list. include_parameters (List[str], optional): List of parameter names to include in the widget. Defaults to an empty list. - display_full_parameter_names (bool, optional): Whether to display the full parameter names. Defaults to True. + display_full_parameter_names (bool, optional): Whether to display the full parameter names. Defaults to False. + display_subsections (bool, optional): Whether to split parameters into subsections based on the prefix (disables display_full_parameter_names). Defaults to False. custom_defaults (dict, optional): Dictionary of custom defaults to use. Defaults to an empty dict. """ # write defaults ini files @@ -391,6 +393,7 @@ def input_TOPP( if encoded_key in param.keys(): param.setValue(encoded_key, value) poms.ParamXMLFile().store(str(ini_file_path), param) + # read into Param object param = poms.Param() @@ -410,7 +413,6 @@ def input_TOPP( valid_keys = [key for key in param.keys() if not (b"input file" in param.getTags(key) or b"output file" in param.getTags(key) or any([k.encode() in key for k in excluded_keys]))] - params_decoded = [] for key in valid_keys: entry = param.getEntry(key) @@ -421,6 +423,7 @@ def input_TOPP( "valid_strings": [v.decode() for v in entry.valid_strings], "description": entry.description.decode(), "advanced": (b"advanced" in param.getTags(key)), + "section_description": param.getSectionDescription(':'.join(key.decode().split(':')[:-1])) } params_decoded.append(tmp) @@ -438,6 +441,7 @@ def input_TOPP( p["value"] = custom_defaults[name] # show input widgets + section_description = None cols = st.columns(num_cols) i = 0 @@ -447,7 +451,17 @@ def input_TOPP( continue key = f"{self.parameter_manager.topp_param_prefix}{p['key'].decode()}" - if display_full_parameter_names: + if display_subsections: + name = p["name"] + if section_description is None: + section_description = p['section_description'] + + elif section_description != p['section_description']: + section_description = p['section_description'] + st.markdown(f"**{section_description}**") + cols = st.columns(num_cols) + i = 0 + elif display_full_parameter_names: name = key.split(":1:")[1].replace("algorithm:", "").replace(":", " : ") else: name = p["name"] @@ -504,7 +518,7 @@ def input_TOPP( ] cols[i].text_area( name, - value="\n".join(p["value"]), + value="\n".join([str(val) for val in p["value"]]), help=p["description"], key=key, )