示例#1
0
 def load_more_data(self, value, rows=False, columns=False):
     old_selection = self.selectionModel().selection()
     old_rows_loaded = old_cols_loaded = None
     
     if rows and value == self.verticalScrollBar().maximum():
         old_rows_loaded = self.model().rows_loaded
         self.model().fetch_more(rows=rows)
         
     if columns and value == self.horizontalScrollBar().maximum():
         old_cols_loaded = self.model().cols_loaded
         self.model().fetch_more(columns=columns)
         
     if old_rows_loaded is not None or old_cols_loaded is not None:
         # if we've changed anything, update selection
         new_selection = QItemSelection()
         for part in old_selection:
             top = part.top()
             bottom = part.bottom()
             if (old_rows_loaded is not None and 
                 top == 0 and bottom == (old_rows_loaded-1)):
                 # complete column selected (so expand it to match updated range)
                 bottom = self.model().rows_loaded-1
             left = part.left()
             right = part.right()
             if (old_cols_loaded is not None
                 and left == 0 and right == (old_cols_loaded-1)):
                 # compete row selected (so expand it to match updated range)
                 right = self.model().cols_loaded-1
             top_left = self.model().index(top, left)
             bottom_right = self.model().index(bottom, right)
             part = QItemSelectionRange(top_left, bottom_right)
             new_selection.append(part)
         self.selectionModel().select(new_selection, self.selectionModel().ClearAndSelect)
示例#2
0
    def load_more_data(self, value, rows=False, columns=False):
        old_selection = self.selectionModel().selection()
        old_rows_loaded = old_cols_loaded = None

        if rows and value == self.verticalScrollBar().maximum():
            old_rows_loaded = self.model().rows_loaded
            self.model().fetch_more(rows=rows)

        if columns and value == self.horizontalScrollBar().maximum():
            old_cols_loaded = self.model().cols_loaded
            self.model().fetch_more(columns=columns)

        if old_rows_loaded is not None or old_cols_loaded is not None:
            # if we've changed anything, update selection
            new_selection = QItemSelection()
            for part in old_selection:
                top = part.top()
                bottom = part.bottom()
                if (old_rows_loaded is not None and top == 0
                        and bottom == (old_rows_loaded - 1)):
                    # complete column selected (so expand it to match updated range)
                    bottom = self.model().rows_loaded - 1
                left = part.left()
                right = part.right()
                if (old_cols_loaded is not None and left == 0
                        and right == (old_cols_loaded - 1)):
                    # compete row selected (so expand it to match updated range)
                    right = self.model().cols_loaded - 1
                top_left = self.model().index(top, left)
                bottom_right = self.model().index(bottom, right)
                part = QItemSelectionRange(top_left, bottom_right)
                new_selection.append(part)
            self.selectionModel().select(new_selection,
                                         self.selectionModel().ClearAndSelect)
示例#3
0
 def selectionChanged(
     self, selected: QItemSelection, deselected: QItemSelection
 ):
     """The Qt Selection has changed. Update the python model."""
     s = self._root.selection
     s.difference_update(i.internalPointer() for i in deselected.indexes())
     s.update(i.internalPointer() for i in selected.indexes())
     return super().selectionChanged(selected, deselected)
示例#4
0
 def _sync_selection_models(self):
     """Clear and re-sync the Qt selection view from the python selection."""
     sel_model = self.selectionModel()
     selection = QItemSelection()
     for i in self._root.selection:
         idx = self.model().findIndex(i)
         selection.select(idx, idx)
     sel_model.select(selection, sel_model.ClearAndSelect)
示例#5
0
 def selectionChanged(
     self: QAbstractItemView,
     selected: QItemSelection,
     deselected: QItemSelection,
 ):
     """The Qt Selection has changed. Update the python model."""
     s = self._root.selection
     s.difference_update(i.data(Qt.UserRole) for i in deselected.indexes())
     s.update(i.data(Qt.UserRole) for i in selected.indexes())
     return super().selectionChanged(selected, deselected)
