Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/navigate/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ def verify_configuration(manager, configuration):
ref_list = {
"filter_wheel": [],
}
filter_wheel_ids_by_microscope = {}
required_devices = [
"camera",
"filter_wheel",
Expand Down Expand Up @@ -1040,15 +1041,32 @@ def verify_configuration(manager, configuration):
)

temp_config = device_config[microscope_name]["filter_wheel"]
current_filter_wheel_ids = []
for _, filter_wheel_config in enumerate(temp_config):
filter_wheel_idx = build_ref_name(
"-",
filter_wheel_config["hardware"]["type"],
filter_wheel_config["hardware"]["wheel_number"],
)
current_filter_wheel_ids.append(filter_wheel_idx)
if filter_wheel_idx not in ref_list["filter_wheel"]:
ref_list["filter_wheel"].append(filter_wheel_idx)
filter_wheel_seq.append(filter_wheel_config)
filter_wheel_ids_by_microscope[microscope_name] = current_filter_wheel_ids

# Record which filter wheel entries belong to each microscope before
# sequence alignment inserts shared placeholders.
for microscope_name in device_config.keys():
present_ids = set(filter_wheel_ids_by_microscope.get(microscope_name, []))
filter_wheel_visibility = [
ref_name in present_ids for ref_name in ref_list["filter_wheel"]
]
update_config_dict(
manager,
device_config[microscope_name],
"filter_wheel_visibility",
filter_wheel_visibility,
)

# make sure all microscopes have the same filter wheel sequence
if len(device_config.keys()) > 1:
Expand Down
42 changes: 42 additions & 0 deletions src/navigate/controller/configuration_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,48 @@ def number_of_filter_wheels(self) -> int:
return len(self.microscope_config["filter_wheel"])
return 1

@property
def filter_wheel_types(self) -> list[str]:
"""Return a list of filter wheel hardware types.

Returns
-------
filter_wheel_types : list
List of filter wheel hardware types.
"""
filter_wheel_types = []
if self.microscope_config is not None:
for i in range(self.number_of_filter_wheels):
hardware_config = self.microscope_config["filter_wheel"][i].get(
"hardware", {}
)
filter_wheel_types.append(hardware_config.get("type", ""))
return filter_wheel_types

@property
def filter_wheel_visibility(self) -> list[bool]:
"""Return a list indicating which filter wheels are native to microscope.

Returns
-------
filter_wheel_visibility : list
``True`` for wheels that are defined for this microscope.
"""
if self.microscope_config is None:
return []

visibility = self.microscope_config.get("filter_wheel_visibility")
if isinstance(visibility, ListProxy):
visibility = list(visibility)

if not isinstance(visibility, list):
return [True] * self.number_of_filter_wheels

if len(visibility) != self.number_of_filter_wheels:
return [True] * self.number_of_filter_wheels

return [bool(value) for value in visibility]

@property
def filter_wheel_names(self) -> list[str]:
"""Return a list of filter wheel names
Expand Down
50 changes: 32 additions & 18 deletions src/navigate/controller/sub_controllers/channels_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,6 @@ def __init__(self, view, parent_controller=None, configuration_controller=None):
#: ConfigurationController: The configuration controller.
self.configuration_controller = configuration_controller

# num: numbers of channels
self.num = self.configuration_controller.number_of_channels
self.number_of_filter_wheels = (
self.configuration_controller.number_of_filter_wheels
)
self.view.populate_frame(
channels=self.num,
filter_wheels=self.number_of_filter_wheels,
filter_wheel_names=self.configuration_controller.filter_wheel_names,
)

#: str: The mode of the channel setting controller. Either 'live' or 'stop'.
self.mode = "stop"

Expand All @@ -87,6 +76,29 @@ def __init__(self, view, parent_controller=None, configuration_controller=None):
#: dict: The channel setting dictionary.
self.channel_setting_dict = None

self.rebuild_view()

def rebuild_view(self) -> None:
"""Rebuild channel widgets from the active microscope configuration."""
# num: numbers of channels
self.num = self.configuration_controller.number_of_channels
self.number_of_filter_wheels = (
self.configuration_controller.number_of_filter_wheels
)
filter_wheel_types = getattr(
self.configuration_controller, "filter_wheel_types", []
)
filter_wheel_visibility = getattr(
self.configuration_controller, "filter_wheel_visibility", []
)
self.view.populate_frame(
channels=self.num,
filter_wheels=self.number_of_filter_wheels,
filter_wheel_names=self.configuration_controller.filter_wheel_names,
filter_wheel_types=filter_wheel_types,
filter_wheel_visibility=filter_wheel_visibility,
)

# widget command binds
for i in range(self.num):
channel_vals = self.get_vals_by_channel(i)
Expand Down Expand Up @@ -189,13 +201,15 @@ def populate_empty_values(self):
self.view.laser_pulldowns[i]["values"][0]
)

if (
self.view.filterwheel_pulldowns[i].get()
not in self.view.filterwheel_pulldowns[i]["values"]
):
self.view.filterwheel_pulldowns[i].set(
self.view.filterwheel_pulldowns[i]["values"][0]
)
for j in range(self.number_of_filter_wheels):
idx = i * self.number_of_filter_wheels + j
if (
self.view.filterwheel_pulldowns[idx].get()
not in self.view.filterwheel_pulldowns[idx]["values"]
):
self.view.filterwheel_pulldowns[idx].set(
self.view.filterwheel_pulldowns[idx]["values"][0]
)

if self.view.exptime_pulldowns[i].get() == "":
self.view.exptime_pulldowns[i].set(100.0)
Expand Down
1 change: 1 addition & 0 deletions src/navigate/controller/sub_controllers/channels_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def initialize(self) -> None:
main window.
"""
config = self.parent_controller.configuration_controller
self.channel_setting_controller.rebuild_view()
self.stack_acq_widgets["cycling"].widget["values"] = ["Per Z", "Per Stack"]

