示例#1
0
文件: ui.py 项目: foopub/Toys
def draw_boxes(stdscr: window):
    """
    This method draws the boxes on startup
    """

    h = curses.LINES  #Total height
    w = curses.COLS  #Total width

    #Some debug values, remove these later
    text = "This is the start of a new window"

    # Clear screen
    stdscr.clear()
    stdscr.addstr(0, 0, 'This is the start of a new window')
    stdscr.noutrefresh()

    theight = 2
    swidth = 15
    mheight = h - theight - 2
    mwidth = w - swidth - 2

    win['t'] = curses.newwin(theight, mwidth, h - 1 - theight, 1)
    win['t'].addstr(0, 0, "This is the messages windows")

    win['m'] = curses.newwin(mheight, mwidth, 1, 1)
    win['m'].addstr(0, 0, "Type something here.")
    win['m'].timeout(0)

    win['s'] = curses.newwin(h - 2, swidth, 1, w - swidth - 1)
    win['s'].addstr(0, 0, "This is a side pane")
示例#2
0
def main_page(scr: window):
    curses.curs_set(0)
    scr.noutrefresh()
    callbacks = {}

    def command_callback(command: str, **kwargs: Any):
        if command in callbacks:
            callbacks[command](**kwargs)

    setup_colours()
    max_rows, max_cols = scr.getmaxyx()
    views: dict[str, AbstractView] = {
        'header': HeaderView(max_cols),
        'footer': FooterView(max_rows, max_cols),
        'a2z': A2ZView(max_rows, command_callback),
        'tabs': TabView(max_cols, command_callback),
        'content': ContentView(max_rows, max_cols, command_callback)
    }
    keypress_table: dict[str, Callable[[int], None]] = {name: view.process_keystroke for name, view in views.items()}
    focus: list[str] = ['a2z']
    dispatch_to: list[Callable[[int], None]] = [keypress_table[focus[0]]]

    full_render_current_state(scr, views, focus[0])
    curses.doupdate()

    callbacks = setup_callbacks(views, focus, dispatch_to)
    command_callback('LOAD_PAGE', page='HOMEPAGE')

    keep_going = True
    while keep_going:
        update_render_current_state(scr, views)
        curses.doupdate()

        key: int = scr.getch()
        if key == ord('q'):
            keep_going = False
        elif key == ord('\t'):
            focus[0] = next_focus(focus[0])
            update_focuses(views, focus[0])
            dispatch_to[0] = keypress_table[focus[0]]
        elif key == curses.KEY_RESIZE:
            curses.resizeterm(*scr.getmaxyx())
            scr.erase()
            scr.noutrefresh()
            resize_all(focus[0], views, scr)
        else:
            dispatch_to[0](key)