def __init__( self, ui_settings: UISettings.UISettings, delegate: typing.Optional[DisplayCanvasItem.DisplayCanvasItemDelegate] ) -> None: super().__init__() self.__ui_settings = ui_settings self.delegate = delegate self.__drawing_context_lock = threading.RLock() self.__drawing_context = DrawingContext.DrawingContext() self.__display_xdata: typing.Optional[ DataAndMetadata.DataAndMetadata] = None self.__display_script: typing.Optional[str] = None self.__closing_lock = threading.RLock() self.__closed = False # canvas items get added back to front # create the child canvas items # the background self.add_canvas_item(CanvasItem.BackgroundCanvasItem()) # frame rate self.__display_frame_rate_id: typing.Optional[str] = None self.__display_frame_rate_last_index = 0
def __init__(self, ui_settings: UISettings.UISettings, delegate, event_loop, draw_background: bool = True): super().__init__() self.__ui_settings = ui_settings self.delegate = delegate self.__drawing_context_lock = threading.RLock() self.__drawing_context = DrawingContext.DrawingContext() self.__display_data = None self.__display_script = None self.__closing_lock = threading.RLock() self.__closed = False self.__data = None self.__last_data = None # canvas items get added back to front # create the child canvas items # the background self.add_canvas_item(CanvasItem.BackgroundCanvasItem()) # frame rate self.__display_frame_rate_id = None self.__display_frame_rate_last_index = 0
def __init__(self, ui, app=None): super().__init__(ui, app) # first create a root canvas item in which the rest of the user interface will go canvas_widget = ui.create_canvas_widget() background_canvas_item = CanvasItem.BackgroundCanvasItem("#FFF") metadata = { "Dictionary1": { "abc": 5, "def": "hello", "List2": ["Red", "Green", "Blue"] }, "List1": [4, 5, 6] } metadata_editor_canvas_item = TreeCanvasItem.TreeCanvasItem( ui.get_font_metrics, MetadataEditorTreeDelegate(metadata)) metadata_editor_canvas_item.reconstruct() # finally add the column to the root canvas item. canvas_widget.canvas_item.add_canvas_item(background_canvas_item) canvas_widget.canvas_item.add_canvas_item(metadata_editor_canvas_item) # attach the root canvas item to the document window self.attach_widget(canvas_widget)
def __init__(self, display_panel, hardware_source_id): assert hardware_source_id is not None hardware_source = HardwareSource.HardwareSourceManager().get_hardware_source_for_hardware_source_id(hardware_source_id) self.type = VideoDisplayPanelController.type self.__hardware_source_id = hardware_source_id # configure the hardware source state controller self.__state_controller = VideoSourceStateController(hardware_source, display_panel.document_controller.queue_task, display_panel.document_controller.document_model) # configure the user interface self.__play_button_enabled = False self.__play_button_play_button_state = "play" self.__data_item_states = list() self.__display_panel = display_panel self.__display_panel.header_canvas_item.end_header_color = "#DAA520" self.__playback_controls_composition = CanvasItem.CanvasItemComposition() self.__playback_controls_composition.layout = CanvasItem.CanvasItemLayout() self.__playback_controls_composition.sizing.set_fixed_height(30) playback_controls_row = CanvasItem.CanvasItemComposition() playback_controls_row.layout = CanvasItem.CanvasItemRowLayout() play_button_canvas_item = CanvasItem.TextButtonCanvasItem() play_button_canvas_item.border_enabled = False abort_button_canvas_item = CanvasItem.TextButtonCanvasItem() abort_button_canvas_item.border_enabled = False status_text_canvas_item = CanvasItem.StaticTextCanvasItem(str()) hardware_source_display_name_canvas_item = CanvasItem.StaticTextCanvasItem(str()) playback_controls_row.add_canvas_item(play_button_canvas_item) playback_controls_row.add_canvas_item(abort_button_canvas_item) playback_controls_row.add_canvas_item(status_text_canvas_item) playback_controls_row.add_stretch() playback_controls_row.add_canvas_item(hardware_source_display_name_canvas_item) self.__playback_controls_composition.add_canvas_item(CanvasItem.BackgroundCanvasItem("#DAA520")) self.__playback_controls_composition.add_canvas_item(playback_controls_row) self.__display_panel.footer_canvas_item.insert_canvas_item(0, self.__playback_controls_composition) def display_name_changed(display_name): hardware_source_display_name_canvas_item.text = display_name hardware_source_display_name_canvas_item.size_to_content(display_panel.image_panel_get_font_metrics) def play_button_state_changed(enabled, play_button_state): play_button_canvas_item.enabled = enabled map_play_button_state_to_text = {"play": _("Play"), "pause": _("Pause")} play_button_canvas_item.text = map_play_button_state_to_text[play_button_state] play_button_canvas_item.size_to_content(display_panel.image_panel_get_font_metrics) def abort_button_state_changed(visible, enabled): abort_button_canvas_item.text = _("Abort") if visible else str() abort_button_canvas_item.enabled = enabled abort_button_canvas_item.size_to_content(display_panel.image_panel_get_font_metrics) def update_status_text(): map_channel_state_to_text = {"stopped": _("Stopped"), "complete": _("Acquiring"), "partial": _("Acquiring"), "marked": _("Stopping")} for data_item_state in self.__data_item_states: channel_state = data_item_state["channel_state"] new_text = map_channel_state_to_text[channel_state] if status_text_canvas_item.text != new_text: status_text_canvas_item.text = new_text status_text_canvas_item.size_to_content(display_panel.image_panel_get_font_metrics) return def data_item_states_changed(data_item_states): self.__data_item_states = data_item_states update_status_text() def display_data_item_changed(data_item): display_panel.set_displayed_data_item(data_item) def display_new_data_item(data_item): result_display_panel = display_panel.document_controller.next_result_display_panel() if result_display_panel: result_display_panel.set_display_panel_data_item(data_item) result_display_panel.request_focus() self.__state_controller.on_display_name_changed = display_name_changed self.__state_controller.on_play_button_state_changed = play_button_state_changed self.__state_controller.on_abort_button_state_changed = abort_button_state_changed self.__state_controller.on_data_item_states_changed = data_item_states_changed self.__state_controller.on_display_data_item_changed = display_data_item_changed self.__state_controller.on_display_new_data_item = display_new_data_item play_button_canvas_item.on_button_clicked = self.__state_controller.handle_play_clicked abort_button_canvas_item.on_button_clicked = self.__state_controller.handle_abort_clicked self.__state_controller.initialize_state() document_model = self.__display_panel.document_controller.document_model
def __init__(self, display_panel: DisplayPanel.DisplayPanel, hardware_source_id: str) -> None: assert hardware_source_id is not None hardware_source = HardwareSource.HardwareSourceManager( ).get_hardware_source_for_hardware_source_id(hardware_source_id) assert isinstance(hardware_source, video_base.VideoHardwareSource) self.type = VideoDisplayPanelController.type self.__hardware_source_id = hardware_source_id # configure the hardware source state controller self.__state_controller = VideoSourceStateController( hardware_source, display_panel.document_controller.queue_task, display_panel.document_controller.document_model) # configure the user interface self.__play_button_enabled = False self.__play_button_play_button_state = "play" self.__display_panel = display_panel self.__display_panel.header_canvas_item.end_header_color = "#DAA520" self.__playback_controls_composition = CanvasItem.CanvasItemComposition( ) self.__playback_controls_composition.layout = CanvasItem.CanvasItemLayout( ) self.__playback_controls_composition.update_sizing( self.__playback_controls_composition.sizing.with_fixed_height(30)) playback_controls_row = CanvasItem.CanvasItemComposition() playback_controls_row.layout = CanvasItem.CanvasItemRowLayout() play_button_canvas_item = CanvasItem.TextButtonCanvasItem() play_button_canvas_item.border_enabled = False abort_button_canvas_item = CanvasItem.TextButtonCanvasItem() abort_button_canvas_item.border_enabled = False status_text_canvas_item = CanvasItem.StaticTextCanvasItem(str()) hardware_source_display_name_canvas_item = CanvasItem.StaticTextCanvasItem( str()) playback_controls_row.add_canvas_item(play_button_canvas_item) playback_controls_row.add_canvas_item(abort_button_canvas_item) playback_controls_row.add_canvas_item(status_text_canvas_item) playback_controls_row.add_stretch() playback_controls_row.add_canvas_item( hardware_source_display_name_canvas_item) self.__playback_controls_composition.add_canvas_item( CanvasItem.BackgroundCanvasItem("#DAA520")) self.__playback_controls_composition.add_canvas_item( playback_controls_row) self.__display_panel.footer_canvas_item.insert_canvas_item( 0, self.__playback_controls_composition) def display_name_changed(display_name: str) -> None: hardware_source_display_name_canvas_item.text = display_name hardware_source_display_name_canvas_item.size_to_content( display_panel.image_panel_get_font_metrics) def play_button_state_changed(enabled: bool, play_button_state: str) -> None: play_button_canvas_item.enabled = enabled map_play_button_state_to_text = { "play": _("Play"), "pause": _("Pause") } play_button_canvas_item.text = map_play_button_state_to_text[ play_button_state] play_button_canvas_item.size_to_content( display_panel.image_panel_get_font_metrics) def abort_button_state_changed(visible: bool, enabled: bool) -> None: abort_button_canvas_item.text = _("Abort") if visible else str() abort_button_canvas_item.enabled = enabled abort_button_canvas_item.size_to_content( display_panel.image_panel_get_font_metrics) def acquisition_state_changed(key: str) -> None: # this may be called on a thread. create an async method (guaranteed to run on the main thread) # and add it to the window event loop. async def update_acquisition_state_label( acquisition_state: typing.Optional[str]) -> None: acquisition_state = acquisition_state or "stopped" status_text_canvas_item.text = map_channel_state_to_text[ acquisition_state] status_text_canvas_item.size_to_content( display_panel.image_panel_get_font_metrics) self.__display_panel.document_controller.event_loop.create_task( update_acquisition_state_label( self.__state_controller.acquisition_state_model.value)) def display_new_data_item(data_item: DataItem.DataItem) -> None: result_display_panel = display_panel.document_controller.next_result_display_panel( ) if result_display_panel: result_display_panel.set_display_panel_data_item(data_item) result_display_panel.request_focus() self.__state_controller.on_display_name_changed = display_name_changed self.__state_controller.on_play_button_state_changed = play_button_state_changed self.__state_controller.on_abort_button_state_changed = abort_button_state_changed self.__state_controller.on_display_new_data_item = display_new_data_item display_panel.set_data_item_reference( self.__state_controller.data_item_reference) play_button_canvas_item.on_button_clicked = self.__state_controller.handle_play_clicked abort_button_canvas_item.on_button_clicked = self.__state_controller.handle_abort_clicked self.__acquisition_state_changed_listener = self.__state_controller.acquisition_state_model.property_changed_event.listen( acquisition_state_changed) self.__state_controller.initialize_state() acquisition_state_changed("value")