def setUp(self): self.app = Application.Application(TestUI.UserInterface(), set_global=False) self.source_image = numpy.random.randn(1024, 1024).astype(numpy.float32) self.exposure = 1.0 HardwareSource.HardwareSourceManager().hardware_sources = [] HardwareSource.HardwareSourceManager().hardware_source_added_event = Event.Event() HardwareSource.HardwareSourceManager().hardware_source_removed_event = Event.Event()
def __init__(self, document_controller, panel_id, properties): super().__init__(document_controller, panel_id, _("Video Source")) ui = document_controller.ui hardware_column = ui.create_column_widget() self.__hardware_source_widgets = dict() hardware_sources = HardwareSource.HardwareSourceManager().hardware_sources hardware_sources.sort(key=lambda hardware_source: hardware_source.display_name) def hardware_source_added(hardware_source): if hasattr(hardware_source, "video_device"): hardware_source_widget = VideoSourceWidget(document_controller, hardware_source) hardware_column.add(hardware_source_widget) self.__hardware_source_widgets[hardware_source.hardware_source_id] = hardware_source_widget def hardware_source_removed(hardware_source): hardware_source_widget = self.__hardware_source_widgets.get(hardware_source.hardware_source_id) if hardware_source_widget: hardware_column.remove(hardware_source_widget) for hardware_source in hardware_sources: hardware_source_added(hardware_source) hardware_column.add_stretch() self.__hardware_source_added_event = HardwareSource.HardwareSourceManager().hardware_source_added_event.listen(hardware_source_added) self.__hardware_source_removed_event = HardwareSource.HardwareSourceManager().hardware_source_removed_event.listen(hardware_source_removed) self.widget = hardware_column
def _get_stem_controller_and_camera(self, initialize: bool=True, is_eels: bool=False): # this is simulator specific. replace this code but be sure to set up self.exposure and blanked and positioned # initial settings. self.exposure = 0.04 instrument = InstrumentDevice.Instrument("usim_stem_controller") Registry.register_component(instrument, {"stem_controller"}) camera_id = "usim_ronchigram_camera" if not is_eels else "usim_eels_camera" camera_type = "ronchigram" if not is_eels else "eels" camera_name = "uSim Camera" camera_settings = CameraDevice.CameraSettings(camera_id) camera_device = CameraDevice.Camera(camera_id, camera_type, camera_name, instrument) camera_hardware_source = camera_base.CameraHardwareSource("usim_stem_controller", camera_device, camera_settings, None, None) if is_eels: camera_hardware_source.features["is_eels_camera"] = True camera_hardware_source.add_channel_processor(0, HardwareSource.SumProcessor(((0.25, 0.0), (0.5, 1.0)))) camera_hardware_source.set_frame_parameters(0, camera_base.CameraFrameParameters({"exposure_ms": self.exposure * 1000, "binning": 2})) camera_hardware_source.set_frame_parameters(1, camera_base.CameraFrameParameters({"exposure_ms": self.exposure * 1000, "binning": 2})) camera_hardware_source.set_frame_parameters(2, camera_base.CameraFrameParameters({"exposure_ms": self.exposure * 1000 * 2, "binning": 1})) camera_hardware_source.set_selected_profile_index(0) HardwareSource.HardwareSourceManager().register_hardware_source(camera_hardware_source) return instrument, camera_hardware_source
def setUp(self): #self.app = Application.Application(TestUI.UserInterface(), set_global=False) HardwareSource.HardwareSourceManager().hardware_sources = [] HardwareSource.HardwareSourceManager( ).hardware_source_added_event = Event.Event() HardwareSource.HardwareSourceManager( ).hardware_source_removed_event = Event.Event()
def start(self, skip_choose=False, fixed_workspace_dir=None): """ Start the application. Looks for workspace_location persistent string. If it doesn't find it, uses a default workspace location. Then checks to see if that workspace exists. If not and if skip_choose has not been set to True, asks the user for a workspace location. User may choose new folder or existing location. This works by putting up the dialog which will either call start again or exit. Creates workspace in location if it doesn't exist. Migrates database to latest version. Creates document model, resources path, etc. """ logging.getLogger("migration").setLevel(logging.INFO) if fixed_workspace_dir: workspace_dir = fixed_workspace_dir else: documents_dir = self.ui.get_document_location() workspace_dir = os.path.join(documents_dir, "Nion Swift Libraries") workspace_dir = self.ui.get_persistent_string("workspace_location", workspace_dir) welcome_message_enabled = fixed_workspace_dir is None profile, is_created = Profile.create_profile(pathlib.Path(workspace_dir), welcome_message_enabled, skip_choose) if not profile: self.choose_library() return True self.workspace_dir = workspace_dir DocumentModel.DocumentModel.computation_min_period = 0.2 DocumentModel.DocumentModel.computation_min_factor = 1.0 document_model = DocumentModel.DocumentModel(profile=profile) document_model.create_default_data_groups() document_model.start_dispatcher() # parse the hardware aliases file alias_path = os.path.join(self.workspace_dir, "aliases.ini") HardwareSource.parse_hardware_aliases_config_file(alias_path) # create the document controller document_controller = self.create_document_controller(document_model, "library") if self.__resources_path is not None: document_model.create_sample_images(self.__resources_path) workspace_history = self.ui.get_persistent_object("workspace_history", list()) if workspace_dir in workspace_history: workspace_history.remove(workspace_dir) workspace_history.insert(0, workspace_dir) self.ui.set_persistent_object("workspace_history", workspace_history) self.ui.set_persistent_string("workspace_location", workspace_dir) if welcome_message_enabled: logging.info("Welcome to Nion Swift.") if is_created and len(document_model.display_items) > 0: document_controller.selected_display_panel.set_display_panel_display_item(document_model.display_items[0]) document_controller.selected_display_panel.perform_action("set_fill_mode") return True
def _get_stem_controller_and_camera(self, initialize: bool = True, is_eels: bool = False): # this is simulator specific. replace this code but be sure to set up self.exposure and blanked and positioned # initial settings. self.exposure = 0.04 instrument = InstrumentDevice.Instrument("usim_stem_controller") Registry.register_component(instrument, {"stem_controller"}) camera_id = "usim_ronchigram_camera" if not is_eels else "usim_eels_camera" camera_type = "ronchigram" if not is_eels else "eels" camera_name = "uSim Camera" camera_settings = CameraDevice.CameraSettings(camera_id) camera_device = CameraDevice.Camera(camera_id, camera_type, camera_name, instrument) camera_hardware_source = camera_base.CameraHardwareSource( "usim_stem_controller", camera_device, camera_settings, None, None) if is_eels: camera_hardware_source.features["is_eels_camera"] = True camera_hardware_source.add_channel_processor( 0, HardwareSource.SumProcessor(((0.25, 0.0), (0.5, 1.0)))) # EELS camera only produces data if a valid scan context is presend in intrument controller, so set one up here scan_context = stem_controller.ScanContext() scan_context.update(Geometry.IntSize(128, 128), Geometry.FloatPoint(), 10.0, 0.0) # This is the only method that allows access to the scan context instrument._set_scan_context_probe_position( scan_context, Geometry.FloatPoint(0.5, 0.5)) camera_hardware_source.set_frame_parameters( 0, camera_base.CameraFrameParameters({ "exposure_ms": self.exposure * 1000, "binning": 2 })) camera_hardware_source.set_frame_parameters( 1, camera_base.CameraFrameParameters({ "exposure_ms": self.exposure * 1000, "binning": 2 })) camera_hardware_source.set_frame_parameters( 2, camera_base.CameraFrameParameters({ "exposure_ms": self.exposure * 1000 * 2, "binning": 1 })) camera_hardware_source.set_selected_profile_index(0) HardwareSource.HardwareSourceManager().register_hardware_source( camera_hardware_source) return instrument, camera_hardware_source
def __init__(self, document_model, event_loop): assert event_loop is not None self.__document_model = document_model self.__event_loop = event_loop # be sure to keep a reference or it will be closed immediately. self.__instrument_added_event_listener = None self.__instrument_removed_event_listener = None self.__instrument_added_event_listener = HardwareSource.HardwareSourceManager().instrument_added_event.listen(self.register_instrument) self.__instrument_removed_event_listener = HardwareSource.HardwareSourceManager().instrument_removed_event.listen(self.unregister_instrument) for instrument in HardwareSource.HardwareSourceManager().instruments: self.register_instrument(instrument)
def component_unregistered(component, component_types): if "video_device" in component_types: for hardware_source in HardwareSource.HardwareSourceManager( ).hardware_sources: if getattr(hardware_source, "video_device", None) and hardware_source.video_device == component: video_configuration.video_sources.remove_item( video_configuration.video_sources.items.index( hardware_source)) video_configuration._remove_video_device(component) HardwareSource.HardwareSourceManager( ).unregister_hardware_source(hardware_source)
def component_registered(component, component_types): if "scan_device" in component_types: stem_controller = HardwareSource.HardwareSourceManager( ).get_instrument_by_id(component.stem_controller_id) if not stem_controller: print("STEM Controller (" + component.stem_controller_id + ") for (" + component.scan_device_id + ") not found. Using proxy.") from nion.instrumentation import stem_controller stem_controller = stem_controller.STEMController() scan_hardware_source = ScanHardwareSource( stem_controller, component, component.scan_device_id, component.scan_device_name) HardwareSource.HardwareSourceManager().register_hardware_source( scan_hardware_source)
def __init__(self, hardware_source, queue_task, document_model): self.__hardware_source = hardware_source self.queue_task = queue_task self.__document_model = document_model self.__data_item_states_changed_event_listener = None self.__acquisition_state_changed_event_listener = None self.on_display_name_changed = None self.on_play_button_state_changed = None self.on_abort_button_state_changed = None self.on_data_item_states_changed = None self.on_display_new_data_item = None self.data_item_reference = document_model.get_data_item_reference( self.__hardware_source.hardware_source_id) def hardware_source_removed(hardware_source): if self.__hardware_source == hardware_source: self.__property_changed_event_listener.close() self.__property_changed_event_listener = None self.__hardware_source = None self.__hardware_source_removed_event = HardwareSource.HardwareSourceManager( ).hardware_source_removed_event.listen(hardware_source_removed) def hardware_source_property_changed(property_name): if property_name == "display_name": if callable(self.on_display_name_changed): self.on_display_name_changed( self.__hardware_source.display_name) self.__property_changed_event_listener = self.__hardware_source.property_changed_event.listen( hardware_source_property_changed)
def _get_scan_controller(self, stem_controller: InstrumentDevice): scan_hardware_source = scan_base.ScanHardwareSource( stem_controller, ScanDevice.Device(stem_controller), "usim_scan_device", "uSim Scan") HardwareSource.HardwareSourceManager().register_hardware_source( scan_hardware_source) return scan_hardware_source
def run(): global hardware_source_added_event_listener, hardware_source_removed_event_listener hardware_control_panels = dict() def register_hardware_panel(hardware_source): if hardware_source.features.get("is_video", False): panel_id = "video-control-panel-" + hardware_source.hardware_source_id hardware_control_panels[hardware_source.hardware_source_id] = panel_id class HardwareDisplayPanelControllerFactory: def __init__(self): self.priority = 1 def build_menu(self, display_type_menu, selected_display_panel): # return a list of actions that have been added to the menu. def switch_to_live_controller(hardware_source): d = {"type": "image", "controller_type": VideoDisplayPanelController.type, "hardware_source_id": hardware_source.hardware_source_id} selected_display_panel.change_display_panel_content(d) action = display_type_menu.add_menu_item(hardware_source.display_name, functools.partial(switch_to_live_controller, hardware_source)) action.checked = False return [action] def make_new(self, controller_type, display_panel, d): # make a new display panel controller, typically called to restore contents of a display panel. # controller_type will match the type property of the display panel controller when it was saved. # d is the dictionary that is saved when the display panel controller closes. hardware_source_id = d.get("hardware_source_id") if controller_type == VideoDisplayPanelController.type and hardware_source_id == hardware_source.hardware_source_id: return VideoDisplayPanelController(display_panel, hardware_source_id) return None def match(self, document_model, data_item): if HardwareSource.matches_hardware_source(hardware_source.hardware_source_id, None, document_model, data_item): return {"controller_type": VideoDisplayPanelController.type, "hardware_source_id": hardware_source.hardware_source_id} return None DisplayPanel.DisplayPanelManager().register_display_panel_controller_factory("video-live-" + hardware_source.hardware_source_id, HardwareDisplayPanelControllerFactory()) def unregister_hardware_panel(hardware_source): if hardware_source.features.get("is_video", False): DisplayPanel.DisplayPanelManager().unregister_display_panel_controller_factory("video-live-" + hardware_source.hardware_source_id) hardware_source_added_event_listener = HardwareSource.HardwareSourceManager().hardware_source_added_event.listen(register_hardware_panel) hardware_source_removed_event_listener = HardwareSource.HardwareSourceManager().hardware_source_removed_event.listen(unregister_hardware_panel) for hardware_source in HardwareSource.HardwareSourceManager().hardware_sources: register_hardware_panel(hardware_source)
def component_registered(component, component_types): if "video_device" in component_types: hardware_source = VideoHardwareSource(component) Registry.register_component( hardware_source, {"hardware_source", "video_hardware_source"}) HardwareSource.HardwareSourceManager().register_hardware_source( hardware_source) video_configuration.video_sources.append_item(hardware_source)
def __get_stem_controller(self): if not self.__stem_controller: self.__stem_controller = HardwareSource.HardwareSourceManager().get_instrument_by_id(self.__stem_controller_id) if not self.__stem_controller: print("STEM Controller (" + self.__stem_controller_id + ") for (" + self.hardware_source_id + ") not found. Using proxy.") from nion.instrumentation import stem_controller self.__stem_controller = self.__stem_controller or stem_controller.STEMController() return self.__stem_controller
def _setup_hardware_source(self, instrument) -> HardwareSource.HardwareSource: stem_controller = HardwareSource.HardwareSourceManager( ).get_instrument_by_id("usim_stem_controller") scan_hardware_source = scan_base.ScanHardwareSource( stem_controller, ScanDevice.Device(instrument), "usim_scan_device", "uSim Scan") return scan_hardware_source
def component_registered(component, component_types): if "camera_device" in component_types: stem_controller_id = getattr(component, "stem_controller_id", "autostem_controller") camera_hardware_source = CameraHardwareSource( stem_controller_id, component) HardwareSource.HardwareSourceManager().register_hardware_source( camera_hardware_source)
def __generate_device_id(self) -> str: n = 1 while True: device_id = "video_device_" + str(n) if not HardwareSource.HardwareSourceManager( ).get_hardware_source_for_hardware_source_id(device_id): break n += 1 return device_id
def deinitialize(self): # shut down hardware source manager, unload plug-ins, and really exit ui if self.__profile: self.__profile.close() self.__profile = None HardwareSource.HardwareSourceManager().close() PlugInManager.unload_plug_ins() self.__class__.count -= 1 super().deinitialize()
def __init__(self): # these are required to register the device self.scan_device_id = "orsay_scan_device" self.scan_device_name = _("Orsay Scan") self.stem_controller_id = AUTOSTEM_CONTROLLER_ID self.__is_scanning = False self.on_device_state_changed = None self.flyback_pixels = 0 self.__frame_number = 0 self.__scan_size = [512, 512] self.__sizez = 2 self.orsayscan = orsayScan(1) self.spimscan = orsayScan(2, self.orsayscan.orsayscan) #list all inputs totalinputs = self.orsayscan.getInputsCount() self.dinputs = dict() for index in range(totalinputs): prop = self.orsayscan.getInputProperties(index) self.dinputs[index] = [prop, False] self.usedinputs = [[0, False, self.dinputs[0][0]], [1, False, self.dinputs[1][0]], [6, False, self.dinputs[6][0]], [7, False, self.dinputs[7][0]]] self.orsayscan.SetInputs([1, 0]) __inputs = self.orsayscan.GetInputs() for inp in __inputs[1]: for k in self.usedinputs: if k[0] == inp: k[1] = True # # Add eels camera if there # self.__eelscamera = HardwareSource.HardwareSourceManager().get_hardware_source_for_hardware_source_id("orsay_camera_kuro") self.usedinputs.append([100, False, [0, 0, "eels", 100]]) channels = list(self.usedinputs[ch][1] for ch in range(len(self.usedinputs))) self.__cameras_parsed = False self.__profiles = list() self.__profiles.append(scan_base.ScanFrameParameters({"size": (512, 512), "pixel_time_us": 0.2, "channels":channels})) self.__profiles.append(scan_base.ScanFrameParameters({"size": (1024, 1024), "pixel_time_us": 0.2, "channels":channels})) self.__profiles.append(scan_base.ScanFrameParameters({"size": (64, 64), "pixel_time_us": 1000, "channels":channels})) self.__profiles.append(scan_base.ScanFrameParameters({"size": (2048, 2048), "pixel_time_us": 2.5, "channels":channels})) self.__frame_parameters = copy.deepcopy(self.__profiles[0]) self.imagedata = numpy.empty((self.__sizez * self.__scan_size[1], self.__scan_size[0]), dtype = numpy.int16) self.imagedata_ptr = self.imagedata.ctypes.data_as(ctypes.c_void_p) self.has_data_event = threading.Event() self.fnlock = LOCKERFUNC(self.__data_locker) self.orsayscan.registerLocker(self.fnlock) self.fnunlock = UNLOCKERFUNCA(self.__data_unlockerA) self.orsayscan.registerUnlockerA(self.fnunlock) self.orsayscan.pixelTime = 0.000002 # set the scan scale to 5v to match SuperScan, which output bank, then one for each direction self.orsayscan.setScanScale(0, 5.0, 5.0) #for channel_index in range(self.channel_count): # self.set_channel_enabled(channel_index, channels_enabled[channel_index]) print(f"OrsayScan Version: {self.orsayscan._major}") self.__angle = 0
def close(self): # close will be called when the extension is unloaded. in turn, close any references so they get closed. this # is not strictly necessary since the references will be deleted naturally when this object is deleted. for instrument in HardwareSource.HardwareSourceManager().instruments: self.unregister_instrument(instrument) self.__instrument_added_event_listener.close() self.__instrument_added_event_listener = None self.__instrument_removed_event_listener.close() self.__instrument_removed_event_listener = None
def shift_click(self, mouse_position, camera_shape): autostem = HardwareSource.HardwareSourceManager().get_instrument_by_id(AUTOSTEM_CONTROLLER_ID) if autostem: radians_per_pixel = autostem.get_value("TVPixelAngle") defocus_value = autostem.get_value("C10") # get the defocus dx = radians_per_pixel * defocus_value * (mouse_position[1] - (camera_shape[1] / 2)) dy = radians_per_pixel * defocus_value * (mouse_position[0] - (camera_shape[0] / 2)) logging.info("Shifting (%s,%s) um.\n", dx * 1e6, dy * 1e6) autostem.set_value("SShft.x", autostem.get_value("SShft.x") - dx) autostem.set_value("SShft.y", autostem.get_value("SShft.y") - dy)
def component_registered(component, component_types): if "camera_device" in component_types: stem_controller_id = getattr(component, "stem_controller_id", "autostem_controller") camera_hardware_source = CameraHardwareSource(stem_controller_id, component) if hasattr(component, "priority"): camera_hardware_source.priority = component.priority component_types = {"hardware_source", "camera_hardware_source"}.union({component.camera_type + "_camera_hardware_source"}) Registry.register_component(camera_hardware_source, component_types) HardwareSource.HardwareSourceManager().register_hardware_source(camera_hardware_source) component.hardware_source = camera_hardware_source
def tilt_click(self, mouse_position, camera_shape): autostem = HardwareSource.HardwareSourceManager().get_instrument_by_id(AUTOSTEM_CONTROLLER_ID) if autostem: defocus_sign = numpy.sign(autostem.get_value("C10")) # get the defocus radians_per_pixel = autostem.get_value("TVPixelAngle") da = radians_per_pixel * (mouse_position[1] - (camera_shape[1] / 2)) db = radians_per_pixel * (mouse_position[0] - (camera_shape[0] / 2)) logging.info("Tilting (%s,%s) rad.\n", da, db) autostem.set_value("STilt.x", autostem.get_value("STilt.x") - defocus_sign * da) autostem.set_value("STilt.y", autostem.get_value("STilt.y") - defocus_sign * db)
def match(self, document_model, data_item): if HardwareSource.matches_hardware_source( hardware_source.hardware_source_id, None, document_model, data_item): return { "controller_type": VideoDisplayPanelController.type, "hardware_source_id": hardware_source.hardware_source_id } return None
def register_camera(hardware_source_id, display_name): # create the camera camera = temperature.Camera() # create the hardware source camera_adapter = TemperatureCameraManagerImageSource.CameraAdapter( hardware_source_id, display_name, camera) hardware_source = CameraHardwareSource.CameraHardwareSource( camera_adapter, None) hardware_source.modes = camera_adapter.modes # register it with the manager HardwareSource.HardwareSourceManager().register_hardware_source( hardware_source)
def acquire(self, number_frames, energy_offset, sleep_time): eels_camera = self.__eels_camera_choice.hardware_source if eels_camera: # setup the workspace layout self.__configure_start_workspace( self.document_controller.workspace_controller, eels_camera.hardware_source_id) # start the EELS acquisition eels_camera.start_playing() autostem_controller = HardwareSource.HardwareSourceManager( ).get_instrument_by_id(STEM_CONTROLLER_ID) AcquireController().start_threaded_acquire_and_sum( autostem_controller, eels_camera, number_frames, energy_offset, sleep_time, self.document_controller, functools.partial(self.set_final_layout))
def acquire_data_elements(self): if self.__pending_frame_parameters: self.__activate_frame_parameters() assert self.__frame_parameters is not None frame_parameters = self.__frame_parameters exposure_ms = frame_parameters.exposure_ms binning = frame_parameters.binning data_element = self.__camera.acquire_image() #sub_area = (0, 0), data_element["data"].shape data_element["version"] = 1 #data_element["sub_area"] = sub_area data_element["state"] = "complete" # add optional calibration properties if "spatial_calibrations" in data_element["properties"]: data_element["spatial_calibrations"] = data_element["properties"][ "spatial_calibrations"] else: # handle backwards compatible case for nionccd1010 data_element["spatial_calibrations"] = self.__camera.calibration if "intensity_calibration" in data_element["properties"]: data_element["intensity_calibration"] = data_element["properties"][ "intensity_calibration"] # grab metadata from the autostem autostem = HardwareSource.HardwareSourceManager().get_instrument_by_id( AUTOSTEM_CONTROLLER_ID) if autostem: try: autostem_properties = autostem.get_autostem_properties() data_element["properties"]["autostem"] = copy.copy( autostem_properties) # TODO: file format: remove extra_high_tension high_tension_v = autostem_properties.get("high_tension_v") if high_tension_v: data_element["properties"][ "extra_high_tension"] = high_tension_v except Exception as e: print(e) data_element["properties"][ "hardware_source_name"] = self.__display_name data_element["properties"][ "hardware_source_id"] = self.hardware_source_id data_element["properties"]["exposure"] = exposure_ms / 1000.0 data_element["properties"]["binning"] = binning #data_element["properties"]["valid_rows"] = sub_area[0][0] + sub_area[1][0] data_element["properties"]["frame_index"] = data_element["properties"][ "frame_number"] return [data_element]
def start_frame(self, is_continuous: bool) -> int: """Start acquiring. Return the frame number.""" if not self.__is_scanning: __inputs = [] self.isSpim = False pos = 0 for l in self.__frame_parameters.channels: #if l[1][1]: if l: self.isSpim = self.usedinputs[pos][0] >= 100 if not self.isSpim: __inputs.append(self.usedinputs[pos][0]) pos = pos + 1 lg = len(__inputs) # # si le nombre d'entrée est plus grand que 1, il doit être pair! # limitation du firmware. # if lg > 0: if lg % 2: __inputs.append(6) self.orsayscan.SetInputs(__inputs) self.__scan_size = self.orsayscan.getImageSize() self.__sizez = self.orsayscan.GetInputs()[0] if self.__sizez % 2: self.__sizez += 1 self.imagedata = numpy.empty((self.__sizez * self.__scan_size[1], self.__scan_size[0]), dtype = numpy.int16) self.imagedata_ptr = self.imagedata.ctypes.data_as(ctypes.c_void_p) self.__angle = 0 self.orsayscan.setScanRotation(self.__angle) if self.isSpim: self.__eelscamera = HardwareSource.HardwareSourceManager().get_hardware_source_for_hardware_source_id("orsay_camera_kuro").camera if self.__eelscamera is not None: self.__eelscamera.acquire_sequence_prepare(self.__scan_size[1] * self.__scan_size[0]) self.__is_scanning = self.orsayscan.startImaging(0, 1) if self.isSpim: self.__eelscamera.acquire_sequence_orsay(4) self.__frame_number = 0 return self.__frame_number
def __init__(self, hardware_source, queue_task, document_model): self.__hardware_source = hardware_source self.queue_task = queue_task self.__document_model = document_model self.__data_item_states_changed_event_listener = None self.__acquisition_state_changed_event_listener = None self.on_display_name_changed = None self.on_play_button_state_changed = None self.on_abort_button_state_changed = None self.on_data_item_states_changed = None self.on_display_data_item_changed = None self.on_display_new_data_item = None # this function is threadsafe # it queues the threadsafe call to the UI thread, checking to make sure the # hardware source wasn't closed before being called (mainly to make tests run). def handle_data_item_changed(): def update_display_data_item(): if self.__hardware_source: self.__update_display_data_item() self.queue_task(update_display_data_item) self.__data_item = None data_item_reference = document_model.get_data_item_reference(self.__hardware_source.hardware_source_id) self.__data_item_changed_event_listener = data_item_reference.data_item_changed_event.listen(handle_data_item_changed) def hardware_source_removed(hardware_source): if self.__hardware_source == hardware_source: self.__property_changed_event_listener.close() self.__property_changed_event_listener = None self.__hardware_source = None self.__hardware_source_removed_event = HardwareSource.HardwareSourceManager().hardware_source_removed_event.listen(hardware_source_removed) def hardware_source_property_changed(property_name): if property_name == "display_name": if callable(self.on_display_name_changed): self.on_display_name_changed(self.__hardware_source.display_name) self.__property_changed_event_listener = self.__hardware_source.property_changed_event.listen(hardware_source_property_changed)
def __data_unlockerA(self, gene, newdata, imagenb, rect): if newdata: # message = "Image: " + str(imagenb) + " pos: [" + str(rect[0]) + ", " + str(rect[1]) + "] size: [" + str(rect[2]) + ", " + str(rect[3]) + "]" # print (message) # rect[0] x corner of rectangle updated # rect[1] y corner of rectangle updated # rect[2] horizontal size of the rectangle. # rect[3] vertical size of the rectangle. # image has all its data if . # numpy may only take the rectangle. # if rect[1] + rect[3] == self.__scan_size[1]: # self.__angle = self.__angle + 5 # self.orsayscan.setScanRotation(self.__angle) # print("Frame number: " + str(imagenb) + " New rotation: " + str(self.__angle)) self.__frame_number = imagenb self.has_data_event.set() if self.isSpim: status = self.__eelscamera.camera.getCCDStatus() if status["mode"] == "idle": hardware_source = HardwareSource.HardwareSourceManager().get_hardware_source_for_hardware_source_id( self.scan_device_id) hardware_source.stop_playing()