当前位置: 首页>>代码示例>>Python>>正文


Python curses.has_colors方法代码示例

本文整理汇总了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() 
开发者ID:hexway,项目名称:apple_bleee,代码行数:18,代码来源:npysThemeManagers.py

示例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 
开发者ID:hexway,项目名称:apple_bleee,代码行数:18,代码来源:npysThemeManagers.py

示例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) 
开发者ID:Battelle,项目名称:sandsifter,代码行数:43,代码来源:gui.py

示例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 
开发者ID:torproject,项目名称:stem,代码行数:38,代码来源:event_listening.py

示例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 
开发者ID:hexway,项目名称:apple_bleee,代码行数:8,代码来源:wgwidget.py

示例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() 
开发者ID:hexway,项目名称:apple_bleee,代码行数:17,代码来源:fmForm.py

示例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() 
开发者ID:hexway,项目名称:apple_bleee,代码行数:9,代码来源:fmForm.py

示例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 
开发者ID:caktux,项目名称:pytrader,代码行数:13,代码来源:pytrader.py

示例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 
开发者ID:tildeclub,项目名称:ttrv,代码行数:14,代码来源:terminal.py

示例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')) 
开发者ID:tildeclub,项目名称:ttrv,代码行数:39,代码来源:terminal.py

示例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() 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:31,代码来源:curses_display.py

示例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() 
开发者ID:guohuadeng,项目名称:odoo13-x64,代码行数:17,代码来源:life.py

示例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) 
开发者ID:guohuadeng,项目名称:odoo13-x64,代码行数:14,代码来源:life.py

示例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 
开发者ID:sabri-zaki,项目名称:EasY_HaCk,代码行数:38,代码来源:worldmap.py


注:本文中的curses.has_colors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。