本文整理匯總了Python中curses.has_colors方法的典型用法代碼示例。如果您正苦於以下問題:Python curses.has_colors方法的具體用法?Python curses.has_colors怎麽用?Python curses.has_colors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類curses
的用法示例。
在下文中一共展示了curses.has_colors方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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()
示例2: findPair
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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
示例3: init_colors
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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)
示例4: __init__
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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
示例5: do_colors
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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
示例6: display
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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()
示例7: draw_form
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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()
示例8: init_colors
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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
示例9: check_theme
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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
示例10: set_theme
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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'))
示例11: start
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
def start(self):
"""
Initialize the screen and input mode.
"""
assert self._started == False
self.s = curses.initscr()
self.has_color = curses.has_colors()
if self.has_color:
curses.start_color()
if curses.COLORS < 8:
# not colourful enough
self.has_color = False
if self.has_color:
try:
curses.use_default_colors()
self.has_default_colors=True
except _curses.error:
self.has_default_colors=False
self._setup_colour_pairs()
curses.noecho()
curses.meta(1)
curses.halfdelay(10) # use set_input_timeouts to adjust
self.s.keypad(0)
if not self._signal_keys_set:
self._old_signal_keys = self.tty_signal_keys()
super(Screen, self).start()
示例12: toggle
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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()
示例13: display_menu
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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)
示例14: __init__
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import has_colors [as 別名]
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