Exemplo n.º 1
0
 def fetch_more(self, rows=False, columns=False):
     if self.can_fetch_more(rows=rows):
         reminder = self.total_rows - self.rows_loaded
         items_to_fetch = min(reminder, self.ROWS_TO_LOAD)
         self.beginInsertRows(QtCore.QModelIndex(), self.rows_loaded,
                              self.rows_loaded + items_to_fetch - 1)
         self.rows_loaded += items_to_fetch
         self.endInsertRows()
     if self.can_fetch_more(columns=columns):
         reminder = self.total_cols - self.cols_loaded
         items_to_fetch = min(reminder, self.COLS_TO_LOAD)
         self.beginInsertColumns(QtCore.QModelIndex(), self.cols_loaded,
                                 self.cols_loaded + items_to_fetch - 1)
         self.cols_loaded += items_to_fetch
         self.endInsertColumns()
Exemplo n.º 2
0
 def load_new_marks(self, mark):
     new = [mark.y, mark]
     self.marks.append(new)
     self.sort_marks()
     idx = self.marks.index(new)
     self.beginInsertRows(QtCore.QModelIndex(), idx, idx)
     self.endInsertRows()
     mark.moved.connect(self.update_after_move)
     self.update_lines()
Exemplo n.º 3
0
 def columnCount(self, index=QtCore.QModelIndex()):
     """DataFrame column number"""
     # This is done to implement series
     if len(self.df.shape) == 1:
         return 2
     elif self.total_cols <= self.cols_loaded:
         return self.total_cols + 1
     else:
         return self.cols_loaded + 1
Exemplo n.º 4
0
 def delRow(self, irow):
     mark = self.marks[irow][1]
     try:
         mark.moved.disconnect(self.update_after_move)
     except ValueError:
         pass
     try:
         self._remove_mark(mark)
     except ValueError:
         pass
     del self.marks[irow]
     self.beginRemoveRows(QtCore.QModelIndex(), irow, irow)
     self.endRemoveRows()
     self.update_lines()
Exemplo n.º 5
0
 def remove_mark(self, mark):
     found = False
     for i, (y, m) in enumerate(self.marks):
         if m is mark:
             found = True
             break
     if found:
         try:
             mark.moved.disconnect(self.update_after_move)
         except ValueError:
             pass
         del self.marks[i]
         self.beginRemoveRows(QtCore.QModelIndex(), i, i)
         self.endRemoveRows()
         self.update_lines()
Exemplo n.º 6
0
    def insertRows(self, irow, nrows=1):
        """Insert a row into the :attr:`df`

        Parameters
        ----------
        irow: int
            The row index. If `irow` is equal to the length of the
            :attr:`df`, the rows will be appended.
        nrows: int
            The number of rows to insert"""
        df = self.df
        if not irow:
            if not len(df):
                idx = 0
            else:
                idx = df.index.values[0]
        else:
            try:
                idx = df.index.values[irow-1:irow+1].mean()
            except TypeError:
                idx = df.index.values[min(irow, len(df) - 1)]
            else:
                idx = df.index.values[min(irow, len(df) - 1)].__class__(idx)
        # reset the index to sort it correctly
        idx_name = df.index.name
        dtype = df.index.dtype
        df.reset_index(inplace=True)
        new_idx_name = df.columns[0]
        current_len = len(df)
        for i in range(nrows):
            df.loc[current_len + i, new_idx_name] = idx
        df[new_idx_name] = df[new_idx_name].astype(dtype)
        if irow < current_len:
            changed = df.index.values.astype(float)
            changed[current_len:] = irow - 0.5
            df.index = changed
            df.sort_index(inplace=True)
        df.set_index(new_idx_name, inplace=True, drop=True)
        df.index.name = idx_name
        self.update_df_index()
        self.beginInsertRows(QtCore.QModelIndex(), self.rows_loaded,
                             self.rows_loaded + nrows - 1)
        self.total_rows += nrows
        self.rows_loaded += nrows
        self.endInsertRows()
        self._parent.rows_inserted.emit(irow, nrows)
Exemplo n.º 7
0
    def load_new_marks(self, mark):
        """Add a new mark into the table after they have been added by the user

        Parameters
        ----------
        mark: straditize.cross_mark.CrossMarks
            The added mark"""
        self._new_marks.append(mark)
        mark.moved.connect(self.update_after_move)
        if len(self._new_marks) == self.columnCount() - 1:
            new = (self._new_marks[0].y, self._new_marks)
            self.marks.append(new)
            self._new_marks = []
            self.sort_marks()
            idx = self.marks.index(new)
            self.beginInsertRows(QtCore.QModelIndex(), idx, idx)
            self.endInsertRows()
            self.update_lines()
Exemplo n.º 8
0
    def remove_mark(self, mark):
        """Remove a mark from the table after it has been removed by the user

        Parameters
        ----------
        mark: straditize.cross_mark.CrossMarks
            The removed mark"""
        found = False
        for i, (y, marks) in enumerate(self.marks):
            if mark in marks:
                found = True
                break
        if found:
            for m in self.marks[i][1]:
                try:
                    m.moved.disconnect(self.update_after_move)
                except ValueError:
                    pass
            del self.marks[i]
            self.beginRemoveRows(QtCore.QModelIndex(), i, i)
            self.endRemoveRows()
            self.update_lines()
Exemplo n.º 9
0
    def insertRow(self, irow, xa=None, ya=None):
        """Insert a row into the table

        Parameters
        ----------
        irow: int
            The row index. If `irow` is equal to the length of the
            :attr:`marks`, the rows will be appended"""
        if xa is None or ya is None:
            mark = self.marks[min(irow, len(self.marks) - 1)][1]
            new = self._new_mark(mark.xa[0], mark.ya[0])[0]
        else:
            new = self._new_mark(xa + self._bounds[:, 0], ya + self._y0)[0]
            new.set_pos((xa + self._bounds[:, 0], ya + self._y0))
        y = new.y
        new.moved.connect(self.update_after_move)
        if irow == len(self.marks):
            self.marks.append((y, new))
        else:
            self.marks.insert(irow, (y, new))
        self.beginInsertRows(QtCore.QModelIndex(), irow, irow)
        self.endInsertRows()
        self.update_lines()
Exemplo n.º 10
0
 def columnCount(self, index=QtCore.QModelIndex()):
     return len(self._column_names) + 1
Exemplo n.º 11
0
 def columnCount(self, index=QtCore.QModelIndex()):
     """The number of rows in the table"""
     return len(self.axes) + 1
Exemplo n.º 12
0
 def rowCount(self, index=QtCore.QModelIndex()):
     """The number of rows in the table"""
     return len(self.marks)
Exemplo n.º 13
0
 def rowCount(self, index=QtCore.QModelIndex()):
     """DataFrame row number"""
     if self.total_rows <= self.rows_loaded:
         return self.total_rows
     else:
         return self.rows_loaded
Exemplo n.º 14
0
 def columnCount(self, index=QtCore.QModelIndex()):
     return self.color_da.shape[1]
Exemplo n.º 15
0
 def rowCount(self, index=QtCore.QModelIndex()):
     return self.color_da.shape[0]