menu.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:aws-ec2rescue-linux 作者: awslabs 项目源码 文件源码
def draw_menu(self, stdscr):
        # Setup the title
        # bitwise OR the color_pair and A_BOLD ints since addstr can only take one attr int
        stdscr.addstr(0, 0, "ec2rl module configurator", curses.color_pair(2) | curses.A_BOLD)
        stdscr.chgat(-1, curses.color_pair(2))
        curses.curs_set(0)

        # Configure a main window to hold the subwindows
        main_window = curses.newwin(curses.LINES - 1, curses.COLS, 1, 0)

        tmp_str = ""
        x_pos = 0
        for item in self.key_bind_help:
            if len(tmp_str) + len(item) < curses.COLS - 6:
                if not tmp_str:
                    tmp_str += item
                else:
                    tmp_str = "  ".join((tmp_str, item))
            else:
                main_window.addstr(x_pos, 3, tmp_str)
                tmp_str = ""
                tmp_str += item
                x_pos += 1
        main_window.addstr(x_pos, 3, tmp_str)

        # Create subwindows for displaying dict items and a footer for select/exit
        screen = main_window.subwin(curses.LINES - 7, curses.COLS - 4, 4, 2)
        footer = main_window.subwin(3, curses.COLS - 4, curses.LINES - 3, 2)

        # Setup background colors
        main_window.bkgd(" ", curses.color_pair(1))
        screen.bkgd(" ", curses.color_pair(2))
        footer.bkgd(" ", curses.color_pair(2))

        # Draw borders around the subwindows
        screen.box()
        footer.box()

        # Erase the screen so it can be cleanly redrawn
        screen.erase()
        screen.border(0)

        # Draw the initial screen for the user prior to entering the user input handling loop
        self._draw_menu(screen)
        # Add the footer
        self._draw_footer(footer)

        # Update the pieces
        stdscr.noutrefresh()
        main_window.noutrefresh()
        screen.noutrefresh()
        footer.noutrefresh()
        curses.doupdate()

        return main_window, screen, footer
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号