Python curses.A_NORMAL Examples
The following are 30
code examples of curses.A_NORMAL().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
curses
, or try the search function
.
Example #1
Source File: event_listening.py From stem with GNU Lesser General Public License v3.0 | 7 votes |
def addstr(self, y, x, msg, color = None, attr = curses.A_NORMAL): # Curses throws an error if we try to draw a message that spans out of the # window's bounds (... seriously?), so doing our best to avoid that. if color is not None: if color not in self._colors: recognized_colors = ", ".join(self._colors.keys()) raise ValueError("The '%s' color isn't recognized: %s" % (color, recognized_colors)) attr |= self._colors[color] max_y, max_x = self._stdscr.getmaxyx() if max_x > x and max_y > y: try: self._stdscr.addstr(y, x, msg[:max_x - x], attr) except: pass # maybe an edge case while resizing the window
Example #2
Source File: curses_ui.py From deep_image_model with Apache License 2.0 | 6 votes |
def _screen_draw_text_line(self, row, line, attr=curses.A_NORMAL, color=None): """Render a line of text on the screen. Args: row: (int) Row index. line: (str) The line content. attr: curses font attribute. color: (str) font foreground color name. Raises: TypeError: If row is not of type int. """ if not isinstance(row, int): raise TypeError("Invalid type in row") if len(line) > self._max_x: line = line[:self._max_x] if color is None: self._stdscr.addstr(row, 0, line, attr) else: self._stdscr.addstr(row, 0, line, self._color_pairs[color]) self._screen_refresh()
Example #3
Source File: curses_reporter.py From copycat with MIT License | 6 votes |
def depict_fps(self): w = self.fpsWindow now = time.time() elapsed = now - self.fpsSince fps = self.fpsTicks / elapsed if self.fpsGoal is not None: seconds_of_work_per_frame = (elapsed / self.fpsTicks) - self.fpsDelay desired_time_working_per_second = self.fpsGoal * seconds_of_work_per_frame if desired_time_working_per_second < 1.0: self.fpsDelay = (1.0 - desired_time_working_per_second) / fps else: self.fpsDelay = 0 w.addstr(1, 1, 'FPS:%3d' % fps, curses.A_NORMAL) w.refresh() self.fpsSince = now self.fpsTicks = 0 self.fpsMeasured = fps
Example #4
Source File: curses_reporter.py From copycat with MIT License | 6 votes |
def depict_workspace_object(self, w, row, column, o, maxImportance, description_structures): if maxImportance != 0.0 and o.relativeImportance == maxImportance: attr = curses.A_BOLD else: attr = curses.A_NORMAL w.addstr(row, column, str(o), attr) column += len(str(o)) if o.descriptions: w.addstr(row, column, ' (', curses.A_NORMAL) column += 2 for i, d in enumerate(o.descriptions): if i != 0: w.addstr(row, column, ', ', curses.A_NORMAL) column += 2 s, attr = self.slipnode_name_and_attr(d.descriptor) if d not in description_structures: s = '[%s]' % s w.addstr(row, column, s, attr) column += len(s) w.addstr(row, column, ')', curses.A_NORMAL) column += 1 return column
Example #5
Source File: episodemenu.py From castero with MIT License | 6 votes |
def _items(self): """A list of items in the menu represented as dictionaries. Overrides method from Menu; see documentation in that class. """ result = [] for episode in self._filtered_episodes: tags = [] if episode.downloaded: tags.append('D') result.append({ 'attr': curses.color_pair(5) if episode.played else curses.A_NORMAL, 'tags': tags, 'text': str(episode) }) return result
Example #6
Source File: curses_ui.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def _screen_draw_text_line(self, row, line, attr=curses.A_NORMAL, color=None): """Render a line of text on the screen. Args: row: (int) Row index. line: (str) The line content. attr: curses font attribute. color: (str) font foreground color name. Raises: TypeError: If row is not of type int. """ if not isinstance(row, int): raise TypeError("Invalid type in row") if len(line) > self._max_x: line = line[:self._max_x] color_pair = (self._default_color_pair if color is None else self._color_pairs[color]) self._stdscr.addstr(row, 0, line, color_pair | attr) self._screen_refresh()
Example #7
Source File: curses_ui.py From lambda-packs with MIT License | 6 votes |
def _screen_draw_text_line(self, row, line, attr=curses.A_NORMAL, color=None): """Render a line of text on the screen. Args: row: (int) Row index. line: (str) The line content. attr: curses font attribute. color: (str) font foreground color name. Raises: TypeError: If row is not of type int. """ if not isinstance(row, int): raise TypeError("Invalid type in row") if len(line) > self._max_x: line = line[:self._max_x] color_pair = (self._default_color_pair if color is None else self._color_pairs[color]) self._stdscr.addstr(row, 0, line, color_pair | attr) self._screen_refresh()
Example #8
Source File: fmFormWithMenus.py From TelegramTUI with MIT License | 5 votes |
def draw_form(self): super(FormWithMenus, self).draw_form() menu_advert = " " + self.__class__.MENU_KEY + ": Menu " y, x = self.display_menu_advert_at() if isinstance(menu_advert, bytes): menu_advert = menu_advert.decode('utf-8', 'replace') self.add_line(y, x, menu_advert, self.make_attributes_list(menu_advert, curses.A_NORMAL), self.columns - x - 1 ) # The following class does not inherit from FormWithMenus and so some code is duplicated. # The pig is getting to inherit edit() from ActionForm, but draw_form from FormWithMenus
Example #9
Source File: wgtexttokens.py From TelegramTUI with MIT License | 5 votes |
def get_literal_text_and_highlighting_generator(self, start_at=0,): # could perform initialization here. index = start_at string_length = 0 output = '' while string_length <= self.maximum_string_length and len(self.value) > index: token_output = self.decode_token(self.value[index]) if isinstance(token_output, bytes): token_output = token_output.decode(self.encoding, 'replace') highlighting = [curses.A_NORMAL for c in token_output] yield(token_output, highlighting) index += 1
Example #10
Source File: wgmultilinetreeselectable.py From TelegramTUI with MIT License | 5 votes |
def _print_select_controls(self): SELECT_DISPLAY = None if self._tree_real_value.selectable: if self.value.selected: SELECT_DISPLAY = self.CAN_SELECT_SELECTED else: SELECT_DISPLAY = self.CAN_SELECT else: if self.value.selected: SELECT_DISPLAY = self.CANNOT_SELECT_SELECTED else: SELECT_DISPLAY = self.CANNOT_SELECT if self.do_colors(): attribute_list = self.parent.theme_manager.findPair(self, 'CONTROL') else: attribute_list = curses.A_NORMAL #python2 compatibility if isinstance(SELECT_DISPLAY, bytes): SELECT_DISPLAY = SELECT_DISPLAY.decode() self.add_line(self.rely, self.left_margin+self.relx, SELECT_DISPLAY, self.make_attributes_list(SELECT_DISPLAY, attribute_list), self.width-self.left_margin, ) return len(SELECT_DISPLAY)
Example #11
Source File: feedmenu.py From castero with MIT License | 5 votes |
def _items(self): """A list of items in the menu represented as dictionaries. Overrides method from Menu; see documentation in that class. """ return [ { 'attr': curses.A_NORMAL, 'tags': [], 'text': str(feed) } for feed in self._feeds ]
Example #12
Source File: downloadedmenu.py From castero with MIT License | 5 votes |
def _items(self): """A list of items in the menu represented as dictionaries. Overrides method from Menu; see documentation in that class. """ result = [] for episode in self._filtered_episodes: result.append({ 'attr': curses.color_pair(5) if episode.played else curses.A_NORMAL, 'tags': [], 'text': "[%s] %s" % (episode.feed_str, str(episode)) }) return result
Example #13
Source File: queuemenu.py From castero with MIT License | 5 votes |
def _items(self): """A list of items in the menu represented as dictionaries. Overrides method from Menu; see documentation in that class. """ return [ { 'attr': curses.A_NORMAL, 'tags': [], 'text': str(player) } for player in self._source ]
Example #14
Source File: wgmultilinetreeselectable.py From TelegramTUI with MIT License | 5 votes |
def _print(self, left_margin=0): if not hasattr(self._tree_real_value, 'selected'): return None self.left_margin = left_margin self.parent.curses_pad.bkgdset(' ',curses.A_NORMAL) self.left_margin += self._print_tree(self.relx) self.left_margin += self._print_select_controls() + 1 if self.highlight: self.parent.curses_pad.bkgdset(' ',curses.A_STANDOUT) super(wgmultilinetree.TreeLine, self)._print()
Example #15
Source File: fmFormWithMenus.py From EDCOP with Apache License 2.0 | 5 votes |
def draw_form(self): super(ActionFormWithMenus, self).draw_form() menu_advert = " " + self.__class__.MENU_KEY + ": Menu " y, x = self.display_menu_advert_at() if isinstance(menu_advert, bytes): menu_advert = menu_advert.decode('utf-8', 'replace') self.add_line(y, x, menu_advert, self.make_attributes_list(menu_advert, curses.A_NORMAL), self.columns - x - 1 )
Example #16
Source File: wgmultilinetree.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def _print(self, left_margin=0): self.left_margin = left_margin self.parent.curses_pad.bkgdset(' ',curses.A_NORMAL) self.left_margin += self._print_tree(self.relx) if self.highlight: self.parent.curses_pad.bkgdset(' ',curses.A_STANDOUT) super(TreeLine, self)._print()
Example #17
Source File: fmFormWithMenus.py From EDCOP with Apache License 2.0 | 5 votes |
def draw_form(self): super(FormWithMenus, self).draw_form() menu_advert = " " + self.__class__.MENU_KEY + ": Menu " y, x = self.display_menu_advert_at() if isinstance(menu_advert, bytes): menu_advert = menu_advert.decode('utf-8', 'replace') self.add_line(y, x, menu_advert, self.make_attributes_list(menu_advert, curses.A_NORMAL), self.columns - x - 1 ) # The following class does not inherit from FormWithMenus and so some code is duplicated. # The pig is getting to inherit edit() from ActionForm, but draw_form from FormWithMenus
Example #18
Source File: wgtexttokens.py From EDCOP with Apache License 2.0 | 5 votes |
def get_literal_text_and_highlighting_generator(self, start_at=0,): # could perform initialization here. index = start_at string_length = 0 output = '' while string_length <= self.maximum_string_length and len(self.value) > index: token_output = self.decode_token(self.value[index]) if isinstance(token_output, bytes): token_output = token_output.decode(self.encoding, 'replace') highlighting = [curses.A_NORMAL for c in token_output] yield(token_output, highlighting) index += 1
Example #19
Source File: unimatrix.py From unimatrix with GNU General Public License v3.0 | 5 votes |
def draw_flasher(self, flasher): """ Draws characters, included spaces to overwrite/erase characters. """ color = curses.color_pair(1) attr = choice([curses.A_BOLD, curses.A_NORMAL]) y = flasher[0] x = flasher[1] try: self.screen.addstr(y, x, self.get_char(), color | attr) except curses.error: pass ### Main loop
Example #20
Source File: wgmultilinetreeselectable.py From EDCOP with Apache License 2.0 | 5 votes |
def _print(self, left_margin=0): if not hasattr(self._tree_real_value, 'selected'): return None self.left_margin = left_margin self.parent.curses_pad.bkgdset(' ',curses.A_NORMAL) self.left_margin += self._print_tree(self.relx) self.left_margin += self._print_select_controls() + 1 if self.do_colors(): self.left_margin += self.annotationColor(self.left_margin+self.relx) else: self.left_margin += self.annotationNoColor(self.left_margin+self.relx) if self.highlight: self.parent.curses_pad.bkgdset(' ',curses.A_STANDOUT) super(wgmultilinetree.TreeLine, self)._print()
Example #21
Source File: wgmultilinetreeselectable.py From EDCOP with Apache License 2.0 | 5 votes |
def _print(self, left_margin=0): if not hasattr(self._tree_real_value, 'selected'): return None self.left_margin = left_margin self.parent.curses_pad.bkgdset(' ',curses.A_NORMAL) self.left_margin += self._print_tree(self.relx) self.left_margin += self._print_select_controls() + 1 if self.highlight: self.parent.curses_pad.bkgdset(' ',curses.A_STANDOUT) super(wgmultilinetree.TreeLine, self)._print()
Example #22
Source File: wgmultilinetreeselectable.py From EDCOP with Apache License 2.0 | 5 votes |
def _print_select_controls(self): SELECT_DISPLAY = None if self._tree_real_value.selectable: if self.value.selected: SELECT_DISPLAY = self.CAN_SELECT_SELECTED else: SELECT_DISPLAY = self.CAN_SELECT else: if self.value.selected: SELECT_DISPLAY = self.CANNOT_SELECT_SELECTED else: SELECT_DISPLAY = self.CANNOT_SELECT if self.do_colors(): attribute_list = self.parent.theme_manager.findPair(self, 'CONTROL') else: attribute_list = curses.A_NORMAL #python2 compatibility if isinstance(SELECT_DISPLAY, bytes): SELECT_DISPLAY = SELECT_DISPLAY.decode() self.add_line(self.rely, self.left_margin+self.relx, SELECT_DISPLAY, self.make_attributes_list(SELECT_DISPLAY, attribute_list), self.width-self.left_margin, ) return len(SELECT_DISPLAY)
Example #23
Source File: command.py From SpotipyTUI with MIT License | 5 votes |
def draw_track_list(self): """Handles all of the track list displaying.""" self.track_window.clear() result_line = '{0:<2} | {1:<40} | {2:<25} | {3:<40}' result_header = result_line.format('#', 'Song Name', 'Artist', 'Album') separator_bar = '=' * (self.track_window.getmaxyx()[1] - 5) self.track_window.addstr(0, 0, result_header) self.track_window.addstr(1, 0, separator_bar) for song_index, track in enumerate(self.track_list, start=1): if (self.curr_position - self.track_start) == track[0]: mode = curses.A_REVERSE else: mode = curses.A_NORMAL song_index = str(song_index) if len(song_index) == 1: song_index = '0' + song_index track_string = result_line.format(song_index, track[1][:40], track[2][:25], track[3][:40]) self.track_window.addstr(track[0] + self.track_start, 0, track_string, mode) bottom_bar_position = self.track_start + len(self.track_list) self.track_window.addstr(bottom_bar_position, 0, separator_bar) self.track_window.refresh()
Example #24
Source File: tui.py From wifiphisher with GNU General Public License v3.0 | 5 votes |
def gather_info(self, screen, info): """ Get the information from pywifiphisher and print them out :param self: A TuiApSel object :type self: TuiApSel :param screen: A curses window object :type screen: _curses.curses.window :param info: A namedtuple of information from pywifiphisher :type info: namedtuple :return AccessPoint object if users type enter :rtype AccessPoint if users type enter else None """ # setup curses # make cursor invisible try: curses.curs_set(0) except curses.error: pass # don't wait for user input screen.nodelay(True) # setup the font color curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN) self.highlight_text = curses.color_pair(1) self.normal_text = curses.A_NORMAL # information regarding access points ap_info = self.init_display_info(screen, info) # show information until user presses Esc key while ap_info.key != 27: # display info will modifiy the key value is_done = self.display_info(screen, ap_info) if is_done: # turn off access point discovery and return the result self.access_point_finder.stop_finding_access_points() return self.access_points[ap_info.pos - 1] # turn off access point discovery self.access_point_finder.stop_finding_access_points()
Example #25
Source File: wgbutton.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def update(self, clear=True): if clear: self.clear() if self.hidden: self.clear() return False if self.value and self.do_colors(): self.parent.curses_pad.addstr(self.rely, self.relx, '>', self.parent.theme_manager.findPair(self)) self.parent.curses_pad.addstr(self.rely, self.relx+self.width-1, '<', self.parent.theme_manager.findPair(self)) elif self.value: self.parent.curses_pad.addstr(self.rely, self.relx, '>') self.parent.curses_pad.addstr(self.rely, self.relx+self.width-1, '<') if self.editing: button_state = curses.A_STANDOUT else: button_state = curses.A_NORMAL button_name = self.name if isinstance(button_name, bytes): button_name = button_name.decode(self.encoding, 'replace') button_name = button_name.center(self.label_width) if self.do_colors(): if self.cursor_color: if self.editing: button_attributes = self.parent.theme_manager.findPair(self, self.cursor_color) else: button_attributes = self.parent.theme_manager.findPair(self, self.color) else: button_attributes = self.parent.theme_manager.findPair(self, self.color) | button_state else: button_attributes = button_state self.add_line(self.rely, self.relx+1, button_name, self.make_attributes_list(button_name, button_attributes), self.label_width )
Example #26
Source File: wgboxwidget.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def get_footer_attributes(self, footer_text): footer_attributes = curses.A_NORMAL if self.do_colors() and not self.editing: footer_attributes = footer_attributes | self.parent.theme_manager.findPair(self, self.color) # | curses.A_BOLD elif self.editing: footer_attributes = footer_attributes | self.parent.theme_manager.findPair(self, 'HILIGHT') else: footer_attributes = footer_attributes # | curses.A_BOLD if self.editing: footer_attributes = footer_attributes | curses.A_BOLD # footer_attributes = self.parent.theme_manager.findPair(self, self.color) return self.make_attributes_list(footer_text, footer_attributes)
Example #27
Source File: fmFormMultiPage.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def display_page_number(self): if not self.display_pages: return False if len(self._pages__) > 1: display_text = "%s%s %s %s %s%s" % ( self.page_info_pre_pages_display, self.page_info_pages_name, self._active_page + 1, self.page_info_out_of, len(self._pages__), self.page_info_post_pages_display, ) # for python2 if isinstance(display_text, bytes): display_text = display_text.decode('utf-8', 'replace') maxy,maxx = self.curses_pad.getmaxyx() if (maxx-5) <= len(display_text): # then give up. return False self.add_line( maxy - 1, maxx - len(display_text) - 2, display_text, self.make_attributes_list(display_text, curses.A_NORMAL | self.theme_manager.findPair(self, self.pages_label_color)), maxx - len(display_text) - 2, )
Example #28
Source File: fmForm.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def draw_title_and_help(self): try: if self.name: _title = self.name[:(self.columns-4)] _title = ' ' + str(_title) + ' ' #self.curses_pad.addstr(0,1, ' '+str(_title)+' ') if isinstance(_title, bytes): _title = _title.decode('utf-8', 'replace') self.add_line(0,1, _title, self.make_attributes_list(_title, curses.A_NORMAL), self.columns-4 ) except: pass if self.help and self.editing: try: help_advert = " Help: F1 or ^O " if isinstance(help_advert, bytes): help_advert = help_advert.decode('utf-8', 'replace') self.add_line( 0, self.curses_pad.getmaxyx()[1]-len(help_advert)-2, help_advert, self.make_attributes_list(help_advert, curses.A_NORMAL), len(help_advert) ) except: pass
Example #29
Source File: wgmultilinetree.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def _print(self): self.left_margin = 0 self.parent.curses_pad.bkgdset(' ',curses.A_NORMAL) self.left_margin += self._print_tree(self.relx) if self.do_colors(): self.left_margin += self.annotationColor(self.left_margin+self.relx) else: self.left_margin += self.annotationNoColor(self.left_margin+self.relx) if self.highlight: self.parent.curses_pad.bkgdset(' ',curses.A_STANDOUT) super(TreeLine, self)._print()
Example #30
Source File: fmFormWithMenus.py From TelegramTUI with MIT License | 5 votes |
def draw_form(self): super(ActionFormWithMenus, self).draw_form() menu_advert = " " + self.__class__.MENU_KEY + ": Menu " y, x = self.display_menu_advert_at() if isinstance(menu_advert, bytes): menu_advert = menu_advert.decode('utf-8', 'replace') self.add_line(y, x, menu_advert, self.make_attributes_list(menu_advert, curses.A_NORMAL), self.columns - x - 1 )