Python源码示例:PyQt5.QtCore.Qt.CheckStateRole()

示例1
def data(self, index, role):
        if not index.isValid():
            return None
        if index.column() == 0:
            value = ('' if self.my_data[index.row()][index.column() + 1]
                     else 'Skip')
        else:
            value = self.my_data[index.row()][index.column() + 1]
        if role == Qt.EditRole:
            return value
        elif role == Qt.DisplayRole:
            return value
        elif role == Qt.CheckStateRole:
            if index.column() == 0:
                return (
                    Qt.Checked if self.my_data[index.row()][index.column() + 1]
                    else Qt.Unchecked) 
示例2
def data(self, index, rola=Qt.DisplayRole):
        """ Wyświetlanie danych """
        i = index.row()
        j = index.column()

        if rola == Qt.DisplayRole:
            return '{0}'.format(self.tabela[i][j])
        elif rola == Qt.CheckStateRole and (j == 3 or j == 4):
            if self.tabela[i][j]:
                return Qt.Checked
            else:
                return Qt.Unchecked
        elif rola == Qt.EditRole and j == 1:
            return self.tabela[i][j]
        else:
            return QVariant() 
示例3
def data(self, index, rola=Qt.DisplayRole):
        """ Wyświetlanie danych """
        i = index.row()
        j = index.column()

        if rola == Qt.DisplayRole:
            return '{0}'.format(self.tabela[i][j])
        elif rola == Qt.CheckStateRole and (j == 3 or j == 4):
            if self.tabela[i][j]:
                return Qt.Checked
            else:
                return Qt.Unchecked
        elif rola == Qt.EditRole and j == 1:
            return self.tabela[i][j]
        else:
            return QVariant() 
示例4
def setData(self, index: QModelIndex, value, role=None):
        if not index.isValid():
            return False

        i, j = index.row(), index.column()
        device = self.get_device_at(i)
        if role == Qt.CheckStateRole:
            enabled = bool(value)
            if j == 0:
                device.is_enabled = enabled
            if j == 2:
                if enabled and device.has_native_backend:
                    device.selected_backend = Backends.native
                elif not enabled and device.has_gnuradio_backend:
                    device.selected_backend = Backends.grc
            elif j == 3:
                if enabled and device.has_gnuradio_backend:
                    device.selected_backend = Backends.grc
                elif not enabled and device.has_native_backend:
                    device.selected_backend = Backends.native

            self.update()
            device.write_settings()
            return True 
示例5
def setData(self, index: QModelIndex, value, role=None):
        row = index.row()
        lbl = self.display_labels[row]
        if role == Qt.EditRole and index.column() in (0, 1, 2, 3):
            if index.column() == 0:
                lbl.name = value
                new_field_type = self.controller.field_types_by_caption.get(value, None)
                self.controller.active_message_type.change_field_type_of_label(lbl, new_field_type)
            elif index.column() == 1:
                lbl.color_index = value
                self.label_color_changed.emit(lbl)
            elif index.column() == 2:
                lbl.display_format_index = value
            elif index.column() == 3:
                lbl.display_order_str = value

            self.dataChanged.emit(self.index(row, 0),
                                  self.index(row, self.columnCount()))
        elif role == Qt.CheckStateRole and index.column() == 0:
            lbl.show = value
            self.protolabel_visibility_changed.emit(lbl)
            return True 
示例6
def data(self, index, role=Qt.DisplayRole):
        row = index.row()
        if row >= len(self.labels):
            return

        if role == Qt.DisplayRole:
            nfuzzval = len(self.labels[row].fuzz_values)
            nfuzzval = str(nfuzzval - 1) if nfuzzval > 1 else "empty"
            try:
                return self.labels[row].name + " (" + nfuzzval + ")"
            except TypeError:
                return ""
        elif role == Qt.CheckStateRole:
            return self.labels[row].fuzz_me
        elif role == Qt.BackgroundColorRole:
            return settings.LABEL_COLORS[self.labels[row].color_index] 
