*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit ccb8dd8d authored by Moser, Maximilian's avatar Moser, Maximilian
Browse files

Cache the size requirements for the listboxes

* this simple implementation works for us because the listbox content
  doesn't change once it's set
* otherwise, the scrollbar causes the listbox to recalculate its size
  requirements on every render, which gets very laggy with many widgets
  in the listbox
parent efb1f3f0
No related branches found
No related tags found
1 merge request!16Fixes for formatscaper & resultman
...@@ -64,6 +64,26 @@ class SimpleButton(uw.Button): ...@@ -64,6 +64,26 @@ class SimpleButton(uw.Button):
format: Optional[Format] = None format: Optional[Format] = None
class CachingListBox(uw.ListBox):
"""ListBox with caching for sizes."""
def __init__(self, body):
"""Constructor."""
super().__init__(body)
self._cached_sizes = {}
self._body._modified
def rows_max(self, size, focus):
"""Scrollable protocol for sized iterable and not wrapped around contents."""
if size in self._cached_sizes:
return self._cached_sizes[size]
result = super().rows_max(size, focus)
self._cached_sizes[size] = result
return result
# parsing CLI arguments # parsing CLI arguments
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="TUI tool for managing file format information" description="TUI tool for managing file format information"
...@@ -168,7 +188,7 @@ def handle_select_format(format: Format, button: uw.Button): ...@@ -168,7 +188,7 @@ def handle_select_format(format: Format, button: uw.Button):
_files = "file" if num_files == 1 else "files" _files = "file" if num_files == 1 else "files"
_records = "record" if len(relevant_results) == 1 else "records" _records = "record" if len(relevant_results) == 1 else "records"
bottom = uw.ScrollBar( bottom = uw.ScrollBar(
uw.ListBox( CachingListBox(
uw.SimpleFocusListWalker( uw.SimpleFocusListWalker(
[ [
uw.Divider(), uw.Divider(),
...@@ -236,7 +256,7 @@ def create_format_buttons(filter: FormatFilter): ...@@ -236,7 +256,7 @@ def create_format_buttons(filter: FormatFilter):
formats_list = uw.ScrollBar( formats_list = uw.ScrollBar(
uw.ListBox(uw.SimpleFocusListWalker(create_format_buttons(current_filter))) CachingListBox(uw.SimpleFocusListWalker(create_format_buttons(current_filter)))
) )
formats_list._command_map["l"] = "activate" formats_list._command_map["l"] = "activate"
formats_label = uw.Filler(uw.AttrMap(uw.Text("FORMATS", align="center"), "border")) formats_label = uw.Filler(uw.AttrMap(uw.Text("FORMATS", align="center"), "border"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment