我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用curses.doupdate()。
def refresh(self): prior, (cursr_y, cursr_x) = curses.curs_set(0), curses.getsyx() for idx, item in enumerate(self.items): fmt = '{{: <{}}}'.format(self.width-1) s = fmt.format(str(item))[:self.width-1] # s = str(item)[:self.width-1] if len(str(item)) > self.width-1 else str(item) color = colors.get_colorpair(self.default_color) if self.current == idx: if self.is_selected: color = colors.get_colorpair('black-white') else: color = colors.get_colorpair(self.highlight_color) self.textinpt.addstr(idx, 0, s, color) if self.is_selected: self.borderbox.bkgd(' ', curses.A_BOLD) else: self.borderbox.bkgd(' ', curses.A_DIM) self.borderbox.border() self.borderbox.refresh() self.textinpt.refresh() curses.curs_set(prior) curses.setsyx(cursr_y, cursr_x) curses.doupdate()
def enter(self): self.history_point = 0 curses.curs_set(1) curses.setsyx(2, 2) curses.doupdate() self.inp.erase() self.canceled = False res = self.text.edit(self._handle_key).strip() curses.curs_set(0) if self.canceled: self.inp.erase() self.inp.refresh() return '' elif (not(self.search_history) or self.search_history[-1] != res): self.search_history.append(res) return res
def display(self, title, content): curses.curs_set(0) self.infowin.clear() y, x = self.infowin.getmaxyx() self.infowin.bkgd(" ", curses.color_pair(6)) self.infowin.box() self.infowin.addstr(0, 0, title + " - 'q' to close", curses.A_UNDERLINE | curses.A_BOLD) for count, line in enumerate(content.split('\n'), start=1): try: self.infowin.addstr(count, 1, line) except: pass self.infopanel.show() curses.panel.update_panels() curses.doupdate() while self.infowin.getch() != ord('q'): pass curses.curs_set(1)
def update(self): for index, item in enumerate(self.employees): mode = self.select_mode(index) try: if item.unlocked_age < 2: mode = mode | curses.A_BOLD | curses.A_UNDERLINE except: pass if self.first_item_index > 0: self.window.addstr(0, 20, self.arrow_up) order = self.first_item_index + index + 1 msg = self.item_message.format(order, item) self.window.addstr(1 + index, 1, msg, mode) if self.last_item_index < len(self.items): self.window.addstr(self.LIST_SIZE + 1, 20, self.arrow_down) self.window.refresh() curses.doupdate()
def display(self): self.panel.top() self.panel.show() self.window.clear() while True: self.window.refresh() curses.doupdate() for index, item in enumerate(self.items): if index == self.position: mode = curses.A_REVERSE else: mode = curses.A_NORMAL msg = '%d. %s' % (index, item[0]) self.window.addstr(1+index, 1, msg, mode) key = self.window.getch() if key in [curses.KEY_ENTER, ord('\n')]: # Handle exit from menu if self.position == len(self.items)-1 or str(self.items[self.position][1]) == "exit": break else: if self.rootmenu.set_selection(self.items[self.position][1]): break elif key == curses.KEY_UP: self.navigate(-1) elif key == curses.KEY_DOWN: self.navigate(1) self.window.clear() self.panel.hide() panel.update_panels() curses.doupdate()
def pflush(): panel.update_panels() curses.doupdate()
def hide(self): self.infopanel.hide() curses.panel.update_panels() curses.doupdate()
def add(self, args_list, clear=False, save_history=True): w = self.curses_window if clear: w.clear() if save_history: self.history = [] for args in args_list: w.addstr(*args) w.noutrefresh() if save_history: self.history.append(args) curses.doupdate() if save_history and len(self.history) > self.history_size: self.history = self.history[-self.history_size:]
def init_display(self): self.window.clear() self.showdetail() self.update() self.window.refresh() curses.doupdate()
def display(self): self.window.clear() self.showdetail() while True: self.has_focus = True self.next_window.has_focus = False self.window.refresh() curses.doupdate() self.update() key = self.window.getch() if key in [curses.KEY_ENTER, ord('\n')]: return self.position if key == curses.KEY_UP: if self.position == 0: self.navigate(self.last_item_index) else: self.navigate(-1) elif key == curses.KEY_DOWN: self.navigate(1) elif key == curses.KEY_RIGHT or key == curses.KEY_LEFT: self.has_focus = False self.update() self.next_window.display()
def action(self): self.items[self.position].fire() self.detailwindow.window.clear() self.window.clear() self.has_focus = False self.position = 0 self.update() self.window.refresh() curses.doupdate()
def display(self): self.window.clear() self.showdetail() while True: self.has_focus = True self.next_window.has_focus = False self.window.refresh() curses.doupdate() self.update() key = self.window.getch() if key in [curses.KEY_ENTER, ord('\n')]: self.action() return if key == curses.KEY_UP: if self.position == 0: self.navigate(self.last_item_index) else: self.navigate(-1) elif key == curses.KEY_DOWN: self.navigate(1) elif key == curses.KEY_RIGHT or key == curses.KEY_LEFT: self.has_focus = False self.update() return # TODO: scrolling this
def setup_draw(self): # get screen dimensions self.maxY, self.maxX = self.stdscr.getmaxyx() # n_lines, n_cols, begin_y, begin_x self.head_win = curses.newwin(1, self.maxX, 0, 0) # left panel, contacts self.body_win = curses.newwin( self.maxY - 1, int(self.maxX * self.body_proportion), 1, 0) # chat frame self.chat_win = curses.newwin( self.maxY - 1 - int(self.maxY * self.text_area_proportion), self.maxX - int(self.maxX * self.body_proportion), 1, int(self.maxX * self.body_proportion)) # chat window (displays text) self.chatarea = curses.newwin( self.maxY - 1 - int(self.maxY * self.text_area_proportion) - 2, self.maxX - int(self.maxX * self.body_proportion) - 2, 2, int(self.maxX * self.body_proportion) + 1) # bottom frame window self.text_win = curses.newwin( int(self.maxY * self.text_area_proportion), self.maxX - int(self.maxX * self.body_proportion), self.maxY - int(self.maxY * self.text_area_proportion), int(self.maxX * self.body_proportion)) # bottom textarea self.textarea = curses.newwin( int(self.maxY * self.text_area_proportion) - 2, self.maxX - int(self.maxX * self.body_proportion) - 2, self.maxY - int(self.maxY * self.text_area_proportion) + 1, int(self.maxX * self.body_proportion) + 1) self.init_head() self.init_body() self.init_chat() self.init_chatarea() self.init_textbox() self.init_textarea() self.body_win.keypad(1) curses.doupdate()
def draw_screen(self): """This function will handle all screen renders. It takes a list of things and a grid (with is a list of lists of tiles. It will draw them all on the screen. The next step will be splitting out messaging and finally Character sheet display.""" x_offset = floor((self.width - 20) / 2) minX = self.player.x - x_offset maxX = self.player.x + x_offset - 1 if minX < 0: minX = 0 if maxX > self.current_level.width: maxX = self.current_level.width if maxX - minX < self.width - 20: if minX == 0: maxX = self.width-20 else: minX = maxX - (self.width - 20) y_offset = floor((self.height - 10) / 2) minY = self.player.y - y_offset maxY = self.player.y + y_offset - 1 if minY < 0: minY = 0 if maxY > self.current_level.height: maxY = self.current_level.height if maxY - minY < self.height - 10: if minY == 0: maxY = self.height-10 else: minY = maxY - (self.height-10) log.info("minX = %s, maxX = %s, minY = %s, maxY = %s" % (minX, maxX, minY, maxY)) grid,things = self.current_level.full_render(minX,maxX,minY,maxY) for y in range(len(grid)): for x in range(len(grid[y])): wall = grid[y][x].blocked if wall: try: self.map_view.addch(y, x," ", curses.color_pair(self.color_palette["dark_wall"])) except curses.error: pass else: try: self.map_view.addch(y,x," ", curses.color_pair(self.color_palette["dark_floor"])) except curses.error: pass for thing in things: if thing.ai_comp: self.draw_thing(thing,minX,minY) self.draw_thing(self.player,minX,minY) self.msg_handler.update_messages() self.char_sheet.update_sheet() self.map_view.noutrefresh() curses.doupdate()
def _draw_input(self, stdscr, header, message): """ Draw an input window with the provided message. Parameters: stdscr (WindowObject): the screen; handled by curses.wrapper header (str): header message displayed above the text entry box message (str): the message to the user displayed between the header and the text entry Returns: (Textbox): the Textbox's edit() returns a string representing the user's input """ stdscr.clear() # Setup the title stdscr.addstr("ec2rl module configurator", curses.A_REVERSE) stdscr.chgat(-1, curses.A_REVERSE) curses.curs_set(0) num_columns = 30 num_lines = 1 uly = 3 ulx = 3 main_window = curses.newwin(curses.LINES - 1, curses.COLS, 1, 0) screen = main_window.subwin(curses.LINES - 7, curses.COLS - 4, 4, 2) # Setup background colors main_window.bkgd(" ", curses.color_pair(1)) screen.bkgd(" ", curses.color_pair(2)) # Draw borders around the screen subwindow screen.box() input_screen = main_window.subwin(num_lines, num_columns, uly + 5, ulx + 3) ec2rlcore.menu_textpad_mod.rectangle(screen, uly, ulx, uly + 1 + num_lines, ulx + 1 + num_columns) screen.addstr(1, 2, header, curses.A_UNDERLINE) # Truncate the string, if needed display_str = message[:curses.COLS - 10] screen.addstr(2, 5, display_str) # Draw the pieces of the overall screen (order matters) stdscr.refresh() main_window.noutrefresh() screen.noutrefresh() input_screen.noutrefresh() stdscr.noutrefresh() curses.doupdate() return ec2rlcore.menu_textpad_mod.Textbox(input_screen, bkgd_color=curses.color_pair(2)).edit()
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
def _draw_notification(stdscr, message): """ Draw a notification window with the provided message. Parameters: stdscr (WindowObject): the screen; handled by curses.wrapper message (str): the message to the user Returns: True (bool) """ stdscr.clear() # Setup the title stdscr.addstr("ec2rl module configurator", curses.color_pair(2) | curses.A_BOLD) stdscr.chgat(-1, curses.color_pair(2)) curses.curs_set(0) message_list = [message.rstrip() for message in message.split(os.linesep)] current_row = 1 main_window = curses.newwin(curses.LINES - 1, curses.COLS, 1, 0) 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() footer.addstr(1, 1, "Exit", curses.color_pair(1) | curses.A_BOLD) for message in message_list: if current_row < curses.LINES - 7: # Truncate the string, if needed display_str = message[:curses.COLS - 8] screen.addstr(current_row, 3, display_str) current_row += 1 else: break # Draw the pieces of the overall screen (order matters) stdscr.noutrefresh() main_window.noutrefresh() screen.noutrefresh() curses.doupdate() while True: # Get a character from the keyboard key = stdscr.getch() # The user can exit via the enter key if key == ord("\n"): return True
def _get_input(self, wait_tenths): # this works around a strange curses bug with window resizing # not being reported correctly with repeated calls to this # function without a doupdate call in between curses.doupdate() key = self._getch(wait_tenths) resize = False raw = [] keys = [] while key >= 0: raw.append(key) if key==KEY_RESIZE: resize = True elif key==KEY_MOUSE: keys += self._encode_mouse_event() else: keys.append(key) key = self._getch_nodelay() processed = [] try: while keys: run, keys = escape.process_keyqueue(keys, True) processed += run except escape.MoreInputRequired: key = self._getch(self.complete_tenths) while key >= 0: raw.append(key) if key==KEY_RESIZE: resize = True elif key==KEY_MOUSE: keys += self._encode_mouse_event() else: keys.append(key) key = self._getch_nodelay() while keys: run, keys = escape.process_keyqueue(keys, False) processed += run if resize: processed.append('window resize') return processed, raw