def addRows(self, rows, index=None, undo=True):

        # identify empty rows and expand them to column width with None
        rows_exp = []
        for row in rows:
            if len(row) == 0:
                rows_exp.append(
                        list(None for _ in range(len(self.frame.columns)))
                        )
            else:
                rows_exp.append(row)

        if index is None:
            index = len(self.frame) # needed for undo
            f = frame.from_records(rows_exp, columns=self.frame.columns)
            self.frame = frame.from_concat(self.frame, f, index=IndexAutoFactory)
        else:
            f = frame.from_records(rows_exp, columns=self.frame.columns)
            self.frame = frame.from_concat((
                    self.frame.iloc[0: index],
                    f,
                    self.frame.iloc[index:],
                    ), index=IndexAutoFactory)

        self._checkSelectedIndex()
        if undo:
            vd.addUndo(self._deleteRows, range(index, index + len(rows)))
Exemplo n.º 2
0
 def editOption(self, row):
     currentValue = options.get(row.name, self.source)
     vd.addUndo(options.set, row.name, currentValue, self.source)
     if isinstance(row.value, bool):
         options.set(row.name, not currentValue, self.source)
     else:
         options.set(row.name, self.editCell(1, value=currentValue),
                     self.source)
Exemplo n.º 3
0
    def setKeys(self, cols):
        vd.addUndo(undoAttrFunc(cols, 'keycol'))
        for col in cols:
            lastkeycol = 0

            if self.keyCols:
                lastkeycol = max(c.keycol for c in self.keyCols)

            col.keycol = lastkeycol+1
Exemplo n.º 4
0
 def addColumn(self, col, index=None):
     'Insert column at given index or after all columns.'
     if col:
         vd.addUndo(self.columns.remove, col)
         if index is None:
             index = len(self.columns)
         col.recalc(self)
         self.columns.insert(index, col)
         Sheet.visibleCols.fget.cache_clear()
         return col
    def deleteBy(self, by):
        '''Delete rows for which func(row) is true.  Returns number of deleted rows.'''
        # oldidx = self.cursorRowIndex # NOTE: not used
        nRows = self.nRows
        vd.addUndo(setattr, self, 'frame', self.frame)

        self.frame = self.frame[~by].reindex(IndexAutoFactory)
        ndeleted = nRows - self.nRows

        vd.status('deleted %s %s' % (ndeleted, self.rowtype))
        return ndeleted
Exemplo n.º 6
0
def addUndoSetValues(vd, cols, rows):
    oldvals = [
        (c, r, c.getValue(r))
        for c, r in itertools.product(cols, vd.Progress(rows, gerund='doing'))
    ]

    def _undo():
        for c, r, v in oldvals:
            c.setValue(r, v)

    vd.addUndo(_undo)
Exemplo n.º 7
0
def normalize_column_names(sheet):
    """
    Normalize the names of all non-hidden columns on the active sheet.
    """

    init_names = []
    gen = gen_normalize_names(c.name for c in sheet.visibleCols)
    prog = Progress(gen, gerund="normalizing", total=sheet.nVisibleCols)

    for i, norm_name in enumerate(prog):
        col = sheet.visibleCols[i]
        init_names.append(col.name)  # Store for undo
        col.name = norm_name

    @asyncthread
    def undo():
        for i, c in enumerate(init_names):
            sheet.visibleCols[i].name = c

    vd.addUndo(undo)
Exemplo n.º 8
0
def orderBy(sheet, *cols, reverse=False):
    'Add cols to the internal ordering. No cols (or first col None) remove any previous ordering. call sort() if the ordering changes.'
    if options.undo:
        vd.addUndo(setattr, sheet, '_ordering', copy(sheet._ordering))
        if sheet._ordering:
            vd.addUndo(sheet.sort)
        else:
            vd.addUndo(setattr, sheet, 'rows', copy(sheet.rows))

    do_sort = False
    if not cols or cols[0] is None:
        sheet._ordering.clear()
        cols = cols[1:]
        do_sort = True

    for c in cols:
        sheet._ordering.append((c, reverse))
        do_sort = True

    if do_sort:
        sheet.sort()
Exemplo n.º 9
0
def paste_before(sheet, rowidx):
    sheet.rows[sheet.cursorRowIndex:sheet.cursorRowIndex] = list(
        deepcopy(r) for s, i, r in vd.cliprows)
    vd.addUndo(sheet.rows.pop, rowidx)
Exemplo n.º 10
0
 def unsetKeys(self, cols):
     vd.addUndo(undoAttrFunc(cols, 'keycol'))
     for col in cols:
         col.keycol = 0
Exemplo n.º 11
0
def addUndoSelection(sheet):
    vd.addUndo(undoAttrCopyFunc([sheet], '_selectedRows'))
Exemplo n.º 12
0
def slide_row(sheet, rowidx, newcolidx):
    vd.addUndo(moveListItem, sheet.rows, newcolidx, rowidx)
    return moveListItem(sheet.rows, rowidx, newcolidx)
Exemplo n.º 13
0
 def type(self, t):
     if self._type != t:
         vd.addUndo(setattr, self, 'type', self._type)
     self._type = t
 def addRow(self, row, index=None):
     self.addRows([row], index)
     vd.addUndo(self._deleteRows, index or self.nRows - 1)
 def delete_row(self, rowidx):
     oldrow = self.frame.iloc[rowidx].values.tolist()  # a series
     vd.addUndo(self.addRows, [oldrow], rowidx, False)
     self._deleteRows(rowidx)
     vd.memory.cliprows = [oldrow]
Exemplo n.º 16
0
def slide_col(sheet, colidx, newcolidx):
    vd.addUndo(moveVisibleCol, sheet, newcolidx, colidx)
    return moveVisibleCol(sheet, colidx, newcolidx)
 def addUndoSelection(self):
     vd.addUndo(undoAttrCopyFunc([self], '_selectedMask'))
Exemplo n.º 18
0
 def name(self, name):
     'Set name without spaces.'
     vd.addUndo(setattr, self, '_name', self._name)
     self._name = name.strip().replace(' ', '_')
Exemplo n.º 19
0
def setWidth(self, w):
    if self.width != w:
        if self.width == 0 or w == 0:  # hide/unhide
            vd.addUndo(setattr, self, 'width', self.width)
    self.width = w
Exemplo n.º 20
0
def paste_after(sheet, rowidx):
    vd.addUndo(sheet.rows.pop, rowidx + 1)
    sheet.rows[rowidx + 1:rowidx + 1] = list(
        deepcopy(r) for s, i, r in vd.cliprows)
Exemplo n.º 21
0
def delete_row(sheet, rowidx):
    oldrow = sheet.rows.pop(rowidx)
    vd.addUndo(sheet.rows.insert, rowidx, oldrow)
    vd.cliprows = [(sheet, rowidx, oldrow)]
Exemplo n.º 22
0
 def __setattr__(self, k, v):
     vd.addUndo(undoAttrFunc(self, k))
     for o in self:
         setattr(o, k, v)