示例7
def data(self, index: QModelIndex, role=None):
        item = self.getItem(index)
        if role == Qt.DisplayRole:
            return item.data()
        elif role == Qt.DecorationRole and item.is_group:
            return QIcon.fromTheme("folder")
        elif role == Qt.CheckStateRole:
            return item.show
        elif role == Qt.FontRole:
            if item.is_group and self.rootItem.index_of(item) in self.controller.active_group_ids:
                font = QFont()
                font.setBold(True)
                return font
            elif item.protocol in self.controller.selected_protocols:
                font = QFont()
                font.setBold(True)
                return font
        elif role == Qt.ToolTipRole:
            return item.data() 
示例8
def data(self, index, role=Qt.DisplayRole):
        row = index.row()
        if not index.isValid() or row >= len(self.message_types):
            return

        message_type = self.message_types[row]

        if role == Qt.DisplayRole:
            if index.column() == 0:
                return message_type.name
            elif index.column() == 1:
                return ""
        elif role == Qt.CheckStateRole:
            if index.column() == 0:
                return message_type.show
            elif index.column() == 1:
                return None
        elif role == Qt.EditRole:
            if index.column() == 0:
                return message_type.name
        elif role == Qt.FontRole and index.column() == 0:
            font = QFont()
            font.setBold(index.row() in self.selected_message_type_indices)
            return font 
示例9
def data(self, index: QModelIndex, role=None):
        row = index.row()
        if role == Qt.DisplayRole:
            if row == 0:
                return "not assigned"
            else:
                try:
                    return str(self.participants[row-1])
                except IndexError:
                    return None

        elif role == Qt.CheckStateRole:
            if row == 0:
                return Qt.Checked if self.show_unassigned else Qt.Unchecked
            else:
                try:
                    return Qt.Checked if self.participants[row-1].show else Qt.Unchecked
                except IndexError:
                    return None 
示例10
def data(self, index, role=None):
        value = self._anchor_positions[index.row()][index.column()]
        if index.isValid():
            if index.column() == 0:
                if role == Qt.CheckStateRole:
                    return QVariant(value)
            elif index.column() == 1:
                if role == Qt.DisplayRole:
                    return QVariant(value)
            else:
                if role == Qt.DisplayRole:
                    return QVariant('%.2f' % (value))
                elif role == Qt.EditRole:
                    return QVariant(value)
                elif role == Qt.BackgroundRole:
                    return self._get_background(index.row(), index.column())

        return QVariant() 
示例11
def data(self, index, role):
        if not index.isValid():
            return None

        item = index.internalPointer()

        if role == Qt.DisplayRole:
            return item.data(index.column())
        elif role == Qt.CheckStateRole and index.column() == 0:
            return item.getCheckedState()
        else:
            return None 
示例12
def setData(self, index, value, role=Qt.EditRole):
        if role == Qt.CheckStateRole:
            item = index.internalPointer()
            item.setCheckedState(value)
            self.dataChanged.emit(QModelIndex(), QModelIndex(), [])

        return True 
示例13
def data(self, index, role):
        if role == Qt.DisplayRole:
            if index.column() == 1:
                rowdata = self.macros[index.row()]
                macro = rowdata[index.column()]
                return macro.fname
        if role == Qt.CheckStateRole:
            if index.column() == 0:
                if self.macros[index.row()][0]:
                    return 2
                return 0
        return QVariant() 
示例14
def setData(self, index, value, role):
        if role == Qt.CheckStateRole and index.column() == 0:
            if value:
                self.enable_macro(index.row())
            else:
                self.disable_macro(index.row())
            return True
        return False

    # Non model functions 
示例15
def setData(self, index, value, role):
        if not index.isValid():
            return False
        if role == Qt.CheckStateRole and index.column() == 0:
            self.my_data[index.row()][index.column() + 1] = value == Qt.Checked
        self.dataChanged.emit(index, index)
        return True 
示例16
def setData(self, index, value, rola=Qt.DisplayRole):
        """ Zmiana danych """
        i = index.row()
        j = index.column()
        if rola == Qt.EditRole and j == 1:
            self.tabela[i][j] = value
        elif rola == Qt.CheckStateRole and (j == 3 or j == 4):
            if value:
                self.tabela[i][j] = True
            else:
                self.tabela[i][j] = False

        return True 
