Example #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)
Example #2
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)
Example #3
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)
Example #4
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)