From 3cfb15ed6e060069425c21adde9036468bf123a3 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 31 May 2020 22:59:37 -0400 Subject: [PATCH] Make monitor handle non-full quote messages --- piker/ui/monitor.py | 21 +++++++++++++-------- piker/ui/tabular.py | 3 ++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/piker/ui/monitor.py b/piker/ui/monitor.py index a7778fbf..cd73c3fa 100644 --- a/piker/ui/monitor.py +++ b/piker/ui/monitor.py @@ -51,23 +51,25 @@ async def update_quotes( chngcell = row.get_cell('%') # determine daily change color - color = colorcode('gray') percent_change = record.get('%') - if percent_change: - daychange = float(record['%']) + if percent_change is not None and percent_change != chngcell: + daychange = float(percent_change) if daychange < 0.: color = colorcode('red2') elif daychange > 0.: color = colorcode('forestgreen') + else: + color = colorcode('gray') - # update row header and '%' cell text color - if chngcell: - chngcell.color = color - hdrcell.color = color # if the cell has been "highlighted" make sure to change its color if hdrcell.background_color != [0]*4: hdrcell.background_color = color + # update row header and '%' cell text color + chngcell.color = color + hdrcell.color = color + + # briefly highlight bg of certain cells on each trade execution unflash = set() tick_color = None @@ -123,10 +125,13 @@ async def update_quotes( record, displayable = formatter( quote, symbol_data=symbol_data) + # don't red/green the header cell in ``row.update()`` + record.pop('symbol') + # determine if sorting should happen sort_key = table.sort_key - new = record[sort_key] last = row.get_field(sort_key) + new = record.get(sort_key, last) if new != last: to_sort.add(row.widget) diff --git a/piker/ui/tabular.py b/piker/ui/tabular.py index d995848a..27c1e091 100644 --- a/piker/ui/tabular.py +++ b/piker/ui/tabular.py @@ -340,6 +340,7 @@ class Row(HoverBehavior, GridLayout): gray = colorcode('gray') fgreen = colorcode('forestgreen') red = colorcode('red2') + for key, val in record.items(): last = self.get_field(key) color = gray @@ -361,7 +362,7 @@ class Row(HoverBehavior, GridLayout): if color != gray: cells[key] = cell - self._last_record = record + self._last_record.update(record) return cells # mouse over handlers