示例17
def setData(self, index, value, rola=Qt.DisplayRole):
        """ Zmiana danych """
        i = index.row()
        j = index.column()
        if rola == Qt.EditRole and j == 1:
            self.tabela[i][j] = value
        elif rola == Qt.CheckStateRole and (j == 3 or j == 4):
            if value:
                self.tabela[i][j] = True
            else:
                self.tabela[i][j] = False

        return True 
示例18
def itemCheckState(self, index):
        """
        Return the check state for item at `index`
        Parameters
        ----------
        index : int
        Returns
        -------
        state : Qt.CheckState
        """
        state = self.itemData(index, role=Qt.CheckStateRole)
        if isinstance(state, int):
            return Qt.CheckState(state)
        else:
            return Qt.Unchecked 
示例19
def setItemCheckState(self, index, state):
        """
        Set the check state for item at `index` to `state`.
        Parameters
        ----------
        index : int
        state : Qt.CheckState
        """
        self.setItemData(index, state, Qt.CheckStateRole) 
示例20
def data(self, index: QModelIndex, role=Qt.DisplayRole):
        if not index.isValid():
            return None

        i = index.row()
        j = index.column()
        device = self.get_device_at(i)
        if role == Qt.DisplayRole:
            if j == 0:
                return self.backend_handler.DEVICE_NAMES[i]
            elif j == 1:
                if device.is_enabled:
                    if device.supports_rx and device.supports_tx:
                        device_info = "supports RX and TX"
                    elif device.supports_rx and not device.supports_tx:
                        device_info = "supports RX only"
                    elif not device.supports_rx and device.supports_tx:
                        device_info = "supports TX only"
                    else:
                        device_info = ""
                else:
                    device_info = "disabled"

                return device_info
            elif j == 2:
                return "" if device.has_native_backend else "not available"
            elif j == 3:
                return "" if device.has_gnuradio_backend else "not available"
        elif role == Qt.CheckStateRole:
            if j == 0 and (device.has_native_backend or device.has_gnuradio_backend):
                return Qt.Checked if device.is_enabled else Qt.Unchecked
            elif j == 2 and device.has_native_backend:
                return Qt.Checked if device.selected_backend == Backends.native else Qt.Unchecked
            elif j == 3 and device.has_gnuradio_backend:
                return Qt.Checked if device.selected_backend == Backends.grc else Qt.Unchecked 
示例21
def data(self, index: QModelIndex, role=None):
        row = index.row()
        if role == Qt.DisplayRole:
            return self.plugins[row].name
        elif role == Qt.CheckStateRole:
            return self.plugins[row].enabled
        elif role == Qt.TextColorRole and self.plugins[row] in self.highlighted_plugins:
            return settings.HIGHLIGHT_TEXT_FOREGROUND_COLOR
        elif role == Qt.BackgroundColorRole and self.plugins[row] in self.highlighted_plugins:
            return settings.HIGHLIGHT_TEXT_BACKGROUND_COLOR
        elif role == Qt.FontRole and self.plugins[row] in self.highlighted_plugins:
            font = QFont()
            font.setBold(True)
            return font 
示例22
def setData(self, index: QModelIndex, value, role=None):
        if role == Qt.CheckStateRole:
            self.plugins[index.row()].enabled = value
        return True 
示例23
def setData(self, index: QModelIndex, value, role=None):
        item = self.getItem(index)

        if role == Qt.EditRole and len(value) > 0:
            item.setData(value)
            return True
        elif role == Qt.CheckStateRole:
            item.show = value
            return True

        return False 
示例24
def setData(self, index: QModelIndex, value, role=None):
        if index.row() == 0 and role == Qt.CheckStateRole:
            if bool(value) != self.show_unassigned:
                self.show_unassigned = bool(value)
                self.show_state_changed.emit()

        elif role == Qt.CheckStateRole:
            try:
                if self.participants[index.row()-1].show != value:
                    self.participants[index.row()-1].show = value
                    self.show_state_changed.emit()
            except IndexError:
                return False

        return True 
示例25
def data(self, index: QModelIndex, role=Qt.DisplayRole):
        i = index.row()
        participant = self.simulator_config.active_participants[i]

        if not index.isValid():
            return None

        if role == Qt.DisplayRole:
            return participant.name + " (" + participant.shortname + ")"
        elif role == Qt.CheckStateRole:
            return Qt.Checked if participant.simulate else Qt.Unchecked 
