Use trio memory channels throughout UIs

kivy_mainline_and_py3.8
Tyler Goodlet 2019-02-21 23:09:19 -05:00
parent cbb973ae9d
commit 7ee731faac
2 changed files with 9 additions and 8 deletions

View File

@ -148,13 +148,14 @@ async def stream_symbol_selection():
"""
widgets = tractor.current_actor().statespace['widgets']
table = widgets['table']
q = trio.Queue(1)
table._click_queues.append(q)
send_chan, recv_chan = trio.open_memory_channel(0)
table._click_queues.append(send_chan)
try:
async for symbol in q:
async with recv_chan:
async for symbol in recv_chan:
yield symbol
finally:
table._click_queues.remove(q)
table._click_queues.remove(send_chan)
async def _async_main(

View File

@ -383,8 +383,8 @@ class Row(HoverBehavior, GridLayout):
def on_press(self, value=None):
log.info(f"Pressed row for {self._last_record['symbol']}")
if self.table and not self.is_header:
for q in self.table._click_queues:
q.put_nowait(self._last_record['symbol'])
for sendchan in self.table._click_queues:
sendchan.send_nowait(self._last_record['symbol'])
class TickerTable(GridLayout):
@ -399,7 +399,7 @@ class TickerTable(GridLayout):
self._auto_sort = auto_sort
self._symbols2index = {}
self._sorted = []
self._click_queues: List[trio.Queue] = []
self._click_queues: List[trio.abc.SendChannel[str]] = []
def append_row(self, key, row):
"""Append a `Row` of `Cell` objects to this table.