menu.py 文件源码

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

项目:aws-ec2rescue-linux 作者: awslabs 项目源码 文件源码
def _draw_menu(self, screen):
        """
        Given a menu window, draw the rows including the header and the scrollable rows representing menu items.

        Parameters:
            screen (WindowObject): the window that will be drawn to
        """
        # Add the header
        screen.addstr(0, int((curses.COLS - 6) / 2 - len(self.header) / 2),
                      self.header,
                      curses.A_BOLD)

        # Add each item to the menu
        for row in range(1 + (self.max_displayed_rows * (self.current_page - 1)),
                         self.max_displayed_rows + 1 +
                         (self.max_displayed_rows * (self.current_page - 1))):
            # Pad or truncate the module name to 40 characters
            row_item_name = "{:40}".format(str(self._items[row - 1])[:40])
            # Truncate the row's string to the drawable width
            display_str = str(row_item_name + "  " + self._items[row - 1].row_right)[:curses.COLS - 6]
            # Draw the row
            if row + (self.max_displayed_rows * (self.current_page - 1)) == \
                self.current_row + \
                    (self.max_displayed_rows * (self.current_page - 1)):
                # Highlight the item that is currently selected
                screen.addstr(row - (self.max_displayed_rows * (self.current_page - 1)),
                              1,
                              display_str.rstrip(),
                              curses.color_pair(1) | curses.A_BOLD)
            else:
                screen.addstr(row - (self.max_displayed_rows * (self.current_page - 1)),
                              1,
                              display_str)

            # Stop printing items when the end of the drawable space is reached
            if row == self.num_rows:
                break
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号