Exemplo n.º 1
0
def _do_rgennums(scr, startKey, endKey, tokens):
    '''
    Add numeric content to cells starting from startKey to endKey
    with values from start with delta increments.
    '''
    if len(tokens) > 0:
        start = int(tokens[0])
    else:
        start = 1
    if len(tokens) > 1:
        delta = int(tokens[1])
    else:
        delta = 1
    curValue = start
    clearedSet = set()
    for r in range(startKey[0], endKey[0] + 1):
        for c in range(startKey[1], endKey[1] + 1):
            me['data'][(r, c)] = "{}".format(curValue)
            syncd.cell_updated((r, c), "", clearedSet=clearedSet)
            curValue += delta
    if endKey[0] > me['numRows']:
        me['numRows'] = endKey[0]
    if endKey[1] > me['numCols']:
        me['numCols'] = endKey[1]
    return True
Exemplo n.º 2
0
def del_cell():
    '''
    Delete current cell's content, if available.

    If there was content to del, then set dirty flag and
    clear calc cache as required.
    '''
    if me['data'].pop((me['curRow'], me['curCol']), None) != None:
        me['dirty'] = True
        syncd.cell_updated((me['curRow'], me['curCol']), "", clearedSet=set())
Exemplo n.º 3
0
def _do_rclear(scr, dstSKey, dstEKey):
    '''
    Clear a block of cells at dst.

    NOTE: Doesnt alert if clearing cells with data|content in them.
    '''
    clearedSet = set()
    for dR in range(dstSKey[0], dstEKey[0] + 1):
        for dC in range(dstSKey[1], dstEKey[1] + 1):
            me['data'].pop((dR, dC), None)
            syncd.cell_updated((dR, dC), "", clearedSet=clearedSet)
    return True
Exemplo n.º 4
0
def _do_rclear_err(scr, dstSKey, dstEKey):
    '''
    Clear error tags in the specified block of cells at dst.
    '''
    clearedSet = set()
    for dR in range(dstSKey[0], dstEKey[0] + 1):
        for dC in range(dstSKey[1], dstEKey[1] + 1):
            sData = me['data'].get((dR, dC), None)
            if sData != None:
                if sData.startswith("#Err") and (sData[7] == '#'):
                    sData = sData[8:]
                    me['data'][(dR, dC)] = sData
                    syncd.cell_updated(
                        (dR, dC), sData, clearedSet=clearedSet
                    )  # Can do without in most cases, but just in case
    return True
Exemplo n.º 5
0
def _do_rcopy(scr, srcSKey, srcEKey, dstSKey, dstEKey, bAdjustCellAddrs=True):
    '''
    Copy a block of cells from src to dst.

    The Src and Dst blocks need not be same nor multiple of one another.
    If the Src block is bigger, then only the part that fits in the dst
    block will be copied.
    If the Src block is smaller, then it will be duplicated as required
    to fill the dst block.

    If bAdjustCellAddrs is true, then cell addresses in the copied =expressions
    will be adjusted as required.

    NOTE: Doesnt alert if overwriting cells with data|content in them.
    NOTE: Ensure that the source and dest blocks dont overlap. Else cell content may get corrupted.
    '''
    srcRLen = srcEKey[0] - srcSKey[0] + 1
    srcCLen = srcEKey[1] - srcSKey[1] + 1
    baseSrcR = srcSKey[0]
    baseSrcC = srcSKey[1]
    r = 0
    clearedSet = set()
    for dR in range(dstSKey[0], dstEKey[0] + 1):
        sR = baseSrcR + (r % srcRLen)
        c = 0
        for dC in range(dstSKey[1], dstEKey[1] + 1):
            sC = baseSrcC + (c % srcCLen)
            sData = me['data'].get((sR, sC))
            if (sData != None) and (sData != ""):
                if sData.startswith("=") and bAdjustCellAddrs:
                    incR = dR - sR
                    incC = dC - sC
                    sData = update_celladdrs_exceptfixed(
                        sData, 0, incR, 0, incC)
            syncd.cell_updated((dR, dC), sData, clearedSet=clearedSet)
            me['data'][(dR, dC)] = sData
            c += 1
        r += 1
    if dstEKey[0] > me['numRows']:
        me['numRows'] = dstEKey[0]
    if dstEKey[1] > me['numCols']:
        me['numCols'] = dstEKey[1]
    return True
Exemplo n.º 6
0
def paste_cell(bAdjustCellAddress=True):
    '''
    Paste into current cell.

    Adjust the cell addresses if any in the =expression, during paste, if requested.

    Also set dirty flag and clear calc cache as required.
    '''
    if me['copyData'] != None:
        theData = me['copyData']
        if bAdjustCellAddress:
            # Calculate row and col adjustment required
            incR = me['curRow'] - me['copySrcCell'][0]
            incC = me['curCol'] - me['copySrcCell'][1]
            # Adjust cell addresses if =expression
            if theData.startswith('='):
                theData = update_celladdrs_exceptfixed(theData, 0, incR, 0,
                                                       incC)
        # Paste data
        me['data'][(me['curRow'], me['curCol'])] = theData
        me['dirty'] = True
        syncd.cell_updated((me['curRow'], me['curCol']),
                           theData,
                           clearedSet=set())
