Python curses 模块,KEY_RESIZE 实例源码

我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用curses.KEY_RESIZE

项目:logviewer    作者:romuloceccon    | 项目源码 | 文件源码
def loop(self):
        self._curses_window.erase()
        self._curses_window.noutrefresh()

        for window in self._stack:
            window.refresh()

        self._curses.doupdate()

        self.wait()
        for k in self._get_chars():
            if k == curses.KEY_RESIZE:
                h, w = self._curses_window.getmaxyx()
                for window in self._stack:
                    window.resize(h, w)
            elif self._stack:
                self._stack[-1].handle_key(k)
项目:s2e-env    作者:S2E    | 项目源码 | 文件源码
def _run(self, callback):
        self._create_desktop()

        if not callback(self):
            return

        self._redraw()
        self._desktop.window.nodelay(True)

        while True:
            c = self._desktop.window.getch()
            if c == curses.ERR:
                if not callback(self):
                    return

                time.sleep(1)

            elif c == ord('q'):
                break
            elif c == curses.KEY_RESIZE:
                self._updated = True

            if self._updated:
                self._redraw()
                self._updated = False
项目:notex    作者:adiultra    | 项目源码 | 文件源码
def keys_init_noedit(self):
        """Define methods for each key for non-editing mode.

        """
        self.keys = {
            curses.ascii.ETX:               self.close,
            curses.KEY_DOWN:                self.down_noedit,
            CTRL('n'):                      self.down_noedit,
            'j':                            self.down_noedit,
            curses.KEY_F1:                  self.help,
            curses.KEY_NPAGE:               self.page_down,
            'J':                            self.page_down,
            CTRL('f'):                      self.page_up,
            curses.KEY_PPAGE:               self.page_up,
            'K':                            self.page_up,
            CTRL('b'):                      self.page_up,
            CTRL('x'):                      self.quit,
            curses.KEY_F2:                  self.quit,
            curses.KEY_F3:                  self.quit_nosave,
            curses.ascii.ESC:               self.quit_nosave,
            curses.KEY_RESIZE:              self.resize,
            -1:                             self.resize,
            curses.KEY_UP:                  self.up_noedit,
            CTRL('p'):                      self.up_noedit,
            'k':                            self.up_noedit,
        }
项目:notex    作者:adiultra    | 项目源码 | 文件源码
def get_key(self):
        c = self.stdscr.getch()
        if c == curses.KEY_RESIZE:
            self.resize()
            return True
        # 127 and 27 are to make sure the Backspace/ESC keys work properly
        if 0 < c < 256 and c != 127 and c != 27:
            c = chr(c)
        try:
            loop = self.keys[c]()
        except KeyError:
            if self.edit is True:
                self.insert_char(c)
            loop = True
        return loop
项目:botany    作者:jifunks    | 项目源码 | 文件源码
def get_user_input(self):
        # gets the user's input
        try:
            user_in = self.screen.getch() # Gets user input
        except Exception as e:
            self.__exit__()
        ## DEBUG KEYS - enable these lines to see curses key codes
        # self.screen.addstr(1, 1, str(user_in), curses.A_NORMAL)
        # self.screen.refresh()

        # Resize sends curses.KEY_RESIZE, update display
        if user_in == curses.KEY_RESIZE:
            self.maxy,self.maxx = self.screen.getmaxyx()
            self.screen.clear()
            self.screen.refresh()

        # enter and exit Keys are special cases
        if user_in == 10:
            return self.options[self.selected]
        if user_in == 27:
            return self.options[-1]

        # this is a number; check to see if we can set it
        if user_in >= ord('1') and user_in <= ord(str(min(9,len(self.options)+1))):
            self.selected = user_in - ord('0') - 1 # convert keypress back to a number, then subtract 1 to get index
            return

        # increment or Decrement
        down_keys = [curses.KEY_DOWN, 14, ord('j')]
        up_keys = [curses.KEY_UP, 16, ord('k')]

        if user_in in down_keys: # down arrow
            self.selected += 1
        if user_in in up_keys: # up arrow
            self.selected -=1

        # modulo to wrap menu cursor
        self.selected = self.selected % len(self.options)
        return
