Python curses.KEY_NPAGE Examples

The following are 24 code examples of curses.KEY_NPAGE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module curses , or try the search function .
Example #1
Source File: test_curses.py    From memory-analyzer with MIT License 6 votes vote down vote up
def setUp(self):
        self.mock_curses = mock.patch(
            "memory_analyzer.frontend.memanz_curses.curses"
        ).start()
        self.addCleanup(self.mock_curses.stop)
        self.mock_curses.LINES = 2
        self.mock_curses.COLS = 100
        self.mock_curses.KEY_DOWN = curses.KEY_DOWN
        self.mock_curses.KEY_UP = curses.KEY_UP
        self.mock_curses.KEY_PPAGE = curses.KEY_PPAGE
        self.mock_curses.KEY_NPAGE = curses.KEY_NPAGE
        self.mock_curses.KEY_RIGHT = curses.KEY_RIGHT
        self.mock_curses.KEY_LEFT = curses.KEY_LEFT
        self.statusbarstr = " | Navigate with arrows or wasd | Press 'q' to exit"
        self.pages = [["Page1", 10, 1024], ["Page2", 90, 100]]
        self.titles = ["Analysis of 1234", "Snapshot Differences"]
        self.win = memanz_curses.Window(self.mock_curses, self.pages, self.titles) 
Example #2
Source File: keyboard.py    From MARA_Framework with GNU Lesser General Public License v3.0 6 votes vote down vote up
def get_keyboard_codes():
    """get_keyboard_codes() -> 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, ``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``
    """
    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())) 
Example #3
Source File: wgmultiline.py    From HomePWN with GNU General Public License v3.0 5 votes vote down vote up
def set_up_handlers(self):
        super(Pager, self).set_up_handlers()
        self.handlers = {
            curses.KEY_UP: self.h_scroll_line_up,
            curses.KEY_LEFT: self.h_scroll_line_up,
            curses.KEY_DOWN: self.h_scroll_line_down,
            curses.KEY_RIGHT: self.h_scroll_line_down,
            curses.KEY_NPAGE: self.h_scroll_page_down,
            curses.KEY_PPAGE: self.h_scroll_page_up,
            curses.KEY_HOME: self.h_show_beginning,
            curses.KEY_END: self.h_show_end,
            curses.ascii.NL: self.h_exit,
            curses.ascii.CR: self.h_exit,
            curses.ascii.SP: self.h_scroll_page_down,
            curses.ascii.TAB: self.h_exit,
            ord('j'): self.h_scroll_line_down,
            ord('k'): self.h_scroll_line_up,
            ord('x'): self.h_exit,
            ord('q'): self.h_exit,
            ord('g'): self.h_show_beginning,
            ord('G'): self.h_show_end,
            curses.ascii.ESC: self.h_exit_escape,
        }

        self.complex_handlers = [
        ] 
Example #4
Source File: curses_ui_test.py    From keras-lambda with MIT License 5 votes vote down vote up
def testRunUIScrollTallOutputPageDownUp(self):
    """Scroll tall output with PageDown and PageUp."""

    # Use PageDown and PageUp to scroll back and forth a little before exiting.
    ui = MockCursesUI(
        40,
        80,
        command_sequence=[string_to_codes("babble\n"), [curses.KEY_NPAGE] * 2 +
                          [curses.KEY_PPAGE] + self._EXIT])

    ui.register_command_handler("babble", self._babble, "")
    ui.run_ui()

    # Screen output/scrolling should have happened exactly once.
    self.assertEqual(4, len(ui.unwrapped_outputs))
    self.assertEqual(4, len(ui.wrapped_outputs))
    self.assertEqual(4, len(ui.scroll_messages))

    # Before scrolling.
    self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[0].lines)
    self.assertEqual(["bar"] * 60, ui.wrapped_outputs[0].lines[:60])

    # Initial scroll: At the top.
    self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[0])
    self.assertIn("Mouse:", ui.scroll_messages[0])

    # After 1st scrolling (PageDown).
    # The screen output shouldn't have changed. Only the viewport should.
    self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[0].lines)
    self.assertEqual(["bar"] * 60, ui.wrapped_outputs[0].lines[:60])
    self.assertIn("Scroll (PgDn/PgUp): 1.69%", ui.scroll_messages[1])
    self.assertIn("Mouse:", ui.scroll_messages[1])

    # After 2nd scrolling (PageDown).
    self.assertIn("Scroll (PgDn/PgUp): 3.39%", ui.scroll_messages[2])
    self.assertIn("Mouse:", ui.scroll_messages[2])

    # After 3rd scrolling (PageUp).
    self.assertIn("Scroll (PgDn/PgUp): 1.69%", ui.scroll_messages[3])
    self.assertIn("Mouse:", ui.scroll_messages[3]) 
