diff --git a/visidata/basesheet.py b/visidata/basesheet.py index e3502986b..1b309ed1b 100644 --- a/visidata/basesheet.py +++ b/visidata/basesheet.py @@ -107,12 +107,12 @@ def _class_options(cls): class_options = options = _dualproperty(_obj_options, _class_options) - def __init__(self, *names, **kwargs): + def __init__(self, *names, rows=UNLOADED, **kwargs): self._name = None # initial cache value necessary for self.options self.names = list(names) self.name = self.options.name_joiner.join(str(x) for x in self.names if x) self.source = None - self.rows = UNLOADED # list of opaque objects + self.rows = rows # list of opaque objects self._scr = None self.hasBeenModified = False @@ -151,6 +151,14 @@ def __len__(self): def __str__(self): return self.name + @property + def rows(self): + return self._rows + + @rows.setter + def rows(self, rows): + self._rows = rows + @property def nRows(self): 'Number of rows on this sheet. Override in subclass.' diff --git a/visidata/freqtbl.py b/visidata/freqtbl.py index 992376b23..584321322 100644 --- a/visidata/freqtbl.py +++ b/visidata/freqtbl.py @@ -126,6 +126,15 @@ def makeFreqTableSheetSummary(sheet, *groupByCols): source=sheet) +@VisiData.api +class FreqTablePreviewSheet(Sheet): + @property + def rows(self): + return self.source.cursorRow.sourcerows + + +FreqTableSheet.addCommand('', 'open-preview', 'vd.push(FreqTablePreviewSheet(sheet.name, "preview", source=sheet, columns=source.columns), pane=2); vd.options.disp_splitwin_pct=50', 'open split preview of source rows at cursor') + Sheet.addCommand('F', 'freq-col', 'vd.push(makeFreqTable(sheet, cursorCol))', 'open Frequency Table grouped on current column, with aggregations of other columns') Sheet.addCommand('gF', 'freq-keys', 'vd.push(makeFreqTable(sheet, *keyCols))', 'open Frequency Table grouped by all key columns on source sheet, with aggregations of other columns') Sheet.addCommand('zF', 'freq-summary', 'vd.push(makeFreqTableSheetSummary(sheet, Column("Total", sheet=sheet, getter=lambda col, row: "Total")))', 'open one-line summary for all rows and selected rows') diff --git a/visidata/sheets.py b/visidata/sheets.py index c17261a44..4609e0117 100644 --- a/visidata/sheets.py +++ b/visidata/sheets.py @@ -124,9 +124,8 @@ class TableSheet(BaseSheet): ] nKeys = 0 # columns[:nKeys] are key columns - def __init__(self, *names, **kwargs): - super().__init__(*names, **kwargs) - self.rows = UNLOADED # list of opaque row objects (UNLOADED before first reload) + def __init__(self, *names, rows=UNLOADED, **kwargs): + super().__init__(*names, rows=rows, **kwargs) self.cursorRowIndex = 0 # absolute index of cursor into self.rows self.cursorVisibleColIndex = 0 # index of cursor into self.visibleCols