visidata
visidata copied to clipboard
[colorizers] custom colorizers not shown in sheet context
Small description
if a user (mainly a dev!) does =sheet.colorizers
a list of colorizers is shown in the next column, however this is not a complete list that is being currently applied to the sheet.
Expected result To show all colorizers relevant to the sheet
Actual result with screenshot
Only the following default colorizers are shown
Repro
Add a new colorizer with:
Ctrl+x
vd.sheet.addColorizer(RowColorizer(1000, 'green',lambda s,c,r,v: True))
Additional context 2.7
I noticed this as I was creating a plugin that adds/activates colorizers via a long command, and wanted to add a long command to remove the colorizers, but I can't seem to find them!
This is tricky, because colorizers
is the list of colorizers at the class-level, and _colorizers
is the list at the object-level. And note that colorizers from parent classes also apply. You can get the computed full list of colorizers from the (undocumented) allColorizers
property on the sheet.
For future ref:
Did it this way as sheet
apparently doesn't have a property of allColorizers
[vd.sheet._colorizers.remove(c) for c in vd.sheet.allColorizers if c.coloropt=='green']
Hmm, just looking at this a little more:
So when adding colorizers at the class-level, and the object is initiated they are exposed via sheet.colorizers
(as expected) and also, sheet.allColorizers
. However when added at runtime with sheet.addColorizer, they get added to sheet._colorizers
.
So to account for this, the colorizer toggle off command to allow a user to remove the colorizers needs to look like this:
for c in sheet.allColorizers:
if 'custom_colorizer' in str(c.func):
# on sheet load colorizers are placed into `sheet.colorizers`
try: sheet.colorizers.remove(c)
except ValueError: pass
# when `sheet.addColorizer(c)` used, it is placed into `sheet._colorizers`
try: sheet.removeColorizer(c)
except ValueError: pass
From your comment above, this seems to be expected, but shouldn't all colorizers reside in sheet._colorizers
to allow sheet.add/removeColorizer
to work consistently?
You might be right, @geekscrapy, we'll look at this.
Okay, so I made a fix so that all class colorizers are set in sheet._colorizers
when the Sheet is created, so addColorizer
will just add to this list and then resort it. So now if you look at sheet._colorizers
in vd it will be an accurate list, and removeColorizer
should work consistently.