Python PyQt5.QtCore.QItemSelection() Examples

The following are 11 code examples of PyQt5.QtCore.QItemSelection(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtCore , or try the search function .
Example #1
Source File: ParticipantTableModel.py    From urh with GNU General Public License v3.0 6 votes vote down vote up
def remove_participants(self, selection: QItemSelection):
        if len(self.participants) < 1:
            return

        if selection.isEmpty():
            start, end = len(self.participants) - 1, len(self.participants) - 1  # delete last element
        else:
            start, end = min([rng.top() for rng in selection]), max([rng.bottom() for rng in selection])

        del self.participants[start:end + 1]
        num_removed = (end + 1) - start
        for participant in self.participants:
            if participant.relative_rssi > len(self.participants) - 1:
                participant.relative_rssi -= num_removed

        # fix duplicates
        n = len(self.participants)
        for p1, p2 in itertools.combinations(self.participants, 2):
            if p1.relative_rssi == p2.relative_rssi:
                p1.relative_rssi = next((i for i in range(n)
                                         if i not in set(p.relative_rssi for p in self.participants)),
                                        0)

        self.update()
        self.participant_edited.emit() 
Example #2
Source File: mainwindow.py    From opcua-client-gui with GNU General Public License v3.0 5 votes vote down vote up
def show_refs(self, selection):
        if isinstance(selection, QItemSelection):
            if not selection.indexes(): # no selection
                return

        node = self.get_current_node()
        if node:
            self.refs_ui.show_refs(node) 
Example #3
Source File: mainwindow.py    From opcua-client-gui with GNU General Public License v3.0 5 votes vote down vote up
def show_attrs(self, selection):
        if isinstance(selection, QItemSelection):
            if not selection.indexes(): # no selection
                return

        node = self.get_current_node()
        if node:
            self.attrs_ui.show_attrs(node) 
Example #4
Source File: image_viewer_widget.py    From CvStudio with MIT License 5 votes vote down vote up
def default_label_changed_slot(self, selection: QItemSelection):
        selected_rows = self.treeview_labels.selectionModel().selectedRows(2)
        if len(selected_rows) > 0:
            index: QModelIndex = selected_rows[0]
            current_label: LabelVO = self.treeview_labels.model().data(index)
            self.image_viewer.current_label = current_label 
Example #5
Source File: dataframe_viewer.py    From pandasgui with MIT License 5 votes vote down vote up
def on_selectionChanged(self):
        """
        Runs when cells are selected in the Header. This selects columns in the data table when the header is clicked,
        and then calls selectAbove()
        """
        # Check focus so we don't get recursive loop, since headers trigger selection of data cells and vice versa
        if self.hasFocus():
            dataView = self.parent.dataView

            # Set selection mode so selecting one row or column at a time adds to selection each time
            if self.orientation == Qt.Horizontal:  # This case is for the horizontal header
                # Get the header's selected columns
                selection = self.selectionModel().selection()

                # Removes the higher levels so that only the lowest level of the header affects the data table selection
                last_row_ix = self.df.columns.nlevels - 1
                last_col_ix = self.model().columnCount() - 1
                higher_levels = QtCore.QItemSelection(self.model().index(0, 0),
                                                      self.model().index(last_row_ix - 1, last_col_ix))
                selection.merge(higher_levels, QtCore.QItemSelectionModel.Deselect)

                # Select the cells in the data view
                dataView.selectionModel().select(selection,
                                                 QtCore.QItemSelectionModel.Columns | QtCore.QItemSelectionModel.ClearAndSelect)
            if self.orientation == Qt.Vertical:
                selection = self.selectionModel().selection()

                last_row_ix = self.model().rowCount() - 1
                last_col_ix = self.df.index.nlevels - 1
                higher_levels = QtCore.QItemSelection(self.model().index(0, 0),
                                                      self.model().index(last_row_ix, last_col_ix - 1))
                selection.merge(higher_levels, QtCore.QItemSelectionModel.Deselect)

                dataView.selectionModel().select(selection,
                                                 QtCore.QItemSelectionModel.Rows | QtCore.QItemSelectionModel.ClearAndSelect)

        self.selectAbove()

    # Take the current set of selected cells and make it so that any spanning cell above a selected cell is selected too
    # This should happen after every selection change 
Example #6
Source File: ParticipantTableModel.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def move_up(self, selection: QItemSelection):
        if selection.isEmpty() or len(self.participants) < 1:
            return None, None

        start, end = min([rng.top() for rng in selection]), max([rng.bottom() for rng in selection])
        if start == 0:
            return None, None

        for i in range(start, end + 1):
            self.participants[i], self.participants[i - 1] = self.participants[i - 1], self.participants[i]

        self.update()
        self.participant_edited.emit()

        return start, end 
Example #7
Source File: ParticipantTableModel.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def move_down(self, selection: QItemSelection):
        if selection.isEmpty() or len(self.participants) < 1:
            return None, None

        start, end = min([rng.top() for rng in selection]), max([rng.bottom() for rng in selection])
        if end >= len(self.participants) - 1:
            return None, None

        for i in reversed(range(start, end + 1)):
            self.participants[i], self.participants[i + 1] = self.participants[i + 1], self.participants[i]

        self.update()
        self.participant_edited.emit()

        return start, end 
Example #8
Source File: ProtocolTreeView.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def selectionChanged(self, selection1: QItemSelection, selection2: QItemSelection):
        self.selection_changed.emit()
        super().selectionChanged(selection1, selection2) 
Example #9
Source File: ParticipantTableView.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def select(self, row_1, col_1, row_2, col_2):
        selection = QItemSelection()
        start_index = self.model().index(row_1, col_1)
        end_index = self.model().index(row_2, col_2)
        selection.select(start_index, end_index)
        self.selectionModel().select(selection, QItemSelectionModel.Select) 
Example #10
Source File: TableView.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def select(self, row_1, col_1, row_2, col_2):
        selection = QItemSelection()
        start_index = self.model().index(row_1, col_1)
        end_index = self.model().index(row_2, col_2)
        selection.select(start_index, end_index)
        self.selectionModel().select(selection, QItemSelectionModel.Select) 
Example #11
Source File: ProtocolTableView.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def selectionChanged(self, selection_1: QItemSelection, selection_2: QItemSelection):
        self.selection_changed.emit()
        super().selectionChanged(selection_1, selection_2)