From 8e577cd0d006e072fbdc8f6b31513f707fcf01c1 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 12 Feb 2018 16:11:31 -0500 Subject: [PATCH] Use lighter red; sort rows on startup --- piker/ui/watchlist.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/piker/ui/watchlist.py b/piker/ui/watchlist.py index 953ccd21..ea9c053a 100644 --- a/piker/ui/watchlist.py +++ b/piker/ui/watchlist.py @@ -297,6 +297,16 @@ async def update_quotes( if hdrcell.background_color != [0]*4: hdrcell.background_color != color + def render_rows(pairs, sort_key='%'): + """Sort and render all rows on the ticker grid. + """ + grid.clear_widgets() + sort_key = grid.sort_key + for data, row in reversed( + sorted(pairs.values(), key=lambda item: item[0][sort_key]) + ): + grid.add_widget(row) # row append + cache = {} # initial coloring @@ -307,6 +317,8 @@ async def update_quotes( color_row(row, data) cache[sym] = (data, row) + render_rows(cache, grid.sort_key) + # core cell update loop while True: log.debug("Waiting on quotes") @@ -320,9 +332,9 @@ async def update_quotes( for key, val in data.items(): # logic for cell text coloring: up-green, down-red if row._last_record[key] < val: - color = colorcode('green') + color = colorcode('forestgreen') elif row._last_record[key] > val: - color = colorcode('red') + color = colorcode('red2') else: color = colorcode('gray') @@ -333,13 +345,7 @@ async def update_quotes( color_row(row, data) row._last_record = data - # sort rows by daily % change since open - grid.clear_widgets() - sort_key = grid.sort_key - for data, row in reversed( - sorted(cache.values(), key=lambda item: item[0][sort_key]) - ): - grid.add_widget(row) # row append + render_rows(cache, grid.sort_key) async def run_kivy(root, nursery):