Example #5
Source File: wggrid.py    From TelegramTUI with MIT License 5 votes vote down vote up
def set_up_handlers(self):
        super(SimpleGrid, self).set_up_handlers()
        self.handlers = {
                    curses.KEY_UP:      self.h_move_line_up,
                    curses.KEY_LEFT:    self.h_move_cell_left,
                    curses.KEY_DOWN:    self.h_move_line_down,
                    curses.KEY_RIGHT:   self.h_move_cell_right,
                    "k":                self.h_move_line_up,
                    "h":                self.h_move_cell_left,
                    "j":                self.h_move_line_down,
                    "l":                self.h_move_cell_right,
                    curses.KEY_NPAGE:   self.h_move_page_down,
                    curses.KEY_PPAGE:   self.h_move_page_up,
                    curses.KEY_HOME:    self.h_show_beginning,
                    curses.KEY_END:     self.h_show_end,
                    ord('g'):           self.h_show_beginning,
                    ord('G'):           self.h_show_end,
                    curses.ascii.TAB:   self.h_exit,
                    curses.KEY_BTAB:     self.h_exit_up,
                    '^P':               self.h_exit_up,
                    '^N':               self.h_exit_down,
                    #curses.ascii.NL:    self.h_exit,
                    #curses.ascii.SP:    self.h_exit,
                    #ord('x'):       self.h_exit,
                    ord('q'):       self.h_exit,
                    curses.ascii.ESC:   self.h_exit,
                    curses.KEY_MOUSE:    self.h_exit_mouse,
                }

        self.complex_handlers = [
                    ] 
Example #6
Source File: wgmultiline.py    From TelegramTUI with MIT License 5 votes vote down vote up
def set_up_handlers(self):
        super(Pager, self).set_up_handlers()
        self.handlers = {
            curses.KEY_UP: self.h_scroll_line_up,
            curses.KEY_LEFT: self.h_scroll_line_up,
            curses.KEY_DOWN: self.h_scroll_line_down,
            curses.KEY_RIGHT: self.h_scroll_line_down,
            curses.KEY_NPAGE: self.h_scroll_page_down,
            curses.KEY_PPAGE: self.h_scroll_page_up,
            curses.KEY_HOME: self.h_show_beginning,
            curses.KEY_END: self.h_show_end,
            curses.ascii.NL: self.h_exit,
            curses.ascii.CR: self.h_exit,
            curses.ascii.SP: self.h_scroll_page_down,
            curses.ascii.TAB: self.h_exit,
            ord('j'): self.h_scroll_line_down,
            ord('k'): self.h_scroll_line_up,
            ord('x'): self.h_exit,
            ord('q'): self.h_exit,
            ord('g'): self.h_show_beginning,
            ord('G'): self.h_show_end,
            curses.ascii.ESC: self.h_exit_escape,
        }

        self.complex_handlers = [
        ] 
