refactor ui input
@@ -99,9 +99,10 @@ DEFAULT_GAMMA_OPTIONS = {
"max_gamma": 5,
}
+
st.sidebar.markdown(
"""
- ## Advanced Options
+ # Advanced Options
Enable advanced functionality by ticking the below.
"""
@@ -112,7 +113,7 @@ if advanced_mode:
st.sidebar.markdown(
"""
- ### Gamma parameters
+ ## Gamma parameters
"""
)
gamma_options = {
@@ -283,7 +284,7 @@ def dicom_input_method( # pylint: disable = too-many-return-statements
try:
dicom_plan = pydicom.read_file(dicom_plan_bytes, force=True)
- except:
+ except: # pylint: disable = bare-except
st.write(WrongFileType("Does not appear to be a DICOM file"))
return {}
@@ -387,8 +388,6 @@ def dicom_input_method( # pylint: disable = too-many-return-statements
"deliveries": deliveries,
}
- return {}
-
def icom_input_method(
patient_id="", icom_directory=DEFAULT_ICOM_DIRECTORY, key_namespace="", **_
@@ -531,42 +530,41 @@ def display_deliveries(deliveries):
### Reference
"""
+
+def get_input_data_ui(default_method, key_namespace, **previous_results):
if advanced_mode:
- reference_data_method = st.selectbox(
+ data_method = st.selectbox(
"Data Input Method",
data_method_options,
- index=data_method_options.index(DEFAULT_REFERENCE),
+ index=data_method_options.index(default_method),
)
else:
- reference_data_method = DEFAULT_REFERENCE
+ data_method = default_method
-reference_results = data_method_map[reference_data_method]( # type: ignore
- key_namespace="reference"
+ results = data_method_map[data_method]( # type: ignore
+ key_namespace=key_namespace, **previous_results
)
-display_deliveries(reference_results["deliveries"])
+ try:
+ display_deliveries(results["deliveries"])
+ except KeyError:
+ pass
+
+ return results
+
+
+reference_results = get_input_data_ui(DEFAULT_REFERENCE, "reference")
+
"""
### Evaluation
"""
-if advanced_mode:
- evaluation_data_method = st.selectbox(
- "Data Input Method",
- data_method_options,
- index=data_method_options.index(DEFAULT_EVALUATION),
- )
-else:
- evaluation_data_method = DEFAULT_EVALUATION
-
-evaluation_results = data_method_map[evaluation_data_method]( # type: ignore
- key_namespace="evaluation", **reference_results
+evaluation_results = get_input_data_ui(
+ DEFAULT_EVALUATION, "evaluation", **reference_results
)
-display_deliveries(evaluation_results["deliveries"])
-
-
"""
## Output Locations
"""
