Пример #1
0
    def __init__(self):
        super().__init__()
        self.distances = None
        self.items = None

        self.tablemodel = DistanceMatrixModel()
        view = self.tableview = TableView()
        view.setWordWrap(False)
        view.setTextElideMode(Qt.ElideNone)
        view.setEditTriggers(QTableView.NoEditTriggers)
        view.setItemDelegate(TableBorderItem())
        view.setModel(self.tablemodel)
        view.setShowGrid(False)
        for header in (view.horizontalHeader(), view.verticalHeader()):
            header.setResizeContentsPrecision(1)
            header.setSectionResizeMode(QHeaderView.ResizeToContents)
            header.setHighlightSections(True)
            header.setSectionsClickable(False)
        view.verticalHeader().setDefaultAlignment(Qt.AlignRight
                                                  | Qt.AlignVCenter)
        selmodel = SymmetricSelectionModel(view.model(), view)
        view.setSelectionModel(selmodel)
        view.setSelectionBehavior(QTableView.SelectItems)
        self.mainArea.layout().addWidget(view)

        settings_box = gui.hBox(self.mainArea)

        self.annot_combo = gui.comboBox(settings_box,
                                        self,
                                        "annotation_idx",
                                        label="Labels: ",
                                        orientation=Qt.Horizontal,
                                        callback=self._invalidate_annotations,
                                        contentsLength=12)
        self.annot_combo.setModel(VariableListModel())
        self.annot_combo.model()[:] = ["None", "Enumeration"]
        gui.rubber(settings_box)
        acb = gui.auto_send(settings_box, self, "auto_commit", box=None)
        acb.setFixedWidth(200)
        # Signal must be connected after self.commit is redirected
        selmodel.selectionChanged.connect(self.commit)
Пример #2
0
    def __init__(self):
        super().__init__()
        self.distances = None
        self.items = None

        self.tablemodel = DistanceMatrixModel()
        view = self.tableview = TableView()
        view.setWordWrap(False)
        view.setTextElideMode(Qt.ElideNone)
        view.setEditTriggers(QTableView.NoEditTriggers)
        view.setItemDelegate(
            TableBorderItem(roles=(Qt.DisplayRole, Qt.BackgroundRole,
                                   Qt.ForegroundRole)))
        view.setModel(self.tablemodel)
        view.setShowGrid(False)
        for header in (view.horizontalHeader(), view.verticalHeader()):
            header.setResizeContentsPrecision(1)
            header.setSectionResizeMode(QHeaderView.ResizeToContents)
            header.setHighlightSections(True)
            header.setSectionsClickable(False)
        view.verticalHeader().setDefaultAlignment(Qt.AlignRight
                                                  | Qt.AlignVCenter)
        selmodel = SymmetricSelectionModel(view.model(), view)
        selmodel.selectionChanged.connect(self.commit.deferred)
        view.setSelectionModel(selmodel)
        view.setSelectionBehavior(QTableView.SelectItems)
        self.controlArea.layout().addWidget(view)

        self.annot_combo = gui.comboBox(self.buttonsArea,
                                        self,
                                        "annotation_idx",
                                        label="标签: ",
                                        orientation=Qt.Horizontal,
                                        callback=self._invalidate_annotations,
                                        contentsLength=12)
        self.annot_combo.setModel(VariableListModel())
        self.annot_combo.model()[:] = ["无", "枚举"]
        gui.rubber(self.buttonsArea)
        acb = gui.auto_send(self.buttonsArea, self, "auto_commit", box=False)
        acb.setFixedWidth(200)
Пример #3
0
    def test_symmetricselectionmodel(self):
        model = QStandardItemModel()
        model.setRowCount(4)
        model.setColumnCount(4)
        sel = SymmetricSelectionModel(model)
        sel.select(model.index(0, 0), BlockSelectionModel.Select)
        self.assertSetEqual(selected(sel), {(0, 0)})
        sel.select(model.index(0, 2), BlockSelectionModel.Select)
        self.assertSetEqual(selected(sel), {(0, 0), (0, 2), (2, 0), (2, 2)})
        sel.select(model.index(0, 0), BlockSelectionModel.Deselect)
        self.assertSetEqual(selected(sel), {(2, 2)})
        sel.select(model.index(2, 3), BlockSelectionModel.ClearAndSelect)
        self.assertSetEqual(selected(sel), {(2, 2), (2, 3), (3, 2), (3, 3)})

        self.assertSetEqual(set(sel.selectedItems()), {2, 3})
        sel.setSelectedItems([1, 2])
        self.assertSetEqual(set(sel.selectedItems()), {1, 2})