Python curses 模块,KEY_NPAGE 实例源码

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

项目:sciibo    作者:fdev    | 项目源码 | 文件源码
def on_key(self, ch):
        if ch not in (curses.KEY_UP, curses.KEY_DOWN, curses.KEY_PPAGE, curses.KEY_NPAGE):
            return

        if ch == curses.KEY_UP:
            self.scroll = max(self.scroll - 1, 0)

        if ch == curses.KEY_DOWN:
            self.scroll = min(self.scroll + 1, self.maxscroll)

        if ch == curses.KEY_PPAGE:
            self.scroll = max(self.scroll - self.perpage, 0)

        if ch == curses.KEY_NPAGE:
            self.scroll = min(self.scroll + self.perpage, self.maxscroll)

        self.update()
项目:ascii_qgis    作者:NathanW2    | 项目源码 | 文件源码
def focus(self):
        modeline.update_activeWindow("Map")
        curses.curs_set(0)
        while True:
            event = self.mapwin.getch()
            # if event == -1:
            #     continue
            logging.info(event)
            try_handle_global_event(event)

            if event == curses.KEY_UP:
                self.pan("up")
            if event == curses.KEY_DOWN:
                self.pan("down")
            if event == curses.KEY_LEFT:
                self.pan("left")
            if event == curses.KEY_RIGHT:
                self.pan("right")
            if event == curses.KEY_NPAGE:
                self.zoom_out(5)
            if event == curses.KEY_PPAGE:
                self.zoom_in(5)
项目:logviewer    作者:romuloceccon    | 项目源码 | 文件源码
def handle_key(self, k):
        if k == ord('q'):
            self.close(None)
        elif k == ord('d'):
            self._change_date()
        elif k == ord('l'):
            self._change_level()
        elif k == ord('f'):
            self._change_facility()
        elif k == ord('h'):
            self._change_host()
        elif k == ord('p'):
            self._change_program()
        elif k == curses.KEY_NPAGE:
            self._buf.go_to_next_page()
        elif k == curses.KEY_PPAGE:
            self._buf.go_to_previous_page()
        elif k == curses.KEY_DOWN:
            self._buf.go_to_next_line()
        elif k == curses.KEY_UP:
            self._buf.go_to_previous_line()
        elif k == curses.KEY_RIGHT:
            self.scroll_right()
        elif k == curses.KEY_LEFT:
            self.scroll_left()
项目: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,
        }
项目:pysk    作者:ph1l    | 项目源码 | 文件源码
def command(self, char):
        """handle page specific commands"""
        if char == curses.KEY_DOWN or char == ord('j'):
            if self.pad_pos < self.row_count-1:
                self.pad_pos += 1
        elif char == curses.KEY_UP or char == ord('k'):
            if self.pad_pos > 0:
                self.pad_pos -= 1
        elif char == curses.KEY_NPAGE or char == ord('J'):
            if self.pad_pos < self.row_count-((self.max_y)/2):
                self.pad_pos += (self.max_y)/2
            else:
                self.pad_pos = self.row_count-1
        elif char == curses.KEY_PPAGE or char == ord('K'):
            if self.pad_pos > ((self.max_y)/2):
                self.pad_pos -= (self.max_y)/2
            else:
                self.pad_pos = 0
        elif char == curses.KEY_RIGHT or char == ord('l'):
            if self.row_index[self.pad_pos][0] == 'vessel':
                vessel = self.row_index[self.pad_pos][1]
                return ('VESSEL_DETAIL', vessel)

            if self.row_index[self.pad_pos][0] == 'target':
                vessel = self.row_index[self.pad_pos][1]
                path = self.row_index[self.pad_pos][2]
                return ('TARGET_DETAIL', (vessel, path))
        return (None, None)
