show all tags in tag panel by default

This commit is contained in:
yedpodtrzitko 2024-05-01 00:04:37 +08:00
parent a10478bc8b
commit d478116094
2 changed files with 46 additions and 49 deletions

View file

@ -1577,7 +1577,8 @@ class Library:
# NOTE: I'd expect a blank query to return all with the other implementation, but
# it misses stuff like Archive (id 0) so here's this as a catch-all.
if query == '':
query = query.strip()
if not query:
all: list[int] = []
for tag in self.tags:
if ignore_builtin and tag.id >= 1000:

View file

@ -27,7 +27,7 @@ class TagSearchPanel(PanelWidget):
super().__init__()
self.lib: Library = library
# self.callback = callback
self.first_tag_id = -1
self.first_tag_id = None
self.tag_limit = 30
# self.selected_tag: int = 0
self.setMinimumSize(300, 400)
@ -68,6 +68,7 @@ class TagSearchPanel(PanelWidget):
self.root_layout.addWidget(self.search_field)
self.root_layout.addWidget(self.scroll_area)
self.update_tags('')
# def reset(self):
# self.search_field.setText('')
@ -75,7 +76,7 @@ class TagSearchPanel(PanelWidget):
# self.search_field.setFocus()
def on_return(self, text:str):
if text and self.first_tag_id >= 0:
if text and self.first_tag_id is not None:
# callback(self.first_tag_id)
self.tag_chosen.emit(self.first_tag_id)
self.search_field.setText('')
@ -87,17 +88,14 @@ class TagSearchPanel(PanelWidget):
def update_tags(self, query:str):
# for c in self.scroll_layout.children():
# c.widget().deleteLater()
while self.scroll_layout.itemAt(0):
while self.scroll_layout.count():
# logging.info(f"I'm deleting { self.scroll_layout.itemAt(0).widget()}")
self.scroll_layout.takeAt(0).widget().deleteLater()
if query:
first_id_set = False
for tag_id in self.lib.search_tags(query, include_cluster=True)[:self.tag_limit-1]:
if not first_id_set:
self.first_tag_id = tag_id
first_id_set = True
found_tags = self.lib.search_tags(query, include_cluster=True)[:self.tag_limit - 1]
self.first_tag_id = found_tags[0] if found_tags else None
for tag_id in found_tags:
c = QWidget()
l = QHBoxLayout(c)
l.setContentsMargins(0, 0, 0, 0)
@ -136,8 +134,6 @@ class TagSearchPanel(PanelWidget):
l.addWidget(tw)
l.addWidget(ab)
self.scroll_layout.addWidget(c)
else:
self.first_tag_id = -1
self.search_field.setFocus()