Example #7
Source File: wggrid.py    From EDCOP with Apache License 2.0 5 votes vote down vote up
def set_up_handlers(self):
        super(SimpleGrid, self).set_up_handlers()
        self.handlers = {
                    curses.KEY_UP:      self.h_move_line_up,
                    curses.KEY_LEFT:    self.h_move_cell_left,
                    curses.KEY_DOWN:    self.h_move_line_down,
                    curses.KEY_RIGHT:   self.h_move_cell_right,
                    "k":                self.h_move_line_up,
                    "h":                self.h_move_cell_left,
                    "j":                self.h_move_line_down,
                    "l":                self.h_move_cell_right,
                    curses.KEY_NPAGE:   self.h_move_page_down,
                    curses.KEY_PPAGE:   self.h_move_page_up,
                    curses.KEY_HOME:    self.h_show_beginning,
                    curses.KEY_END:     self.h_show_end,
                    ord('g'):           self.h_show_beginning,
                    ord('G'):           self.h_show_end,
                    curses.ascii.TAB:   self.h_exit,
                    curses.KEY_BTAB:     self.h_exit_up,
                    '^P':               self.h_exit_up,
                    '^N':               self.h_exit_down,
                    #curses.ascii.NL:    self.h_exit,
                    #curses.ascii.SP:    self.h_exit,
                    #ord('x'):       self.h_exit,
                    ord('q'):       self.h_exit,
                    curses.ascii.ESC:   self.h_exit,
                    curses.KEY_MOUSE:    self.h_exit_mouse,
                }

        self.complex_handlers = [
                    ] 
Example #8
Source File: wgmultiline.py    From EDCOP with Apache License 2.0 5 votes vote down vote up
def set_up_handlers(self):
        super(Pager, self).set_up_handlers()
        self.handlers = {
                    curses.KEY_UP:      self.h_scroll_line_up,
                    curses.KEY_LEFT:    self.h_scroll_line_up,
                    curses.KEY_DOWN:    self.h_scroll_line_down,
                    curses.KEY_RIGHT:   self.h_scroll_line_down,
                    curses.KEY_NPAGE:   self.h_scroll_page_down,
                    curses.KEY_PPAGE:   self.h_scroll_page_up,
                    curses.KEY_HOME:    self.h_show_beginning,
                    curses.KEY_END:     self.h_show_end,
                    curses.ascii.NL:    self.h_exit,
                    curses.ascii.CR:    self.h_exit,
                    curses.ascii.SP:    self.h_scroll_page_down,
                    curses.ascii.TAB:   self.h_exit,
                    ord('j'):           self.h_scroll_line_down,
                    ord('k'):           self.h_scroll_line_up,
                    ord('x'):           self.h_exit,
                    ord('q'):           self.h_exit,
                    ord('g'):           self.h_show_beginning,
                    ord('G'):           self.h_show_end,
                    curses.ascii.ESC:   self.h_exit_escape,
                }

        self.complex_handlers = [
                    ] 
Example #9
Source File: picker.py    From Spelt with MIT License 5 votes vote down vote up
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 -= 1
            elif c == curses.KEY_DOWN:
                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.get_selected()
            self.selcount = len(temp) 
Example #10
Source File: screen.py    From pyModeS with GNU General Public License v3.0 5 votes vote down vote up
def kye_handling(self):
        self.draw_frame()
        self.scr_h, self.scr_w = self.screen.getmaxyx()

        while True:
            c = self.screen.getch()

            if c == curses.KEY_HOME:
                self.x = 1
                self.y = 1
            elif c == curses.KEY_NPAGE:
                offset_intent = self.offset + (self.scr_h - 4)
                if offset_intent < len(self.acs) - 5:
                    self.offset = offset_intent
            elif c == curses.KEY_PPAGE:
                offset_intent = self.offset - (self.scr_h - 4)
                if offset_intent > 0:
                    self.offset = offset_intent
                else:
                    self.offset = 0
            elif c == curses.KEY_DOWN:
                y_intent = self.y + 1
                if y_intent < self.scr_h - 3:
                    self.y = y_intent
            elif c == curses.KEY_UP:
                y_intent = self.y - 1
                if y_intent > 2:
                    self.y = y_intent
            elif c == curses.KEY_ENTER or c == 10 or c == 13:
                self.lock_icao = (self.screen.instr(self.y, 1, 6)).decode()
            elif c == 27:  # escape key
                self.lock_icao = None
            elif c == curses.KEY_F5:
                self.screen.refresh()
                self.draw_frame() 
Example #11
Source File: wggrid.py    From HomePWN with GNU General Public License v3.0 5 votes vote down vote up
def set_up_handlers(self):
        super(SimpleGrid, self).set_up_handlers()
        self.handlers = {
                    curses.KEY_UP:      self.h_move_line_up,
                    curses.KEY_LEFT:    self.h_move_cell_left,
                    curses.KEY_DOWN:    self.h_move_line_down,
                    curses.KEY_RIGHT:   self.h_move_cell_right,
                    "k":                self.h_move_line_up,
                    "h":                self.h_move_cell_left,
                    "j":                self.h_move_line_down,
                    "l":                self.h_move_cell_right,
                    curses.KEY_NPAGE:   self.h_move_page_down,
                    curses.KEY_PPAGE:   self.h_move_page_up,
                    curses.KEY_HOME:    self.h_show_beginning,
                    curses.KEY_END:     self.h_show_end,
                    ord('g'):           self.h_show_beginning,
                    ord('G'):           self.h_show_end,
                    curses.ascii.TAB:   self.h_exit,
                    curses.KEY_BTAB:     self.h_exit_up,
                    '^P':               self.h_exit_up,
                    '^N':               self.h_exit_down,
                    #curses.ascii.NL:    self.h_exit,
                    #curses.ascii.SP:    self.h_exit,
                    #ord('x'):       self.h_exit,
                    ord('q'):       self.h_exit,
                    curses.ascii.ESC:   self.h_exit,
                    curses.KEY_MOUSE:    self.h_exit_mouse,
                }

        self.complex_handlers = [
                    ] 
Example #12
Source File: test_curses.py    From memory-analyzer with MIT License 5 votes vote down vote up
def test_user_input_attempt_to_scroll_down_off_window(self):
        self.win.position = self.win.bottom
        self.win.window.getch.side_effect = [self.mock_curses.KEY_DOWN, ord("q")]
        self.win.user_input()
        self.assertEqual(self.win.position, self.win.bottom)
        self.win.window.getch.side_effect = [self.mock_curses.KEY_NPAGE, ord("q")]
        self.win.user_input()
        self.assertEqual(self.win.position, self.win.bottom) 
Example #13
Source File: memanz_curses.py    From memory-analyzer with MIT License 5 votes vote down vote up
def scroll_down(self, user_select):
        if (
            user_select in [curses.KEY_DOWN, ord("s"), ord("j")]
            and self.position + self.height <= self.bottom
        ):
            self.position += self.DOWN
        elif user_select == ord("G") and self.position + self.height != self.bottom:
            self.position = self.bottom - self.height + 1
        elif user_select == curses.KEY_NPAGE:
            if self.position + self.height < self.bottom - self.height:
                self.position = self.position + self.height
            else:
                self.position = self.bottom - self.height + 1 
Example #14
Source File: curses_ui_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testRunUIScrollTallOutputPageDownUp(self):
    """Scroll tall output with PageDown and PageUp."""

    # Use PageDown and PageUp to scroll back and forth a little before exiting.
    ui = MockCursesUI(
        40,
        80,
        command_sequence=[string_to_codes("babble\n"), [curses.KEY_NPAGE] * 2 +
                          [curses.KEY_PPAGE] + self._EXIT])

    ui.register_command_handler("babble", self._babble, "")
    ui.run_ui()

    # Screen output/scrolling should have happened exactly once.
    self.assertEqual(4, len(ui.unwrapped_outputs))
    self.assertEqual(4, len(ui.wrapped_outputs))
    self.assertEqual(4, len(ui.scroll_messages))

    # Before scrolling.
    self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[0].lines)
    self.assertEqual(["bar"] * 60, ui.wrapped_outputs[0].lines[:60])

    # Initial scroll: At the top.
    self.assertIn("Scroll: 0.00%", ui.scroll_messages[0])

    # After 1st scrolling (PageDown).
    # The screen output shouldn't have changed. Only the viewport should.
    self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[0].lines)
    self.assertEqual(["bar"] * 60, ui.wrapped_outputs[0].lines[:60])
    self.assertIn("Scroll: 1.69%", ui.scroll_messages[1])

    # After 2nd scrolling (PageDown).
    self.assertIn("Scroll: 3.39%", ui.scroll_messages[2])

    # After 3rd scrolling (PageUp).
    self.assertIn("Scroll: 1.69%", ui.scroll_messages[3]) 
