Exemplo n.º 1
0
def help_info(app):
    """Return a widget displaying help information."""
    # system title
    items = [
        urwid.Text(r'''
                   _        _         _
                  | |      | |       (_)
         ___ _   _| | ___  | |_ _   _ _
        / __| | | | |/ __| | __| | | | |
       | (__| |_| | | (__  | |_| |_| | |
        \___|\__, |_|\___|  \__|\__,_|_|
                __/ |
               |___/

          ( scroll using arrow keys )

        '''),
        urwid.Text(TUI)
    ]

    # list key bindings
    for group, bindings in BINDINGS.list_groups():
        items.append(urwid.Text([f'{group["desc"]}:']))
        for binding in bindings:
            keystr = ' '.join(binding['keys'])
            items.append(
                urwid.Text([('key', keystr), (' ' * (10 - len(keystr))),
                            binding['desc']]))
        items.append(urwid.Divider())

    # mouse interaction
    items.extend([urwid.Text('Shift+Click to select text'), urwid.Divider()])

    # list task states
    items.append(urwid.Divider())
    items.append(urwid.Text('Task Icons:'))
    for state in TASK_STATUSES_ORDERED:
        items.append(
            urwid.Text(get_task_icon(state, is_held=False) + [' ', state]))
    items.append(urwid.Divider())
    items.append(urwid.Text('Special States:'))
    items.append(
        urwid.Text(
            get_task_icon(TASK_STATUS_WAITING, is_held=True) + [' ', 'held']))

    # list job states
    items.append(urwid.Divider())
    items.append(urwid.Text('Job Icons:'))
    for state in JOB_COLOURS:
        items.append(
            urwid.Text([(f'overlay_job_{state}', JOB_ICON), ' ', state]))

    widget = urwid.ListBox(urwid.SimpleFocusListWalker(items))

    return (widget, {'width': 60, 'height': 40})
Exemplo n.º 2
0
def filter_task_state(app):
    """Return a widget for adjusting the task state filter."""
    def toggle(state, *_):
        """Toggle a filter state."""
        app.filter_states[state] = not app.filter_states[state]

    checkboxes = [
        urwid.CheckBox(get_task_icon(state) + [' ' + state],
                       state=is_on,
                       on_state_change=partial(toggle, state))
        for state, is_on in app.filter_states.items()
    ]

    def invert(*_):
        """Invert the state of all filters."""
        for checkbox in checkboxes:
            checkbox.set_state(not checkbox.state)

    widget = urwid.ListBox(
        urwid.SimpleFocusListWalker([
            urwid.Text('Filter Task States'),
            urwid.Divider(),
            urwid.Padding(urwid.Button('Invert', on_press=invert), right=19)
        ] + checkboxes))

    return (widget, {'width': 35, 'height': 23})
Exemplo n.º 3
0
def test_get_task_icon(status, is_held, start_offset, mean_time, expected):
    """It renders task icons."""
    start_time = None
    if start_offset is not None:
        start_time = get_time_string(
            datetime.utcnow() - timedelta(seconds=start_offset)
        )
    assert (
        get_task_icon(status, is_held, start_time, mean_time)
    ) == expected