Skip to content

Commit

Permalink
hide results in case nothing searched, fix panel size
Browse files Browse the repository at this point in the history
  • Loading branch information
haesleinhuepf committed Nov 10, 2021
1 parent fda8f37 commit de38df7
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions napari_plugin_search/_dock_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@ def __init__(self, napari_viewer):

seach_field = MyQLineEdit("")
results = QListWidget()
results.setVisible(False)

def text_changed(*args, **kwargs):
search_string = seach_field.text().lower()
results.clear()
for hook_type, (plugin_name, widgets) in plugin_manager.iter_widgets():
for widget in widgets:
if search_string in plugin_name.lower() or search_string in widget.lower():
_add_result(results, plugin_name, widget)
results.sortItems()
if len(search_string) > 0:
results.setVisible(True)
for hook_type, (plugin_name, widgets) in plugin_manager.iter_widgets():
for widget in widgets:
if search_string in plugin_name.lower() or search_string in widget.lower():
_add_result(results, plugin_name, widget)
results.sortItems()
self.setMaximumHeight(300)
else:
results.setVisible(False)
self.setMaximumHeight(50)

def key_up():
if results.currentRow() > 0:
Expand All @@ -48,6 +55,8 @@ def key_down():
seach_field.keyup.connect(key_up)
seach_field.keydown.connect(key_down)
seach_field.textChanged.connect(text_changed)
seach_field.setMaximumHeight(30)
self.setMaximumHeight(50)

def item_double_clicked():
item = results.currentItem()
Expand Down

0 comments on commit de38df7

Please sign in to comment.