Attempt to keep selected item highlighted
This attempt was unsuccessful since trying to (re)select the last highlighted item on both an "enter" or "click" of that item causes a hang and then segfault in `Qt`; no clue why.. Adds a `keep_current_item_selected: bool` flag to `CompleterView.show_cache_entries()` but using it seems to always cause a hang and crash; we keep all potential use spots commented for now obviously to avoid this. Also included is a bunch of tidying to logic blocks in the kb-control loop for readability.multichartz
parent
c15a2babc1
commit
3b15e76285
|
@ -144,15 +144,29 @@ class CompleterView(QTreeView):
|
||||||
self._font_size: int = 0 # pixels
|
self._font_size: int = 0 # pixels
|
||||||
self._init: bool = False
|
self._init: bool = False
|
||||||
|
|
||||||
async def on_pressed(self, idx: QModelIndex) -> None:
|
async def on_pressed(
|
||||||
|
self,
|
||||||
|
idx: QModelIndex,
|
||||||
|
) -> None:
|
||||||
'''
|
'''
|
||||||
Mouse pressed on view handler.
|
Mouse pressed on view handler.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
search = self.parent()
|
search = self.parent()
|
||||||
await search.chart_current_item()
|
|
||||||
|
await search.chart_current_item(
|
||||||
|
clear_to_cache=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# XXX: this causes Qt to hang and segfault..lovely
|
||||||
|
# self.show_cache_entries(
|
||||||
|
# only=True,
|
||||||
|
# keep_current_item_selected=True,
|
||||||
|
# )
|
||||||
|
|
||||||
search.focus()
|
search.focus()
|
||||||
|
|
||||||
|
|
||||||
def set_font_size(self, size: int = 18):
|
def set_font_size(self, size: int = 18):
|
||||||
# print(size)
|
# print(size)
|
||||||
if size < 0:
|
if size < 0:
|
||||||
|
@ -288,7 +302,7 @@ class CompleterView(QTreeView):
|
||||||
def select_first(self) -> QStandardItem:
|
def select_first(self) -> QStandardItem:
|
||||||
'''
|
'''
|
||||||
Select the first depth >= 2 entry from the completer tree and
|
Select the first depth >= 2 entry from the completer tree and
|
||||||
return it's item.
|
return its item.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
# ensure we're **not** selecting the first level parent node and
|
# ensure we're **not** selecting the first level parent node and
|
||||||
|
@ -615,6 +629,8 @@ class SearchWidget(QtWidgets.QWidget):
|
||||||
def show_cache_entries(
|
def show_cache_entries(
|
||||||
self,
|
self,
|
||||||
only: bool = False,
|
only: bool = False,
|
||||||
|
keep_current_item_selected: bool = False,
|
||||||
|
|
||||||
) -> None:
|
) -> None:
|
||||||
'''
|
'''
|
||||||
Clear the search results view and show only cached (aka recently
|
Clear the search results view and show only cached (aka recently
|
||||||
|
@ -629,6 +645,10 @@ class SearchWidget(QtWidgets.QWidget):
|
||||||
for fqsn in set(multi_fqsns):
|
for fqsn in set(multi_fqsns):
|
||||||
fqsns.add(fqsn)
|
fqsns.add(fqsn)
|
||||||
|
|
||||||
|
if keep_current_item_selected:
|
||||||
|
sel = self.view.selectionModel()
|
||||||
|
cidx = sel.currentIndex()
|
||||||
|
|
||||||
self.view.set_section_entries(
|
self.view.set_section_entries(
|
||||||
'cache',
|
'cache',
|
||||||
list(fqsns),
|
list(fqsns),
|
||||||
|
@ -637,7 +657,17 @@ class SearchWidget(QtWidgets.QWidget):
|
||||||
reverse=True,
|
reverse=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_current_item(self) -> Optional[tuple[str, str]]:
|
if (
|
||||||
|
keep_current_item_selected
|
||||||
|
and cidx.isValid()
|
||||||
|
):
|
||||||
|
# set current selection back to what it was before filling out
|
||||||
|
# the view results.
|
||||||
|
self.view.select_from_idx(cidx)
|
||||||
|
else:
|
||||||
|
self.view.select_first()
|
||||||
|
|
||||||
|
def get_current_item(self) -> tuple[QModelIndex, str, str] | None:
|
||||||
'''
|
'''
|
||||||
Return the current completer tree selection as
|
Return the current completer tree selection as
|
||||||
a tuple ``(parent: str, child: str)`` if valid, else ``None``.
|
a tuple ``(parent: str, child: str)`` if valid, else ``None``.
|
||||||
|
@ -665,7 +695,11 @@ class SearchWidget(QtWidgets.QWidget):
|
||||||
if provider == 'cache':
|
if provider == 'cache':
|
||||||
symbol, _, provider = symbol.rpartition('.')
|
symbol, _, provider = symbol.rpartition('.')
|
||||||
|
|
||||||
return provider, symbol
|
return (
|
||||||
|
cidx,
|
||||||
|
provider,
|
||||||
|
symbol,
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
@ -686,7 +720,7 @@ class SearchWidget(QtWidgets.QWidget):
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
provider, symbol = value
|
cidx, provider, symbol = value
|
||||||
godw = self.godwidget
|
godw = self.godwidget
|
||||||
|
|
||||||
fqsn = f'{symbol}.{provider}'
|
fqsn = f'{symbol}.{provider}'
|
||||||
|
@ -715,7 +749,9 @@ class SearchWidget(QtWidgets.QWidget):
|
||||||
godw.rt_linked,
|
godw.rt_linked,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.show_cache_entries(only=True)
|
self.show_cache_entries(
|
||||||
|
only=True,
|
||||||
|
)
|
||||||
|
|
||||||
self.bar.focus()
|
self.bar.focus()
|
||||||
return fqsn
|
return fqsn
|
||||||
|
@ -956,11 +992,10 @@ async def handle_keyboard_input(
|
||||||
global _search_active, _search_enabled
|
global _search_active, _search_enabled
|
||||||
|
|
||||||
# startup
|
# startup
|
||||||
bar = searchbar
|
searchw = searchbar.parent()
|
||||||
search = searchbar.parent()
|
godwidget = searchw.godwidget
|
||||||
godwidget = search.godwidget
|
view = searchbar.view
|
||||||
view = bar.view
|
view.set_font_size(searchbar.dpi_font.px_size)
|
||||||
view.set_font_size(bar.dpi_font.px_size)
|
|
||||||
send, recv = trio.open_memory_channel(616)
|
send, recv = trio.open_memory_channel(616)
|
||||||
|
|
||||||
async with trio.open_nursery() as n:
|
async with trio.open_nursery() as n:
|
||||||
|
@ -971,13 +1006,13 @@ async def handle_keyboard_input(
|
||||||
n.start_soon(
|
n.start_soon(
|
||||||
partial(
|
partial(
|
||||||
fill_results,
|
fill_results,
|
||||||
search,
|
searchw,
|
||||||
recv,
|
recv,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
bar.focus()
|
searchbar.focus()
|
||||||
search.show_cache_entries()
|
searchw.show_cache_entries()
|
||||||
await trio.sleep(0)
|
await trio.sleep(0)
|
||||||
|
|
||||||
async for kbmsg in recv_chan:
|
async for kbmsg in recv_chan:
|
||||||
|
@ -994,16 +1029,24 @@ async def handle_keyboard_input(
|
||||||
Qt.Key_Return
|
Qt.Key_Return
|
||||||
):
|
):
|
||||||
_search_enabled = False
|
_search_enabled = False
|
||||||
await search.chart_current_item(clear_to_cache=True)
|
await searchw.chart_current_item(clear_to_cache=True)
|
||||||
search.show_cache_entries(only=True)
|
|
||||||
|
# XXX: causes hang and segfault..
|
||||||
|
# searchw.show_cache_entries(
|
||||||
|
# only=True,
|
||||||
|
# keep_current_item_selected=True,
|
||||||
|
# )
|
||||||
|
|
||||||
view.show_matches()
|
view.show_matches()
|
||||||
search.focus()
|
searchw.focus()
|
||||||
|
|
||||||
elif not ctl and not bar.text():
|
|
||||||
|
|
||||||
|
elif (
|
||||||
|
not ctl
|
||||||
|
and not searchbar.text()
|
||||||
|
):
|
||||||
# TODO: really should factor this somewhere..bc
|
# TODO: really should factor this somewhere..bc
|
||||||
# we're doin it in another spot as well..
|
# we're doin it in another spot as well..
|
||||||
search.show_cache_entries(only=True)
|
searchw.show_cache_entries(only=True)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# cancel and close
|
# cancel and close
|
||||||
|
@ -1012,7 +1055,7 @@ async def handle_keyboard_input(
|
||||||
Qt.Key_Space, # i feel like this is the "native" one
|
Qt.Key_Space, # i feel like this is the "native" one
|
||||||
Qt.Key_Alt,
|
Qt.Key_Alt,
|
||||||
}:
|
}:
|
||||||
bar.unfocus()
|
searchbar.unfocus()
|
||||||
|
|
||||||
# kill the search and focus back on main chart
|
# kill the search and focus back on main chart
|
||||||
if godwidget:
|
if godwidget:
|
||||||
|
@ -1020,41 +1063,54 @@ async def handle_keyboard_input(
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if ctl and key in {
|
if (
|
||||||
Qt.Key_L,
|
ctl
|
||||||
}:
|
and key in {Qt.Key_L}
|
||||||
|
):
|
||||||
# like url (link) highlight in a web browser
|
# like url (link) highlight in a web browser
|
||||||
bar.focus()
|
searchbar.focus()
|
||||||
|
|
||||||
# selection navigation controls
|
# selection navigation controls
|
||||||
elif ctl and key in {
|
elif (
|
||||||
Qt.Key_D,
|
ctl
|
||||||
}:
|
and key in {Qt.Key_D}
|
||||||
|
):
|
||||||
view.next_section(direction='down')
|
view.next_section(direction='down')
|
||||||
_search_enabled = False
|
_search_enabled = False
|
||||||
|
|
||||||
elif ctl and key in {
|
elif (
|
||||||
Qt.Key_U,
|
ctl
|
||||||
}:
|
and key in {Qt.Key_U}
|
||||||
|
):
|
||||||
view.next_section(direction='up')
|
view.next_section(direction='up')
|
||||||
_search_enabled = False
|
_search_enabled = False
|
||||||
|
|
||||||
# selection navigation controls
|
# selection navigation controls
|
||||||
elif (ctl and key in {
|
elif (
|
||||||
|
ctl and (
|
||||||
|
key in {
|
||||||
Qt.Key_K,
|
Qt.Key_K,
|
||||||
Qt.Key_J,
|
Qt.Key_J,
|
||||||
|
}
|
||||||
|
|
||||||
}) or key in {
|
or key in {
|
||||||
|
|
||||||
Qt.Key_Up,
|
Qt.Key_Up,
|
||||||
Qt.Key_Down,
|
Qt.Key_Down,
|
||||||
}:
|
}
|
||||||
|
)
|
||||||
|
):
|
||||||
_search_enabled = False
|
_search_enabled = False
|
||||||
if key in {Qt.Key_K, Qt.Key_Up}:
|
|
||||||
|
if key in {
|
||||||
|
Qt.Key_K,
|
||||||
|
Qt.Key_Up
|
||||||
|
}:
|
||||||
item = view.select_previous()
|
item = view.select_previous()
|
||||||
|
|
||||||
elif key in {Qt.Key_J, Qt.Key_Down}:
|
elif key in {
|
||||||
|
Qt.Key_J,
|
||||||
|
Qt.Key_Down,
|
||||||
|
}:
|
||||||
item = view.select_next()
|
item = view.select_next()
|
||||||
|
|
||||||
if item:
|
if item:
|
||||||
|
@ -1063,15 +1119,18 @@ async def handle_keyboard_input(
|
||||||
# if we're in the cache section and thus the next
|
# if we're in the cache section and thus the next
|
||||||
# selection is a cache item, switch and show it
|
# selection is a cache item, switch and show it
|
||||||
# immediately since it should be very fast.
|
# immediately since it should be very fast.
|
||||||
if parent_item and parent_item.text() == 'cache':
|
if (
|
||||||
await search.chart_current_item(clear_to_cache=False)
|
parent_item
|
||||||
|
and parent_item.text() == 'cache'
|
||||||
|
):
|
||||||
|
await searchw.chart_current_item(clear_to_cache=False)
|
||||||
|
|
||||||
# ACTUAL SEARCH BLOCK #
|
# ACTUAL SEARCH BLOCK #
|
||||||
# where we fuzzy complete and fill out sections.
|
# where we fuzzy complete and fill out sections.
|
||||||
elif not ctl:
|
elif not ctl:
|
||||||
# relay to completer task
|
# relay to completer task
|
||||||
_search_enabled = True
|
_search_enabled = True
|
||||||
send.send_nowait(search.bar.text())
|
send.send_nowait(searchw.bar.text())
|
||||||
_search_active.set()
|
_search_active.set()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue