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
评论列表
文章目录