These will each be described in detail below. See the API reference for the full API.
Sheet Example Code
Here is the complete code for a simple DictSheet.
# rowdef: source key class DictSheet(Sheet): rowtype = 'items' columns = [ Column('key'), Column('value', getter=lambda col,row: col.sheet.source[row]) ] def reload(self): self.rows = list(self.source.keys()) globalCommand('1', 'vd.push(DictSheet("globals", source=globals()))', 'push globals dict')
If this code is loaded, pressing
1 will push a fresh instance of
DictSheet, showing each key in the
globals() dict with its corresponding value.
The Essential Steps to Create a Sheet
1. Gather the name and sources for the constructor
The constructor of a sheet should always take a
name (str). Additional Sheet parameters are passed via
kwargs, and will be made available as attributes on the Sheet instance.
source of a Sheet is usually passed into the constructor. For a sheet loaded from a file, the source will be a
Derived sheets will have other
Sheet instances as their
But really, the source needed is dependent on that Sheet's
reload() which collects the data.
reload() member on a Sheet must populate the
3. Enumerate the
Columns can either be specified in the class scope (as per the example), populated in the constructor (if dependent on the sources), or if necessary, populated by reload if dependent on the data itself.
4. Instantiate the sheet in a
5. Enjoy your new sheet!
Here is a diagram of the screen layout:
topRowIndexindex of row just below header row
nScreenRows: simply based on terminal height, the number of rows that can be displayed.
visibleRows: the contiguous slice of
rowswhich is visible onscreen
Column layout is more involved:
- the first
nKeyscolumns are 'key' columns, which are pinned to the left and always visible.
- columns are variable width.
- if a column's width is 0, it is not visible (
Invisible columns make it more difficult to move the column cursor sensibly. So Sheet has a computed property
visibleCols, which is the better choice for most tasks.
hidden columns still exist (go to the
Columns sheet to unhide them), but they should remain invisible in most cases.
visibleCols: (O(ncols), cached between frames): list of all non-hidden columns
leftVisibleColIndexis the first non-key column on the left.
Sheet.calcColLayout(), assignment will be ignored)
the Row and Column Cursor [name=cursor]
The primary (settable) row cursor is
cursorRowIndex, which is an index into
The primary (settable) column cursor is
cursorVisibleColIndex, which is an index into
The other cursor properties are computed:
cursorColIndex(O(ncols)); index into .columns
cursorRow: equivalent to
cursorCol: equivalent to
the value at the cursor (the current cell)