Example #15
Source File: wggrid.py    From apple_bleee with GNU General Public License v3.0 5 votes vote down vote up
def set_up_handlers(self):
        super(SimpleGrid, self).set_up_handlers()
        self.handlers = {
                    curses.KEY_UP:      self.h_move_line_up,
                    curses.KEY_LEFT:    self.h_move_cell_left,
                    curses.KEY_DOWN:    self.h_move_line_down,
                    curses.KEY_RIGHT:   self.h_move_cell_right,
                    "k":                self.h_move_line_up,
                    "h":                self.h_move_cell_left,
                    "j":                self.h_move_line_down,
                    "l":                self.h_move_cell_right,
                    curses.KEY_NPAGE:   self.h_move_page_down,
                    curses.KEY_PPAGE:   self.h_move_page_up,
                    curses.KEY_HOME:    self.h_show_beginning,
                    curses.KEY_END:     self.h_show_end,
                    ord('g'):           self.h_show_beginning,
                    ord('G'):           self.h_show_end,
                    curses.ascii.TAB:   self.h_exit,
                    curses.KEY_BTAB:     self.h_exit_up,
                    '^P':               self.h_exit_up,
                    '^N':               self.h_exit_down,
                    #curses.ascii.NL:    self.h_exit,
                    #curses.ascii.SP:    self.h_exit,
                    #ord('x'):       self.h_exit,
                    ord('q'):       self.h_exit,
                    curses.ascii.ESC:   self.h_exit,
                    curses.KEY_MOUSE:    self.h_exit_mouse,
                }

        self.complex_handlers = [
                    ] 
Example #16
Source File: wgmultiline.py    From apple_bleee with GNU General Public License v3.0 5 votes vote down vote up
def set_up_handlers(self):
        super(Pager, self).set_up_handlers()
        self.handlers = {
            curses.KEY_UP: self.h_scroll_line_up,
            curses.KEY_LEFT: self.h_scroll_line_up,
            curses.KEY_DOWN: self.h_scroll_line_down,
            curses.KEY_RIGHT: self.h_scroll_line_down,
            curses.KEY_NPAGE: self.h_scroll_page_down,
            curses.KEY_PPAGE: self.h_scroll_page_up,
            curses.KEY_HOME: self.h_show_beginning,
            curses.KEY_END: self.h_show_end,
            curses.ascii.NL: self.h_exit,
            curses.ascii.CR: self.h_exit,
            curses.ascii.SP: self.h_scroll_page_down,
            curses.ascii.TAB: self.h_exit,
            ord('j'): self.h_scroll_line_down,
            ord('k'): self.h_scroll_line_up,
            ord('x'): self.h_exit,
            ord('q'): self.h_exit,
            ord('g'): self.h_show_beginning,
            ord('G'): self.h_show_end,
            curses.ascii.ESC: self.h_exit_escape,
        }

        self.complex_handlers = [
        ] 
Example #17
Source File: keyboard.py    From deepWordBug with Apache License 2.0 5 votes vote down vote up
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())) 
Example #18
Source File: curses_ui_test.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def testRunUIScrollTallOutputPageDownUp(self):
    """Scroll tall output with PageDown and PageUp."""

    # Use PageDown and PageUp to scroll back and forth a little before exiting.
    ui = MockCursesUI(
        40,
        80,
        command_sequence=[string_to_codes("babble\n"), [curses.KEY_NPAGE] * 2 +
                          [curses.KEY_PPAGE] + self._EXIT])

    ui.register_command_handler("babble", self._babble, "")
    ui.run_ui()

    # Screen output/scrolling should have happened exactly once.
    self.assertEqual(4, len(ui.unwrapped_outputs))
    self.assertEqual(4, len(ui.wrapped_outputs))
    self.assertEqual(4, len(ui.scroll_messages))

    # Before scrolling.
    self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[0].lines)
    self.assertEqual(["bar"] * 60, ui.wrapped_outputs[0].lines[:60])

    # Initial scroll: At the top.
    self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[0])
    self.assertIn("Mouse:", ui.scroll_messages[0])

    # After 1st scrolling (PageDown).
    # The screen output shouldn't have changed. Only the viewport should.
    self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[0].lines)
    self.assertEqual(["bar"] * 60, ui.wrapped_outputs[0].lines[:60])
    self.assertIn("Scroll (PgDn/PgUp): 1.69%", ui.scroll_messages[1])
    self.assertIn("Mouse:", ui.scroll_messages[1])

    # After 2nd scrolling (PageDown).
    self.assertIn("Scroll (PgDn/PgUp): 3.39%", ui.scroll_messages[2])
    self.assertIn("Mouse:", ui.scroll_messages[2])

    # After 3rd scrolling (PageUp).
    self.assertIn("Scroll (PgDn/PgUp): 1.69%", ui.scroll_messages[3])
    self.assertIn("Mouse:", ui.scroll_messages[3]) 
Example #19
Source File: wgmultiline.py    From HomePWN with GNU General Public License v3.0 4 votes vote down vote up
def set_up_handlers(self):
        super(MultiLine, self).set_up_handlers()
        self.handlers.update({
            curses.KEY_UP: self.h_cursor_line_up,
            ord('k'): self.h_cursor_line_up,
            curses.KEY_LEFT: self.h_cursor_line_up,
            curses.KEY_DOWN: self.h_cursor_line_down,
            ord('j'): self.h_cursor_line_down,
            curses.KEY_RIGHT: self.h_cursor_line_down,
            curses.KEY_NPAGE: self.h_cursor_page_down,
            curses.KEY_PPAGE: self.h_cursor_page_up,
            curses.ascii.TAB: self.h_exit_down,
            curses.ascii.NL: self.h_select_exit,
            curses.KEY_HOME: self.h_cursor_beginning,
            curses.KEY_END: self.h_cursor_end,
            ord('g'): self.h_cursor_beginning,
            ord('G'): self.h_cursor_end,
            ord('x'): self.h_select,
            # "^L":        self.h_set_filtered_to_selected,
            curses.ascii.SP: self.h_select,
            curses.ascii.ESC: self.h_exit_escape,
            curses.ascii.CR: self.h_select_exit,
        })

        if self.allow_filtering:
            self.handlers.update({
                ord('l'): self.h_set_filter,
                ord('L'): self.h_clear_filter,
                ord('n'): self.move_next_filtered,
                ord('N'): self.move_previous_filtered,
                ord('p'): self.move_previous_filtered,
                # "^L":        self.h_set_filtered_to_selected,

            })

        if self.exit_left:
            self.handlers.update({
                curses.KEY_LEFT: self.h_exit_left
            })

        if self.exit_right:
            self.handlers.update({
                curses.KEY_RIGHT: self.h_exit_right
            })

        self.complex_handlers = [
            # (self.t_input_isprint, self.h_find_char)
        ] 
Example #20
Source File: tabview.py    From OpenTrader with GNU Lesser General Public License v3.0 4 votes vote down vote up
def define_keys(self):
        self.keys = {'j':   self.down,
                     'k':   self.up,
                     'h':   self.left,
                     'l':   self.right,
                     'J':   self.page_down,
                     'K':   self.page_up,
                     'm':   self.mark,
                     "'":   self.goto_mark,
                     'L':   self.page_right,
                     'H':   self.page_left,
                     'q':   self.quit,
                     'Q':   self.quit,
                     '$':   self.line_end,
                     '^':   self.line_home,
                     '0':   self.line_home,
                     'g':   self.home,
                     'G':   self.goto_row,
                     '|':   self.goto_col,
                     '\n':  self.show_cell,
                     '/':   self.search,
                     'n':   self.search_results,
                     'p':   self.search_results_prev,
                     't':   self.toggle_header,
                     '-':   self.column_gap_down,
                     '+':   self.column_gap_up,
                     '<':   self.column_width_all_down,
                     '>':   self.column_width_all_up,
                     ',':   self.column_width_down,
                     '.':   self.column_width_up,
                     'a':   self.sort_by_column_natural,
                     'A':   self.sort_by_column_natural_reverse,
                     's':   self.sort_by_column,
                     'S':   self.sort_by_column_reverse,
                     'y':   self.yank_cell,
                     'r':   self.reload,
                     'c':   self.toggle_column_width,
                     'C':   self.set_current_column_width,
                     ']':   self.skip_to_row_change,
                     '[':   self.skip_to_row_change_reverse,
                     '}':   self.skip_to_col_change,
                     '{':   self.skip_to_col_change_reverse,
                     '?':   self.help,
                     curses.KEY_F1:     self.help,
                     curses.KEY_UP:     self.up,
                     curses.KEY_DOWN:   self.down,
                     curses.KEY_LEFT:   self.left,
                     curses.KEY_RIGHT:  self.right,
                     curses.KEY_HOME:   self.line_home,
                     curses.KEY_END:    self.line_end,
                     curses.KEY_PPAGE:  self.page_up,
                     curses.KEY_NPAGE:  self.page_down,
                     curses.KEY_IC:     self.mark,
                     curses.KEY_DC:     self.goto_mark,
                     curses.KEY_ENTER:  self.show_cell,
                     KEY_CTRL('a'):  self.line_home,
                     KEY_CTRL('e'):  self.line_end,
                     } 
