Use trio memory channels throughout UIs
parent
cbb973ae9d
commit
7ee731faac
|
@ -148,13 +148,14 @@ async def stream_symbol_selection():
|
||||||
"""
|
"""
|
||||||
widgets = tractor.current_actor().statespace['widgets']
|
widgets = tractor.current_actor().statespace['widgets']
|
||||||
table = widgets['table']
|
table = widgets['table']
|
||||||
q = trio.Queue(1)
|
send_chan, recv_chan = trio.open_memory_channel(0)
|
||||||
table._click_queues.append(q)
|
table._click_queues.append(send_chan)
|
||||||
try:
|
try:
|
||||||
async for symbol in q:
|
async with recv_chan:
|
||||||
yield symbol
|
async for symbol in recv_chan:
|
||||||
|
yield symbol
|
||||||
finally:
|
finally:
|
||||||
table._click_queues.remove(q)
|
table._click_queues.remove(send_chan)
|
||||||
|
|
||||||
|
|
||||||
async def _async_main(
|
async def _async_main(
|
||||||
|
|
|
@ -383,8 +383,8 @@ class Row(HoverBehavior, GridLayout):
|
||||||
def on_press(self, value=None):
|
def on_press(self, value=None):
|
||||||
log.info(f"Pressed row for {self._last_record['symbol']}")
|
log.info(f"Pressed row for {self._last_record['symbol']}")
|
||||||
if self.table and not self.is_header:
|
if self.table and not self.is_header:
|
||||||
for q in self.table._click_queues:
|
for sendchan in self.table._click_queues:
|
||||||
q.put_nowait(self._last_record['symbol'])
|
sendchan.send_nowait(self._last_record['symbol'])
|
||||||
|
|
||||||
|
|
||||||
class TickerTable(GridLayout):
|
class TickerTable(GridLayout):
|
||||||
|
@ -399,7 +399,7 @@ class TickerTable(GridLayout):
|
||||||
self._auto_sort = auto_sort
|
self._auto_sort = auto_sort
|
||||||
self._symbols2index = {}
|
self._symbols2index = {}
|
||||||
self._sorted = []
|
self._sorted = []
|
||||||
self._click_queues: List[trio.Queue] = []
|
self._click_queues: List[trio.abc.SendChannel[str]] = []
|
||||||
|
|
||||||
def append_row(self, key, row):
|
def append_row(self, key, row):
|
||||||
"""Append a `Row` of `Cell` objects to this table.
|
"""Append a `Row` of `Cell` objects to this table.
|
||||||
|
|
Loading…
Reference in New Issue