示例#6
0
    def selectionChanged(
        self: QAbstractItemView,
        selected: QItemSelection,
        deselected: QItemSelection,
    ):
        """The Qt Selection has changed. Update the python model."""
        sel = {i.data(ItemRole) for i in selected.indexes()}
        desel = {i.data(ItemRole) for i in deselected.indexes()}

        if not self._root.selection.events.changed._emitting:
            self._root.selection.update(sel)
            self._root.selection.difference_update(desel)
        return super().selectionChanged(selected, deselected)
示例#7
0
 def selectionChanged(self, selected: QItemSelection,
                      deselected: QItemSelection) -> None:
     selected_indexes = selected.indexes()
     if not selected_indexes:
         return
     index = selected_indexes[0]
     self._activate(index)
示例#8
0
    def _on_tree_selection(self, selected: QItemSelection,
                           deselected: QItemSelection):
        item = self.model.itemFromIndex(selected.indexes()[0])
        self.thumb_grid.set_item(item)

        if item.isImage():
            QCoreApplication.processEvents()
            self.load_image(item.wrapper)
示例#9
0
    def selectionChanged(self, selected: QItemSelection, deselected: QItemSelection):
        selected_indexes = selected.indexes()
        if not selected_indexes:
            return
        data = selected_indexes[0].data(BrokerModel.broker_role)
        if data and data != self._current_broker:
            print(data)
            self._current_broker = data
            self.sigCurrentBrokerChanged.emit(data)

        super(BrokerView, self).selectionChanged(selected, deselected)
示例#10
0
 def select_channel(self, channel_index: int):
     top_left = self._channel_table_model.index(channel_index, 0)
     top_left = self._channel_table_proxy_model.mapFromSource(top_left)
     bottom_right = self._channel_table_model.index(
         channel_index,
         self._channel_table_model.columnCount() - 1)
     bottom_right = self._channel_table_proxy_model.mapFromSource(
         bottom_right)
     selection_model: QItemSelectionModel = self._channel_table_view.selectionModel(
     )
     selection_model.clearSelection(
     )  # first clear the selection, to make sure the channel controls refresh
     selection_model.select(QItemSelection(top_left, bottom_right),
                            QItemSelectionModel.Select)
示例#11
0
    def paste(self):
        bounds = self.view_data._selection_bounds()
        if bounds is None:
            return
        row_min, row_max, col_min, col_max = bounds
        clipboard = QApplication.clipboard()
        text = str(clipboard.text())
        list_data = [line.split('\t') for line in text.splitlines()]
        try:
            # take the first cell which contains '\'
            pos_last = next(i for i, v in enumerate(list_data[0]) if '\\' in v)
        except StopIteration:
            # if there isn't any, assume 1d array
            pos_last = 0
        if pos_last or '\\' in list_data[0][0]:
            # ndim > 1
            list_data = [line[pos_last + 1:] for line in list_data[1:]]
        elif len(list_data) == 2 and list_data[1][0] == '':
            # ndim == 1
            list_data = [list_data[1][1:]]
        new_data = np.array(list_data)
        if new_data.shape[0] > 1:
            row_max = row_min + new_data.shape[0]
        if new_data.shape[1] > 1:
            col_max = col_min + new_data.shape[1]

        result = self.model_data.set_values(row_min, col_min, row_max, col_max,
                                            new_data)

        if result is None:
            return

        # TODO: when pasting near bottom/right boundaries and size of
        # new_data exceeds destination size, we should either have an error
        # or clip new_data
        self.view_data.selectionModel().select(
            QItemSelection(*result), QItemSelectionModel.ClearAndSelect)
示例#12
0
文件: layerlist.py 项目: pcbre/pcbre
 def layer_selection_changed(self, selected: QtCore.QItemSelection,
                             deselected: QtCore.QItemSelection) -> None:
     if self.suppress_sel_change:
         return
     layer_index = selected.indexes()[0].row()
     self.win.changeViewLayer(self.win.project.stackup.layers[layer_index])