python类use_default_colors()的实例源码

edit.py 文件源码 项目:notex 作者: adiultra 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def win_init(self):
        """Set initial editor window size parameters, and reset them if window
        is resized.

        """
        # self.cur_pos is the current y,x position of the cursor relative to
        # the visible area of the box
        self.cur_pos_y = 0
        self.cur_pos_x = 0
        # y_offset controls the up-down scrolling feature
        self.y_offset = 0
        # Position of the cursor relative to the upper left corner of the data
        # (self.flattend_text)
        self.buffer_idx_y = 0
        self.buffer_idx_x = 0
        # Make sure requested window size is < available window size
        self.max_win_size_y, self.max_win_size_x = self.scr.getmaxyx()
        # Keep the input box inside the physical window
        self.win_size_y = min(self.win_size_orig_y, self.max_win_size_y)
        self.win_size_x = min(self.win_size_orig_x, self.max_win_size_x)
        # Validate win_location settings
        self.win_location_x = min(max(0, self.max_win_size_x -
                                      self.win_size_x),
                                  self.win_location_orig_x)
        self.win_location_y = min(max(0, self.max_win_size_y -
                                      self.win_size_y),
                                  self.win_location_orig_y)
        # Adjust max_win_size for different possible offsets
        # (e.g. if there is a title and/or a box) and initiate the curses
        # screen(s)
        self._win_scr_init()
        self.title, self.title_help = self._title_init()
        self.stdscr.keypad(1)
        try:
            curses.use_default_colors()
        except _curses.error:
            pass
        if self.pw_mode is True:
            try:
                curses.curs_set(0)
            except _curses.error:
                pass
matrix.py 文件源码 项目:hakkuframework 作者: 4shadoww 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def main():
    steps = 0
    scr = curses.initscr()
    scr.nodelay(1)
    curses.curs_set(0)
    curses.noecho()

    if USE_COLORS:
        curses.start_color()
        curses.use_default_colors()
        curses.init_pair(COLOR_CHAR_NORMAL, curses.COLOR_GREEN, curses.COLOR_BLACK)
        curses.init_pair(COLOR_CHAR_HIGHLIGHT, curses.COLOR_WHITE, curses.COLOR_GREEN)
        curses.init_pair(COLOR_WINDOW, curses.COLOR_GREEN, curses.COLOR_GREEN)

    height, width = scr.getmaxyx()    
    window_animation = None
    lines = []
    for i in range(DROPPING_CHARS):
        l = FallingChar(width, MIN_SPEED, MAX_SPEED)
        l.y = randint(0, height-2)
        lines.append(l)

    scr.refresh()
    while True:
        height, width = scr.getmaxyx()
        for line in lines:
            line.tick(scr, steps)
        for i in range(RANDOM_CLEANUP):
            x = randint(0, width-1)
            y = randint(0, height-1)
            scr.addstr(y, x, ' ')
        if randint(0, WINDOW_CHANCE) == 1:
            if window_animation is None:
                #start window animation
                line = random.choice(lines)
                window_animation = WindowAnimation(line.x, line.y)
        if not window_animation is None:
           still_active = window_animation.tick(scr, steps)
           if not still_active:
               window_animation = None

        scr.refresh()
        time.sleep(SLEEP_MILLIS)
        if SCREENSAVER_MODE:
            key_pressed = scr.getch() != -1
            if key_pressed:
                raise KeyboardInterrupt()
        steps += 1
