add support for Frames to find_with_pred in view_helpers

This commit is contained in:
Michael Hudson-Doyle 2018-05-01 12:17:53 +12:00
parent 259c3c71e9
commit 07438a1049
1 changed files with 7 additions and 0 deletions

View File

@ -4,6 +4,8 @@ import urwid
def find_with_pred(w, pred, return_path=False):
def _walk(w, path):
if not isinstance(w, urwid.Widget):
raise RuntimeError("_walk walked to non-widget %r via %r" % (w, path))
if pred(w):
return w, path
if hasattr(w, '_wrapped_widget'):
@ -15,6 +17,11 @@ def find_with_pred(w, pred, return_path=False):
r, p = _walk(w, (w,) + path)
if r:
return r, p
elif isinstance(w, urwid.Frame):
for w, _ in w.contents.values():
r, p = _walk(w, (w,) + path)
if r:
return r, p
elif hasattr(w, 'contents'):
contents = w.contents
for w, _ in contents: