Only resort when the sort field actually changed
parent
d4e36b1e55
commit
11222e1176
|
@ -7,7 +7,7 @@ Launch with ``piker monitor <watchlist name>``.
|
||||||
"""
|
"""
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from types import ModuleType, AsyncGeneratorType
|
from types import ModuleType, AsyncGeneratorType
|
||||||
from typing import List, Callable, Dict
|
from typing import List, Callable
|
||||||
from bisect import bisect
|
from bisect import bisect
|
||||||
|
|
||||||
import trio
|
import trio
|
||||||
|
@ -21,6 +21,7 @@ from kivy import utils
|
||||||
from kivy.app import async_runTouchApp
|
from kivy.app import async_runTouchApp
|
||||||
from kivy.core.window import Window
|
from kivy.core.window import Window
|
||||||
from kivy.properties import BooleanProperty
|
from kivy.properties import BooleanProperty
|
||||||
|
from kivy.uix.behaviors import ButtonBehavior
|
||||||
|
|
||||||
from ..log import get_logger
|
from ..log import get_logger
|
||||||
from .pager import PagerView
|
from .pager import PagerView
|
||||||
|
@ -161,8 +162,12 @@ class Cell(Button):
|
||||||
def __init__(self, key=None, is_header=False, **kwargs):
|
def __init__(self, key=None, is_header=False, **kwargs):
|
||||||
super(Cell, self).__init__(**kwargs)
|
super(Cell, self).__init__(**kwargs)
|
||||||
self.key = key
|
self.key = key
|
||||||
|
self.row = None
|
||||||
self.is_header = is_header
|
self.is_header = is_header
|
||||||
|
|
||||||
|
# def on_press(self, value=None):
|
||||||
|
# self.row.on_press()
|
||||||
|
|
||||||
|
|
||||||
class HeaderCell(Cell):
|
class HeaderCell(Cell):
|
||||||
"""Column header cell label.
|
"""Column header cell label.
|
||||||
|
@ -257,7 +262,7 @@ class BidAskLayout(StackLayout):
|
||||||
return [self.last, self.bid, self.ask]
|
return [self.last, self.bid, self.ask]
|
||||||
|
|
||||||
|
|
||||||
class Row(GridLayout, HoverBehavior):
|
class Row(ButtonBehavior, HoverBehavior, GridLayout):
|
||||||
"""A grid for displaying a row of ticker quote data.
|
"""A grid for displaying a row of ticker quote data.
|
||||||
"""
|
"""
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -271,7 +276,7 @@ class Row(GridLayout, HoverBehavior):
|
||||||
cell_type=None,
|
cell_type=None,
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
super(Row, self).__init__(cols=len(record), **kwargs)
|
super().__init__(cols=len(record), **kwargs)
|
||||||
self._cell_widgets = {}
|
self._cell_widgets = {}
|
||||||
self._last_record = record
|
self._last_record = record
|
||||||
self.table = table
|
self.table = table
|
||||||
|
@ -383,16 +388,20 @@ class Row(GridLayout, HoverBehavior):
|
||||||
log.debug(
|
log.debug(
|
||||||
f"Left row {self} through {self.border_point}")
|
f"Left row {self} through {self.border_point}")
|
||||||
|
|
||||||
|
def on_press(self, value=None):
|
||||||
|
log.info(f"Pressed row for {self._last_record['symbol']}")
|
||||||
|
|
||||||
|
|
||||||
class TickerTable(GridLayout):
|
class TickerTable(GridLayout):
|
||||||
"""A grid for displaying ticker quote records as a table.
|
"""A grid for displaying ticker quote records as a table.
|
||||||
"""
|
"""
|
||||||
def __init__(self, sort_key='%', **kwargs):
|
def __init__(self, sort_key='%', auto_sort=True, **kwargs):
|
||||||
super(TickerTable, self).__init__(**kwargs)
|
super(TickerTable, self).__init__(**kwargs)
|
||||||
self.symbols2rows = {}
|
self.symbols2rows = {}
|
||||||
self.sort_key = sort_key
|
self.sort_key = sort_key
|
||||||
# for tracking last clicked column header cell
|
# for tracking last clicked column header cell
|
||||||
self.last_clicked_col_cell = None
|
self.last_clicked_col_cell = None
|
||||||
|
self._auto_sort = auto_sort
|
||||||
self._symbols2index = {}
|
self._symbols2index = {}
|
||||||
self._sorted = []
|
self._sorted = []
|
||||||
|
|
||||||
|
@ -558,15 +567,21 @@ async def update_quotes(
|
||||||
async for quotes in agen: # new quotes data only
|
async for quotes in agen: # new quotes data only
|
||||||
to_sort = set()
|
to_sort = set()
|
||||||
for symbol, quote in quotes.items():
|
for symbol, quote in quotes.items():
|
||||||
|
row = table.get_row(symbol)
|
||||||
record, displayable = formatter(
|
record, displayable = formatter(
|
||||||
quote, symbol_data=symbol_data)
|
quote, symbol_data=symbol_data)
|
||||||
row = table.get_row(symbol)
|
|
||||||
|
# determine if sorting should happen
|
||||||
|
sort_key = table.sort_key
|
||||||
|
new = record[sort_key]
|
||||||
|
last = row.get_field(sort_key)
|
||||||
|
if new != last:
|
||||||
|
to_sort.add(row.widget)
|
||||||
|
|
||||||
|
# update and color
|
||||||
cells = row.update(record, displayable)
|
cells = row.update(record, displayable)
|
||||||
color_row(row, record, cells)
|
color_row(row, record, cells)
|
||||||
|
|
||||||
if table.sort_key in record:
|
|
||||||
to_sort.add(row.widget)
|
|
||||||
|
|
||||||
if to_sort:
|
if to_sort:
|
||||||
table.render_rows(to_sort)
|
table.render_rows(to_sort)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue