Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def Pad(weight=1):
return ('weight',
weight,
urwid.BoxAdapter(urwid.SolidFill(SPACE_CHAR), height=FILL_HEIGHT))
def __init__(self, *args, **kwargs):
self.footer_left = urwid.Text('r - Repeat question; q - Quit')
self.footer_right = urwid.Text('--', align='right')
header = urwid.AttrMap(urwid.Padding(urwid.Text('birdears ─ Functional'
' Ear Training')),
'header')
footer = urwid.AttrMap(urwid.Padding(urwid.Columns(widget_list=[
self.footer_left, self.footer_right])), 'footer')
loading = urwid.Text('loading...')
adapter = urwid.Filler(loading)
super(TextUserInterfaceWidget, self).__init__(body=adapter,
header=header,
footer=footer)
def get_first_child(self):
"""Return the first TreeNode in the directory."""
child_keys = self.get_child_keys()
return self.get_child_node(child_keys[0])
def get_last_child(self):
"""Return the last TreeNode in the directory."""
child_keys = self.get_child_keys()
return self.get_child_node(child_keys[-1])
def has_children(self):
"""Does this node have any children?"""
return len(self.get_child_keys())>0
class TreeWalker(urwid.ListWalker):
"""ListWalker-compatible class for displaying TreeWidgets
positions are TreeNodes."""
def __init__(self, start_from):
"""start_from: TreeNode with the initial focus."""
self.focus = start_from
def get_focus(self):
widget = self.focus.get_widget()
return widget, self.focus
def set_focus(self, focus):
self.focus = focus
self._modified()
else:
if KEY_PADS[first_chromatic.note]:
weight = (KEY_PADS[first_chromatic.note]/2) + 1
chromatic_keys.append(Pad(weight=weight))
if not KEY_PADS[first_chromatic.note]:
weight = 0.5
chromatic_keys.append(Pad(weight=weight))
self.key_index = {item.pitch_str: item
for item in chromatic_keys+diatonic_keys
if type(item).__name__ == 'KeyboardButton'}
chromatic = urwid.Columns(widget_list=chromatic_keys, dividechars=1)
diatonic = urwid.Columns(widget_list=diatonic_keys, dividechars=1)
keyboard = urwid.Pile([chromatic, diatonic])
box = urwid.LineBox(keyboard)
super(Keyboard, self).__init__(body=box, min_height=10,
*args, **kwargs)
def get_indented_widget(self):
widget = self.get_inner_widget()
if not self.is_leaf:
widget = urwid.Columns([('fixed', 1,
[self.unexpanded_icon, self.expanded_icon][self.expanded]),
widget], dividechars=1)
indent_cols = self.get_indent_cols()
return urwid.Padding(widget,
width=('relative', 100), left=indent_cols)
def __init__(self, *args, **kwargs):
self.footer_left = urwid.Text('r - Repeat question; q - Quit')
self.footer_right = urwid.Text('--', align='right')
header = urwid.AttrMap(urwid.Padding(urwid.Text('birdears ─ Functional'
' Ear Training')),
'header')
footer = urwid.AttrMap(urwid.Padding(urwid.Columns(widget_list=[
self.footer_left, self.footer_right])), 'footer')
loading = urwid.Text('loading...')
adapter = urwid.Filler(loading)
super(TextUserInterfaceWidget, self).__init__(body=adapter,
header=header,
footer=footer)
def __init__(self, top="", middle="", bottom="", pitch=None, *args,
**kwargs):
self.pitch = pitch
self.pitch_str = str(pitch)
self.note_str = pitch.note
top = self.note_str
text = urwid.Text("{}\n{}\n{}".format(top, middle, bottom))
fill = urwid.Filler(text)
adapter = urwid.BoxAdapter(fill, height=3)
pad = urwid.Padding(adapter)
box = urwid.LineBox(pad)
attr = urwid.AttrMap(w=box, attr_map='default')
super(KeyboardButton, self).__init__(w=attr, *args, **kwargs)