當前位置: 首頁>>代碼示例>>Python>>正文


Python curses.KEY_BACKSPACE屬性代碼示例

本文整理匯總了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 
開發者ID:cslarsen,項目名稱:wpm,代碼行數:23,代碼來源:screen.py

示例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),
                        )) 
開發者ID:hexway,項目名稱:apple_bleee,代碼行數:25,代碼來源:wgtextbox.py

示例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 
開發者ID:mingrammer,項目名稱:awesome-finder,代碼行數:27,代碼來源:tui.py

示例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 
開發者ID:caktux,項目名稱:pytrader,代碼行數:22,代碼來源:pytrader.py

示例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 
開發者ID:cslarsen,項目名稱:wpm,代碼行數:9,代碼來源:screen.py

示例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 
開發者ID:cslarsen,項目名稱:wpm,代碼行數:32,代碼來源:screen.py

示例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 
開發者ID:esotericnonsense,項目名稱:bitcoind-ncurses,代碼行數:37,代碼來源:getstr.py

示例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,
                } ) 
開發者ID:hexway,項目名稱:apple_bleee,代碼行數:15,代碼來源:wgmultilineeditable.py

示例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),
                        )) 
開發者ID:hexway,項目名稱:apple_bleee,代碼行數:31,代碼來源:wgeditmultiline.py

示例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() 
開發者ID:PacktPublishing,項目名稱:Modern-Python-Standard-Library-Cookbook,代碼行數:13,代碼來源:terminal_10.py

示例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) 
開發者ID:tildeclub,項目名稱:ttrv,代碼行數:45,代碼來源:terminal.py

示例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 
開發者ID:ihabunek,項目名稱:toot,代碼行數:50,代碼來源:app.py


注:本文中的curses.KEY_BACKSPACE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。