Python curses.KEY_RESIZE Examples
The following are 30
code examples of curses.KEY_RESIZE().
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: curses_ui_test.py From keras-lambda with MIT License | 6 votes |
def testTerminalResize(self): ui = MockCursesUI( 40, 80, command_sequence=[string_to_codes("babble\n"), [curses.KEY_RESIZE, 100, 85], # Resize to [100, 85] self._EXIT]) ui.register_command_handler( "babble", self._babble, "babble some", prefix_aliases=["b"]) ui.run_ui() # The resize event should have caused a second screen output event. self.assertEqual(2, len(ui.unwrapped_outputs)) self.assertEqual(2, len(ui.wrapped_outputs)) self.assertEqual(2, len(ui.scroll_messages)) # The 1st and 2nd screen outputs should be identical (unwrapped). self.assertEqual(ui.unwrapped_outputs[0], ui.unwrapped_outputs[1]) # The 1st scroll info should contain scrolling, because the screen size # is less than the number of lines in the output. self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[0])
Example #2
Source File: key_debug_test.py From babi with MIT License | 6 votes |
def test_key_debug(run): with run('--key-debug') as h: h.await_text(VERSION_STR, timeout=2) h.await_text('press q to quit') h.press('a') h.await_text("'a' 'STRING'") h.press('^X') h.await_text(r"'\x18' '^X'") with h.resize(width=20, height=20): h.await_text(f"{curses.KEY_RESIZE} 'KEY_RESIZE'") h.press('q') h.await_exit()
Example #3
Source File: main.py From babi with MIT License | 6 votes |
def _key_debug(stdscr: 'curses._CursesWindow', perf: Perf) -> int: screen = Screen(stdscr, ['<<key debug>>'], [0], perf) screen.file.buf = Buf(['']) while True: screen.status.update('press q to quit') screen.draw() screen.file.move_cursor(screen.stdscr, screen.margin) key = screen.get_char() screen.file.buf.insert(-1, f'{key.wch!r} {key.keyname.decode()!r}') screen.file.down(screen.margin) if key.wch == curses.KEY_RESIZE: screen.resize() if key.wch == 'q': return 0
Example #4
Source File: inspect.py From flowcraft with GNU General Public License v3.0 | 6 votes |
def _curses_keybindings(self): c = self.screen.getch() # Provide scroll up/down with keys or mouse wheel if c == curses.KEY_UP: self._updown("up") elif c == curses.KEY_DOWN: self._updown("down") elif c == curses.KEY_LEFT: self._rightleft("left") elif c == curses.KEY_RIGHT: self._rightleft("right") # Trigger screen size update on resize elif c == curses.KEY_RESIZE: self.screen_lines = self.screen.getmaxyx()[0] # Exit interface when pressing q elif c == ord('q'): raise Exception
Example #5
Source File: top.py From python-scripts with GNU General Public License v3.0 | 6 votes |
def event_listener(scr, timeout): ''' Wait for curses events on screen ``scr`` at mot ``timeout`` ms return - 1 OK - 2 redraw - 0 error ''' try: scr.timeout(timeout) c = scr.getch() if c == -1: return 1 elif c == curses.KEY_MOUSE: return on_mouse() elif c == curses.KEY_RESIZE: return on_resize() else: return on_keyboard(scr, c) except _curses.error: return 0
Example #6
Source File: cgroup_top.py From python-scripts with GNU General Public License v3.0 | 6 votes |
def event_listener(scr, timeout): ''' Wait for curses events on screen ``scr`` at mot ``timeout`` ms return - 1 OK - 2 redraw - 0 error ''' try: scr.timeout(timeout) c = scr.getch() if c == -1: return 1 elif c == curses.KEY_MOUSE: return on_mouse() elif c == curses.KEY_RESIZE: return on_resize() else: return on_keyboard(c) except _curses.error: return 0
Example #7
Source File: cgroup_top.py From ctop with MIT License | 6 votes |
def event_listener(scr, timeout): ''' Wait for curses events on screen ``scr`` at mot ``timeout`` ms return - 1 OK - 2 redraw - 0 error ''' try: scr.timeout(timeout) c = scr.getch() if c == -1: return 1 elif c == curses.KEY_MOUSE: return on_mouse() elif c == curses.KEY_RESIZE: return on_resize() else: return on_keyboard(c) except _curses.error: return 0
Example #8
Source File: ncurses.py From collection with MIT License | 6 votes |
def test1(): def main(scr): scr.border() while True: print('fuck') ch = scr.getch() if ch == ord('q'): break if ch == curses.KEY_RESIZE: y, x = scr.getmaxyx() print('resize %dx%d'%(x, y)) return 0 print('hello') nc.wrapper(main) print('end') return 0
Example #9
Source File: curses_ui_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def testTerminalResize(self): ui = MockCursesUI( 40, 80, command_sequence=[string_to_codes("babble\n"), [curses.KEY_RESIZE, 100, 85], # Resize to [100, 85] self._EXIT]) ui.register_command_handler( "babble", self._babble, "babble some", prefix_aliases=["b"]) ui.run_ui() # The resize event should have caused a second screen output event. self.assertEqual(2, len(ui.unwrapped_outputs)) self.assertEqual(2, len(ui.wrapped_outputs)) self.assertEqual(2, len(ui.scroll_messages)) # The 1st and 2nd screen outputs should be identical (unwrapped). self.assertEqual(ui.unwrapped_outputs[0], ui.unwrapped_outputs[1]) # The 1st scroll info should contain scrolling, because the screen size # is less than the number of lines in the output. self.assertIn("Scroll: 0.00%", ui.scroll_messages[0])
Example #10
Source File: curses_ui_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def _screen_get_user_command(self): command = self._command_sequence[self._command_counter] self._command_key_counter = 0 for c in command: if c == curses.KEY_RESIZE: # Special case for simulating a terminal resize event in curses. self._height = command[1] self._width = command[2] self._on_textbox_keypress(c) self._command_counter += 1 return "" y = self._on_textbox_keypress(c) self._command_key_counter += 1 if y == curses_ui.CursesUI.CLI_TERMINATOR_KEY: break self._command_counter += 1 # Take into account pre-existing string automatically entered on textbox # creation. return self._curr_existing_command + codes_to_string(command)
Example #11
Source File: screen.py From wpm with GNU Affero General Public License v3.0 | 6 votes |
def _get_key_py33(self): """Python 3.3+ implementation of get_key.""" # pylint: disable=too-many-return-statements try: # Curses in Python 3.3 handles unicode via get_wch key = self.window.get_wch() if isinstance(key, int): if key == curses.KEY_BACKSPACE: return "KEY_BACKSPACE" if key == curses.KEY_LEFT: return "KEY_LEFT" if key == curses.KEY_RIGHT: return "KEY_RIGHT" if key == curses.KEY_RESIZE: return "KEY_RESIZE" return None return key except curses.error: return None except KeyboardInterrupt: raise
Example #12
Source File: test_terminal.py From rtv with MIT License | 6 votes |
def test_terminal_text_input(terminal, stdscr, use_ascii): terminal.config['ascii'] = use_ascii stdscr.nlines = 1 # Text will be wrong because stdscr.inch() is not implemented # But we can at least tell if text was captured or not stdscr.getch.side_effect = [ord('h'), ord('i'), ord('!'), terminal.RETURN] assert isinstance(terminal.text_input(stdscr), six.text_type) stdscr.getch.side_effect = [ord('b'), ord('y'), ord('e'), terminal.ESCAPE] assert terminal.text_input(stdscr) is None stdscr.getch.side_effect = [ord('h'), curses.KEY_RESIZE, terminal.RETURN] assert terminal.text_input(stdscr, allow_resize=True) is not None stdscr.getch.side_effect = [ord('h'), curses.KEY_RESIZE, terminal.RETURN] assert terminal.text_input(stdscr, allow_resize=False) is None
Example #13
Source File: curses_ui_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testTerminalResize(self): ui = MockCursesUI( 40, 80, command_sequence=[string_to_codes("babble\n"), [curses.KEY_RESIZE, 100, 85], # Resize to [100, 85] self._EXIT]) ui.register_command_handler( "babble", self._babble, "babble some", prefix_aliases=["b"]) ui.run_ui() # The resize event should have caused a second screen output event. self.assertEqual(2, len(ui.unwrapped_outputs)) self.assertEqual(2, len(ui.wrapped_outputs)) self.assertEqual(2, len(ui.scroll_messages)) # The 1st and 2nd screen outputs should be identical (unwrapped). self.assertEqual(ui.unwrapped_outputs[0], ui.unwrapped_outputs[1]) # The 1st scroll info should contain scrolling, because the screen size # is less than the number of lines in the output. self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[0])
Example #14
Source File: tabview.py From OpenTrader with GNU Lesser General Public License v3.0 | 6 votes |
def handle_keys(self): """Determine what method to call for each keypress. """ c = self.scr.getch() # Get a keystroke if c == curses.KEY_RESIZE: self.resize() return if 0 < c < 256: c = chr(c) # Digits are commands without a modifier try: found_digit = c.isdigit() except AttributeError: # Since .isdigit() doesn't exist if c > 256, we need to catch the # error for those keys. found_digit = False if found_digit and (len(self.modifier) > 0 or c not in self.keys): self.handle_modifier(c) elif c in self.keys: self.keys[c]() else: self.modifier = str()
Example #15
Source File: screen.py From wpm with GNU Affero General Public License v3.0 | 5 votes |
def _get_key_py27(self): """Python 2.7 implementation of get_key.""" # pylint: disable=too-many-return-statements try: key = self.window.getkey() # Start of UTF-8 multi-byte character? if self.encoding == "utf-8" and ord(key[0]) & 0x80: multibyte = key[0] cont_bytes = ord(key[0]) << 1 while cont_bytes & 0x80: cont_bytes <<= 1 multibyte += self.window.getkey()[0] return multibyte.decode(self.encoding) if isinstance(key, int): if key == curses.KEY_BACKSPACE: return "KEY_BACKSPACE" if key == curses.KEY_LEFT: return "KEY_LEFT" if key == curses.KEY_RIGHT: return "KEY_RIGHT" if key == curses.KEY_RESIZE: return "KEY_RESIZE" return None return key.decode("ascii") except KeyboardInterrupt: raise except curses.error: return None
Example #16
Source File: program_window.py From ci_edit with Apache License 2.0 | 5 votes |
def executeCommandList(self, cmdList): for cmd, eventInfo in cmdList: self.doPreCommand() 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()
Example #17
Source File: curses_util.py From ci_edit with Apache License 2.0 | 5 votes |
def hackCursesFixes(): if sys.platform == u'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)
Example #18
Source File: conftest.py From babi with MIT License | 5 votes |
def resize(self, *, width, height): orig_width, orig_height = self.screen.width, self.screen.height self._ops.append(Resize(width, height)) self._ops.append(KeyPress(curses.KEY_RESIZE)) try: yield finally: self._ops.append(Resize(orig_width, orig_height)) self._ops.append(KeyPress(curses.KEY_RESIZE))
Example #19
Source File: fake_curses_testing.py From ci_edit with Apache License 2.0 | 5 votes |
def resizeScreen(self, rows, cols): assert isinstance(rows, int) assert isinstance(cols, int) def setScreenSize(display, cmdIndex): self.cursesScreen.fakeDisplay.setScreenSize(rows, cols) return curses.KEY_RESIZE return setScreenSize
Example #20
Source File: tabview.py From OpenTrader with GNU Lesser General Public License v3.0 | 5 votes |
def setup_handlers(self): self.handlers = {'\n': self.close, curses.KEY_ENTER: self.close, 'q': self.close, curses.KEY_RESIZE: self.close, curses.KEY_DOWN: self.scroll_down, 'j': self.scroll_down, curses.KEY_UP: self.scroll_up, 'k': self.scroll_up, }
Example #21
Source File: curses_ui_test.py From keras-lambda with MIT License | 5 votes |
def _screen_get_user_command(self): command = self._command_sequence[self._command_counter] self._command_key_counter = 0 for c in command: if c == curses.KEY_RESIZE: # Special case for simulating a terminal resize event in curses. self._height = command[1] self._width = command[2] self._on_textbox_keypress(c) self._command_counter += 1 return "" elif c == curses.KEY_MOUSE: mouse_x = command[1] mouse_y = command[2] self._command_counter += 1 self._textbox_curr_terminator = c return self._fetch_hyperlink_command(mouse_x, mouse_y) else: y = self._on_textbox_keypress(c) self._command_key_counter += 1 if y == curses_ui.CursesUI.CLI_TERMINATOR_KEY: break self._command_counter += 1 # Take into account pre-existing string automatically entered on textbox # creation. return self._curr_existing_command + codes_to_string(command)
Example #22
Source File: screen.py From asciimatics with Apache License 2.0 | 5 votes |
def get_event(self): """ Check for an event without waiting. """ # Spin through notifications until we find something we want. key = 0 while key != -1: # Get the next key key = self._screen.getch() if key == curses.KEY_RESIZE: # Handle screen resize self._re_sized = True elif key == curses.KEY_MOUSE: # Handle a mouse event _, x, y, _, bstate = curses.getmouse() buttons = 0 # Some Linux modes only report clicks, so check for any # button down or click events. if (bstate & curses.BUTTON1_PRESSED != 0 or bstate & curses.BUTTON1_CLICKED != 0): buttons |= MouseEvent.LEFT_CLICK if (bstate & curses.BUTTON3_PRESSED != 0 or bstate & curses.BUTTON3_CLICKED != 0): buttons |= MouseEvent.RIGHT_CLICK if bstate & curses.BUTTON1_DOUBLE_CLICKED != 0: buttons |= MouseEvent.DOUBLE_CLICK return MouseEvent(x, y, buttons) elif key != -1: # Handle any byte streams first logger.debug("Processing key: %x", key) if self._unicode_aware and key > 0: if key & 0xC0 == 0xC0: self._bytes_to_return = struct.pack(b"B", key) self._bytes_to_read = bin(key)[2:].index("0") - 1 logger.debug("Byte stream: %d bytes left", self._bytes_to_read) continue elif self._bytes_to_read > 0: self._bytes_to_return += struct.pack(b"B", key) self._bytes_to_read -= 1 if self._bytes_to_read > 0: continue else: key = ord(self._bytes_to_return.decode("utf-8")) # Handle a genuine key press. logger.debug("Returning key: %x", key) if key in self._KEY_MAP: return KeyboardEvent(self._KEY_MAP[key]) elif key != -1: return KeyboardEvent(key) return None
Example #23
Source File: app.py From toot with GNU General Public License v3.0 | 5 votes |
def loop(self): self.show() while True: ch = self.window.getch() key = chr(ch).lower() if curses.ascii.isprint(ch) else None if key == 'q': break elif ch == curses.KEY_RESIZE: if self.resize_callback: self.resize_callback() self.full_redraw() self.hide()
Example #24
Source File: fmForm.py From EDCOP with Apache License 2.0 | 5 votes |
def set_up_handlers(self): self.complex_handlers = [] self.handlers = { curses.KEY_F1: self.h_display_help, "KEY_F(1)": self.h_display_help, "^O": self.h_display_help, "^L": self.h_display, curses.KEY_RESIZE: self._resize, }
Example #25
Source File: termpdf.py From termpdf.py with MIT License | 5 votes |
def __init__(self): self.GOTO_PAGE = [ord('G')] self.GOTO = [ord('g')] self.NEXT_PAGE = [ord('j'), curses.KEY_DOWN, ord(' ')] self.PREV_PAGE = [ord('k'), curses.KEY_UP] self.GO_BACK = [ord('p')] self.NEXT_CHAP = [ord('l'), curses.KEY_RIGHT] self.PREV_CHAP = [ord('h'), curses.KEY_LEFT] self.BUFFER_CYCLE = [ord('b')] self.BUFFER_CYCLE_REV = [ord('B')] self.HINTS = [ord('f')] self.OPEN = [curses.KEY_ENTER, curses.KEY_RIGHT, 10] self.SHOW_TOC = [ord('t')] self.SHOW_META = [ord('M')] self.UPDATE_FROM_BIB = [ord('b')] self.SHOW_LINKS = [ord('f')] self.TOGGLE_TEXT_MODE = [ord('T')] self.ROTATE_CW = [ord('r')] self.ROTATE_CCW = [ord('R')] self.VISUAL_MODE = [ord('s')] self.SELECT = [ord('v')] self.YANK = [ord('y')] self.INSERT_NOTE = [ord('n')] self.APPEND_NOTE = [ord('a')] self.TOGGLE_AUTOCROP = [ord('c')] self.TOGGLE_ALPHA = [ord('A')] self.TOGGLE_INVERT = [ord('i')] self.TOGGLE_TINT = [ord('d')] self.SET_PAGE_LABEL = [ord('P')] self.SET_PAGE_ALT = [ord('I')] self.INC_FONT = [ord('=')] self.DEC_FONT = [ord('-')] self.OPEN_GUI = [ord('X')] self.REFRESH = [18, curses.KEY_RESIZE] # CTRL-R self.QUIT = [3, ord('q')] self.DEBUG = [ord('D')] # Kitty graphics functions
Example #26
Source File: app.py From toot with GNU General Public License v3.0 | 5 votes |
def loop(self): while True: ch = self.left.pad.getch() key = chr(ch).lower() if curses.ascii.isprint(ch) else None if key == 'q': return elif key == 'h': self.help_modal.loop() self.full_redraw() elif key == 'v': status = self.get_selected_status() if status: webbrowser.open(status['url']) elif key == 'j' or ch == curses.KEY_DOWN: self.select_next() elif key == 'k' or ch == curses.KEY_UP: self.select_previous() elif key == 's': self.show_sensitive() elif key == 'b': self.toggle_reblog() elif key == 'f': self.toggle_favourite() elif key == 'c': self.compose() elif key == 'r': self.reply() elif ch == curses.KEY_RESIZE: self.on_resize()
Example #27
Source File: fmForm.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def set_up_handlers(self): self.complex_handlers = [] self.handlers = { curses.KEY_F1: self.h_display_help, "KEY_F(1)": self.h_display_help, "^O": self.h_display_help, "^L": self.h_display, curses.KEY_RESIZE: self._resize, }
Example #28
Source File: fmForm.py From TelegramTUI with MIT License | 5 votes |
def set_up_handlers(self): self.complex_handlers = [] self.handlers = { curses.KEY_F1: self.h_display_help, "KEY_F(1)": self.h_display_help, "^O": self.h_display_help, "^L": self.h_display, curses.KEY_RESIZE: self._resize, }
Example #29
Source File: curses_ui_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _screen_get_user_command(self): command = self._command_sequence[self._command_counter] self._command_key_counter = 0 for c in command: if c == curses.KEY_RESIZE: # Special case for simulating a terminal resize event in curses. self._height = command[1] self._width = command[2] self._on_textbox_keypress(c) self._command_counter += 1 return "" elif c == curses.KEY_MOUSE: mouse_x = command[1] mouse_y = command[2] self._command_counter += 1 self._textbox_curr_terminator = c return self._fetch_hyperlink_command(mouse_x, mouse_y) else: y = self._on_textbox_keypress(c) self._command_key_counter += 1 if y == curses_ui.CursesUI.CLI_TERMINATOR_KEY: break self._command_counter += 1 # Take into account pre-existing string automatically entered on textbox # creation. return self._curr_existing_command + codes_to_string(command)
Example #30
Source File: fmForm.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
def set_up_handlers(self): self.complex_handlers = [] self.handlers = { curses.KEY_F1: self.h_display_help, "KEY_F(1)": self.h_display_help, "^O": self.h_display_help, "^L": self.h_display, curses.KEY_RESIZE: self._resize, }