Use lighter red; sort rows on startup

kivy_mainline_and_py3.8
Tyler Goodlet 2018-02-12 16:11:31 -05:00
parent 274a5a728a
commit 8e577cd0d0
1 changed files with 15 additions and 9 deletions

View File

@ -297,6 +297,16 @@ async def update_quotes(
if hdrcell.background_color != [0]*4: if hdrcell.background_color != [0]*4:
hdrcell.background_color != color 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 = {} cache = {}
# initial coloring # initial coloring
@ -307,6 +317,8 @@ async def update_quotes(
color_row(row, data) color_row(row, data)
cache[sym] = (data, row) cache[sym] = (data, row)
render_rows(cache, grid.sort_key)
# core cell update loop # core cell update loop
while True: while True:
log.debug("Waiting on quotes") log.debug("Waiting on quotes")
@ -320,9 +332,9 @@ async def update_quotes(
for key, val in data.items(): for key, val in data.items():
# logic for cell text coloring: up-green, down-red # logic for cell text coloring: up-green, down-red
if row._last_record[key] < val: if row._last_record[key] < val:
color = colorcode('green') color = colorcode('forestgreen')
elif row._last_record[key] > val: elif row._last_record[key] > val:
color = colorcode('red') color = colorcode('red2')
else: else:
color = colorcode('gray') color = colorcode('gray')
@ -333,13 +345,7 @@ async def update_quotes(
color_row(row, data) color_row(row, data)
row._last_record = data row._last_record = data
# sort rows by daily % change since open render_rows(cache, grid.sort_key)
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
async def run_kivy(root, nursery): async def run_kivy(root, nursery):