Example #21
Source File: wgmultiline.py    From EDCOP with Apache License 2.0 4 votes vote down vote up
def set_up_handlers(self):
        super(MultiLine, self).set_up_handlers()
        self.handlers.update ( {
                    curses.KEY_UP:      self.h_cursor_line_up,
                    ord('k'):       self.h_cursor_line_up,
                    curses.KEY_LEFT:    self.h_cursor_line_up,
                    curses.KEY_DOWN:    self.h_cursor_line_down,
                    ord('j'):       self.h_cursor_line_down,
                    curses.KEY_RIGHT:   self.h_cursor_line_down,
                    curses.KEY_NPAGE:   self.h_cursor_page_down,
                    curses.KEY_PPAGE:   self.h_cursor_page_up,
                    curses.ascii.TAB:   self.h_exit_down,
                    curses.ascii.NL:    self.h_select_exit,
                    curses.KEY_HOME:    self.h_cursor_beginning,
                    curses.KEY_END:     self.h_cursor_end,
                    ord('g'):           self.h_cursor_beginning,
                    ord('G'):           self.h_cursor_end,
                    ord('x'):           self.h_select,
                    # "^L":        self.h_set_filtered_to_selected,
                    curses.ascii.SP:    self.h_select,
                    curses.ascii.ESC:   self.h_exit_escape,
                    curses.ascii.CR:    self.h_select_exit,
                } )
                
        if self.allow_filtering:
            self.handlers.update ( {
                ord('l'):       self.h_set_filter,
                ord('L'):       self.h_clear_filter,
                ord('n'):       self.move_next_filtered,
                ord('N'):       self.move_previous_filtered,
                ord('p'):       self.move_previous_filtered,
                # "^L":        self.h_set_filtered_to_selected,
                
            } )
            
                
        if self.exit_left:
            self.handlers.update({
                    curses.KEY_LEFT:    self.h_exit_left
            })
        
        if self.exit_right:
            self.handlers.update({
                    curses.KEY_RIGHT:   self.h_exit_right
            })

        self.complex_handlers = [
                    #(self.t_input_isprint, self.h_find_char)
                    ] 
Example #22
Source File: __init__.py    From pipenv-pipes with MIT License 4 votes vote down vote up
def run_loop(self):
        debug_info = None
        while True:
            self.draw(debug_info=debug_info)
            key = self.screen.getch()

            try:
                key_string = chr(key)
            except ValueError:
                continue

            if self.debug_mode and key > 0:
                # when stretching windows, key = -1
                debug_info = {'key': key}

            if key in KEYS_ESCAPE:
                sys.exit(0)

            if key in KEYS_ENTER:
                if not self.environments:
                    continue
                return self.get_selected()

            if re.search(r'[A-Za-z0-9\s\-_]', key_string):
                self.query += key_string
                self.expanded = 0
                for n, environment in enumerate(self.environments):
                    if environment.envname.startswith(self.query):
                        self.index = n
                        break

            elif key == curses.KEY_PPAGE:
                self.move_up(5)

            elif key == curses.KEY_NPAGE:
                self.move_down(5)

            elif key in KEYS_UP:
                self.move_up(1)

            elif key in KEYS_DOWN:
                self.move_down(1)

            elif key in KEYS_HOME:
                self.move_top()

            elif key in KEYS_END:
                self.move_bottom()

            elif key in KEYS_CLEAR:
                self.clear_query()

            elif key in KEYS_RIGHT:
                self.expand_next()

            elif key in KEYS_LEFT:
                self.expand_prev()

            elif key in KEYS_BACKSPACE:
                self.query = self.query[:-1] 
