Merge pull request #361 from mwhudson/better-WidgetWrap

add our own version of WidgetWrap
This commit is contained in:
Michael Hudson-Doyle 2018-06-12 09:04:06 +12:00 committed by GitHub
commit c9e87438ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 8 deletions

View File

@ -23,11 +23,16 @@ from urwid import (
SelectableIcon,
SimpleFocusListWalker,
Text,
WidgetWrap,
)
from subiquitycore.ui.buttons import ok_btn, cancel_btn, other_btn
from subiquitycore.ui.container import Columns, ListBox, Pile, ScrollBarListBox
from subiquitycore.ui.container import (
Columns,
ListBox,
Pile,
ScrollBarListBox,
WidgetWrap,
)
from subiquitycore.ui.utils import button_pile, Color, screen
from subiquitycore.view import BaseView
@ -67,12 +72,6 @@ class SnapInfoView(WidgetWrap):
# the channel list is given a third of the space. If there is
# space for both, they are packed into the upper part of the view.
def _select_first_selectable(self):
self._w._select_first_selectable()
def _select_last_selectable(self):
self._w._select_last_selectable()
def __init__(self, parent, snap, cur_channel):
self.parent = parent
self.snap = snap

View File

@ -62,6 +62,7 @@ too many elements in the ListBox.
"""
import logging
import operator
import urwid
@ -496,3 +497,22 @@ def ListBox(body=None):
if body is getattr(body, 'get_focus', None) is None:
body = urwid.SimpleFocusListWalker(body)
return ScrollBarListBox(FocusTrackingListBox(body))
get_delegate = operator.attrgetter("_wrapped_widget")
class OurWidgetWrap(urwid.WidgetWrap):
# A wrapped widget needs to have a _select_first/last_selectable
# method if and only if the widget being wrapped does, so we
# define our own WidgetWrap class that uses the same technique to
# forward these methods along if present as urwid's WidgetWrap
# does.
_select_first_selectable = property(
lambda self: get_delegate(self)._select_first_selectable)
_select_last_selectable = property(
lambda self: get_delegate(self)._select_last_selectable)
WidgetWrap = OurWidgetWrap