python类color_pair()的实例源码

display.py 文件源码 项目:defuse_division 作者: lelandbatey 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def get_colorpair(pair_name):
    val = curses_colors.CURSES_COLORPAIRS[pair_name]
    return curses.color_pair(val)
curses_colors.py 文件源码 项目:defuse_division 作者: lelandbatey 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get_colorpair(pair_name):
    '''
    Returns the color attribute for the given foreground-background attribute,
    ready for use in a call to addstr.
    '''
    val = CURSES_COLORPAIRS[pair_name]
    return curses.color_pair(val)
recipe-577933.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def display_time(scr):
    t = time.ctime().split()
    write(scr, 0, 0,  t[0], curses.color_pair(9))
    write(scr, 0, 4,  t[1], curses.color_pair(9))
    write(scr, 0, 8,  t[2], curses.color_pair(9))
    write(scr, 0, 11, t[3], curses.color_pair(9))
    write(scr, 0, 20, t[4], curses.color_pair(9))
recipe-577933.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def display_loadavg(scr):
    lavg = os.getloadavg()
    write(scr, 1, 0, 'System',             curses.color_pair(9))
    write(scr, 1, 7, 'Load:',              curses.color_pair(9))
    write(scr, 1, 13, '%.02f' % lavg[0],   curses.color_pair(9))
    write(scr, 1, 20, '%.02f' % lavg[1],   curses.color_pair(9))
    write(scr, 1, 27, '%.02f' % lavg[2],   curses.color_pair(9))
menu_screen.py 文件源码 项目:botany 作者: jifunks 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def __init__(self, this_plant, this_data):
        '''Initialization'''
        self.initialized = False
        self.screen = curses.initscr()
        curses.noecho()
        curses.raw()
        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.user_data = this_data
        self.plant_string = self.plant.parse_plant()
        self.plant_ticks = str(self.plant.ticks)
        self.exit = False
        self.infotoggle = 0
        self.maxy, self.maxx = self.screen.getmaxyx()
        # Highlighted and Normal line definitions
        self.define_colors()
        self.highlighted = curses.color_pair(1)
        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()
        self.screen.clear()
        self.show(["water","look","garden","instructions"], title=' botany ', subtitle='options')
skin.py 文件源码 项目:slacky 作者: mathiasbc 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def init_head(self):
        name = "Slacky (github.com/mathiasbc)"
        middle_pos = int(self.maxX/2 - len(name)/2)
        self.head_win.addstr(0, middle_pos, name, curses.color_pair(2))
        self.head_win.bkgd(' ', curses.color_pair(7))
        self.head_win.noutrefresh()
skin.py 文件源码 项目:slacky 作者: mathiasbc 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def push_chat(self, username, chat):
        """
        write the given string at the correct position
        in the chatarea
        """
        # FIXME: fails when text goes beyond window limit
        # highlight username
        col = curses.color_pair(8)
        self.chatarea.addstr(self.chat_at, 0, username + ':', col)
        # write the actual chat content
        self.chatarea.addstr(chat)
        # update cursor
        self.chat_at, _ = self.chatarea.getyx()
        self.chat_at += 1
        self.chatarea.refresh()
pyStationInfoEdit.py 文件源码 项目:Parallel.GAMIT 作者: demiangomez 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def enter_edit_mode(self, value=None):

        if self.items[self.position]['field'] == 'Comments':
            editwin = curses.newwin(10, 60, self.position+2, 27)
            rectangle(self.window, self.position + 1, 26, self.position + 12, 26 + 61)
        else:
            editwin = curses.newwin(1, 30, self.position+2, 27)

        editwin.attron(curses.color_pair(2))
        curses.curs_set(1)
        if value:
            box = _Textbox(editwin, True, text=value)
        else:
            box = _Textbox(editwin, True, text=self.items[self.position]['value'])

        _Textbox.stripspaces = True

        self.window.refresh()

        while True:
            edit_field = box.edit()
            if not edit_field is None:
                result = self.validate(edit_field.strip())
                if result:
                    self.navigate(1)
                    break
            else:
                break

        curses.curs_set(0)

        self.window.clear()
pyStationInfoEdit.py 文件源码 项目:Parallel.GAMIT 作者: demiangomez 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def ShowError(self, error):
        self.window.addstr(self.position + 2, 60, ' -> ' + error, curses.color_pair(2))
        self.window.refresh()
tui.py 文件源码 项目:awesome-finder 作者: mingrammer 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def init_curses(self):
        """Setup the curses"""
        self.window = curses.initscr()
        self.window.keypad(True)

        curses.noecho()
        curses.cbreak()

        curses.start_color()
        curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_CYAN)

        self.current = curses.color_pair(2)
cryptop.py 文件源码 项目:cryptop 作者: huwwp 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def write_scr(stdscr, wallet, y, x):
    '''Write text and formatting to screen'''
    first_pad = '{:>{}}'.format('', CONFIG['theme'].getint('dec_places', 2) + 10 - 3)
    second_pad = ' ' * (CONFIG['theme'].getint('field_length', 13) - 2)
    third_pad =  ' ' * (CONFIG['theme'].getint('field_length', 13) - 3)

    if y >= 1:
        stdscr.addnstr(0, 0, 'cryptop v0.2.0', x, curses.color_pair(2))
    if y >= 2:
        header = '  COIN{}PRICE{}HELD {}VAL{}HIGH {}LOW  '.format(first_pad, second_pad, third_pad, first_pad, first_pad)
        stdscr.addnstr(1, 0, header, x, curses.color_pair(3))

    total = 0
    coinl = list(wallet.keys())
    heldl = list(wallet.values())
    if coinl:
        coinvl = get_price(','.join(coinl))

        if y > 3:
            s = sorted(list(zip(coinl, coinvl, heldl)), key=SORT_FNS[SORTS[COLUMN]], reverse=ORDER)
            coinl = list(x[0] for x in s)
            coinvl = list(x[1] for x in s)
            heldl = list(x[2] for x in s)
            for coin, val, held in zip(coinl, coinvl, heldl):
                if coinl.index(coin) + 2 < y:
                    stdscr.addnstr(coinl.index(coin) + 2, 0,
                    str_formatter(coin, val, held), x, curses.color_pair(2))
                total += float(held) * val[0]

    if y > len(coinl) + 3:
        stdscr.addnstr(y - 2, 0, 'Total Holdings: {:10}    '
            .format(locale.currency(total, grouping=True)), x, curses.color_pair(3))
        stdscr.addnstr(y - 1, 0,
            '[A] Add/update coin [R] Remove coin [S] Sort [C] Cycle sort [0\Q]Exit', x,
            curses.color_pair(2))
cryptop.py 文件源码 项目:cryptop 作者: huwwp 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def get_string(stdscr, prompt):
    '''Requests and string from the user'''
    curses.echo()
    stdscr.clear()
    stdscr.addnstr(0, 0, prompt, -1, curses.color_pair(2))
    curses.curs_set(1)
    stdscr.refresh()
    in_str = stdscr.getstr(1, 0, 20).decode()
    curses.noecho()
    curses.curs_set(0)
    stdscr.clear()
    curses.halfdelay(10)
    return in_str
world.py 文件源码 项目:loltanks 作者: whentze 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def draw(self, win):
    h, w = win.getmaxyx()
    win.bkgdset(' ', self.skycolor)
    # Draw Particles
    parttype = self.conf['particles_type']
    for part in self.particles:
      part[0] = part[0]%w
      part[1] = part[1]%h
      try:
        if(parttype == 'Snow'):
          if(part[2] > 60):
            win.addstr(int(part[1]), int(part[0]), '?')
          else:
            win.addstr(int(part[1]), int(part[0]), '·')
        elif(parttype == 'Rain'):
          win.addstr(int(part[1]), int(part[0]), '|', curses.color_pair(2))
        elif(parttype == 'Stars'):
          if(randint(0, 200) == 0):
            if(part[2] > 60):
              win.addstr(int(part[1]), int(part[0]), '?')
            else:
              win.addstr(int(part[1]), int(part[0]), '?')
          else:
            if(part[2] > 60):
              win.addstr(int(part[1]), int(part[0]), '?')
            elif(part[2] > 40):
              win.addstr(int(part[1]), int(part[0]), '·')
            else:
              win.addstr(int(part[1]), int(part[0]), '?')
      except curses.error:
        pass

    # Draw Ground
    try:
      for x, col in enumerate(self.ground):
        for y, cell in enumerate(col):
          if(cell):
              win.addstr(y, x, self.groundchars[x][y], self.groundcolor)
    except curses.error:
      # The very last character will error so except only once
      pass
shot.py 文件源码 项目:loltanks 作者: whentze 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def draw(self, win):
    for p in self.laser_points:
      try:
        win.addch(p.y, p.x, ['?', '?', '?', '?', ' '][int(self.age/5)], curses.color_pair(self.owner.colors))
      except curses.error:
        pass
tetris_game.py 文件源码 项目:reinforcement_learning 作者: andreweskeclarke 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def tetris_print(array, reward, screen):
    curses.noecho()
    curses.curs_set(0)
    screen.erase()
    for y, row in reversed(list(enumerate(array[0]))):
        for x, value in enumerate(row):
            character = "\u2588" if value else "."
            color = curses.color_pair(value)
            screen.addch(len(array[0]) - y, 3*x, character, color)
            screen.addch(len(array[0]) - y, 3*x + 1, character, color)
    screen.addstr(len(array[0]) + 5, 0, 'Reward: {}'.format(reward))
    screen.refresh()
