Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
T = '?'
hdrs = col.name.split('\n')
for i in range(h):
name = ' ' # save room at front for LeftMore
if h-i-1 < len(hdrs):
name += hdrs[::-1][h-i-1]
if len(name) > colwidth-1:
name = name[:colwidth-len(options.disp_truncator)] + options.disp_truncator
if i == h-1:
hdrattr = hdrattr.update_attr(colors.color_bottom_hdr, 5)
clipdraw(scr, y+i, x, name, hdrattr.attr, colwidth)
vd.onMouse(scr, y+i, x, 1, colwidth, BUTTON3_RELEASED='rename-col')
if C and x+colwidth+len(C) < self.windowWidth:
scr.addstr(y+i, x+colwidth, C, sepattr)
clipdraw(scr, y+h-1, x+colwidth-len(T), T, hdrattr.attr, len(T))
try:
if vcolidx == self.leftVisibleColIndex and col not in self.keyCols and self.nonKeyVisibleCols.index(col) > 0:
A = options.disp_more_left
scr.addstr(y, x, A, sepattr)
except ValueError: # from .index
pass
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
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
def getValue(self, row):
try:
v = self.func(row)
except Exception as e:
vd().exceptionCaught(status=False)
raise
try:
return self.type(v) # convert type on-the-fly
except Exception as e:
vd().exceptionCaught(status=False)
return self.type() # return a suitable value for this type
def exec_command(self, cmd, args='', vdglobals=None, keystrokes=None):
"Execute `cmd` tuple with `vdglobals` as globals and this sheet's attributes as locals. Returns True if user cancelled."
if not cmd:
vd.debug('no command "%s"' % keystrokes)
return True
escaped = False
err = ''
if vdglobals is None:
vdglobals = getGlobals()
self.sheet = self
try:
if vd.cmdlog:
vd.cmdlog.beforeExecHook(self, cmd, '', keystrokes)
code = compile(cmd.execstr, cmd.longname, 'exec')
vd.debug(cmd.longname)
exec(code, vdglobals, LazyChainMap(vd, self))
@functools.wraps(vd().toplevelTryFunc)
def threadProfileCode(func, *args, **kwargs):
'Toplevel thread profile wrapper.'
with ThreadProfiler(threading.current_thread()) as prof:
try:
prof.thread.status = threadProfileCode.__wrapped__(func, *args, **kwargs)
except EscapeException as e:
prof.thread.status = e
sheets = [] # sheets to apply startrow:startcol to
if not startsheets:
sheets = sources # apply row/col to all sheets
else:
vs = vd.getSheet(startsheets[0]) or sources[-1]
vd.sync(vs.ensureLoaded())
vd.clear_caches()
for startsheet in startsheets[1:]:
rowidx = vs.getRowIndexFromStr(startsheet)
if rowidx is None:
vs = None
vd.warning(f'no sheet "{startsheet}"')
break
vs = vs.rows[rowidx]
vd.sync(vs.ensureLoaded())
vd.clear_caches()
if vs:
vd.push(vs)
sheets = [vs]
if startrow:
for vs in sheets:
if vs:
vs.moveToRow(startrow) or vd.warning(f'{vs} has no row "{startrow}"')
if startcol:
for vs in sheets:
if vs:
vs.moveToCol(startcol) or vd.warning(f'{vs} has no column "{startcol}"')
if not args.batch:
run(vd.sheets[0])
vd.cmdlog.beforeExecHook(self, cmd, '', keystrokes)
code = compile(cmd.execstr, cmd.longname, 'exec')
vd.debug(cmd.longname)
exec(code, vdglobals, LazyChainMap(vd, self))
except EscapeException as e: # user aborted
vd.warning('aborted')
escaped = True
except Exception as e:
vd.debug(cmd.execstr)
err = vd.exceptionCaught(e)
escaped = True
try:
if vd.cmdlog:
# sheet may have changed
vd.cmdlog.afterExecSheet(vd.sheets[0] if vd.sheets else None, escaped, err)
except Exception as e:
vd.exceptionCaught(e)
self.checkCursorNoExceptions()
vd.clear_caches()
return escaped
def updateExpr(col, val):
col.name = val
try:
col.expr = val
except SyntaxError:
col.expr = None
col.sheet.draw(vd.scr)
if opt:
curval = opt.value
t = type(curval)
if v is None and curval is not None:
v = t() # empty value
elif isinstance(v, str) and t is bool: # special case for bool options
v = v and (v[0] not in "0fFnN") # ''/0/false/no are false, everything else is true
elif type(v) is t: # if right type, no conversion
pass
elif curval is None: # if None, do not apply type conversion
pass
else:
v = t(v)
if curval != v and self._get(k, 'global').replayable:
if vd.cmdlog: # options set on init aren't recorded
vd.cmdlog.set_option(k, v, obj)
else:
curval = None
vd.warning('setting unknown option %s' % k)
return self._set(k, v, obj)