Example #23
Source File: wgmultiline.py    From TelegramTUI with MIT License 4 votes vote down vote up
def set_up_handlers(self):
        super(MultiLine, self).set_up_handlers()
        self.handlers.update({
            curses.KEY_UP: self.h_cursor_line_up,
            ord('k'): self.h_cursor_line_up,
            curses.KEY_LEFT: self.h_cursor_line_up,
            curses.KEY_DOWN: self.h_cursor_line_down,
            ord('j'): self.h_cursor_line_down,
            curses.KEY_RIGHT: self.h_cursor_line_down,
            curses.KEY_NPAGE: self.h_cursor_page_down,
            curses.KEY_PPAGE: self.h_cursor_page_up,
            curses.ascii.TAB: self.h_exit_down,
            curses.ascii.NL: self.h_select_exit,
            curses.KEY_HOME: self.h_cursor_beginning,
            curses.KEY_END: self.h_cursor_end,
            ord('g'): self.h_cursor_beginning,
            ord('G'): self.h_cursor_end,
            ord('x'): self.h_select,
            # "^L":        self.h_set_filtered_to_selected,
            curses.ascii.SP: self.h_select,
            curses.ascii.ESC: self.h_exit_escape,
            curses.ascii.CR: self.h_select_exit,
        })

        if self.allow_filtering:
            self.handlers.update({
                ord('l'): self.h_set_filter,
                ord('L'): self.h_clear_filter,
                ord('n'): self.move_next_filtered,
                ord('N'): self.move_previous_filtered,
                ord('p'): self.move_previous_filtered,
                # "^L":        self.h_set_filtered_to_selected,

            })

        if self.exit_left:
            self.handlers.update({
                curses.KEY_LEFT: self.h_exit_left
            })

        if self.exit_right:
            self.handlers.update({
                curses.KEY_RIGHT: self.h_exit_right
            })

        self.complex_handlers = [
            # (self.t_input_isprint, self.h_find_char)
        ] 
Example #24
Source File: wgmultiline.py    From apple_bleee with GNU General Public License v3.0 4 votes vote down vote up
def set_up_handlers(self):
        super(MultiLine, self).set_up_handlers()
        self.handlers.update({
            curses.KEY_UP: self.h_cursor_line_up,
            ord('k'): self.h_cursor_line_up,
            curses.KEY_LEFT: self.h_cursor_line_up,
            curses.KEY_DOWN: self.h_cursor_line_down,
            ord('j'): self.h_cursor_line_down,
            curses.KEY_RIGHT: self.h_cursor_line_down,
            curses.KEY_NPAGE: self.h_cursor_page_down,
            curses.KEY_PPAGE: self.h_cursor_page_up,
            curses.ascii.TAB: self.h_exit_down,
            curses.ascii.NL: self.h_select_exit,
            curses.KEY_HOME: self.h_cursor_beginning,
            curses.KEY_END: self.h_cursor_end,
            ord('g'): self.h_cursor_beginning,
            ord('G'): self.h_cursor_end,
            ord('x'): self.h_select,
            # "^L":        self.h_set_filtered_to_selected,
            curses.ascii.SP: self.h_select,
            curses.ascii.ESC: self.h_exit_escape,
            curses.ascii.CR: self.h_select_exit,
        })

        if self.allow_filtering:
            self.handlers.update({
                ord('l'): self.h_set_filter,
                ord('L'): self.h_clear_filter,
                ord('n'): self.move_next_filtered,
                ord('N'): self.move_previous_filtered,
                ord('p'): self.move_previous_filtered,
                # "^L":        self.h_set_filtered_to_selected,

            })

        if self.exit_left:
            self.handlers.update({
                curses.KEY_LEFT: self.h_exit_left
            })

        if self.exit_right:
            self.handlers.update({
                curses.KEY_RIGHT: self.h_exit_right
            })

        self.complex_handlers = [
            # (self.t_input_isprint, self.h_find_char)
        ]