paint-it.py 文件源码 项目:paint-it 作者: plainspooky 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, arena_size):
        self.arena_size = arena_size
        self.max_moves = int(25*(2*arena_size*COLORS)/(28*6))
        self.screen = curses.initscr()
        curses.noecho()
        curses.cbreak()
        curses.start_color()
        try:
            curses.curs_set(False)
        except curses.error:
            pass
        self.screen.nodelay(True)
        self.window_size = self.screen.getmaxyx()

        if self.window_size[0] < self.arena_size+4 or self.window_size[1] < self.arena_size*2:
            print('Your screen is too short!')
            exit()

        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
        curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_GREEN)
        curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_CYAN)
        curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_RED)
        curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_MAGENTA)
        curses.init_pair(6, curses.COLOR_WHITE, curses.COLOR_YELLOW)
        curses.init_pair(7, curses.COLOR_WHITE, curses.COLOR_WHITE)

        self.offset_x = int((self.window_size[1]-2*self.arena_size)/2)
        self.offset_y = int((self.window_size[0]-self.arena_size)/2)
        self.moves_position=[ self.offset_y+self.arena_size+1, self.offset_x+self.arena_size-5 ]

        self.arena_initialize()

        self.screen.addstr( self.offset_y-2, self.offset_x, self.title, curses.color_pair(0))
        self.screen.addstr( self.offset_y-2, self.offset_x+2*self.arena_size-17, "Press '?' to help", curses.color_pair(0))
paint-it.py 文件源码 项目:paint-it 作者: plainspooky 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def check_game(self):
        if self.moves > self.max_moves:
            self.status='lose'
            self.screen.addstr( self.moves_position[0], self.offset_x, "YOU LOSE!", curses.color_pair(4))
        else:
            self.status='win'
            color = self.arena[0][0]
            for y in range(self.arena_size):
                for x in range(self.arena_size):
                    if self.arena[y][x] != color:
                        self.status='play'
                        break;
        if self.status=='win' and self.moves<=self.max_moves:
            self.screen.addstr( self.moves_position[0], self.offset_x, "YOU WIN!", curses.color_pair(2))
paint-it.py 文件源码 项目:paint-it 作者: plainspooky 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def display_help(self):
        for y in range(len(self.helper)):
            x = int((self.arena_size*2-WINDOW)/2)
            self.screen.addstr( self.offset_y + 1 + y, self.offset_x + x, " "*WINDOW, curses.color_pair(0))
            x = int((self.arena_size*2-len(self.helper[y]))/2)
            self.screen.addstr( self.offset_y + 1 + y, self.offset_x + x, self.helper[y], curses.color_pair(0))
        while self.screen.getch()!=27:
            pass
paint-it.py 文件源码 项目:paint-it 作者: plainspooky 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def refresh_screen(self):
        for y in range(self.arena_size):
            for x in range(self.arena_size):
                try:
                    self.screen.addstr( self.offset_y + y, self.offset_x + x*2, "  ", curses.color_pair( self.arena[y][x] ))
                except curses.error:
                    pass
        self.screen.addstr( self.moves_position[0], self.moves_position[1], "Moves {}/{} ".format(self.moves,self.max_moves), curses.color_pair(0))
        self.screen.refresh()
pfserver.py 文件源码 项目:pyfeld 作者: scjurgen 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def show_notification_state(self, uuid_store):
        self.notification_count += 1
        col = curses.color_pair(3)
        self.window.addstr(self.screen_height - 1, 30, str(self.notification_count), col)

        key_list = UuidStoreKeys.get_key_and_setting()
        y = 3
        col = curses.color_pair(3)
        for k in key_list:
            if k[1] is True:
                self.window.addstr(1 + y, 1, "{0}".format(k[0]), col)
                y += 1

        columns = len(uuid_store.uuid)
        self.window.addstr(0, 50, "columns = {0}".format(columns), col)
        x = 1
        xw = 30
        current_time = time.time()
        for dummy, item in uuid_store.uuid.items():
            self.window.addstr(1, x*xw, "{0}".format(item.rf_type))
            self.window.addstr(2, x*xw, "{0}".format(item.name))
            y = 3
            for k in key_list:
                if k[1] is True:
                    self.window.addstr(1 + y, x * xw, "-" * (xw - 1), curses.color_pair(3))
                    if k[0] in item.itemMap:
                        deltatime = current_time - item.itemMap[k[0]].timeChanged
                        if deltatime > 5:
                            col = curses.color_pair(3)
                        else:
                            col = curses.color_pair(4)

                        self.window.addstr(1+y, x*xw, "{0}".format(item.itemMap[k[0]].value), col)
                    y += 1
            x += 1
        self.window.move(1, 1)
        self.window.refresh()


问题


面经


文章

微信
公众号

扫码关注公众号