Add label to search bar

symbol_search
Tyler Goodlet 2021-05-25 17:10:46 -04:00
parent 46d88965d3
commit 924960a359
2 changed files with 33 additions and 12 deletions

View File

@ -106,8 +106,6 @@ class ChartSpace(QtGui.QWidget):
self._chart_cache = {} self._chart_cache = {}
self.linkedcharts: 'LinkedSplitCharts' = None self.linkedcharts: 'LinkedSplitCharts' = None
self.symbol_label: Optional[QtGui.QLabel] = None
self._root_n: Optional[trio.Nursery] = None self._root_n: Optional[trio.Nursery] = None
def set_chart_symbol( def set_chart_symbol(
@ -1660,11 +1658,7 @@ async def _async_main(
chart_app._root_n = root_n chart_app._root_n = root_n
# setup search widget # setup search widget
# search.installEventFilter(self) search = _search.SearchWidget(chart_space=chart_app)
search = _search.SearchWidget(
chart_space=chart_app,
)
# the main chart's view is given focus at startup # the main chart's view is given focus at startup
search.bar.unfocus() search.bar.unfocus()

View File

@ -408,7 +408,7 @@ class SearchBar(QtWidgets.QLineEdit):
return psh return psh
def unfocus(self) -> None: def unfocus(self) -> None:
self.hide() self.parent().hide()
self.clearFocus() self.clearFocus()
if self.view: if self.view:
@ -431,10 +431,29 @@ class SearchWidget(QtGui.QWidget):
) )
self.chart_app = chart_space self.chart_app = chart_space
self.vbox = QtGui.QVBoxLayout(self) self.vbox = QtGui.QVBoxLayout(self)
self.vbox.setContentsMargins(0, 0, 0, 0) self.vbox.setContentsMargins(0, 0, 0, 0)
self.vbox.setSpacing(4) self.vbox.setSpacing(4)
# split layout for the (label:| search bar entry)
self.bar_hbox = QtGui.QHBoxLayout(self)
self.bar_hbox.setContentsMargins(0, 0, 0, 0)
self.bar_hbox.setSpacing(4)
self.label = label = QtGui.QLabel(parent=self)
label.setTextFormat(3) # markdown
label.setFont(_font.font)
label.setMargin(4)
label.setText("`search`:")
label.show()
label.setAlignment(
QtCore.Qt.AlignVCenter
| QtCore.Qt.AlignLeft
)
self.bar_hbox.addWidget(label)
# https://doc.qt.io/qt-5/qlayout.html#SizeConstraint-enum # https://doc.qt.io/qt-5/qlayout.html#SizeConstraint-enum
# self.vbox.setSizeConstraint(QLayout.SetMaximumSize) # self.vbox.setSizeConstraint(QLayout.SetMaximumSize)
@ -447,7 +466,12 @@ class SearchWidget(QtGui.QWidget):
parent_chart=chart_space, parent_chart=chart_space,
view=self.view, view=self.view,
) )
self.vbox.addWidget(self.bar) self.bar_hbox.addWidget(self.bar)
# self.vbox.addWidget(self.bar)
# self.vbox.setAlignment(self.bar, Qt.AlignTop | Qt.AlignRight)
self.vbox.addLayout(self.bar_hbox)
self.vbox.setAlignment(self.bar, Qt.AlignTop | Qt.AlignRight) self.vbox.setAlignment(self.bar, Qt.AlignTop | Qt.AlignRight)
self.vbox.addWidget(self.bar.view) self.vbox.addWidget(self.bar.view)
self.vbox.setAlignment(self.view, Qt.AlignTop | Qt.AlignLeft) self.vbox.setAlignment(self.view, Qt.AlignTop | Qt.AlignLeft)
@ -456,9 +480,11 @@ 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(reversed(self.chart_app._chart_cache))}) self.view.set_results(
{'cache': list(reversed(self.chart_app._chart_cache))})
self.bar.focus() self.bar.focus()
self.show()
def get_current_item(self) -> Optional[Tuple[str, str]]: def get_current_item(self) -> Optional[Tuple[str, str]]:
'''Return the current completer tree selection as '''Return the current completer tree selection as
@ -580,6 +606,7 @@ async def handle_keyboard_input(
global _search_active, _search_enabled global _search_active, _search_enabled
# startup # startup
chart = search.chart_app
bar = search.bar bar = search.bar
view = bar.view view = bar.view
view.set_font_size(bar.dpi_font.px_size) view.set_font_size(bar.dpi_font.px_size)
@ -625,14 +652,14 @@ async def handle_keyboard_input(
log.info(f'Requesting symbol: {symbol}.{provider}') log.info(f'Requesting symbol: {symbol}.{provider}')
chart = search.chart_app
chart.load_symbol( chart.load_symbol(
provider, provider,
symbol, symbol,
'info', 'info',
) )
# fully qualified symbol name (SNS i guess is what we're making?) # fully qualified symbol name (SNS i guess is what we're
# making?)
fqsn = '.'.join([symbol, provider]).lower() fqsn = '.'.join([symbol, provider]).lower()
# Re-order the symbol cache on the chart to display in # Re-order the symbol cache on the chart to display in