Exemplo n.º 7
0
def delete_rc(cmd, args):
    '''
    Delete the current+ row(s) or column(s), as specified in the cmd.
    '''
    # Identify the delete operation details
    bRowMode = False
    bColMode = False
    cnt = int(args)
    incR = incC = 0
    sR = me['curRow']
    sC = me['curCol']
    if cmd[1] == 'r':
        bRowMode = True
        eR = sR + cnt - 1
        if eR > me['numRows']:
            eR = me['numRows']
        cnt = eR - sR + 1
        incR = -1 * cnt
        sC = 0
        eC = me['numCols']
    elif cmd[1] == 'c':
        bColMode = True
        eC = sC + cnt - 1
        if eC > me['numCols']:
            eC = me['numCols']
        cnt = eC - sC + 1
        incC = -1 * cnt
        sR = 0
        eR = me['numRows']

    # clear the calc cache of cells affected_by|dependent_on
    # the cells about to be deleted.
    # THe dependents could be either direct or indirect.
    clearedSet = set()
    for r in range(sR, eR + 1):
        for c in range(sC, eC + 1):
            syncd.cell_updated((r, c), None, clearedSet=clearedSet)
    # update the affected =expressions
    # as well as update the data and calc cache dictionaries
    newDict = dict()
    newCDataDict = dict()
    for k in me['data']:
        r, c = k
        curData = me['data'][k]
        curCData = None
        fwdLinks = me['fwdLinks'].get(k)
        if (fwdLinks != None) and (len(fwdLinks) > 0):
            curData = update_celladdrs_all(curData,
                                           sR - 1,
                                           incR,
                                           sC - 1,
                                           incC,
                                           bUpdateFixed=True)
            if curData.find("#Err") == -1:
                curCData = me['cdata'].get(k)
        else:
            curCData = me['cdata'].get(k)
        if bRowMode:
            if r < sR:
                newDict[k] = curData
                if curCData != None:
                    newCDataDict[k] = curCData
            elif r > eR:
                newDict[(r + incR, c)] = curData
                if curCData != None:
                    newCDataDict[(r + incR, c)] = curCData
        if bColMode:
            if c < sC:
                newDict[k] = curData
                if curCData != None:
                    newCDataDict[k] = curCData
            elif c > eC:
                newDict[(r, c + incC)] = curData
                if curCData != None:
                    newCDataDict[(r, c + incC)] = curCData
    me['data'] = newDict
    me['cdata'] = newCDataDict
    if bRowMode:
        me['numRows'] -= cnt
    if bColMode:
        me['numCols'] -= cnt
Exemplo n.º 8
0
def rl_editplusmode(stdscr, key):
    '''
    Handle key presses in edit/insert/explicit command modes

    ESC key allows returning back to the implicit command mode.
    Enter key either saves the text entry/changes till now to
        a temporary buffer, if in edit/insert mode.
            It also sets the dirty flag.
        Or trigger the explicit command handling logic in
        explicit command mode.
    '''
    global GBSHOWCOLHDR

    if (key == curses.ascii.ESC):
        tabcomplete_clear()
        GBSHOWCOLHDR = True
        if me['state'] == 'E':
            setdata_from_savededitbuf(stdscr)
        me['state'] = 'C'
    elif (key == curses.KEY_BACKSPACE):
        if me['crsrOffset'] > 0:
            _colhdr_explicit_rcmds()
            tabcomplete_baseupdate()
            sBefore = me['gotStr'][0:me['crsrOffset'] - 1]
            sAfter = me['gotStr'][me['crsrOffset']:]
            me['gotStr'] = sBefore + sAfter
            me['crsrOffset'] -= 1
            if me['crsrOffset'] < 0:
                me['crsrOffset'] = 0
    elif (key == curses.ascii.NL):
        tabcomplete_clear()
        GBSHOWCOLHDR = True
        if me['state'] == 'E':
            me['backupEdit'] = me['gotStr']
            if gbEnterExitsEditMode:
                setdata_from_savededitbuf(stdscr)
                me['state'] = 'C'
            me['dirty'] = True
            # sync up things
            #me['cdataUpdate'] = True
            tData = me['data'].get((me['curRow'], me['curCol']))
            if tData != None:
                syncd.cell_updated((me['curRow'], me['curCol']),
                                   tData,
                                   clearedSet=set())
        elif me['state'] == ':':
            explicit_commandmode(stdscr, me['gotStr'])
            me['state'] = 'C'
            me['fpc'] = dict()
            me['tc'] = dict()
        #print("runLogic:{}".format(me), file=GLOGFILE)
    elif key == curses.KEY_LEFT:
        me['crsrOffset'] -= 1
        if me['crsrOffset'] < 0:
            me['crsrOffset'] = 0
    elif key == curses.KEY_RIGHT:
        me['crsrOffset'] += 1
        if me['crsrOffset'] > len(me['gotStr']):
            me['crsrOffset'] = len(me['gotStr'])
    elif key == curses.ascii.TAB:
        if me['state'] == ':':
            _colhdr_explicit_rcmds()
            tabcomplete_usebase()
            sNew = path_completion(me['fpc'], me['gotStrBase'])
            me['gotStr'] = sNew
            me['crsrOffset'] = len(me['gotStr'])
    elif not key in CursesKeys:  # chr(key).isprintable() wont do
        sBefore = me['gotStr'][0:me['crsrOffset']]
        sAfter = me['gotStr'][me['crsrOffset']:]
        me['gotStr'] = "{}{}{}".format(sBefore, chr(key), sAfter)
        me['crsrOffset'] += 1
        tabcomplete_baseupdate()
        _colhdr_explicit_rcmds()