# Set the default stage for acquiring a z-stack.
Expand Down
89 changes: 86 additions & 3 deletions src/navigate/view/main_window_content/channels_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ def __init__(
self.frame_columns = []

def populate_frame(
self, channels: int, filter_wheels: int, filter_wheel_names: list
self,
channels: int,
filter_wheels: int,
filter_wheel_names: list,
filter_wheel_types: list = None,
filter_wheel_visibility: list = None,
) -> None:
"""Populates the frame with the widgets.

Expand All @@ -222,9 +227,19 @@ def populate_frame(
The number of filter wheels
filter_wheel_names : list
The names of the filter wheels
filter_wheel_types : list
The types of filter wheels
filter_wheel_visibility : list
Indicates whether each filter wheel belongs to this microscope
"""
self.reset_frame()

self.create_labels(filter_wheel_names, filter_wheels)
self.create_labels(
filter_wheel_names,
filter_wheels,
filter_wheel_types,
filter_wheel_visibility,
)

# Configure the columns for consistent spacing
for i in range(len(self.label_text)):
Expand Down Expand Up @@ -286,6 +301,10 @@ def populate_frame(
)
)
self.filterwheel_pulldowns[-1].config(state="readonly")
if self.should_hide_filter_wheel(
i, filter_wheel_types, filter_wheel_visibility
):
continue
self.filterwheel_pulldowns[-1].grid(
row=num + 1,
column=(column_id := column_id + 1),
Expand Down Expand Up @@ -344,7 +363,13 @@ def populate_frame(
pady=self.pad_y,
)

def create_labels(self, filter_wheel_names: list, filter_wheels: int) -> None:
def create_labels(
self,
filter_wheel_names: list,
filter_wheels: int,
filter_wheel_types: list = None,
filter_wheel_visibility: list = None,
) -> None:
"""Create the labels for the columns.

Function to create the labels for the columns of the Channel Creator frame.
Expand All @@ -355,6 +380,10 @@ def create_labels(self, filter_wheel_names: list, filter_wheels: int) -> None:
A list of the names of the filter wheels
filter_wheels : int
Number of filter wheels
filter_wheel_types : list
The types of filter wheels
filter_wheel_visibility : list
Indicates whether each filter wheel belongs to this microscope
"""
# Create the labels for the columns.
self.label_text = [
Expand All @@ -363,6 +392,10 @@ def create_labels(self, filter_wheel_names: list, filter_wheels: int) -> None:
"Power",
]
for i in range(filter_wheels):
if self.should_hide_filter_wheel(
i, filter_wheel_types, filter_wheel_visibility
):
continue
self.label_text.append(filter_wheel_names[i])

self.label_text += ["Exp. Time (ms)", "Interval", "Defocus"]
Expand All @@ -379,6 +412,56 @@ def create_labels(self, filter_wheel_names: list, filter_wheels: int) -> None:
row=0, column=0, sticky=tk.N, pady=self.pad_y, padx=self.pad_x
)

def reset_frame(self) -> None:
"""Destroy existing channel widgets and clear references."""
for child in self.winfo_children():
child.destroy()

self.channel_variables = []
self.channel_checks = []
self.laser_variables = []
self.laser_pulldowns = []
self.laserpower_variables = []
self.laserpower_pulldowns = []
self.filterwheel_variables = []
self.filterwheel_pulldowns = []
self.exptime_variables = []
self.exptime_pulldowns = []
self.interval_variables = []
self.interval_spins = []
self.defocus_variables = []
self.defocus_spins = []
self.labels = []
self.frame_columns = []

@staticmethod
def is_synthetic_filter_wheel(
filter_wheel_idx: int, filter_wheel_types: list
) -> bool:
"""Return whether a filter wheel type should be hidden in the GUI."""
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring is misleading. It states "Return whether a filter wheel type should be hidden in the GUI" but this method only checks if the filter wheel is synthetic, not whether it should be hidden. The actual hiding decision is made by the should_hide_filter_wheel method which considers both synthetic status and visibility. Consider updating the docstring to: "Return whether a filter wheel is a synthetic filter wheel type."

Suggested change
"""Return whether a filter wheel type should be hidden in the GUI."""
"""Return whether a filter wheel is a synthetic filter wheel type."""

Copilot uses AI. Check for mistakes.
if filter_wheel_types is None or filter_wheel_idx >= len(filter_wheel_types):
return False

filter_wheel_type = str(filter_wheel_types[filter_wheel_idx]).strip().lower()
return filter_wheel_type in ("synthetic", "syntheticfilterwheel")

@classmethod
def should_hide_filter_wheel(
cls,
filter_wheel_idx: int,
filter_wheel_types: list,
filter_wheel_visibility: list,
) -> bool:
"""Return whether a filter wheel should be hidden in the GUI."""
if (
filter_wheel_visibility is not None
and filter_wheel_idx < len(filter_wheel_visibility)
and not filter_wheel_visibility[filter_wheel_idx]
):
return True

return cls.is_synthetic_filter_wheel(filter_wheel_idx, filter_wheel_types)


class StackAcquisitionFrame(ttk.Labelframe):
"""This class is the frame that holds the stack acquisition settings."""
Expand Down
Loading