@@ -174,27 +174,24 @@ def __init__(
174174 logger .info (f"Spec - Waveform Constants Path: { waveform_constants_path } " )
175175 logger .info (f"Spec - Rest API Path: { rest_api_path } " )
176176
177- # Wire up pipes
178177 #: mp.Pipe: Pipe for sending images from model to view.
179178 self .show_img_pipe = self .model .create_pipe ("show_img_pipe" )
180179
181- # save default experiment file
182180 #: string: Path to the default experiment yaml file.
183181 self .default_experiment_file = experiment_path
184182
185- # waveform setting file
186183 #: string: Path to the waveform constants yaml file.
187184 self .waveform_constants_path = waveform_constants_path
188185
189- # Configuration Reader
190186 #: ConfigurationController: Configuration Controller object.
191187 self .configuration_controller = ConfigurationController (self .configuration )
192188
193- # Initialize the View
194189 #: View: View object in MVC architecture.
195190 self .view = view (root )
196191
197- # Sub Gui Controllers
192+ #: dict: Event listeners for the controller.
193+ self .event_listeners = {}
194+
198195 #: AcquireBarController: Acquire Bar Sub-Controller.
199196 self .acquire_bar_controller = AcquireBarController (self .view .acqbar , self )
200197
@@ -234,7 +231,7 @@ def __init__(
234231 #: KeystrokeController: Keystroke Sub-Controller.
235232 self .keystroke_controller = KeystrokeController (self .view , self )
236233
237- # Exit
234+ # Exit the program when the window is closed
238235 self .view .root .protocol (
239236 "WM_DELETE_WINDOW" , self .acquire_bar_controller .exit_program
240237 )
@@ -248,22 +245,19 @@ def __init__(
248245 # self.microscope = self.configuration['configuration']
249246 # ['microscopes'].keys()[0] # Default to the first microscope
250247
251- # Initialize the menus
252248 #: MenuController: Menu Sub-Controller.
253249 self .menu_controller = MenuController (view = self .view , parent_controller = self )
254250 self .menu_controller .initialize_menus ()
255251
256252 #: dict: acquisition modes from plugins
257253 self .plugin_acquisition_modes = {}
258254
259- # add plugin menus
260255 #: PluginsController: Plugin Sub-Controller
261256 self .plugin_controller = PluginsController (
262257 view = self .view , parent_controller = self
263258 )
264259 self .plugin_controller .load_plugins ()
265260
266- # Create default data buffer
267261 #: int: Number of x_pixels from microscope configuration file.
268262 self .img_width = 0
269263
@@ -473,6 +467,16 @@ def update_experiment_setting(self):
473467 "multiposition_count"
474468 ] = len (positions )
475469
470+ if (
471+ self .configuration ["experiment" ]["MicroscopeState" ]["is_multiposition" ]
472+ and len (positions ) == 0
473+ ):
474+ # Update the view and override the settings.
475+ self .configuration ["experiment" ]["MicroscopeState" ][
476+ "is_multiposition"
477+ ] = False
478+ self .channels_tab_controller .is_multiposition_val .set (False )
479+
476480 # TODO: validate experiment dict
477481
478482 channel_warning = self .channels_tab_controller .verify_experiment_values ()
@@ -1225,54 +1229,13 @@ def update_event(self):
12251229 # Display a warning that arises from the model as a top-level GUI popup
12261230 messagebox .showwarning (title = "Navigate" , message = value )
12271231
1228- elif event == "waveform" :
1229- # Update the waveform plot.
1230- self .waveform_tab_controller .update_waveforms (
1231- waveform_dict = value ,
1232- sample_rate = self .configuration_controller .daq_sample_rate ,
1233- )
1234-
12351232 elif event == "multiposition" :
12361233 # Update the multi-position tab without appending to the list
12371234 update_table (
12381235 table = self .multiposition_tab_controller .table ,
12391236 pos = value ,
12401237 )
12411238 self .channels_tab_controller .is_multiposition_val .set (True )
1242- self .channels_tab_controller .toggle_multiposition ()
1243-
1244- elif event == "disable_multiposition" :
1245- self .channels_tab_controller .is_multiposition_val .set (False )
1246- self .channels_tab_controller .toggle_multiposition ()
1247-
1248- elif event == "ilastik_mask" :
1249- # Display the ilastik mask
1250- self .camera_view_controller .display_mask (mask = value )
1251-
1252- elif event == "autofocus" :
1253- # Display the autofocus plot
1254- if hasattr (self , "af_popup_controller" ):
1255- self .af_popup_controller .display_plot (
1256- data = value [0 ], line_plot = value [1 ], clear_data = value [2 ]
1257- )
1258-
1259- elif event == "tonywilson" :
1260- if hasattr (self , "ao_popup_controller" ):
1261- # self.ao_popup_controller.set_widgets_from_coef(value['coefs'])
1262- self .ao_popup_controller .plot_tonywilson (value )
1263- # self.ao_popup_controller.plot_mirror(value)
1264- if value ["done" ]:
1265- print ("Tony Wilson done! Updating expt..." )
1266- self .ao_popup_controller .update_experiment_values ()
1267-
1268- elif event == "mirror_update" :
1269- if hasattr (self , "ao_popup_controller" ):
1270- self .ao_popup_controller .set_widgets_from_coef (value ["coefs" ])
1271- self .ao_popup_controller .plot_mirror (value )
1272-
1273- elif event == "ao_save_report" :
1274- if hasattr (self , "ao_popup_controller" ):
1275- self .ao_popup_controller .save_report_to_file (value )
12761239
12771240 elif event == "stop" :
12781241 # Stop the software
@@ -1287,17 +1250,47 @@ def update_event(self):
12871250 time .sleep (0.001 )
12881251 pass
12891252
1290- elif event == "remove_positions" :
1291- self .multiposition_tab_controller .remove_positions (value )
1292-
1293- elif event == "exposure_time" :
1294- self .channels_tab_controller .set_exposure_time (value [0 ], value [1 ])
1295- elif event == "display_camera_parameters" :
1296- self .camera_setting_controller .update_camera_parameters_silent (* value )
1253+ elif event in self .event_listeners .keys ():
1254+ try :
1255+ self .event_listeners [event ](value )
1256+ except Exception :
1257+ print (f"*** unhandled event: { event } , { value } " )
12971258
12981259 def add_acquisition_mode (self , name , acquisition_obj ):
1260+ """Add and Acquisition Mode.
1261+
1262+ Parameters
1263+ ----------
1264+ name : string
1265+ Name of the acquisition mode.
1266+ acquisition_obj : object
1267+ Object of the acquisition mode.
1268+ """
12991269 if name in self .plugin_acquisition_modes :
13001270 print (f"*** plugin acquisition mode { name } exists, can't add another one!" )
13011271 return
13021272 self .plugin_acquisition_modes [name ] = acquisition_obj (name )
13031273 self .acquire_bar_controller .add_mode (name )
1274+
1275+ def register_event_listener (self , event_name , event_handler ):
1276+ """Register an event listener.
1277+
1278+ Parameters
1279+ ----------
1280+ event_name : string
1281+ Name of the event.
1282+ event_handler : function
1283+ Function to handle the event.
1284+ """
1285+ self .event_listeners [event_name ] = event_handler
1286+
1287+ def register_event_listeners (self , events ):
1288+ """Register multiple event listeners.
1289+
1290+ Parameters
1291+ ----------
1292+ events : dict
1293+ Dictionary of event names and handlers.
1294+ """
1295+ for event_name , event_handler in events .items ():
1296+ self .register_event_listener (event_name , event_handler )
0 commit comments