Skip to content

Commit

Permalink
add subsection parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mdavid-m committed May 16, 2024
1 parent 11d2ae4 commit e81b673
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/workflow/StreamlitUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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

Expand All @@ -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"]
Expand Down Expand Up @@ -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,
)
Expand Down

0 comments on commit e81b673

Please sign in to comment.