本文整理汇总了Python中curses.KEY_RESIZE属性的典型用法代码示例。如果您正苦于以下问题:Python curses.KEY_RESIZE属性的具体用法?Python curses.KEY_RESIZE怎么用?Python curses.KEY_RESIZE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类curses
的用法示例。
在下文中一共展示了curses.KEY_RESIZE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_keys
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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()
示例2: testTerminalResize
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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])
示例3: _get_key_py33
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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
示例4: _screen_get_user_command
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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)
示例5: testTerminalResize
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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])
示例6: test1
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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
示例7: event_listener
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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
示例8: event_listener
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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
示例9: event_listener
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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
示例10: _key_debug
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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
示例11: test_key_debug
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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()
示例12: _curses_keybindings
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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
示例13: test_terminal_text_input
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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
示例14: setup_handlers
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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,
}
示例15: _screen_get_user_command
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_RESIZE [as 别名]
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)