项目:pyfeld    作者:scjurgen    | 项目源码 | 文件源码
def run_main_loop(self):
        self.draw_ui()
        while 1:
            c = self.window.getch()
            if curses.keyname(c) in [b'h', b'H']:
                self.show_help()
            elif curses.keyname(c) in [b'p', b'P']:
                self.play()
            elif curses.keyname(c) in [b'q', b'Q']:
                return None
            elif c == 27:
                self.returnString = self.dir.get_current_path()
                return self.returnString
            elif c == curses.KEY_ENTER or c == 10:
                self.returnString = self.dir.get_current_path()
                return self.returnString
            elif c == curses.KEY_UP:
                if self.selected_index > 0:
                    self.selected_index -= 1
                self.draw_ui()
            elif c == curses.KEY_DOWN:
                if self.selected_index < self.dir.max_entries_on_level()-1:
                    self.selected_index += 1
                self.draw_ui()
            elif c == curses.KEY_LEFT:
                self.leave_dir()
                self.draw_ui()
            elif c == curses.KEY_RIGHT:
                self.enter_dir()
                self.draw_ui()
            elif c == curses.KEY_RESIZE:
                self.draw_ui()
项目:taskhud    作者:usefulthings    | 项目源码 | 文件源码
def mainloop(self):
        """
        Called after HUD has been set up. Handles rendering and user input.
        """
        # Disable cursor display by default
        curses.curs_set(0)

        # Display initial state
        self.render()

        while True:
            # Render before fetching input
            self.render()

            # note: call is non-blocking, per __init__ calling nodelay(True)
            c = self.screen.getch()

            if c == curses.KEY_RESIZE:
                # Terminal has been resized

                # must be called so that curses.LINES, curses.COLS will change
                curses.update_lines_cols()

                # in case old data won't be redrawn after resize
                self.screen.clear()

            if c == curses.KEY_UP:
                # Move up as far as the 0th record
                self.selectpos = max(self.selectpos - 1, 0)
                if self.selectpos < self.scrollpos:
                    # Handle scrolling if we were at the first record on screen
                    self.scrollpos -= 1

            if c == curses.KEY_DOWN:
                # Move down as far as the Nth record
                self.selectpos = min(self.selectpos + 1, len(self.records) - 1)
                if self.selectpos >= (self.scrollpos + curses.LINES - 2 - self.bottom_panel_height) :
                    # Handle scrolling if we were at the last record on screen
                    self.scrollpos += 1
项目:gintonic    作者:redahe    | 项目源码 | 文件源码
def main_loop():
    while 1:
        time.sleep(0.001)
        c = mainwindow.getch()
        if c == ord('/'):
            word = search_window.enter()
            found = game_menu.find_word(word)
            game_menu.center(found)
        if c == ord('j') or c == curses.KEY_DOWN:
            game_menu.move_down()
        if c == ord('k') or c == curses.KEY_UP:
            game_menu.move_up()
        if c == ord('n'):
            word = search_window.text.gather().strip()
            found = game_menu.find_next(word)
            game_menu.center(found)
        if c == ord('N'):
            word = search_window.text.gather().strip()
            found = game_menu.find_prev(word)
            game_menu.center(found)
        if c == ord('\n') or c == ord('l'):
            cg = game_menu.current_game()
            launch_game(cg)
        if c == ord('q'):
            return
        if c == curses.KEY_RESIZE:
            do_resize()
