def get_content(text):
return urwid.Pile([urwid.SelectableIcon(
s, 0) if i == 0 else urwid.Text(s) for i, s in enumerate(text)])
python类SelectableIcon()的实例源码
def __init__(self, caption, callback, data):
super(CleanButton, self).__init__(caption, callback, data)
self._w = ur.SelectableIcon(caption, 0)
def get_content(text):
return urwid.Pile([urwid.SelectableIcon(
s, 0) if i == 0 else urwid.Text(s) for i, s in enumerate(text)])
def cute_button(label, callback=None, data=None):
"""
Urwid's default buttons are shit, and they have ugly borders.
This function returns buttons that are a bit easier to love.
"""
button = urwid.Button("", callback, data)
super(urwid.Button, button).__init__(
urwid.SelectableIcon(label))
return button
def __init__(self, mod: Mod, *callbacks: Iterable[ModItemCallback]):
"""Wrap mod in the set of display widgets.
Keyword arguments:
mod: The :class:`Mod` to be wrapped.
callbacks: The functions to be called when this object
is selected.
"""
btn_prefix = ' ? '
# Construct button (the selectable part)
btn = urwid.Button('')
btn._w = urwid.AttrMap(
urwid.SelectableIcon([btn_prefix, mod.name], 2),
'title', 'title_focus',
)
for callback in callbacks:
urwid.connect_signal(btn, 'click', callback, user_args=[mod])
# Construct the mod summary
text = urwid.Padding(
urwid.AttrMap(urwid.Text(mod.summary), 'description'),
left=len(btn_prefix)*2,
)
pile = btn, text
super().__init__(pile)
def __init__(self, song, on_pressed_callback, index=0):
super(SongButton, self).__init__('', on_pressed_callback)
self.index = index
self.song = song
self.is_playing = False
self._text = urwid.SelectableIcon(
u'• %s - %s' % (song.title, song.artist),
cursor_position=0)
self._w = urwid.AttrMap(self._text, None, focus_map='reversed')
self.set_is_playing(self.is_playing)
# ????????