window.py 文件源码 项目:grbl-stream 作者: fragmuffin 项目源码 文件源码 阅读 69 收藏 0 点赞 0 评论 0
def using_curses(func):
    def inner(*largs, **kwargs):
        """
        Calls decorated function with initial curses screen inserted as
        first argument.
        Content mostly taken from curses.wrapper, modified to function as a
        decorator, and to introduce cursor removal
        """
        try:
            # Initialize curses
            stdscr = curses.initscr()

            # Turn off echoing of keys, and enter cbreak mode,
            # where no buffering is performed on keyboard input
            curses.noecho()
            curses.cbreak()

            # In keypad mode, escape sequences for special keys
            # (like the cursor keys) will be interpreted and
            # a special value like curses.KEY_LEFT will be returned
            stdscr.keypad(1)

            # Start color, too.  Harmless if the terminal doesn't have
            # color; user can test with has_color() later on.  The try/catch
            # works around a minor bit of over-conscientiousness in the curses
            # module -- the error return from C start_color() is ignorable.
            try:
                curses.start_color()
                curses.use_default_colors()
            except:
                pass

            # Set colour pallet
            curses.init_pair(CPI_GOOD, curses.COLOR_GREEN, -1)
            curses.init_pair(CPI_ERROR, curses.COLOR_RED, -1)
            curses.init_pair(CPI_WARNING, curses.COLOR_YELLOW, -1)

            # Remove blinking cursor
            curses.curs_set(0)

            func(stdscr, *largs, **kwargs)

        finally:
            # Set everything back to normal
            if 'stdscr' in locals():
                curses.curs_set(1)
                stdscr.keypad(0)
                curses.echo()  # revert curses.noecho()
                curses.nocbreak()  # revert curses.cbreak()
                curses.endwin()

    return inner



# ================== Status (header) Window ==================
watcher.py 文件源码 项目:nanosat-control 作者: ceyzeriat 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def init(self, stdscr):
        self.stdscr = stdscr
        curses.curs_set(0)
        self.stdscr.keypad(1)
        self.height, self.width = stdscr.getmaxyx()
        curses.start_color()
        curses.use_default_colors()
        #curses.echo()
        self._init_colors()
        self.bar = curses.newwin(1, self.width, 0, 0)
        self.bar.keypad(True)
        self.barpan = curses.panel.new_panel(self.bar)
        self.TC, self.TCpan, self._TC, self._TCpan =\
                            newlinebox(MAXDISPLAYTC, self.width,
                                       2, 0, "Telecommands")
        self.TC.scrollok(True)
        self.TC.idlok(True)
        self.TC.refresh()
        self.TM, self.TMpan, self._TM, self._TMpan =\
                            newlinebox(MAXDISPLAYTM, self.width,
                                       MAXDISPLAYTC+3, 0, "Telemetries")
        self.TM.scrollok(True)
        self.TM.idlok(True)
        self.TM.refresh()
        self.RP, self.RPpan, self._RP, self._RPpan =\
                            newlinebox(MAXDISPLAYRP, self.width,
                                       MAXDISPLAYTM+MAXDISPLAYTC+4, 0, "Reporting")
        self.RP.refresh()
        self.updpan()
        time.sleep(0.2)  # give it a bit of air
        self.pan_box = 0
        self.PANBOX = {0: self.TC, 1: self.TM}
        self.pan_loc = {0: 0, 1: 0, 2: 0}
        self.running = True
        #self.bar.erase()refresh
        self.disp(self.bar, PrintOut(' '*(self.width-1)))
        self.set_listenico(status=self.NOSTARTED)
        self.set_controlico(status=self.NOSTARTED)
        self.set_saveico(status=self.NOSTARTED)
        loopy = Thread(target=loop_time, args=(self,))
        loopy.daemon = True
        loopy.start()
        loopy = Thread(target=update_it, args=(self,))
        loopy.daemon = True
        loopy.start()
        self._key_catch()
        return
