Merge pull request #361 from mwhudson/better-WidgetWrap
add our own version of WidgetWrap
This commit is contained in:
commit
c9e87438ae
|
@ -23,11 +23,16 @@ from urwid import (
|
||||||
SelectableIcon,
|
SelectableIcon,
|
||||||
SimpleFocusListWalker,
|
SimpleFocusListWalker,
|
||||||
Text,
|
Text,
|
||||||
WidgetWrap,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from subiquitycore.ui.buttons import ok_btn, cancel_btn, other_btn
|
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.ui.utils import button_pile, Color, screen
|
||||||
from subiquitycore.view import BaseView
|
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
|
# 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.
|
# 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):
|
def __init__(self, parent, snap, cur_channel):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.snap = snap
|
self.snap = snap
|
||||||
|
|
|
@ -62,6 +62,7 @@ too many elements in the ListBox.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import operator
|
||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
|
@ -496,3 +497,22 @@ def ListBox(body=None):
|
||||||
if body is getattr(body, 'get_focus', None) is None:
|
if body is getattr(body, 'get_focus', None) is None:
|
||||||
body = urwid.SimpleFocusListWalker(body)
|
body = urwid.SimpleFocusListWalker(body)
|
||||||
return ScrollBarListBox(FocusTrackingListBox(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
|
||||||
|
|
Loading…
Reference in New Issue