|
@@ -8,6 +8,7 @@ from decimal import Decimal
|
|
|
from typing import Callable, Iterable, Union
|
|
|
|
|
|
import urwid
|
|
|
+from additional_urwid_widgets import IndicativeListBox
|
|
|
from urwid import numedit
|
|
|
from urwid.wimp import PopUpLauncher
|
|
|
|
|
@@ -208,16 +209,40 @@ class FocusWidget(urwid.WidgetPlaceholder):
|
|
|
self._set_focus_path(self.initial_focus)
|
|
|
|
|
|
class AutoCompletePopUp(PopUpLauncher):
|
|
|
+ _default_pop_up_parameters = {
|
|
|
+ 'left': 0,
|
|
|
+ 'top': 1,
|
|
|
+ 'overlay_width': 30,
|
|
|
+ 'overlay_height': 15,
|
|
|
+ }
|
|
|
def __init__(self,
|
|
|
widget: Union[AutoCompleteEdit, AutoCompleteFloatEdit],
|
|
|
apply_choice_cb: Callable[[str, str], None]
|
|
|
):
|
|
|
super().__init__(widget)
|
|
|
+ self._pop_up_parameters = dict(**self._default_pop_up_parameters)
|
|
|
self.apply_choice_cb = apply_choice_cb
|
|
|
urwid.connect_signal(self._original_widget, 'open', lambda _, options: self._open_pop_up(options))
|
|
|
|
|
|
def _open_pop_up(self, options):
|
|
|
self.options = options
|
|
|
+ max_height = self._default_pop_up_parameters['overlay_height']
|
|
|
+ height = min(
|
|
|
+ len(options),
|
|
|
+ self._default_pop_up_parameters['overlay_height'],
|
|
|
+ )
|
|
|
+ if 0 < len(options) - height < max_height//3:
|
|
|
+ height = 4 * max_height // 6
|
|
|
+
|
|
|
+ self._pop_up_parameters = dict(**self._default_pop_up_parameters)
|
|
|
+ self._pop_up_parameters.update({
|
|
|
+ 'overlay_width': max(
|
|
|
+ self._original_widget._cache_maxcol,
|
|
|
+ self._default_pop_up_parameters['overlay_width'],
|
|
|
+ ),
|
|
|
+ # account for header and footer rows
|
|
|
+ 'overlay_height': height+2,
|
|
|
+ })
|
|
|
self.open_pop_up()
|
|
|
|
|
|
def create_pop_up(self):
|
|
@@ -230,7 +255,7 @@ class AutoCompletePopUp(PopUpLauncher):
|
|
|
return pop_up
|
|
|
|
|
|
def get_pop_up_parameters(self):
|
|
|
- return {'left':0, 'top':1, 'overlay_width':32, 'overlay_height': 10}
|
|
|
+ return self._pop_up_parameters
|
|
|
|
|
|
class SuggestionPopup(urwid.WidgetWrap):
|
|
|
|
|
@@ -247,10 +272,15 @@ class SuggestionPopup(urwid.WidgetWrap):
|
|
|
button = urwid.Button(c)
|
|
|
urwid.connect_signal(button, 'click', self.apply_cb, c)
|
|
|
urwid.connect_signal(button, 'click', lambda _: self._emit("close"))
|
|
|
- body.append(urwid.AttrMap(button, None, focus_map='reversed'))
|
|
|
+ body.append(urwid.AttrMap(button, None, focus_map='popup_focus'))
|
|
|
walker = urwid.SimpleFocusListWalker(body, wrap_around=False)
|
|
|
- listbox = urwid.ListBox(walker)
|
|
|
- super().__init__(urwid.AttrWrap(listbox, 'banner'))
|
|
|
+ super().__init__(urwid.AttrWrap(IndicativeListBox(walker,
|
|
|
+ topBar_endExposed_prop=("───", None, None),
|
|
|
+ topBar_endCovered_prop=("▲ {} more ▲", None, None),
|
|
|
+ bottomBar_endCovered_prop=("▼ {} more ▼", None, None),
|
|
|
+ bottomBar_endExposed_prop=(f"─── {len(options)} ───", None, None),
|
|
|
+ ), 'popup'))
|
|
|
+
|
|
|
|
|
|
def keypress(self, size, key):
|
|
|
if key == 'esc':
|