项目:cursebox    作者:Tenchi2xh    | 项目源码 | 文件源码
def poll_event(self):
        """
        Checks if an event happens and returns a string related to the event.

        Returns -1 if nothing happened during self.screen.timeout milliseconds.

        If the event is a normal (letter) key press,
        the letter is returned (case sensitive)

        :return: Event type
        """
        self.mutex.acquire()
        ch = self.screen.getch()
        self.mutex.release()

        if ch == -1:
            return EVENT_SKIP
        elif ch == 27:
            return EVENT_ESC
        elif ch == curses.KEY_RESIZE:
            return EVENT_RESIZE
        elif ch == 10 or ch == curses.KEY_ENTER:
            return EVENT_ENTER
        elif ch == 127 or ch == curses.KEY_BACKSPACE:
            return EVENT_BACKSPACE
        elif ch == curses.KEY_UP:
            return EVENT_UP
        elif ch == curses.KEY_DOWN:
            return EVENT_DOWN
        elif ch == curses.KEY_LEFT:
            return EVENT_LEFT
        elif ch == curses.KEY_RIGHT:
            return EVENT_RIGHT
        elif ch == 3:
            return EVENT_CTRL_C
        elif ch == 409:
            return EVENT_CLICK
        elif 0 <= ch < 256:
            return chr(ch)
        else:
            return EVENT_UNHANDLED
项目:ci_edit    作者:google    | 项目源码 | 文件源码
def hackCursesFixes():
  if sys.platform == 'darwin':
    def windowChangedHandler(signum, frame):
      curses.ungetch(curses.KEY_RESIZE)
    signal.signal(signal.SIGWINCH, windowChangedHandler)
  def wakeGetch(signum, frame):
    curses.ungetch(0)
  signal.signal(signal.SIGUSR1, wakeGetch)
项目:ci_edit    作者:google    | 项目源码 | 文件源码
def executeCommandList(self, cmdList):
    for cmd, eventInfo in cmdList:
      if cmd == curses.KEY_RESIZE:
        self.handleScreenResize(self.focusedWindow)
        continue
      self.focusedWindow.controller.doCommand(cmd, eventInfo)
      if cmd == curses.KEY_MOUSE:
        self.handleMouse(eventInfo)
      self.focusedWindow.controller.onChange()
项目:unmessage    作者:AnemoneLabs    | 项目源码 | 文件源码
def do_command(self, ch):
        if ch == curses.KEY_RESIZE:
            raise errors.CursesScreenResizedError()
        if ch == 10:  # Enter
            return 0
        if ch == 127:  # BackSpace
            return 8

        return Textbox.do_command(self, ch)
项目:AutoCode    作者:HashCode55    | 项目源码 | 文件源码
def start(self):   
        """
        start iterates the file and paints the text on the screen.
        exits when q is pressed. 
        """
        try:      
            fileptr = 0
            key = ''
            lines = 1        
            while True:
                # get the cursor position for further manipulation 
                y, x = self.stdscr.getyx()
                key = self.stdscr.getch()
                if key == curses.KEY_BACKSPACE or key == curses.KEY_DC or \
                    key == curses.KEY_DL or key == 127 :  
                    # handle backspace                             
                    if x == 0 and y == 0: 
                        continue                     
                    # take the file pointer back one step 
                    fileptr -= 1
                    # update the screen     
                    if x == 0:   
                        lines -= 1
                        self.stdscr.addstr(y-1, len(self.virtualfile[lines-1]), ' ')
                        self.stdscr.move(y-1, len(self.virtualfile[lines-1]))                                   
                    else:
                        self.stdscr.addstr(y, x-1, ' ')
                        self.stdscr.move(y, x-1)                
                elif key == curses.KEY_UP or key == curses.KEY_DOWN or \
                    key == curses.KEY_RESIZE or key == -1:
                    # ignore 
                    continue                           
                else:   
                    text = self.get_text(fileptr)                    
                    # increase the lines if there are "\n" s 
                    lines += sum([1 if c == '\n' else 0 for c in text])
                    fileptr += self.n        
                    self.stdscr.addstr(text)

                self.stdscr.refresh()                
            # graceful exit                 
            curses.endwin()
        except KeyboardInterrupt:            
            curses.endwin()
            exit()
