Skip to content

Commit db7e539

Browse files
Merge pull request #905 from TheDeanLab/20240524-controller-tests
Update test_controller.py
2 parents 5c7d175 + 4fe230e commit db7e539

File tree

3 files changed

+429
-38
lines changed

3 files changed

+429
-38
lines changed

src/navigate/controller/controller.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,10 @@ def execute(self, command, *args):
814814
feature_list_popup, self
815815
)
816816
self.features_popup_controller.populate_feature_list(feature_id)
817+
817818
# wait until close the popup windows
818819
self.view.wait_window(feature_list_popup.popup)
820+
819821
# do not run acquisition if "cancel" is selected
820822
temp = self.features_popup_controller.start_acquisiton_flag
821823
delattr(self, "features_popup_controller")
@@ -852,16 +854,14 @@ def execute(self, command, *args):
852854

853855
# clear show_img_pipe
854856
while self.show_img_pipe.poll():
855-
# TODO: image_id never called.
856857
self.show_img_pipe.recv()
857-
# image_id = self.show_img_pipe.recv()
858858

859859
elif command == "exit":
860-
"""Exit the program."""
861-
# Save current GUI settings to .navigate/config/experiment.yml file.
862-
self.sloppy_stop()
863-
# self.menu_controller.feature_id_val.set(0)
860+
"""Exit the program.
864861
862+
Saves the current GUI settings to .navigate/config/experiment.yml file.
863+
"""
864+
self.sloppy_stop()
865865
self.update_experiment_setting()
866866
file_directory = os.path.join(get_navigate_path(), "config")
867867
save_yaml_file(
@@ -918,7 +918,7 @@ def sloppy_stop(self):
918918
self.threads_pool.createThread('model', target)
919919
commands and the need to stop as abruptly as
920920
possible when the user hits stop. Here we leverage
921-
ObjectInSubprocess's refusal to let us access
921+
ObjectInSubprocess' refusal to let us access
922922
the model from two threads to our advantage, and just
923923
try repeatedly until we get a command in front
924924
of the next command in the model threads_pool resource.
@@ -940,9 +940,9 @@ def capture_image(self, command, mode, *args):
940940
Parameters
941941
----------
942942
command : string
943-
string = 'acquire' or 'autofocus'
943+
'acquire' or 'autofocus'
944944
mode : string
945-
string = 'continuous', 'z-stack', 'single', or 'projection'
945+
'continuous', 'z-stack', 'single', or 'projection'
946946
args : function-specific passes.
947947
"""
948948
self.camera_view_controller.image_count = 0
@@ -1009,7 +1009,16 @@ def capture_image(self, command, mode, *args):
10091009
)
10101010
# update framerate
10111011
stop_time = time.time()
1012-
frames_per_second = images_received / (stop_time - start_time)
1012+
try:
1013+
frames_per_second = images_received / (stop_time - start_time)
1014+
except ZeroDivisionError:
1015+
frames_per_second = 1 / (
1016+
self.configuration["experiment"]["MicroscopeState"]["channels"][
1017+
"channel_1"
1018+
].get("camera_exposure_time", 200)
1019+
/ 1000
1020+
)
1021+
10131022
# Update the Framerate in the Camera Settings Tab
10141023
self.camera_setting_controller.framerate_widgets["max_framerate"].set(
10151024
frames_per_second
@@ -1210,6 +1219,7 @@ def update_event(self):
12101219
waveform_dict=value,
12111220
sample_rate=self.configuration_controller.daq_sample_rate,
12121221
)
1222+
12131223
elif event == "multiposition":
12141224
# Update the multi-position tab without appending to the list
12151225
update_table(
@@ -1242,10 +1252,12 @@ def update_event(self):
12421252
if value["done"]:
12431253
print("Tony Wilson done! Updating expt...")
12441254
self.ao_popup_controller.update_experiment_values()
1255+
12451256
elif event == "mirror_update":
12461257
if hasattr(self, "ao_popup_controller"):
12471258
self.ao_popup_controller.set_widgets_from_coef(value["coefs"])
12481259
self.ao_popup_controller.plot_mirror(value)
1260+
12491261
elif event == "ao_save_report":
12501262
if hasattr(self, "ao_popup_controller"):
12511263
self.ao_popup_controller.save_report_to_file(value)
@@ -1255,29 +1267,20 @@ def update_event(self):
12551267
break
12561268

12571269
elif event == "update_stage":
1258-
# ZM: I am so sorry for this.
12591270
for _ in range(10):
12601271
try:
12611272
self.update_stage_controller_silent(value)
12621273
break
12631274
except RuntimeError:
12641275
time.sleep(0.001)
12651276
pass
1277+
12661278
elif event == "remove_positions":
12671279
self.multiposition_tab_controller.remove_positions(value)
1280+
12681281
elif event == "exposure_time":
12691282
self.channels_tab_controller.set_exposure_time(value[0], value[1])
12701283

1271-
# def exit_program(self):
1272-
# """Exit the program.
1273-
1274-
# This function is called when the user clicks the exit button in the GUI.
1275-
# """
1276-
# if messagebox.askyesno("Exit", "Are you sure?"):
1277-
# logger.info("Exiting Program")
1278-
# self.execute("exit")
1279-
# sys.exit()
1280-
12811284
def add_acquisition_mode(self, name, acquisition_obj):
12821285
if name in self.plugin_acquisition_modes:
12831286
print(f"*** plugin acquisition mode {name} exists, can't add another one!")

src/navigate/controller/sub_controllers/camera_view_controller.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,12 @@ def mark_position(self):
455455
stage_flip_flags = (
456456
self.parent_controller.configuration_controller.stage_flip_flags
457457
)
458-
stage_position["x"] = float(stage_position["x"]) + offset_x * (-1 if stage_flip_flags["x"] else 1)
459-
stage_position["y"] = float(stage_position["y"]) - offset_y * (-1 if stage_flip_flags["y"] else 1)
458+
stage_position["x"] = float(stage_position["x"]) + offset_x * (
459+
-1 if stage_flip_flags["x"] else 1
460+
)
461+
stage_position["y"] = float(stage_position["y"]) - offset_y * (
462+
-1 if stage_flip_flags["y"] else 1
463+
)
460464

461465
# Place the stage position in the multi-position table.
462466
self.parent_controller.execute("mark_position", stage_position)
@@ -743,7 +747,7 @@ def populate_image(self):
743747
temp_img = Image.blend(img1, img2, 0.2)
744748
else:
745749
temp_img = Image.fromarray(self.cross_hair_image.astype(np.uint8))
746-
750+
747751
# when calling ImageTk.PhotoImage() to generate a new image, it will destroy
748752
# what the canvas is showing and cause a blink.
749753
if self.image_catche_flag:

0 commit comments

Comments
 (0)