def initialize_state(self):
        """ Call this to initialize the state of the UI after everything has been connected. """
        if self.__scan_hardware_source:
            self.__profile_changed_event_listener = self.__scan_hardware_source.profile_changed_event.listen(self.__update_profile_index)
            self.__frame_parameters_changed_event_listener = self.__scan_hardware_source.frame_parameters_changed_event.listen(self.__update_frame_parameters)
            self.__data_item_states_changed_event_listener = self.__scan_hardware_source.data_item_states_changed_event.listen(self.__data_item_states_changed)
            self.__acquisition_state_changed_event_listener = self.__scan_hardware_source.acquisition_state_changed_event.listen(self.__acquisition_state_changed)
            self.__probe_state_changed_event_listener = self.__scan_hardware_source.probe_state_changed_event.listen(self.__probe_state_changed)
            self.__channel_state_changed_event_listener = self.__scan_hardware_source.channel_state_changed_event.listen(self.__channel_state_changed)
            subscan_state_model = self.__scan_hardware_source.subscan_state_model

            def subscan_state_changed(name):
                if callable(self.on_subscan_state_changed):
                    self.on_subscan_state_changed(subscan_state_model.value)

            self.__subscan_state_changed_listener = subscan_state_model.property_changed_event.listen(subscan_state_changed)
            subscan_state_changed("value")
        if self.on_display_name_changed:
            self.on_display_name_changed(self.display_name)
        if self.on_subscan_state_changed:
            self.on_subscan_state_changed(self.__scan_hardware_source.subscan_state)
        channel_count = self.__scan_hardware_source.channel_count
        if self.on_channel_count_changed:
            self.on_channel_count_changed(channel_count)
        self.__channel_enabled = [False] * channel_count
        for channel_index in range(channel_count):
            channel_id, name, enabled = self.__scan_hardware_source.get_channel_state(channel_index)
            self.__channel_state_changed(channel_index, channel_id, name, enabled)
            self.__channel_enabled[channel_index] = enabled
        self.__update_buttons()
        if self.on_profiles_changed:
            profile_items = list(ScanControlStateController.profiles.items())
            profile_items.sort(key=lambda k_v: k_v[1])
            profiles = map(lambda k_v: k_v[0], profile_items)
            self.on_profiles_changed(profiles)
            self.__update_profile_index(self.__scan_hardware_source.selected_profile_index)
        if self.on_linked_changed:
            self.on_linked_changed(self.__linked)
        if self.on_simulate_button_state_changed:
            use_simulator = self.__scan_hardware_source.use_hardware_simulator
            self.on_simulate_button_state_changed(use_simulator, use_simulator)
        if self.on_data_item_states_changed:
            self.on_data_item_states_changed(list())
        probe_state = self.__scan_hardware_source.probe_state
        probe_position = self.__scan_hardware_source.probe_position
        self.__probe_state_changed(probe_state, probe_position)