示例26
def setData(self, index: QModelIndex, value, role=None):
        i = index.row()
        participants = self.simulator_config.active_participants
        if role == Qt.CheckStateRole:
            participants[i].simulate = value
            self.update()
            self.participant_simulate_changed.emit(participants[i])

        return True 
示例27
def on_show_all_action_triggered(self):
        for i in range(self.model().rowCount()):
            self.model().setData(self.model().index(i, 0), Qt.Checked, role=Qt.CheckStateRole) 
示例28
def test_fuzzing_label_list_view(self):
        self.add_signal_to_form("ask.complex")
        gframe = self.form.generator_tab_controller  # type: GeneratorTabController
        gframe.ui.cbViewType.setCurrentText("Bit")

        self.add_signal_to_generator(0)
        gframe.ui.tabWidget.setCurrentWidget(gframe.ui.tab_fuzzing)

        gframe.ui.tableMessages.selectRow(0)
        self.assertEqual(gframe.label_list_model.rowCount(), 0)
        gframe.create_fuzzing_label(0, 10, 20)
        self.assertEqual(gframe.label_list_model.rowCount(), 1)

        model = gframe.label_list_model
        lbl = model.labels[0]
        self.assertTrue(bool(lbl.fuzz_me))
        self.assertEqual(len(lbl.fuzz_values), 1)

        self.assertTrue(bool(model.data(model.index(0,0), role=Qt.CheckStateRole)), True)
        model.setData(model.index(0,0), Qt.Unchecked, role=Qt.CheckStateRole)
        self.assertFalse(lbl.fuzz_me)

        model.setData(model.index(0,0), "test", role=Qt.EditRole)
        self.assertEqual("test (empty)", model.data(model.index(0,0), role=Qt.DisplayRole))

        lbl.fuzz_values.append("101010")
        model.update()
        self.assertEqual("test (1)", model.data(model.index(0, 0), role=Qt.DisplayRole)) 
示例29
def test_participants_list(self):
        alice = Participant("Alice", "A")
        bob = Participant("Bob", "B")
        self.form.project_manager.participants.append(alice)
        self.form.project_manager.participants.append(bob)
        self.form.project_manager.project_updated.emit()

        mt = self.form.compare_frame_controller.proto_analyzer.default_message_type
        msg1 = SimulatorMessage(destination=alice, plain_bits=array("B", [1, 0, 1, 1]), pause=100, message_type=mt)
        msg2 = SimulatorMessage(destination=bob, plain_bits=array("B", [1, 0, 1, 1]), pause=100, message_type=mt)

        simulator_manager = self.form.simulator_tab_controller.simulator_config
        simulator_manager.add_items([msg1, msg2], 0, simulator_manager.rootItem)
        simulator_manager.add_label(5, 15, "test", parent_item=simulator_manager.rootItem.children[0])

        stc = self.form.simulator_tab_controller  # type: SimulatorTabController
        model = stc.ui.listViewSimulate.model()
        self.assertEqual(model.rowCount(), 2)
        self.assertEqual(model.data(model.index(0, 0)), "Alice (A)")
        self.assertEqual(model.data(model.index(1, 0)), "Bob (B)")
        self.assertFalse(self.form.project_manager.participants[0].simulate)
        self.assertEqual(model.data(model.index(0, 0), role=Qt.CheckStateRole), Qt.Unchecked)
        self.assertFalse(self.form.project_manager.participants[1].simulate)
        self.assertEqual(model.data(model.index(1, 0), role=Qt.CheckStateRole), Qt.Unchecked)

        model.setData(model.index(0, 0), Qt.Checked, role=Qt.CheckStateRole)
        self.assertTrue(self.form.project_manager.participants[0].simulate) 
示例30
def data(self,index,role):
        idx = index.row()
        if role == Qt.DisplayRole:
            return self.nativedata[idx][self.key]
        elif role == Qt.ForegroundRole:
            return QtGui.QBrush(Qt.black)
        elif role == Qt.BackgroundRole:
            return QtGui.QBrush(QtGui.QColor(self.nativedata[idx].get('color',Qt.white)))
        elif role == Qt.CheckStateRole:
            return self._checkstate.get(key,Qt.CheckState.Unchecked)