项目:notex    作者:adiultra    | 项目源码 | 文件源码
def keys_init(self):
        """Define methods for each key.

        """
        self.keys = {
            curses.KEY_BACKSPACE:           self.backspace,
            CTRL('h'):                      self.backspace,
            curses.ascii.BS:                self.backspace,
            curses.ascii.DEL:               self.backspace,
            curses.ascii.ETX:               self.close,
            curses.KEY_DC:                  self.del_char,
            CTRL('d'):                      self.del_char,
            CTRL('u'):                      self.del_to_bol,
            CTRL('k'):                      self.del_to_eol,
            curses.KEY_DOWN:                self.down,
            CTRL('n'):                      self.down,
            curses.KEY_END:                 self.end,
            CTRL('e'):                      self.end,
            curses.KEY_F1:                  self.help,
            curses.KEY_HOME:                self.home,
            CTRL('a'):                      self.home,
            curses.KEY_ENTER:               self.insert_line_or_quit,
            curses.ascii.NL:                self.insert_line_or_quit,
            curses.ascii.LF:                self.insert_line_or_quit,
            "\n":                           self.insert_line_or_quit,
            curses.KEY_LEFT:                self.left,
            CTRL('b'):                      self.left,
            curses.KEY_NPAGE:               self.page_down,
            curses.KEY_PPAGE:               self.page_up,
            CTRL('v'):                      self.paste,
            CTRL('x'):                      self.quit,
            curses.KEY_F2:                  self.quit,
            curses.KEY_F3:                  self.quit_nosave,
            curses.ascii.ESC:               self.quit_nosave,
            curses.KEY_RESIZE:              self.resize,
            -1:                             self.resize,
            curses.KEY_RIGHT:               self.right,
            CTRL('f'):                      self.right,
            curses.KEY_UP:                  self.up,
            CTRL('p'):                      self.up,
        }
项目:cryptop    作者:huwwp    | 项目源码 | 文件源码
def mainc(stdscr):
    inp = 0
    wallet = read_wallet()
    y, x = stdscr.getmaxyx()
    conf_scr()
    stdscr.bkgd(' ', curses.color_pair(2))
    stdscr.clear()
    #stdscr.nodelay(1)
    # while inp != 48 and inp != 27 and inp != 81 and inp != 113:
    while inp not in {KEY_ZERO, KEY_ESCAPE, KEY_Q, KEY_q}:
        while True:
            try:
                write_scr(stdscr, wallet, y, x)
            except curses.error:
                pass

            inp = stdscr.getch()
            if inp != curses.KEY_RESIZE:
                break
            stdscr.erase()
            y, x = stdscr.getmaxyx()

        if inp in {KEY_a, KEY_A}:
            if y > 2:
                data = get_string(stdscr,
                    'Enter in format Symbol,Amount e.g. BTC,10')
                wallet = add_coin(data, wallet)
                write_wallet(wallet)

        if inp in {KEY_r, KEY_R}:
            if y > 2:
                data = get_string(stdscr,
                    'Enter the symbol of coin to be removed, e.g. BTC')
                wallet = remove_coin(data, wallet)
                write_wallet(wallet)

        if inp in {KEY_s, KEY_S}:
            if y > 2:
                global ORDER
                ORDER = not ORDER

        if inp in {KEY_c, KEY_C}:
            if y > 2:
                global COLUMN
                COLUMN = (COLUMN + 1) % len(SORTS)
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def _get_input(self, wait_tenths):
        # this works around a strange curses bug with window resizing
        # not being reported correctly with repeated calls to this
        # function without a doupdate call in between
        curses.doupdate()

        key = self._getch(wait_tenths)
        resize = False
        raw = []
        keys = []

        while key >= 0:
            raw.append(key)
            if key==KEY_RESIZE:
                resize = True
            elif key==KEY_MOUSE:
                keys += self._encode_mouse_event()
            else:
                keys.append(key)
            key = self._getch_nodelay()

        processed = []

        try:
            while keys:
                run, keys = escape.process_keyqueue(keys, True)
                processed += run
        except escape.MoreInputRequired:
            key = self._getch(self.complete_tenths)
            while key >= 0:
                raw.append(key)
                if key==KEY_RESIZE:
                    resize = True
                elif key==KEY_MOUSE:
                    keys += self._encode_mouse_event()
                else:
                    keys.append(key)
                key = self._getch_nodelay()
            while keys:
                run, keys = escape.process_keyqueue(keys, False)
                processed += run

        if resize:
            processed.append('window resize')

        return processed, raw