Python curses.has_colors() Examples
The following are 30
code examples of curses.has_colors().
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: npysThemeManagers.py From EDCOP with Apache License 2.0 | 6 votes |
def __init__(self): #curses.use_default_colors() self.define_colour_numbers() self._defined_pairs = {} self._names = {} try: self._max_pairs = curses.COLOR_PAIRS - 1 do_color = True except AttributeError: # curses.start_color has failed or has not been called do_color = False # Disable all color use across the application disableColor() if do_color and curses.has_colors(): self.initialize_pairs() self.initialize_names()
Example #2
Source File: npysThemeManagers.py From TelegramTUI with MIT License | 6 votes |
def findPair(self, caller, request='DEFAULT'): if not curses.has_colors() or npysGlobalOptions.DISABLE_ALL_COLORS: return False if request=='DEFAULT': request = caller.color # Locate the requested colour pair. Default to default if not found. try: pair = self._defined_pairs[self._names[request]] except: pair = self._defined_pairs[self._names['DEFAULT']] # now make the actual attribute color_attribute = curses.color_pair(pair[0]) return color_attribute
Example #3
Source File: npysThemeManagers.py From TelegramTUI with MIT License | 6 votes |
def __init__(self): #curses.use_default_colors() self.define_colour_numbers() self._defined_pairs = {} self._names = {} try: self._max_pairs = curses.COLOR_PAIRS - 1 do_color = True except AttributeError: # curses.start_color has failed or has not been called do_color = False # Disable all color use across the application disableColor() if do_color and curses.has_colors(): self.initialize_pairs() self.initialize_names()
Example #4
Source File: npysThemeManagers.py From apple_bleee with GNU General Public License v3.0 | 6 votes |
def __init__(self): #curses.use_default_colors() self.define_colour_numbers() self._defined_pairs = {} self._names = {} try: self._max_pairs = curses.COLOR_PAIRS - 1 do_color = True except AttributeError: # curses.start_color has failed or has not been called do_color = False # Disable all color use across the application disableColor() if do_color and curses.has_colors(): self.initialize_pairs() self.initialize_names()
Example #5
Source File: npysThemeManagers.py From apple_bleee with GNU General Public License v3.0 | 6 votes |
def findPair(self, caller, request='DEFAULT'): if not curses.has_colors() or npysGlobalOptions.DISABLE_ALL_COLORS: return False if request=='DEFAULT': request = caller.color # Locate the requested colour pair. Default to default if not found. try: pair = self._defined_pairs[self._names[request]] except: pair = self._defined_pairs[self._names['DEFAULT']] # now make the actual attribute color_attribute = curses.color_pair(pair[0]) return color_attribute
Example #6
Source File: npysThemeManagers.py From EDCOP with Apache License 2.0 | 6 votes |
def findPair(self, caller, request='DEFAULT'): if not curses.has_colors() or npysGlobalOptions.DISABLE_ALL_COLORS: return False if request=='DEFAULT': request = caller.color # Locate the requested colour pair. Default to default if not found. try: pair = self._defined_pairs[self._names[request]] except: pair = self._defined_pairs[self._names['DEFAULT']] # now make the actual attribute color_attribute = curses.color_pair(pair[0]) return color_attribute
Example #7
Source File: npysThemeManagers.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def findPair(self, caller, request='DEFAULT'): if not curses.has_colors() or npysGlobalOptions.DISABLE_ALL_COLORS: return False if request=='DEFAULT': request = caller.color # Locate the requested colour pair. Default to default if not found. try: pair = self._defined_pairs[self._names[request]] except: pair = self._defined_pairs[self._names['DEFAULT']] # now make the actual attribute color_attribute = curses.color_pair(pair[0]) return color_attribute
Example #8
Source File: npysThemeManagers.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def __init__(self): #curses.use_default_colors() self.define_colour_numbers() self._defined_pairs = {} self._names = {} try: self._max_pairs = curses.COLOR_PAIRS - 1 do_color = True except AttributeError: # curses.start_color has failed or has not been called do_color = False # Disable all color use across the application disableColor() if do_color and curses.has_colors(): self.initialize_pairs() self.initialize_names()
Example #9
Source File: wgwidget.py From TelegramTUI with MIT License | 5 votes |
def do_colors(self): "Returns True if the widget should try to paint in coloour." if curses.has_colors() and not GlobalOptions.DISABLE_ALL_COLORS: return True else: return False
Example #10
Source File: fmForm.py From EDCOP with Apache License 2.0 | 5 votes |
def display(self, clear=False): #APPLICATION_THEME_MANAGER.setTheme(self) if curses.has_colors() and not npysGlobalOptions.DISABLE_ALL_COLORS: self.curses_pad.attrset(0) color_attribute = self.theme_manager.findPair(self, self.color) self.curses_pad.bkgdset(' ', color_attribute) self.curses_pad.attron(color_attribute) self.curses_pad.erase() self.draw_form() for w in [wg for wg in self._widgets__ if wg.hidden]: w.clear() for w in [wg for wg in self._widgets__ if not wg.hidden]: w.update(clear=clear) self.refresh()
Example #11
Source File: fmForm.py From EDCOP with Apache License 2.0 | 5 votes |
def draw_form(self): if self.framed: if curses.has_colors() and not GlobalOptions.DISABLE_ALL_COLORS: self.curses_pad.attrset(0) self.curses_pad.bkgdset(' ', curses.A_NORMAL | self.theme_manager.findPair(self, self.color)) self.curses_pad.border() self.draw_title_and_help()
Example #12
Source File: worldmap.py From EasY_HaCk with Apache License 2.0 | 5 votes |
def __init__(self, map_name='world', map_conf=None, window=None, encoding=None): if map_conf is None: map_conf = MAPS[map_name] self.map = map_conf['data'] self.coords = map_conf['coords'] self.corners = map_conf['corners'] if window is None: window = curses.newwin(0, 0) self.window = window self.data = [] self.data_timestamp = None # JSON contents _should_ be UTF8 (so, python internal unicode here...) if encoding is None: encoding = locale.getpreferredencoding() self.encoding = encoding # check if we can use transparent background or not if curses.can_change_color(): curses.use_default_colors() background = -1 else: background = curses.COLOR_BLACK tmp_colors = [ ('red', curses.COLOR_RED, background), ('blue', curses.COLOR_BLUE, background), ('pink', curses.COLOR_MAGENTA, background) ] self.colors = {} if curses.has_colors(): for i, (name, fgcolor, bgcolor) in enumerate(tmp_colors, 1): curses.init_pair(i, fgcolor, bgcolor) self.colors[name] = i
Example #13
Source File: life.py From android_universal with MIT License | 5 votes |
def toggle(self, y, x): """Toggle a cell's state between live and dead""" if x < 0 or self.X <= x or y < 0 or self.Y <= y: raise ValueError("Coordinates out of range %i,%i" % (y, x)) if (x, y) in self.state: del self.state[x, y] self.scr.addch(y + 1, x + 1, ' ') else: self.state[x, y] = 1 if curses.has_colors(): # Let's pick a random color! self.scr.attrset(curses.color_pair(random.randrange(1, 7))) self.scr.addch(y + 1, x + 1, self.char) self.scr.attrset(0) self.scr.refresh()
Example #14
Source File: life.py From android_universal with MIT License | 5 votes |
def display_menu(stdscr, menu_y): "Display the menu of possible keystroke commands" erase_menu(stdscr, menu_y) # If color, then light the menu up :-) if curses.has_colors(): stdscr.attrset(curses.color_pair(1)) stdscr.addstr(menu_y, 4, 'Use the cursor keys to move, and space or Enter to toggle a cell.') stdscr.addstr(menu_y + 1, 4, 'E)rase the board, R)andom fill, S)tep once or C)ontinuously, Q)uit') stdscr.attrset(0)
Example #15
Source File: life.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
def display_menu(stdscr, menu_y): "Display the menu of possible keystroke commands" erase_menu(stdscr, menu_y) # If color, then light the menu up :-) if curses.has_colors(): stdscr.attrset(curses.color_pair(1)) stdscr.addstr(menu_y, 4, 'Use the cursor keys to move, and space or Enter to toggle a cell.') stdscr.addstr(menu_y + 1, 4, 'E)rase the board, R)andom fill, S)tep once or C)ontinuously, Q)uit') stdscr.attrset(0)
Example #16
Source File: fmForm.py From TelegramTUI with MIT License | 5 votes |
def display(self, clear=False): #APPLICATION_THEME_MANAGER.setTheme(self) if curses.has_colors() and not npysGlobalOptions.DISABLE_ALL_COLORS: self.curses_pad.attrset(0) color_attribute = self.theme_manager.findPair(self, self.color) self.curses_pad.bkgdset(' ', color_attribute) self.curses_pad.attron(color_attribute) self.curses_pad.erase() self.draw_form() for w in [wg for wg in self._widgets__ if wg.hidden]: w.clear() for w in [wg for wg in self._widgets__ if not wg.hidden]: w.update(clear=clear) self.refresh()
Example #17
Source File: fmForm.py From TelegramTUI with MIT License | 5 votes |
def draw_form(self): if self.framed: if curses.has_colors() and not GlobalOptions.DISABLE_ALL_COLORS: self.curses_pad.attrset(0) self.curses_pad.bkgdset(' ', curses.A_NORMAL | self.theme_manager.findPair(self, self.color)) self.curses_pad.border() self.draw_title_and_help()
Example #18
Source File: terminal.py From rtv with MIT License | 5 votes |
def check_theme(theme): """ Check if the given theme is compatible with the terminal """ terminal_colors = curses.COLORS if curses.has_colors() else 0 if theme.required_colors > terminal_colors: return False elif theme.required_color_pairs > curses.COLOR_PAIRS: return False else: return True
Example #19
Source File: terminal.py From rtv with MIT License | 5 votes |
def set_theme(self, theme=None): """ Check that the terminal supports the provided theme, and applies the theme to the terminal if possible. If the terminal doesn't support the theme, this falls back to the default theme. The default theme only requires 8 colors so it should be compatible with any terminal that supports basic colors. """ terminal_colors = curses.COLORS if curses.has_colors() else 0 default_theme = Theme(use_color=bool(terminal_colors)) if theme is None: theme = default_theme elif theme.required_color_pairs > curses.COLOR_PAIRS: _logger.warning( 'Theme `%s` requires %s color pairs, but $TERM=%s only ' 'supports %s color pairs, switching to default theme', theme.name, theme.required_color_pairs, self._term, curses.COLOR_PAIRS) theme = default_theme elif theme.required_colors > terminal_colors: _logger.warning( 'Theme `%s` requires %s colors, but $TERM=%s only ' 'supports %s colors, switching to default theme', theme.name, theme.required_colors, self._term, curses.COLORS) theme = default_theme theme.bind_curses() self.theme = theme # Apply the default color to the whole screen self.stdscr.bkgd(str(' '), self.attr('Normal'))
Example #20
Source File: menu_screen.py From botany with ISC License | 5 votes |
def __init__(self, this_plant, this_data): '''Initialization''' self.initialized = False self.screen = curses.initscr() curses.noecho() curses.raw() if curses.has_colors(): curses.start_color() try: curses.curs_set(0) except curses.error: # Not all terminals support this functionality. # When the error is ignored the screen will look a little uglier, but that's not terrible # So in order to keep botany as accesible as possible to everyone, it should be safe to ignore the error. pass self.screen.keypad(1) self.plant = this_plant self.visited_plant = None self.user_data = this_data self.plant_string = self.plant.parse_plant() self.plant_ticks = str(int(self.plant.ticks)) self.exit = False self.infotoggle = 0 self.maxy, self.maxx = self.screen.getmaxyx() # Highlighted and Normal line definitions if curses.has_colors(): self.define_colors() self.highlighted = curses.color_pair(1) else: self.highlighted = curses.A_REVERSE self.normal = curses.A_NORMAL # Threaded screen update for live changes screen_thread = threading.Thread(target=self.update_plant_live, args=()) screen_thread.daemon = True screen_thread.start() # Recusive lock to prevent both threads from drawing at the same time self.screen_lock = threading.RLock() self.screen.clear() self.show(["water","look","garden","visit", "instructions"], title=' botany ', subtitle='options')
Example #21
Source File: wgwidget.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def do_colors(self): "Returns True if the widget should try to paint in coloour." if curses.has_colors() and not GlobalOptions.DISABLE_ALL_COLORS: return True else: return False
Example #22
Source File: gui.py From sandsifter with BSD 3-Clause "New" or "Revised" License | 5 votes |
def init_colors(self): if curses.has_colors() and curses.can_change_color(): curses.init_color(self.COLOR_BLACK, 0, 0, 0) curses.init_color(self.COLOR_WHITE, 1000, 1000, 1000) curses.init_color(self.COLOR_BLUE, 0, 0, 1000) curses.init_color(self.COLOR_RED, 1000, 0, 0) curses.init_color(self.COLOR_GREEN, 0, 1000, 0) for i in xrange(0, self.GRAYS): curses.init_color( self.GRAY_BASE + i, i * 1000 / (self.GRAYS - 1), i * 1000 / (self.GRAYS - 1), i * 1000 / (self.GRAYS - 1) ) curses.init_pair( self.GRAY_BASE + i, self.GRAY_BASE + i, self.COLOR_BLACK ) else: self.COLOR_BLACK = curses.COLOR_BLACK self.COLOR_WHITE = curses.COLOR_WHITE self.COLOR_BLUE = curses.COLOR_BLUE self.COLOR_RED = curses.COLOR_RED self.COLOR_GREEN = curses.COLOR_GREEN for i in xrange(0, self.GRAYS): curses.init_pair( self.GRAY_BASE + i, self.COLOR_WHITE, self.COLOR_BLACK ) curses.init_pair(self.BLACK, self.COLOR_BLACK, self.COLOR_BLACK) curses.init_pair(self.WHITE, self.COLOR_WHITE, self.COLOR_BLACK) curses.init_pair(self.BLUE, self.COLOR_BLUE, self.COLOR_BLACK) curses.init_pair(self.RED, self.COLOR_RED, self.COLOR_BLACK) curses.init_pair(self.GREEN, self.COLOR_GREEN, self.COLOR_BLACK)
Example #23
Source File: event_listening.py From stem with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, stdscr): self._stdscr = stdscr # Mappings of names to the curses color attribute. Initially these all # reference black text, but if the terminal can handle color then # they're set with that foreground color. self._colors = dict([(color, 0) for color in COLOR_LIST]) # allows for background transparency try: curses.use_default_colors() except curses.error: pass # makes the cursor invisible try: curses.curs_set(0) except curses.error: pass # initializes colors if the terminal can handle them try: if curses.has_colors(): color_pair = 1 for name, foreground in COLOR_LIST.items(): background = -1 # allows for default (possibly transparent) background curses.init_pair(color_pair, foreground, background) self._colors[name] = curses.color_pair(color_pair) color_pair += 1 except curses.error: pass
Example #24
Source File: wgwidget.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
def do_colors(self): "Returns True if the widget should try to paint in coloour." if curses.has_colors() and not GlobalOptions.DISABLE_ALL_COLORS: return True else: return False
Example #25
Source File: fmForm.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
def display(self, clear=False): #APPLICATION_THEME_MANAGER.setTheme(self) if curses.has_colors() and not npysGlobalOptions.DISABLE_ALL_COLORS: self.curses_pad.attrset(0) color_attribute = self.theme_manager.findPair(self, self.color) self.curses_pad.bkgdset(' ', color_attribute) self.curses_pad.attron(color_attribute) self.curses_pad.erase() self.draw_form() for w in [wg for wg in self._widgets__ if wg.hidden]: w.clear() for w in [wg for wg in self._widgets__ if not wg.hidden]: w.update(clear=clear) self.refresh()
Example #26
Source File: fmForm.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
def draw_form(self): if self.framed: if curses.has_colors() and not GlobalOptions.DISABLE_ALL_COLORS: self.curses_pad.attrset(0) self.curses_pad.bkgdset(' ', curses.A_NORMAL | self.theme_manager.findPair(self, self.color)) self.curses_pad.border() self.draw_title_and_help()
Example #27
Source File: pytrader.py From pytrader with MIT License | 5 votes |
def init_colors(): """initialize curses color pairs and give them names. The color pair can then later quickly be retrieved from the COLOR_PAIR[] dict""" index = 1 for (name, back, fore) in COLORS: if curses.has_colors(): curses.init_pair(index, fore, back) COLOR_PAIR[name] = curses.color_pair(index) else: COLOR_PAIR[name] = 0 index += 1
Example #28
Source File: terminal.py From ttrv with MIT License | 5 votes |
def check_theme(theme): """ Check if the given theme is compatible with the terminal """ terminal_colors = curses.COLORS if curses.has_colors() else 0 if theme.required_colors > terminal_colors: return False elif theme.required_color_pairs > curses.COLOR_PAIRS: return False else: return True
Example #29
Source File: terminal.py From ttrv with MIT License | 5 votes |
def set_theme(self, theme=None): """ Check that the terminal supports the provided theme, and applies the theme to the terminal if possible. If the terminal doesn't support the theme, this falls back to the default theme. The default theme only requires 8 colors so it should be compatible with any terminal that supports basic colors. """ terminal_colors = curses.COLORS if curses.has_colors() else 0 default_theme = Theme(use_color=bool(terminal_colors)) if theme is None: theme = default_theme elif theme.required_color_pairs > curses.COLOR_PAIRS: _logger.warning( 'Theme `%s` requires %s color pairs, but $TERM=%s only ' 'supports %s color pairs, switching to default theme', theme.name, theme.required_color_pairs, self._term, curses.COLOR_PAIRS) theme = default_theme elif theme.required_colors > terminal_colors: _logger.warning( 'Theme `%s` requires %s colors, but $TERM=%s only ' 'supports %s colors, switching to default theme', theme.name, theme.required_colors, self._term, curses.COLORS) theme = default_theme theme.bind_curses() self.theme = theme # Apply the default color to the whole screen self.stdscr.bkgd(str(' '), self.attr('Normal'))
Example #30
Source File: wgwidget.py From EDCOP with Apache License 2.0 | 5 votes |
def do_colors(self): "Returns True if the widget should try to paint in coloour." if curses.has_colors() and not GlobalOptions.DISABLE_ALL_COLORS: return True else: return False