2049.py 文件源码 项目:colorful2048 作者: liuyuxuan123 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def main(stdscr):
    def init():
        game_field.reset()
        return "Game"

    def not_game(state):

        game_field.draw(stdscr)
        action = get_user_action(stdscr)
        responses = defaultdict(lambda:state)
        responses["Restart"],responses["Exit"] = "Init","Exit"
        return responses[action]

    def game():
        game_field.draw(stdscr)
        action = get_user_action(stdscr)

        if action == "Restart":
            return "Init"
        if action == "Exit":
            return "Exit"
        if game_field.move(action):
            if game_field.is_win():
                return "Win"
            if game_field.is_gameover():
                return "Gameover"

        return "Game"

    state_actions = {
            "Init":init,
            "Win":lambda:not_game("Win"),
            "Gameover":lambda:not_game("Gameover"),
            "Game":game
        }
    curses.use_default_colors()
    game_field = GameField(win = 32)

    state = "Init"

    while state != "Exit":
        state = state_actions[state]()
ci_program.py 文件源码 项目:ci_edit 作者: google 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, cursesScreen):
    self.clicks = 0
    self.debugMouseEvent = (0, 0, 0, 0, 0)
    self.exiting = False
    self.modalUi = None
    self.modeStack = []
    self.priorClick = 0
    self.savedMouseButton1Down = False
    self.savedMouseWindow = None
    self.savedMouseX = -1
    self.savedMouseY = -1
    self.cursesScreen = cursesScreen
    self.ch = 0
    curses.mousemask(-1)
    curses.mouseinterval(0)
    # Enable mouse tracking in xterm.
    sys.stdout.write('\033[?1002;h\n')
    #sys.stdout.write('\033[?1005;h\n')
    curses.meta(1)
    # Access ^c before shell does.
    curses.raw()
    # Enable Bracketed Paste Mode.
    sys.stdout.write('\033[?2004;h\n')
    #curses.start_color()
    curses.use_default_colors()
    if 0:
      assert(curses.COLORS == 256)
      assert(curses.can_change_color() == 1)
      assert(curses.has_colors() == 1)
      app.log.detail("color_content:")
      for i in range(0, curses.COLORS):
        app.log.detail("color", i, ": ", curses.color_content(i))
      for i in range(16, curses.COLORS):
        curses.init_color(i, 500, 500, i * 787 % 1000)
      app.log.detail("color_content, after:")
      for i in range(0, curses.COLORS):
        app.log.detail("color", i, ": ", curses.color_content(i))
    self.setUpPalette()
    if 1:
      #rows, cols = self.cursesScreen.getmaxyx()
      cursesWindow = self.cursesScreen
      cursesWindow.leaveok(1)  # Don't update cursor position.
      cursesWindow.scrollok(0)
      cursesWindow.timeout(10)
      cursesWindow.keypad(1)
      self.top, self.left = cursesWindow.getyx()
      self.rows, self.cols = cursesWindow.getmaxyx()
      app.window.mainCursesWindow = cursesWindow
    self.zOrder = []
2048.py 文件源码 项目:PyBook 作者: Windrivder 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def main(stdscr):

    def init():
        # ??????
        game_field.reset()
        return "Game"

    def not_game(state):
        # ?? Win ? GameOver ???
        game_field.draw(stdscr)
        # ????????? action??????????????
        action = get_user_action(stdscr)
        # ???????????????????????
        responses = defaultdict(lambda: state)
        # ???????????????
        responses['Restart'], responses['Exit'] = 'Init', 'Exit'
        return responses[action]

    def game():
        # ????????
        game_field.draw(stdscr)
        # ????????? action?????????
        action = get_user_action(stdscr)

        if action == 'Restart':
            return 'Init'
        if action == 'Exit':
            return 'Exit'
        # move successful
        if game_field.move(action):
            if game_field.is_win():
                return 'Win'
            if game_field.is_gameover():
                return 'Gameover'
        return 'Game'

    state_actions = {
        'Init': init,
        'Win': lambda: not_game('Win'),
        'Gameover': lambda: not_game('Gameover'),
        'Game': game
    }

    curses.use_default_colors()
    game_field = GameField(win=64)

    state = 'Init'

    # ???????
    while state != 'Exit':
        state = state_actions[state]()


问题


面经


文章

微信
公众号

扫码关注公众号