Drop row factories; add ticker search API
parent
fc45e1215d
commit
1e7dc38a50
|
@ -50,7 +50,7 @@ _kv = (f'''
|
||||||
|
|
||||||
<Cell>
|
<Cell>
|
||||||
font_size: 18
|
font_size: 18
|
||||||
text_size: self.size
|
# text_size: self.size
|
||||||
size: self.texture_size
|
size: self.texture_size
|
||||||
color: {colorcode('gray')}
|
color: {colorcode('gray')}
|
||||||
font_color: {colorcode('gray')}
|
font_color: {colorcode('gray')}
|
||||||
|
@ -59,7 +59,7 @@ _kv = (f'''
|
||||||
background_normal: ''
|
background_normal: ''
|
||||||
valign: 'middle'
|
valign: 'middle'
|
||||||
halign: 'center'
|
halign: 'center'
|
||||||
outline_color: [0.1]*4
|
# outline_color: [0.1]*4
|
||||||
|
|
||||||
<HeaderCell>
|
<HeaderCell>
|
||||||
font_size: 20
|
font_size: 20
|
||||||
|
@ -87,9 +87,10 @@ _kv = (f'''
|
||||||
# minimum_width: 200
|
# minimum_width: 200
|
||||||
# row_force_default: True
|
# row_force_default: True
|
||||||
# row_default_height: 75
|
# row_default_height: 75
|
||||||
outline_color: [.7]*4
|
# outline_color: [.7]*4
|
||||||
|
|
||||||
<SearchBar>
|
<SearchBar>
|
||||||
|
# part of the `PagerView`
|
||||||
size_hint: 1, 0.03
|
size_hint: 1, 0.03
|
||||||
font_size: 25
|
font_size: 25
|
||||||
background_color: [0.13]*3 + [1]
|
background_color: [0.13]*3 + [1]
|
||||||
|
@ -172,8 +173,9 @@ class HeaderCell(Button):
|
||||||
"""Column header cell label.
|
"""Column header cell label.
|
||||||
"""
|
"""
|
||||||
def on_press(self, value=None):
|
def on_press(self, value=None):
|
||||||
# clicking on a col header indicates to rows by this column
|
"""Clicking on a col header indicates to sort rows by this column
|
||||||
# in `update_quotes()`
|
in `update_quotes()`.
|
||||||
|
"""
|
||||||
table = self.row.table
|
table = self.row.table
|
||||||
if self.row.is_header:
|
if self.row.is_header:
|
||||||
table.sort_key = self.key
|
table.sort_key = self.key
|
||||||
|
@ -215,7 +217,7 @@ class BidAskLayout(StackLayout):
|
||||||
cell_type = HeaderCell if header else Cell
|
cell_type = HeaderCell if header else Cell
|
||||||
top_size = cell_type().font_size
|
top_size = cell_type().font_size
|
||||||
small_size = top_size - 5
|
small_size = top_size - 5
|
||||||
top_prop = 0.7
|
top_prop = 0.7 # proportion of size used by top cell
|
||||||
bottom_prop = 1 - top_prop
|
bottom_prop = 1 - top_prop
|
||||||
for (key, size_hint, font_size), value in zip(
|
for (key, size_hint, font_size), value in zip(
|
||||||
[('last', (1, top_prop), top_size),
|
[('last', (1, top_prop), top_size),
|
||||||
|
@ -375,22 +377,18 @@ class TickerTable(GridLayout):
|
||||||
):
|
):
|
||||||
self.add_widget(row) # row append
|
self.add_widget(row) # row append
|
||||||
|
|
||||||
|
def ticker_search(self, patt):
|
||||||
|
"""Return sequence of matches when pattern ``patt`` is in a
|
||||||
|
symbol name. Most naive algo possible for the moment.
|
||||||
|
"""
|
||||||
|
for symbol, row in self.symbols2rows.items():
|
||||||
|
if patt in symbol:
|
||||||
|
yield symbol, row
|
||||||
|
|
||||||
def header_row(headers, **kwargs):
|
def search(self, patt):
|
||||||
"""Create a single "header" row from a sequence of keys.
|
"""Search bar api compat.
|
||||||
"""
|
"""
|
||||||
headers_dict = {key: key for key in headers}
|
return dict(self.ticker_search(patt)) or {}
|
||||||
row = Row(headers_dict, headers=headers, is_header_row=True, **kwargs)
|
|
||||||
return row
|
|
||||||
|
|
||||||
|
|
||||||
def ticker_table(quotes, **kwargs):
|
|
||||||
"""Create a new ticker table from a list of quote dicts.
|
|
||||||
"""
|
|
||||||
table = TickerTable(cols=1, **kwargs)
|
|
||||||
for ticker_record in quotes:
|
|
||||||
table.append_row(ticker_record)
|
|
||||||
return table
|
|
||||||
|
|
||||||
|
|
||||||
async def update_quotes(
|
async def update_quotes(
|
||||||
|
@ -484,21 +482,29 @@ async def _async_main(name, watchlists, brokermod):
|
||||||
# build out UI
|
# build out UI
|
||||||
Window.set_title(f"watchlist: {name}\t(press ? for help)")
|
Window.set_title(f"watchlist: {name}\t(press ? for help)")
|
||||||
Builder.load_string(_kv)
|
Builder.load_string(_kv)
|
||||||
# anchor = AnchorLayout(anchor_x='right', anchor_y='bottom')
|
|
||||||
box = BoxLayout(orientation='vertical', padding=5, spacing=5)
|
box = BoxLayout(orientation='vertical', padding=5, spacing=5)
|
||||||
# anchor.add_widget(box)
|
|
||||||
header = header_row(
|
# add header row
|
||||||
first_quotes[0].keys(),
|
headers = first_quotes[0].keys()
|
||||||
|
header = Row(
|
||||||
|
{key: key for key in headers},
|
||||||
|
headers=headers,
|
||||||
|
is_header_row=True,
|
||||||
size_hint=(1, None),
|
size_hint=(1, None),
|
||||||
)
|
)
|
||||||
box.add_widget(header)
|
box.add_widget(header)
|
||||||
grid = ticker_table(
|
|
||||||
first_quotes,
|
# build grid
|
||||||
|
grid = TickerTable(
|
||||||
|
cols=1,
|
||||||
size_hint=(1, None),
|
size_hint=(1, None),
|
||||||
)
|
)
|
||||||
|
for ticker_record in first_quotes:
|
||||||
|
grid.append_row(ticker_record)
|
||||||
# associate the col headers row with the ticker table even though
|
# associate the col headers row with the ticker table even though
|
||||||
# they're technically wrapped separately in containing BoxLayout
|
# they're technically wrapped separately in containing BoxLayout
|
||||||
header.table = grid
|
header.table = grid
|
||||||
|
|
||||||
# mark the initial sorted column header as bold and underlined
|
# mark the initial sorted column header as bold and underlined
|
||||||
sort_cell = header.get_cell(grid.sort_key)
|
sort_cell = header.get_cell(grid.sort_key)
|
||||||
sort_cell.bold = sort_cell.underline = True
|
sort_cell.bold = sort_cell.underline = True
|
||||||
|
@ -506,8 +512,7 @@ async def _async_main(name, watchlists, brokermod):
|
||||||
|
|
||||||
# set up a pager view for large ticker lists
|
# set up a pager view for large ticker lists
|
||||||
grid.bind(minimum_height=grid.setter('height'))
|
grid.bind(minimum_height=grid.setter('height'))
|
||||||
pager = PagerView(box, nursery)
|
pager = PagerView(box, grid, nursery)
|
||||||
pager.add_widget(grid)
|
|
||||||
box.add_widget(pager)
|
box.add_widget(pager)
|
||||||
|
|
||||||
widgets = {
|
widgets = {
|
||||||
|
|
Loading…
Reference in New Issue