本文整理汇总了Python中curses.KEY_BACKSPACE属性的典型用法代码示例。如果您正苦于以下问题:Python curses.KEY_BACKSPACE属性的具体用法?Python curses.KEY_BACKSPACE怎么用?Python curses.KEY_BACKSPACE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类curses
的用法示例。
在下文中一共展示了curses.KEY_BACKSPACE属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_key_py33
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_BACKSPACE [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
示例2: set_up_handlers
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_BACKSPACE [as 别名]
def set_up_handlers(self):
super(Textfield, self).set_up_handlers()
# For OS X
del_key = curses.ascii.alt('~')
self.handlers.update({curses.KEY_LEFT: self.h_cursor_left,
curses.KEY_RIGHT: self.h_cursor_right,
curses.KEY_DC: self.h_delete_right,
curses.ascii.DEL: self.h_delete_left,
curses.ascii.BS: self.h_delete_left,
curses.KEY_BACKSPACE: self.h_delete_left,
# mac os x curses reports DEL as escape oddly
# no solution yet
"^K": self.h_erase_right,
"^U": self.h_erase_left,
})
self.complex_handlers.extend((
(self.t_input_isprint, self.h_addch),
# (self.t_is_ck, self.h_erase_right),
# (self.t_is_cu, self.h_erase_left),
))
示例3: input_stream
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_BACKSPACE [as 别名]
def input_stream(self):
"""Waiting an input and run a proper method according to type of input"""
while True:
self.search(self.query)
self.display()
ch = self.search_window.getch()
if curses.ascii.isprint(ch):
self.write(ch)
self.reset_top()
elif ch in (curses.ascii.BS, curses.ascii.DEL, curses.KEY_BACKSPACE):
self.delete()
self.reset_top()
elif ch == curses.KEY_UP:
self.scroll(self.UP)
elif ch == curses.KEY_DOWN:
self.scroll(self.DOWN)
elif ch == curses.KEY_LEFT:
self.paging(self.UP)
elif ch == curses.KEY_RIGHT:
self.paging(self.DOWN)
elif ch in (curses.ascii.LF, curses.ascii.NL):
self.open_link()
elif ch == curses.ascii.ESC:
break
示例4: validator
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_BACKSPACE [as 别名]
def validator(self, char):
"""here we tweak the behavior slightly, especially we want to
end modal editing mode immediately on arrow up/down and on enter
and we also want to catch ESC and F10, to abort the entire dialog"""
if curses.ascii.isprint(char):
return char
if char == curses.ascii.TAB:
char = curses.KEY_DOWN
if char in [curses.KEY_DOWN, curses.KEY_UP]:
self.result = char
return curses.ascii.BEL
if char in [10, 13, curses.KEY_ENTER, curses.ascii.BEL]:
self.result = 10
return curses.ascii.BEL
if char == 127:
char = curses.KEY_BACKSPACE
if char in [27, curses.KEY_F10]:
self.result = -1
return curses.ascii.BEL
return char
示例5: is_backspace
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_BACKSPACE [as 别名]
def is_backspace(key):
"""Checks for backspace key."""
if len(key) > 1:
return key == "KEY_BACKSPACE"
if ord(key) in (curses.ascii.BS, curses.ascii.DEL):
return True
return False
示例6: _get_key_py27
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_BACKSPACE [as 别名]
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
示例7: getstr
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_BACKSPACE [as 别名]
def getstr(w, y, x):
window = curses.newwin(1, w, y, x)
result = ""
window.addstr("> ", curses.A_BOLD + curses.A_BLINK)
window.refresh()
window.keypad(True)
while True:
try:
character = -1
while (character < 0):
character = window.getch()
except:
break
if character == curses.KEY_ENTER or character == ord('\n'):
break
elif character == curses.KEY_BACKSPACE or character == 127:
if len(result):
window.move(0, len(result)+1)
window.delch()
result = result[:-1]
continue
elif (137 > character > 31 and len(result) < w-3): # ascii range TODO: unicode
result += chr(character)
window.addstr(chr(character))
window.addstr(0, 0, "> ", curses.A_BOLD + curses.color_pair(3))
window.refresh()
window.keypad(False)
return result
示例8: set_up_handlers
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_BACKSPACE [as 别名]
def set_up_handlers(self):
super(MultiLineEditable, self).set_up_handlers()
self.handlers.update ( {
ord('i'): self.h_insert_value,
ord('o'): self.h_insert_next_line,
curses.ascii.CR: self.h_edit_cursor_line_value,
curses.ascii.NL: self.h_edit_cursor_line_value,
curses.ascii.SP: self.h_edit_cursor_line_value,
curses.ascii.DEL: self.h_delete_line_value,
curses.ascii.BS: self.h_delete_line_value,
curses.KEY_BACKSPACE: self.h_delete_line_value,
} )
示例9: set_up_handlers
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_BACKSPACE [as 别名]
def set_up_handlers(self):
super(MultiLineEdit, self).set_up_handlers()
# For OS X
del_key = curses.ascii.alt('~')
self.handlers.update({
curses.ascii.NL: self.h_add_nl,
curses.ascii.CR: self.h_add_nl,
curses.KEY_LEFT: self.h_cursor_left,
curses.KEY_RIGHT: self.h_cursor_right,
curses.KEY_UP: self.h_line_up,
curses.KEY_DOWN: self.h_line_down,
curses.KEY_DC: self.h_delete_right,
curses.ascii.DEL: self.h_delete_left,
curses.ascii.BS: self.h_delete_left,
curses.KEY_BACKSPACE: self.h_delete_left,
"^R": self.full_reformat,
# mac os x curses reports DEL as escape oddly
# no solution yet
#"^K": self.h_erase_right,
#"^U": self.h_erase_left,
})
self.complex_handlers.extend((
(self.t_input_isprint, self.h_addch),
# (self.t_is_ck, self.h_erase_right),
# (self.t_is_cu, self.h_erase_left),
))
示例10: _edit
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_BACKSPACE [as 别名]
def _edit(self, box):
while True:
ch = box.win.getch()
if not ch:
continue
if ch == 127:
ch = curses.KEY_BACKSPACE
if not box.do_command(ch):
break
box.win.refresh()
return box.gather()
示例11: text_input
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_BACKSPACE [as 别名]
def text_input(self, window, allow_resize=False):
"""
Transform a window into a text box that will accept user input and loop
until an escape sequence is entered.
If the escape key (27) is pressed, cancel the textbox and return None.
Otherwise, the textbox will wait until it is full (^j, or a new line is
entered on the bottom line) or the BEL key (^g) is pressed.
"""
window.clear()
# Set cursor mode to 1 because 2 doesn't display on some terminals
self.curs_set(1)
# Keep insert_mode off to avoid the recursion error described here
# http://bugs.python.org/issue13051
textbox = textpad.Textbox(window)
textbox.stripspaces = 0
def validate(ch):
"Filters characters for special key sequences"
if ch == self.ESCAPE:
raise exceptions.EscapeInterrupt()
if (not allow_resize) and (ch == curses.KEY_RESIZE):
raise exceptions.EscapeInterrupt()
# Fix backspace for iterm
if ch == curses.ascii.DEL:
ch = curses.KEY_BACKSPACE
return ch
# Wrapping in an exception block so that we can distinguish when the
# user hits the return character from when the user tries to back out
# of the input.
try:
out = textbox.edit(validate=validate)
if isinstance(out, six.binary_type):
out = out.decode('utf-8')
except exceptions.EscapeInterrupt:
out = None
self.curs_set(0)
return self.strip_textpad(out)
示例12: do_command
# 需要导入模块: import curses [as 别名]
# 或者: from curses import KEY_BACKSPACE [as 别名]
def do_command(self, ch):
if curses.ascii.isprint(ch) or ch == curses.ascii.LF:
text_window_height, text_window_width = self.text_window.getmaxyx()
y, x = size_as_drawn((self.get_content() + chr(ch)).split('\n'), text_window_width)
if y < text_window_height - 1 and x < text_window_width:
self.content.insert(self.cursor_pos, chr(ch))
self.cursor_pos += 1
else:
curses.beep()
elif ch == curses.KEY_BACKSPACE:
if self.cursor_pos > 0:
del self.content[self.cursor_pos - 1]
self.cursor_pos -= 1
else:
curses.beep()
elif ch == curses.KEY_DC:
if self.cursor_pos >= 0 and self.cursor_pos < len(self.content):
del self.content[self.cursor_pos]
else:
curses.beep()
elif ch == curses.KEY_LEFT:
if self.cursor_pos > 0:
self.cursor_pos -= 1
else:
curses.beep()
elif ch == curses.KEY_RIGHT:
if self.cursor_pos + 1 <= len(self.content):
self.cursor_pos += 1
else:
curses.beep()
elif ch in (curses.ascii.EOT, curses.ascii.RS): # ^D or (for some terminals) Ctrl+Enter
return False, False
elif ch == curses.ascii.ESC:
self.clear()
return False, True
elif ch == curses.KEY_RESIZE:
self.on_resize()
return True, False
self.refresh_text()
return True, False