本文整理匯總了Python中curses.ascii方法的典型用法代碼示例。如果您正苦於以下問題:Python curses.ascii方法的具體用法?Python curses.ascii怎麽用?Python curses.ascii使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類curses
的用法示例。
在下文中一共展示了curses.ascii方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _search_validator
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [as 別名]
def _search_validator(self, ch):
"""Fix Enter and backspace for textbox.
Used as an aux function for the textpad.edit method
"""
if ch == curses.ascii.NL: # Enter
return curses.ascii.BEL
elif ch == 127: # Backspace
self.search_str = self.textpad.gather().strip().lower()[:-1]
return 8
else:
if 0 < ch < 256:
c = chr(ch)
if c in string.printable:
res = self.textpad.gather().strip().lower()
self.search_str = res + chr(ch)
self.search_results(look_in_cur=True)
self.display()
return ch
示例2: _insert_printable_char
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [as 別名]
def _insert_printable_char(self, ch):
self._update_max_yx()
(y, x) = self.win.getyx()
backyx = None
while y < self.maxy or x < self.maxx:
if self.insert_mode:
oldch = self.win.inch()
# The try-catch ignores the error we trigger from some curses
# versions by trying to write into the lowest-rightmost spot
# in the window.
try:
self.win.addch(ch)
except curses.error:
pass
if not self.insert_mode or not curses.ascii.isprint(oldch):
break
ch = oldch
(y, x) = self.win.getyx()
# Remember where to put the cursor back since we are in insert_mode
if backyx is None:
backyx = y, x
if backyx is not None:
self.win.move(*backyx)
示例3: gather
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [as 別名]
def gather(self):
"Collect and return the contents of the window."
result = ""
self._update_max_yx()
for y in range(self.maxy+1):
self.win.move(y, 0)
stop = self._end_of_line(y)
if stop == 0 and self.stripspaces:
continue
for x in range(self.maxx+1):
if self.stripspaces and x > stop:
break
result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
if self.maxy > 0:
result = result + "\n"
return result
示例4: _insert_printable_char
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [as 別名]
def _insert_printable_char(self, ch):
(y, x) = self.win.getyx()
if y < self.maxy or x < self.maxx:
if self.insert_mode:
oldch = self.win.inch()
# The try-catch ignores the error we trigger from some curses
# versions by trying to write into the lowest-rightmost spot
# in the window.
try:
self.win.addch(ch)
except curses.error:
pass
if self.insert_mode:
(backy, backx) = self.win.getyx()
if curses.ascii.isprint(oldch):
self._insert_printable_char(oldch)
self.win.move(backy, backx)
示例5: set_up_handlers
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [as 別名]
def set_up_handlers(self):
"""This function should be called somewhere during object initialisation (which all library-defined widgets do). You might like to override this in your own definition,
but in most cases the add_handers or add_complex_handlers methods are what you want."""
#called in __init__
self.handlers = {
curses.ascii.NL: self.h_exit_down,
curses.ascii.CR: self.h_exit_down,
curses.ascii.TAB: self.h_exit_down,
curses.KEY_BTAB: self.h_exit_up,
curses.KEY_DOWN: self.h_exit_down,
curses.KEY_UP: self.h_exit_up,
curses.KEY_LEFT: self.h_exit_left,
curses.KEY_RIGHT: self.h_exit_right,
# "^P": self.h_exit_up,
# "^N": self.h_exit_down,
curses.ascii.ESC: self.h_exit_escape,
curses.KEY_MOUSE: self.h_exit_mouse,
}
self.complex_handlers = []
示例6: set_up_handlers
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [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),
))
示例7: set_up_handlers
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [as 別名]
def set_up_handlers(self):
"""This function should be called somewhere during object initialisation (which all library-defined widgets do). You might like to override this in your own definition,
but in most cases the add_handers or add_complex_handlers methods are what you want."""
#called in __init__
self.handlers = {
curses.ascii.NL: self.h_exit_down,
curses.ascii.CR: self.h_exit_down,
curses.ascii.TAB: self.h_exit_down,
curses.KEY_BTAB: self.h_exit_up,
curses.KEY_DOWN: self.h_exit_down,
curses.KEY_UP: self.h_exit_up,
curses.KEY_LEFT: self.h_exit_left,
curses.KEY_RIGHT: self.h_exit_right,
"^P": self.h_exit_up,
"^N": self.h_exit_down,
curses.ascii.ESC: self.h_exit_escape,
curses.KEY_MOUSE: self.h_exit_mouse,
}
self.complex_handlers = []
示例8: setTextBuffer
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [as 別名]
def setTextBuffer(self, textBuffer):
app.controller.Controller.setTextBuffer(self, textBuffer)
normalCommandSet = {
ord('^'): textBuffer.cursorStartOfLine,
ord('$'): textBuffer.cursorEndOfLine,
ord('h'): textBuffer.cursorLeft,
ord('i'): self.switchToCommandSetInsert,
ord('j'): textBuffer.cursorDown,
ord('k'): textBuffer.cursorUp,
ord('l'): textBuffer.cursorRight,
}
self.commandSet = normalCommandSet
self.commandSet_Insert = {
curses.ascii.ESC: self.switchToCommandSetNormal,
}
self.commandDefault = self.textBuffer.insertPrintable
示例9: KEY_CTRL
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [as 別名]
def KEY_CTRL(key):
return curses.ascii.ctrl(bytes(key))
示例10: _end_of_line
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [as 別名]
def _end_of_line(self, y):
"""Go to the location of the first blank on the given line,
returning the index of the last non-blank character."""
self._update_max_yx()
last = self.maxx
while True:
if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
last = min(self.maxx, last+1)
break
elif last == 0:
break
last = last - 1
return last
示例11: _end_of_line
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [as 別名]
def _end_of_line(self, y):
"""Go to the location of the first blank on the given line,
returning the index of the last non-blank character."""
last = self.maxx
while True:
if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
last = min(self.maxx, last+1)
break
elif last == 0:
break
last = last - 1
return last
示例12: gather
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [as 別名]
def gather(self):
"Collect and return the contents of the window."
result = ""
for y in range(self.maxy+1):
self.win.move(y, 0)
stop = self._end_of_line(y)
if stop == 0 and self.stripspaces:
continue
for x in range(self.maxx+1):
if self.stripspaces and x > stop:
break
result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
if self.maxy > 0:
result = result + "\n"
return result
示例13: is_escape
# 需要導入模塊: import curses [as 別名]
# 或者: from curses import ascii [as 別名]
def is_escape(key):
"""Checks for escape key."""
if len(key) == 1:
return ord(key) == curses.ascii.ESC
return False