Get LIFO sort on cache syms working properly

symbol_search
Tyler Goodlet 2021-05-25 11:55:24 -04:00
parent 44f4fdf043
commit 46d88965d3
2 changed files with 27 additions and 16 deletions

View File

@ -19,7 +19,6 @@ High level Qt chart widgets.
"""
import time
from collections import OrderedDict
from contextlib import AsyncExitStack
from typing import Tuple, Dict, Any, Optional, Callable
from types import ModuleType
@ -105,7 +104,7 @@ class ChartSpace(QtGui.QWidget):
self.vbox.addLayout(self.toolbar_layout)
# self.vbox.addLayout(self.hbox)
self._chart_cache = OrderedDict()
self._chart_cache = {}
self.linkedcharts: 'LinkedSplitCharts' = None
self.symbol_label: Optional[QtGui.QLabel] = None
@ -115,10 +114,12 @@ class ChartSpace(QtGui.QWidget):
self,
symbol_key: str, # of form <fqsn>.<providername>
linked_charts: 'LinkedSplitCharts', # type: ignore
) -> None:
self._chart_cache[symbol_key] = linked_charts
# re-sort list in LIFO order
self._chart_cache.move_to_end(symbol_key, last=False)
# re-sort org cache symbol list in LIFO order
cache = self._chart_cache
cache.pop(symbol_key, None)
cache[symbol_key] = linked_charts
def get_chart_symbol(
self,
@ -176,7 +177,7 @@ class ChartSpace(QtGui.QWidget):
# XXX: pretty sure we don't need this
# remove any existing plots?
# XXX: ahh we might want to support cache unloading..
# self.vbox.removeWidget(self.linkedcharts)
self.vbox.removeWidget(self.linkedcharts)
# switching to a new viewable chart
if linkedcharts is None or reset:
@ -193,10 +194,11 @@ class ChartSpace(QtGui.QWidget):
loglevel,
)
self.vbox.addWidget(linkedcharts)
self.set_chart_symbol(fqsn, linkedcharts)
self.vbox.addWidget(linkedcharts)
# chart is already in memory so just focus it
if self.linkedcharts:
self.linkedcharts.unfocus()

View File

@ -456,7 +456,7 @@ class SearchWidget(QtGui.QWidget):
if self.view.model().rowCount(QModelIndex()) == 0:
# fill cache list if nothing existing
self.view.set_results({'cache': list(self.chart_app._chart_cache)})
self.view.set_results({'cache': list(reversed(self.chart_app._chart_cache))})
self.bar.focus()
@ -625,15 +625,24 @@ async def handle_keyboard_input(
log.info(f'Requesting symbol: {symbol}.{provider}')
# app = search.chart_app
search.chart_app.load_symbol(
chart = search.chart_app
chart.load_symbol(
provider,
symbol,
'info',
)
# fully qualified symbol name (SNS i guess is what we're making?)
fqsn = '.'.join([symbol, provider]).lower()
# Re-order the symbol cache on the chart to display in
# LIFO order. this is normally only done internally by
# the chart on new symbols being loaded into memory
chart.set_chart_symbol(fqsn, chart.linkedcharts)
search.bar.clear()
view.set_results({
'cache': list(search.chart_app._chart_cache)
'cache': list(reversed(chart._chart_cache))
})
_search_enabled = False
@ -644,7 +653,7 @@ async def handle_keyboard_input(
elif not ctl and not bar.text():
# if nothing in search text show the cache
view.set_results({
'cache': list(search.chart_app._chart_cache)
'cache': list(reversed(chart._chart_cache))
})
continue
@ -662,8 +671,8 @@ async def handle_keyboard_input(
search.bar.unfocus()
# kill the search and focus back on main chart
if search.chart_app:
search.chart_app.linkedcharts.focus()
if chart:
chart.linkedcharts.focus()
continue
@ -711,7 +720,7 @@ async def handle_keyboard_input(
if value is not None:
provider, symbol = value
search.chart_app.load_symbol(
chart.load_symbol(
provider,
symbol,
'info',