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

View File

@ -456,7 +456,7 @@ class SearchWidget(QtGui.QWidget):
if self.view.model().rowCount(QModelIndex()) == 0: if self.view.model().rowCount(QModelIndex()) == 0:
# fill cache list if nothing existing # 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() self.bar.focus()
@ -625,15 +625,24 @@ async def handle_keyboard_input(
log.info(f'Requesting symbol: {symbol}.{provider}') log.info(f'Requesting symbol: {symbol}.{provider}')
# app = search.chart_app chart = search.chart_app
search.chart_app.load_symbol( chart.load_symbol(
provider, provider,
symbol, symbol,
'info', '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() search.bar.clear()
view.set_results({ view.set_results({
'cache': list(search.chart_app._chart_cache) 'cache': list(reversed(chart._chart_cache))
}) })
_search_enabled = False _search_enabled = False
@ -644,7 +653,7 @@ async def handle_keyboard_input(
elif not ctl and not bar.text(): elif not ctl and not bar.text():
# if nothing in search text show the cache # if nothing in search text show the cache
view.set_results({ view.set_results({
'cache': list(search.chart_app._chart_cache) 'cache': list(reversed(chart._chart_cache))
}) })
continue continue
@ -662,8 +671,8 @@ async def handle_keyboard_input(
search.bar.unfocus() search.bar.unfocus()
# kill the search and focus back on main chart # kill the search and focus back on main chart
if search.chart_app: if chart:
search.chart_app.linkedcharts.focus() chart.linkedcharts.focus()
continue continue
@ -711,7 +720,7 @@ async def handle_keyboard_input(
if value is not None: if value is not None:
provider, symbol = value provider, symbol = value
search.chart_app.load_symbol( chart.load_symbol(
provider, provider,
symbol, symbol,
'info', 'info',