Exemple #1
0
    def set_activation_config(self, activation_config):
        """

        @param activation_config:
        @return:
        """
        if isinstance(activation_config, list):
            activation_config = set(activation_config)

        # Do nothing if the activation config has not changed or is wrong data type
        if not isinstance(activation_config,
                          set) or activation_config == self.activation_config:
            return

        self.beginResetModel()

        self.activation_config = activation_config
        self.digital_channels = sorted(
            (chnl for chnl in activation_config if chnl.startswith('d')),
            key=lambda chnl: int(chnl.split('ch')[-1]))
        self.analog_channels = sorted(
            (chnl for chnl in activation_config if chnl.startswith('a')),
            key=lambda chnl: int(chnl.split('ch')[-1]))

        analog_shape = {
            chnl: SamplingFunctions.Idle()
            for chnl in self.analog_channels
        }
        digital_state = {chnl: False for chnl in self.digital_channels}
        self.__default_element = PulseBlockElement(pulse_function=analog_shape,
                                                   digital_high=digital_state)

        # The actual model data container with a single default element
        self._pulse_block = PulseBlock(name='EDITOR CONTAINER',
                                       element_list=[self.__default_element])

        self._col_widths = self._get_column_widths()
        self._create_header_data()

        self.endResetModel()

        self._notify_column_width()
        return
Exemple #2
0
    def __init__(self):
        super().__init__()

        self.digital_channels = list()
        self.analog_channels = list()
        self.activation_config = set()

        # The actual model data container.
        self._pulse_block = PulseBlock('EDITOR CONTAINER')
        # The default PulseBlockElement
        self.__default_element = PulseBlockElement()

        # Create header strings
        self._create_header_data()

        # The current column widths.
        # The fact that the widths are stored in the model saves a huge amount of computational
        # time when resizing columns due to item changes.
        self._col_widths = self._get_column_widths()
        # Notify the QTableView about a change in column widths
        self._notify_column_width()
        return
Exemple #3
0
    def setData(self, index, data, role=QtCore.Qt.DisplayRole):
        """
        """
        if isinstance(data, PulseBlockElement):
            self._pulse_block[index.row()] = copy.deepcopy(data)
            return

        if role == self.lengthRole and isinstance(data, (int, float)):
            old_elem = self._pulse_block[index.row()]
            if data != old_elem.init_length_s:
                new_elem = PulseBlockElement(init_length_s=max(0, data),
                                             increment_s=old_elem.increment_s,
                                             pulse_function=old_elem.pulse_function,
                                             digital_high=old_elem.digital_high)
                self._pulse_block[index.row()] = new_elem
        elif role == self.incrementRole and isinstance(data, (int, float)):
            old_elem = self._pulse_block[index.row()]
            if data != old_elem.increment_s:
                new_elem = PulseBlockElement(init_length_s=old_elem.init_length_s,
                                             increment_s=data,
                                             pulse_function=old_elem.pulse_function,
                                             digital_high=old_elem.digital_high)
                self._pulse_block[index.row()] = new_elem
        elif role == self.digitalStateRole and isinstance(data, dict):
            old_elem = self._pulse_block[index.row()]
            if data != old_elem.digital_high:
                new_elem = PulseBlockElement(init_length_s=old_elem.init_length_s,
                                             increment_s=old_elem.increment_s,
                                             pulse_function=old_elem.pulse_function,
                                             digital_high=data.copy())
                self._pulse_block[index.row()] = new_elem
        elif role == self.analogShapeRole and isinstance(data, str):
            if self.data(index=index, role=self.analogShapeRole) != data:
                old_elem = self._pulse_block[index.row()]

                sampling_func = getattr(SamplingFunctions, data)
                col_offset = 3 if self.digital_channels else 2
                chnl = self.analog_channels[(index.column() - col_offset) // 2]

                pulse_function = old_elem.pulse_function.copy()
                pulse_function[chnl] = sampling_func()

                new_elem = PulseBlockElement(init_length_s=old_elem.init_length_s,
                                             increment_s=old_elem.increment_s,
                                             pulse_function=pulse_function,
                                             digital_high=old_elem.digital_high)
                self._pulse_block[index.row()] = new_elem

                new_column_width = self._get_column_width(index.column()+1)
                if new_column_width >= 0 and new_column_width != self._col_widths[index.column()+1]:
                    self._col_widths[index.column() + 1] = new_column_width
                    self._notify_column_width(index.column()+1)

        elif role == self.analogParameterRole and isinstance(data, dict):
            col_offset = 3 if self.digital_channels else 2
            chnl = self.analog_channels[(index.column() - col_offset) // 2]
            self._pulse_block[index.row()].pulse_function[chnl].__init__(**data)
        elif role == self.pulseBlockRole and isinstance(data, PulseBlock):
            self._pulse_block = copy.deepcopy(data)
            self._pulse_block.name = 'EDITOR CONTAINER'
            self._pulse_block.refresh_parameters()
        return