项目:ipmap-creator    作者:ASP-Labs    | 项目源码 | 文件源码
def curses_loop(self, stdscr):
        while 1:
            self.redraw()
            c = stdscr.getch()

            if c == ord('q') or c == ord('Q'):
                self.aborted = True
                break
            elif c == curses.KEY_UP:
                self.cursor = self.cursor - 1
            elif c == curses.KEY_DOWN:
                self.cursor = self.cursor + 1
            # elif c == curses.KEY_PPAGE:
            # elif c == curses.KEY_NPAGE:
            elif c == ord(' '):
                self.all_options[self.selected]["selected"] = \
                    not self.all_options[self.selected]["selected"]
            elif c == 10:
                break

            # deal with interaction limits
            self.check_cursor_up()
            self.check_cursor_down()

            # compute selected position only after dealing with limits
            self.selected = self.cursor + self.offset

            temp = self.getSelected()
            self.selcount = len(temp)
项目:HPCinstall    作者:NCAR    | 项目源码 | 文件源码
def get_keyboard_codes():
    """
    Return mapping of keycode integer values paired by their curses key-name.

    :rtype: dict

    Returns dictionary of (code, name) pairs for curses keyboard constant
    values and their mnemonic name. Such as key ``260``, with the value of
    its identity, ``u'KEY_LEFT'``.  These are derived from the attributes by
    the same of the curses module, with the following exceptions:

    * ``KEY_DELETE`` in place of ``KEY_DC``
    * ``KEY_INSERT`` in place of ``KEY_IC``
    * ``KEY_PGUP`` in place of ``KEY_PPAGE``
    * ``KEY_PGDOWN`` in place of ``KEY_NPAGE``
    * ``KEY_ESCAPE`` in place of ``KEY_EXIT``
    * ``KEY_SUP`` in place of ``KEY_SR``
    * ``KEY_SDOWN`` in place of ``KEY_SF``

    This function is the inverse of :func:`get_curses_keycodes`.  With the
    given override "mixins" listed above, the keycode for the delete key will
    map to our imaginary ``KEY_DELETE`` mnemonic, effectively erasing the
    phrase ``KEY_DC`` from our code vocabulary for anyone that wishes to use
    the return value to determine the key-name by keycode.
    """
    keycodes = OrderedDict(get_curses_keycodes())
    keycodes.update(CURSES_KEYCODE_OVERRIDE_MIXIN)

    # invert dictionary (key, values) => (values, key), preferring the
    # last-most inserted value ('KEY_DELETE' over 'KEY_DC').
    return dict(zip(keycodes.values(), keycodes.keys()))
项目: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,
        }
项目:treesel    作者:mcchae    | 项目源码 | 文件源码
def c_main(stdscr):
    cargo_cult_routine(stdscr)
    stdscr.nodelay(0)
    mydir = factory(start)
    mydir.expand()
    curidx = 3
    pending_action = None
    pending_save = False

    while True:
        stdscr.clear()
        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
        line = 0
        offset = max(0, curidx - curses.LINES + 3)
        for data, depth in mydir.traverse():
            if line == curidx:
                stdscr.attrset(curses.color_pair(1) | curses.A_BOLD)
                if pending_action:
                    getattr(data, pending_action)()
                    pending_action = None
                elif pending_save:
                    global result
                    result = data.name
                    return
            else:
                stdscr.attrset(curses.color_pair(0))
            if 0 <= line - offset < curses.LINES - 1:
                stdscr.addstr(line - offset, 0,
                              data.render(depth, curses.COLS))
            line += 1
        stdscr.refresh()
        ch = stdscr.getch()
        if ch == curses.KEY_UP:
            curidx -= 1
        elif ch == curses.KEY_DOWN:
            curidx += 1
        elif ch == curses.KEY_PPAGE:
            curidx -= curses.LINES
            if curidx < 0: curidx = 0
        elif ch == curses.KEY_NPAGE:
            curidx += curses.LINES
            if curidx >= line: curidx = line - 1
        elif ch == curses.KEY_RIGHT:
            pending_action = 'expand'
        elif ch == curses.KEY_LEFT:
            pending_action = 'collapse'
        elif ch == ESC:
            return
        elif ch == ord('\n'):
            pending_save = True

        curidx %= line


################################################################################