|
@@ -128,21 +128,21 @@ class NoTabCheckBox(urwid.CheckBox):
|
|
|
|
|
|
class FocusWidget(urwid.WidgetWrap):
|
|
|
ignore_focus = True
|
|
|
- def __init__(self, widget, focus_widgets):
|
|
|
+ def __init__(self, widget, focus_order, focus_widgets):
|
|
|
super().__init__(widget)
|
|
|
- self._focus_widgets = [ w for w in focus_widgets ]
|
|
|
- assert len(self._focus_widgets) > 0
|
|
|
- for w, p in self.iter_focus_paths():
|
|
|
- if w is self._focus_widgets[0]:
|
|
|
- self.container.set_focus_path(p)
|
|
|
+ self._focus_order = focus_order
|
|
|
+ self._focus_widgets = focus_widgets
|
|
|
+ p = next(p for (k,w), p in self.iter_focus_paths() if k == focus_order[0])
|
|
|
+ self.container.set_focus_path(p)
|
|
|
|
|
|
@property
|
|
|
def container(self):
|
|
|
return self._w.original_widget.original_widget
|
|
|
|
|
|
def find_widget(self, widget=None):
|
|
|
- if widget in self._focus_widgets:
|
|
|
- return widget
|
|
|
+ found = next((x for x in self._focus_widgets() if x[1] is widget), None)
|
|
|
+ if found is not None:
|
|
|
+ return found
|
|
|
_w1 = getattr(widget, 'original_widget', None)
|
|
|
_w2 = getattr(widget, 'contents', None)
|
|
|
if _w2 is not None:
|
|
@@ -166,7 +166,7 @@ class FocusWidget(urwid.WidgetWrap):
|
|
|
yield from chain(*_chain)
|
|
|
|
|
|
def focus_on(self, w):
|
|
|
- _, p = next(filter(lambda x: x[0] is w, self.iter_focus_paths()))
|
|
|
+ _, p = next(filter(lambda x: x[0][1] is w, self.iter_focus_paths()))
|
|
|
path = self.container.get_focus_path()
|
|
|
while path != p:
|
|
|
self.advance_focus()
|
|
@@ -175,14 +175,16 @@ class FocusWidget(urwid.WidgetWrap):
|
|
|
def iter_focus_paths(self):
|
|
|
for c, path in self.iter_containers():
|
|
|
for idx, w in enumerate(c.contents):
|
|
|
- yield self.find_widget(widget=w[0]), [*path, idx]
|
|
|
+ r = self.find_widget(widget=w[0])
|
|
|
+ if r is not None:
|
|
|
+ yield r, [*path, idx]
|
|
|
|
|
|
def advance_focus(self, reverse=False):
|
|
|
_c = self.container.get_focus_path()
|
|
|
- _p = [ x[1] for w,x in product(self._focus_widgets, [x for x in filter(
|
|
|
- lambda x: x[0] is not None,
|
|
|
- self.iter_focus_paths()
|
|
|
- )]) if x[0] is w ]
|
|
|
+ _p = [ next((x[1] for x in self.iter_focus_paths() if x[0][1] is w)) for k,(n,w) in product(
|
|
|
+ self._focus_order,
|
|
|
+ self._focus_widgets()
|
|
|
+ ) if k == n]
|
|
|
|
|
|
for _prev, _cur, _next in zip([_p[-1], *_p[:-1]], _p, [*_p[1:], _p[0]]):
|
|
|
if list(_c) == list(_cur):
|