diff options
| author | Ian Ward <ian@excess.org> | 2012-03-07 08:10:40 -0500 |
|---|---|---|
| committer | Ian Ward <ian@excess.org> | 2012-03-07 08:10:40 -0500 |
| commit | fc3dfa9b81571420480156caeadfeca2ecfbae03 (patch) | |
| tree | f3cd100c5f3b09e6b3a53ed30cf2bf46d79e80c1 | |
| parent | 7ce836b5e5088ad3c34fca9ceba09f933f61a55e (diff) | |
| download | urwid-ftr-containers.tar.gz | |
tests and fix for set/get_focus_pathftr-containers
--HG--
branch : feature-containers
| -rwxr-xr-x | urwid/container.py | 4 | ||||
| -rwxr-xr-x | urwid/tests.py | 26 |
2 files changed, 28 insertions, 2 deletions
diff --git a/urwid/container.py b/urwid/container.py index 80f271f..d112a50 100755 --- a/urwid/container.py +++ b/urwid/container.py @@ -63,7 +63,7 @@ class WidgetContainerMixin(object): p = w.focus_position except IndexError: return out - out.append[p] + out.append(p) w = w.focus.base_widget def set_focus_path(self, positions): @@ -71,7 +71,7 @@ class WidgetContainerMixin(object): Set the .focus_position property starting from this container widget and proceeding along newly focused child widgets. Any failed assignment due do incompatible position types or invalid - positions will raise a IndexError. + positions will raise an IndexError. This method may be used to restore a particular widget to the focus by passing in the value returned from an earlier call to diff --git a/urwid/tests.py b/urwid/tests.py index 33fb12d..7039eac 100755 --- a/urwid/tests.py +++ b/urwid/tests.py @@ -2597,6 +2597,32 @@ class CommonContainerTest(unittest.TestCase): f.contents['body'] = (t1, 'given') self.assertRaises(urwid.FrameError, set2) + def test_focus_path(self): + # big tree of containers + t = urwid.Text(u'x') + e = urwid.Edit(u'?') + c = urwid.Columns([t, e, t, t]) + p = urwid.Pile([t, t, c, t]) + a = urwid.AttrMap(p, 'gets ignored') + s = urwid.SolidFill(u'/') + o = urwid.Overlay(e, s, 'center', 'pack', 'middle', 'pack') + lb = urwid.ListBox(urwid.SimpleFocusListWalker([t, a, o, t])) + lb.focus_position = 1 + g = urwid.GridFlow([t, t, t, t, e, t], 10, 0, 0, 'left') + g.focus_position = 4 + f = urwid.Frame(lb, header=t, footer=g) + + self.assertEquals(f.get_focus_path(), ['body', 1, 2, 1]) + f.set_focus_path(['footer']) # same as f.focus_position = 'footer' + self.assertEquals(f.get_focus_path(), ['footer', 4]) + f.set_focus_path(['body', 1, 2, 2]) + self.assertEquals(f.get_focus_path(), ['body', 1, 2, 2]) + self.assertRaises(IndexError, lambda: f.set_focus_path([0, 1, 2])) + self.assertRaises(IndexError, lambda: f.set_focus_path(['body', 2, 2])) + f.set_focus_path(['body', 2]) # focus the overlay + self.assertEquals(f.get_focus_path(), ['body', 2, 1]) + + def test_all(): """ |
