summaryrefslogtreecommitdiff
path: root/urwid/listbox.py
diff options
context:
space:
mode:
Diffstat (limited to 'urwid/listbox.py')
-rw-r--r--urwid/listbox.py68
1 files changed, 11 insertions, 57 deletions
diff --git a/urwid/listbox.py b/urwid/listbox.py
index 802b1d6..d2a339f 100644
--- a/urwid/listbox.py
+++ b/urwid/listbox.py
@@ -82,61 +82,14 @@ class ListWalker(with_metaclass(signals.MetaSignals, object)):
return None, None
-class PollingListWalker(object): # NOT ListWalker subclass
- def __init__(self, contents):
- """
- contents -- list to poll for changes
-
- This class is deprecated. Use SimpleFocusListWalker instead.
- """
- import warnings
- warnings.warn("PollingListWalker is deprecated, "
- "use SimpleFocusListWalker instead.", DeprecationWarning)
-
- self.contents = contents
- if not getattr(contents, '__getitem__', None):
- raise ListWalkerError("PollingListWalker expecting list like "
- "object, got: %r" % (contents,))
- self.focus = 0
-
- def _clamp_focus(self):
- if self.focus >= len(self.contents):
- self.focus = len(self.contents)-1
-
- def get_focus(self):
- """Return (focus widget, focus position)."""
- if len(self.contents) == 0: return None, None
- self._clamp_focus()
- return self.contents[self.focus], self.focus
-
- def set_focus(self, position):
- """Set focus position."""
- # this class is deprecated, otherwise I might have fixed this:
- assert type(position) == int
- self.focus = position
-
- def get_next(self, start_from):
- """
- Return (widget after start_from, position after start_from).
- """
- pos = start_from + 1
- if len(self.contents) <= pos: return None, None
- return self.contents[pos],pos
-
- def get_prev(self, start_from):
- """
- Return (widget before start_from, position before start_from).
- """
- pos = start_from - 1
- if pos < 0: return None, None
- return self.contents[pos],pos
-
-
class SimpleListWalker(MonitoredList, ListWalker):
def __init__(self, contents):
"""
contents -- list to copy into this object
+ This class inherits :class:`MonitoredList` which means
+ it can be treated as a list.
+
Changes made to this object (when it is treated as a list) are
detected automatically and will cause ListBox objects using
this list walker to be updated.
@@ -210,6 +163,9 @@ class SimpleFocusListWalker(ListWalker, MonitoredFocusList):
"""
contents -- list to copy into this object
+ This class inherits :class:`MonitoredList` which means
+ it can be treated as a list.
+
Changes made to this object (when it is treated as a list) are
detected automatically and will cause ListBox objects using
this list walker to be updated.
@@ -280,7 +236,7 @@ class ListBox(Widget, WidgetContainerMixin):
widgets to be displayed inside the list box
:type body: ListWalker
"""
- self.body = body
+ self._set_body(body)
try:
connect_signal(self._body, "modified", self._invalidate)
except NameError:
@@ -1019,19 +975,19 @@ class ListBox(Widget, WidgetContainerMixin):
return actual_key(self._keypress_page_down((maxcol, maxrow)))
if self._command_map[key] == CURSOR_MAX_LEFT:
- return actual_key(self._keypress_max_left())
+ return actual_key(self._keypress_max_left((maxcol, maxrow)))
if self._command_map[key] == CURSOR_MAX_RIGHT:
- return actual_key(self._keypress_max_right())
+ return actual_key(self._keypress_max_right((maxcol, maxrow)))
return key
- def _keypress_max_left(self):
+ def _keypress_max_left(self, size):
self.focus_position = next(iter(self.body.positions()))
self.set_focus_valign('top')
return True
- def _keypress_max_right(self):
+ def _keypress_max_right(self, size):
self.focus_position = next(iter(self.body.positions(reverse=True)))
self.set_focus_valign('bottom')
return True
@@ -1691,5 +1647,3 @@ class ListBox(Widget, WidgetContainerMixin):
yield pos
w, pos = self._body.get_next(pos)
if not w: break
-
-