Skip to content

Commit

Permalink
Update the checkbox sizer when changing b0 tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
po09i committed Jan 16, 2024
1 parent 976f36c commit 035b098
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
27 changes: 14 additions & 13 deletions fsleyes_plugin_shimming_toolbox/components/checkbox_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from fsleyes_plugin_shimming_toolbox.components.input_component import InputComponent
from fsleyes_plugin_shimming_toolbox.text_with_button import create_info_icon


class CheckboxComponent(Component):
def __init__(self, panel, label, checkbox_metadata, option_name, components_dict={}, info_text=None):
"""
Expand All @@ -22,17 +23,17 @@ def __init__(self, panel, label, checkbox_metadata, option_name, components_dict
self.children = components_dict

self.create_display()

def create_display(self):
# Button
self.info_icon = create_info_icon(self.panel, self.info_text)
self.button = wx.Button(self.panel, -1, label=self.label)

# Checkboxes
self.checkboxes = []
for metadata in self.checkbox_metadata:
self.checkboxes.append(wx.CheckBox(self.panel, label=metadata["label"]))

# Add checkboxes to sizer
self.checkbox_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.checkbox_sizer.Add(self.info_icon, 0, wx.ALIGN_LEFT | wx.RIGHT, 7)
Expand All @@ -41,13 +42,13 @@ def create_display(self):
# Bind
checkbox.Bind(wx.EVT_CHECKBOX, self.show_children_sizers)
self.checkbox_sizer.Add(checkbox, 0, wx.ALL, 5) # Add to sizer + spacer below

self.sizer.Add(self.checkbox_sizer)
self.sizer.AddSpacer(10)

# Add children
self.add_children()

wx.CallAfter(self.show_children_sizers, None)

def add_children(self):
Expand All @@ -68,14 +69,14 @@ def get_children_to_show(self):
"""Get the children to show based on the checkbox selection"""
checked_indices = {checkbox.GetLabel() for checkbox in self.checkboxes if checkbox.GetValue()}
children_to_show = [child['object'] for child in self.children if set(child['checkbox']).intersection(checked_indices)]

return children_to_show

def create_sizer(self):
"""Create the centre sizer containing tab-specific functionality."""
sizer = wx.BoxSizer(wx.VERTICAL)
return sizer

def get_command(self):
command = []
output = None
Expand All @@ -88,19 +89,19 @@ def get_command(self):
args += '0,'
else:
args += str(checkbox.GetLabel()) + ','

if self.option_name == "arg":
command.append(args[:-1])
else:
command.extend(['--' + self.option_name, args[:-1]])

children_to_return = self.get_children_to_show()
for child in children_to_return:
if type(child) == InputComponent:
cmd, output, overlay = child.get_command()
else:
cmd, _, _ = child.get_command()

command.extend(cmd)

return command, output, overlay
19 changes: 10 additions & 9 deletions fsleyes_plugin_shimming_toolbox/tabs/b0shim_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ def on_choice(self, event):
if selection == 'Dynamic/volume':
self.dropdown_slice_dyn.on_choice(None)
self.dropdown_coil_format_dyn.on_choice(None)
# self.dropdown_scanner_order_dyn.on_choice(None)
self.checkbox_scanner_order_dyn.show_children_sizers(None)
self.dropdown_opt_dyn.on_choice(None)
elif selection == 'Realtime Dynamic':
self.dropdown_slice_rt.on_choice(None)
self.dropdown_coil_format_rt.on_choice(None)
self.checkbox_scanner_order_rt.show_children_sizers(None)
self.dropdown_opt_rt.on_choice(None)
else:
pass
Expand Down Expand Up @@ -188,7 +189,7 @@ def create_sizer_dynamic_shim(self, metadata=None):
},
]
component_scanner = InputComponent(self, input_text_box_metadata_scanner, cli=dynamic_cli)

dropdown_scanner_format_metadata = [
{
"label": "Slicewise per Channel",
Expand Down Expand Up @@ -235,15 +236,15 @@ def create_sizer_dynamic_shim(self, metadata=None):
}
]

self.checkbox_scanner_order = CheckboxComponent(
self.checkbox_scanner_order_dyn = CheckboxComponent(
panel=self,
label="Scanner Order",
checkbox_metadata=checkbox_scanner_order_metadata,
option_name='scanner-coil-order',
components_dict=[{'object': dropdown_scanner_format, 'checkbox': ['f0', '1', '2']},
{'object': component_scanner, 'checkbox': ['f0', '1', '2']}],
)

dropdown_ovf_metadata = [
{
"label": "delta",
Expand Down Expand Up @@ -419,7 +420,7 @@ def create_sizer_dynamic_shim(self, metadata=None):
self.run_component_dyn = RunComponent(
panel=self,
list_components=[self.component_coils_dyn, component_inputs, self.dropdown_opt_dyn, self.dropdown_slice_dyn,
self.checkbox_scanner_order,
self.checkbox_scanner_order_dyn,
self.dropdown_coil_format_dyn, dropdown_ovf, component_output],
st_function="st_b0shim dynamic",
output_paths=["fieldmap_calculated_shim_masked.nii.gz",
Expand Down Expand Up @@ -522,7 +523,7 @@ def create_sizer_realtime_shim(self, metadata=None):
option_name = 'output-file-format-scanner',
cli=realtime_cli
)

checkbox_scanner_order_metadata = [
{
"label": "f0",
Expand All @@ -546,8 +547,8 @@ def create_sizer_realtime_shim(self, metadata=None):
},
]
component_scanner = InputComponent(self, input_text_box_metadata_scanner, cli=realtime_cli)
self.checkbox_scanner_order = CheckboxComponent(

self.checkbox_scanner_order_rt = CheckboxComponent(
panel=self,
label="Scanner Order",
checkbox_metadata=checkbox_scanner_order_metadata,
Expand Down Expand Up @@ -712,7 +713,7 @@ def create_sizer_realtime_shim(self, metadata=None):
self.run_component_rt = RunComponent(
panel=self,
list_components=[self.component_coils_rt, component_inputs, self.dropdown_opt_rt, self.dropdown_slice_rt,
self.checkbox_scanner_order,
self.checkbox_scanner_order_rt,
self.dropdown_coil_format_rt, dropdown_ovf, component_output],
st_function="st_b0shim realtime-dynamic",
# TODO: output paths
Expand Down

0 comments on commit 035b098

Please sign in to comment.