我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用curses.A_STANDOUT。
def box_init(self): """Clear the main screen and redraw the box and/or title """ # Touchwin seems to save the underlying screen and refreshes it (for # example when the help popup is drawn and cleared again) self.scr.touchwin() self.scr.refresh() self.stdscr.clear() self.stdscr.refresh() if self.box is True: self.boxscr.clear() self.boxscr.box() if self.title: addstr(self.boxscr, 1, 1, self.title, curses.A_BOLD) addstr(self.boxscr, self.title_help, curses.A_STANDOUT) self.boxscr.refresh() elif self.title: self.boxscr.clear() addstr(self.boxscr, 0, 0, self.title, curses.A_BOLD) addstr(self.boxscr, self.title_help, curses.A_STANDOUT) self.boxscr.refresh()
def draw(self): pos = self.offset for i in range(self.syswin.getmaxyx()[0]-2): style = 0 if pos == self.list_pos(): style = curses.A_STANDOUT if pos < len(data): dat = (' ' + data[pos][1] + ' ' * 100)[:self.gameswin.getmaxyx()[1] - 3] + ' ' self.gameswin.addstr(i + 1, 1, dat, style) dat = (' ' + data[pos][0] + ' ' * 100)[:self.syswin.getmaxyx()[1] - 3] + ' ' self.syswin.addstr(i + 1, 1, dat, style) else: self.gameswin.addstr(i + 1, 1, (' '*100)[:self.gameswin.getmaxyx()[1] - 2]) self.syswin.addstr(i + 1, 1, (' '*100)[:self.syswin.getmaxyx()[1] - 2]) pos += 1 self.main.addstr(self.main.getmaxyx()[0] - 1, 0, '"q"-quit, "l"-launch, "/"- search, "n"-next, "N"-prev, "j"-down, "k"-up'[:self.main.getmaxyx()[1]-1]) self.main.refresh() self.syswin.border() self.gameswin.border() self.syswin.refresh() self.gameswin.refresh() if preview_window: preview_window.draw()
def do_keyboard_shortcuts(self): w = self.temperatureWindow # just a random window ordch = w.getch() if ordch in [ord('P'), ord('p')]: w.addstr(0, 0, 'PAUSE', curses.A_STANDOUT) w.refresh() ordch = None while ordch not in [ord('P'), ord('p'), 27, ord('Q'), ord('q')]: time.sleep(0.1) ordch = w.getch() self.fpsTicks = 0 self.fpsSince = time.time() w.erase() w.border() w.refresh() if ordch in [27, ord('Q'), ord('q')]: raise KeyboardInterrupt() if ordch in [ord('F')]: self.fpsGoal = (self.fpsGoal or self.fpsMeasured) * 1.25 if ordch in [ord('f')]: self.fpsGoal = (self.fpsGoal or self.fpsMeasured) * 0.8
def Blink(self, *args, **kwargs): if not self.open: raise NotOpenError('Please, open the port first!') screen = args[0] y, x = screen.getmaxyx() screen.border(0) screen.addstr(0, 1, 'Press any button to stop...'[:x-2], curses.A_STANDOUT) t = RepeatingTimer(0.5, self.CmosLed, screen) t.start() screen.refresh() inp = screen.getch() if inp: t.cancel() self.CmosLed(led = False) self._led = False return ['', None] #################################################################### ## All (other) commands:
def print_warning(self, text): """ Print multi-line text in bold font """ for line in text.split("\n"): self.stdscr.addstr(self.row, 0, line, curses.A_STANDOUT) self.nextrow()
def draw_default(self): # draws default menu clear_bar = " " * (int(self.maxx*2/3)) self.screen.addstr(2, 2, self.title, curses.A_STANDOUT) # Title for this menu self.screen.addstr(4, 2, self.subtitle, curses.A_BOLD) #Subtitle for this menu # clear menu on screen for index in range(len(self.options)+1): self.screen.addstr(5+index, 4, clear_bar, curses.A_NORMAL) # display all the menu items, showing the 'pos' item highlighted for index in range(len(self.options)): textstyle = self.normal if index == self.selected: textstyle = self.highlighted self.screen.addstr(5+index ,4, clear_bar, curses.A_NORMAL) self.screen.addstr(5+index ,4, "%d - %s" % (index+1, self.options[index]), textstyle) self.screen.addstr(11, 2, clear_bar, curses.A_NORMAL) self.screen.addstr(12, 2, clear_bar, curses.A_NORMAL) self.screen.addstr(11, 2, "plant: ", curses.A_DIM) self.screen.addstr(11, 9, self.plant_string, curses.A_NORMAL) self.screen.addstr(12, 2, "score: ", curses.A_DIM) self.screen.addstr(12, 9, self.plant_ticks, curses.A_NORMAL) # display fancy water gauge if not self.plant.dead: water_gauge_str = self.water_gauge() self.screen.addstr(5,14, water_gauge_str, curses.A_NORMAL) else: self.screen.addstr(5,13, clear_bar, curses.A_NORMAL) self.screen.addstr(5,13, " ( RIP )", curses.A_NORMAL) # draw cute ascii from files self.draw_plant_ascii(self.plant)
def slipnode_name_and_attr(self, slipnode): if slipnode.activation == 100: return (slipnode.name.upper(), curses.A_STANDOUT) if slipnode.activation > 50: return (slipnode.name.upper(), curses.A_BOLD) else: return (slipnode.name.lower(), curses.A_NORMAL)
def open_menu(stdscr, items): """Opens a menu containing items and returns the selected item. Blocks until the user selected an item. """ width = max(map(len, items)) + 20 height = len(items*2)-1 + 4 # +2 for frame, +2 for padding curses.curs_set(False) selected = 0 while True: center = (curses.COLS//2, curses.LINES//2) menu_rect = Rect(center[0]-width//2, center[1]-height//2, width, height) menu_rect = draw_frame(stdscr, menu_rect, thick_border=True) for i, item in enumerate(items): attr = curses.A_NORMAL if i == selected: attr = curses.A_STANDOUT stdscr.addstr(menu_rect.y + 1 + i*2, center[0] - len(item)//2, item, attr) c = stdscr.getch() if c == curses.KEY_UP: selected -= 1 if c == curses.KEY_DOWN: selected += 1 if c == curses.KEY_ENTER or c == 10: break selected = clamp(selected, 0, len(items)-1) curses.curs_set(True) return items[selected]
def _setattr(self, a): if a is None: self.s.attrset(0) return elif not isinstance(a, AttrSpec): p = self._palette.get(a, (AttrSpec('default', 'default'),)) a = p[0] if self.has_color: if a.foreground_basic: if a.foreground_number >= 8: fg = a.foreground_number - 8 else: fg = a.foreground_number else: fg = 7 if a.background_basic: bg = a.background_number else: bg = 0 attr = curses.color_pair(bg * 8 + 7 - fg) else: attr = 0 if a.bold: attr |= curses.A_BOLD if a.standout: attr |= curses.A_STANDOUT if a.underline: attr |= curses.A_UNDERLINE if a.blink: attr |= curses.A_BLINK self.s.attrset(attr)
def CheckEnrolled(self, *args, **kwargs): if not self.open: raise NotOpenError('Please, open the port first!') screen = args[0] y, x = screen.getmaxyx() # screen.border(0) # screen.addstr(0, 1, 'Enter the ID to check, or empty field to exit...'[:x-2], curses.A_STANDOUT) curses.echo() while True: screen.addstr(2, 2, '>>> ') screen.clrtoeol() screen.border(0) screen.addstr(0, 1, 'Enter the ID to check, or empty field to exit...'[:x-2], curses.A_STANDOUT) ID = screen.getstr(2, 6) if ID.isdigit(): response = self._f.CheckEnrolled(int(ID)) if response[0]['ACK']: screen.addstr(3, 2, 'ID in use!') screen.clrtoeol() else: screen.addstr(3, 2, response[0]['Parameter']) screen.clrtoeol() elif ID.isalnum(): curses.noecho() raise ValueError('Non-numeric value found!') else: break curses.noecho() return [None, None]
def EnrollStart(self, *args, **kwargs): if not self.open: raise NotOpenError('Please, open the port first!') screen = args[0] y, x = screen.getmaxyx() # screen.border(0) # screen.addstr(0, 1, 'Enter the ID to check, or empty field to exit...'[:x-2], curses.A_STANDOUT) curses.echo() ret = [False, None] while True: screen.addstr(2, 2, '>>> ') screen.clrtoeol() screen.border(0) screen.addstr(0, 1, 'Enter a new ID for enrollment, or empty field to cancel...'[:x-2], curses.A_STANDOUT) ID = screen.getstr(2, 6) if ID.isdigit(): response = self._f.EnrollStart(int(ID)) if response[0]['ACK']: # screen.addstr(3, 2, 'ID in use!') # screen.clrtoeol() ret[0] = 'Enrollment of ID {0:d} started'.format(response[0]['Parameter']) break else: screen.addstr(3, 2, response[0]['Parameter']) screen.clrtoeol() elif ID.isalnum(): curses.noecho() raise ValueError('Non-numeric value found!') else: break curses.noecho() return ret
def DeleteID(self, *args, **kwargs): if not self.open: raise NotOpenError('Please, open the port first!') screen = args[0] y, x = screen.getmaxyx() # screen.border(0) # screen.addstr(0, 1, 'Enter the ID to check, or empty field to exit...'[:x-2], curses.A_STANDOUT) curses.echo() ret = [False, None] while True: screen.addstr(2, 2, '>>> ') screen.clrtoeol() screen.border(0) screen.addstr(0, 1, 'Enter an ID to delete, or empty field to cancel...'[:x-2], curses.A_STANDOUT) ID = screen.getstr(2, 6) if ID.isdigit(): response = self._f.DeleteID(int(ID)) if response[0]['ACK']: # screen.addstr(3, 2, 'ID in use!') # screen.clrtoeol() ret[0] = 'ID {0:d} deleted'.format(ID) break else: screen.addstr(3, 2, response[0]['Parameter']) screen.clrtoeol() elif ID.isalnum(): curses.noecho() raise ValueError('Non-numeric value found!') else: break curses.noecho() return ret
def Verify(self, *args, **kwargs): if not self.open: raise NotOpenError('Please, open the port first!') screen = args[0] y, x = screen.getmaxyx() # screen.border(0) # screen.addstr(0, 1, 'Enter the ID to check, or empty field to exit...'[:x-2], curses.A_STANDOUT) curses.echo() ret = [False, None] while True: screen.addstr(2, 2, '>>> ') screen.clrtoeol() screen.border(0) screen.addstr(0, 1, 'Enter an ID to verify, or empty field to cancel...'[:x-2], curses.A_STANDOUT) ID = screen.getstr(2, 6) if ID.isdigit(): response = self._f.Verify(int(ID)) if response[0]['ACK']: # screen.addstr(3, 2, 'ID in use!') # screen.clrtoeol() ret[0] = 'ID {0:d} verified'.format(ID) break else: screen.addstr(3, 2, response[0]['Parameter']) screen.clrtoeol() elif ID.isalnum(): curses.noecho() raise ValueError('Non-numeric value found!') else: break curses.noecho() return ret
def runmenu(menu, parent): if parent is None: lastoption = "Exit" else: lastoption = "Return to %s menu" % parent['title'] optioncount = len(menu['options']) pos=0 oldpos=None x = None while x != ord('\n'): if pos != oldpos: oldpos = pos screen.border(1,1,1,1) screen.addstr(2,2, menu['title'], curses.A_STANDOUT) screen.addstr(4,2, menu['subtitle'], curses.A_BOLD) for index in range(optioncount): textstyle = n if pos == index: textstyle = h screen.addstr(7+index,4, "%d - %s" % (index+1, menu['options'][index]['title']), textstyle) textstyle = n if pos == optioncount: textstyle = h screen.addstr(7+optioncount,4, "%d - %s" % (optioncount+1, lastoption), textstyle) screen.refresh() x = screen.getch() if x >= ord('1') and x <= ord(str(optioncount+1)): pos = x - ord('0') - 1 elif x == 258: if pos < optioncount: pos += 1 else: pos = 0 elif x == 259: if pos > 0: pos += -1 else: pos = optioncount return pos