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


Python curses.keyname方法代碼示例

本文整理匯總了Python中curses.keyname方法的典型用法代碼示例。如果您正苦於以下問題:Python curses.keyname方法的具體用法?Python curses.keyname怎麽用?Python curses.keyname使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在curses的用法示例。


在下文中一共展示了curses.keyname方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: h_addch

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import keyname [as 別名]
def h_addch(self, inp):
        if self.editable:
            #self.value = self.value[:self.cursor_position] + curses.keyname(input) \
            #   + self.value[self.cursor_position:]
            #self.cursor_position += len(curses.keyname(input))
            
            # workaround for the metamode bug:
            if self._last_get_ch_was_unicode == True and isinstance(self.value, bytes):
                # probably dealing with python2.
                ch_adding = inp
                self.value = self.value.decode()
            elif self._last_get_ch_was_unicode == True:
                ch_adding = inp
            else:
                try:
                    ch_adding = chr(inp)
                except TypeError:
                    ch_adding = input
            self.value = self.value[:self.cursor_position] + [ch_adding,] \
                + self.value[self.cursor_position:]
            self.cursor_position += len(ch_adding) 
開發者ID:hexway,項目名稱:apple_bleee,代碼行數:23,代碼來源:wgtexttokens.py

示例2: _get_char

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import keyname [as 別名]
def _get_char(self) -> Key:
        if self._buffered_input is not None:
            wch, self._buffered_input = self._buffered_input, None
        else:
            try:
                wch = self.stdscr.get_wch()
            except curses.error:  # pragma: no cover (macos bug?)
                wch = self.stdscr.get_wch()
        if isinstance(wch, str) and wch == '\x1b':
            wch = self._get_sequence(wch)
            if len(wch) == 2:
                return Key(wch, f'M-{wch[1]}'.encode())
            elif len(wch) > 1:
                keyname = SEQUENCE_KEYNAME.get(wch, b'unknown')
                return Key(wch, keyname)
        elif isinstance(wch, str) and wch.isprintable():
            wch = self._get_string(wch)
            return Key(wch, b'STRING')

        key = wch if isinstance(wch, int) else ord(wch)
        keyname = curses.keyname(key)
        keyname = KEYNAME_REWRITE.get(keyname, keyname)
        return Key(wch, keyname) 
開發者ID:asottile,項目名稱:babi,代碼行數:25,代碼來源:screen.py

示例3: test_curses_key_name

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import keyname [as 別名]
def test_curses_key_name(self):
        # These actually test the fake curses.
        def test1():
            curses.keyname(-3)

        self.assertRaises(ValueError, test1)

        def test2():
            curses.keyname([])

        self.assertRaises(TypeError, test2)

        def test3():
            curses.keyname(9**999)

        self.assertRaises(OverflowError, test3) 
開發者ID:google,項目名稱:ci_edit,代碼行數:18,代碼來源:unit_test_curses_util.py

示例4: h_find_char

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import keyname [as 別名]
def h_find_char(self, input):
        # The following ought to work, but there is a curses keyname bug
        # searchingfor = curses.keyname(input).upper()
        # do this instead:
        searchingfor = chr(input).upper()
        for counter in range(len(self.values)):
            try:
                if self.values[counter].find(searchingfor) is not -1:
                    self.cursor_line = counter
                    break
            except AttributeError:
                break 
開發者ID:hexway,項目名稱:apple_bleee,代碼行數:14,代碼來源:wgmultiline.py

示例5: h_addch

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import keyname [as 別名]
def h_addch(self, inp):
        if self.editable:
            #self.value = self.value[:self.cursor_position] + curses.keyname(input) \
            #   + self.value[self.cursor_position:]
            #self.cursor_position += len(curses.keyname(input))
            
            # workaround for the metamode bug:
            if self._last_get_ch_was_unicode == True and isinstance(self.value, bytes):
                # probably dealing with python2.
                ch_adding = inp
                self.value = self.value.decode()
            elif self._last_get_ch_was_unicode == True:
                ch_adding = inp
            else:
                try:
                    ch_adding = chr(inp)
                except TypeError:
                    ch_adding = input
            self.value = self.value[:self.cursor_position] + ch_adding \
                + self.value[self.cursor_position:]
            self.cursor_position += len(ch_adding)

            # or avoid it entirely:
            #self.value = self.value[:self.cursor_position] + curses.ascii.unctrl(input) \
            #   + self.value[self.cursor_position:]
            #self.cursor_position += len(curses.ascii.unctrl(input)) 
開發者ID:hexway,項目名稱:apple_bleee,代碼行數:28,代碼來源:wgtextbox.py

示例6: _curses_key_name

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import keyname [as 別名]
def _curses_key_name(self, key):
        """Return the curses key name for keys received from get_wch (and getch)."""
        # Handle multibyte get_wch input in Python 3.3
        if isinstance(key, str):
            return str(curses.keyname(ord(key)).decode("utf-8"))
        # Fallback to try and handle Python < 3.3
        # Special keys can also be ints on Python > 3.3
        if isinstance(key, int):  # getch fallback
            try:  # Try to convert to a curses key name
                name = str(curses.keyname(key).decode("utf-8"))
                return name
            except:  # Otherwise try to convert to a character
                return False
        return False 
開發者ID:richrd,項目名稱:suplemon,代碼行數:16,代碼來源:ui.py

示例7: get_char

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import keyname [as 別名]
def get_char(self) -> Key:
        self.perf.end()
        ret = self._get_char()
        self.perf.start(ret.keyname.decode())
        return ret 
開發者ID:asottile,項目名稱:babi,代碼行數:7,代碼來源:screen.py

示例8: cursesKeyName

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import keyname [as 別名]
def cursesKeyName(keyCode):
    try:
        return curses.keyname(keyCode)
    except Exception:
        pass
    return None 
開發者ID:google,項目名稱:ci_edit,代碼行數:8,代碼來源:curses_util.py

示例9: quick_prompt

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import keyname [as 別名]
def quick_prompt(
            self,
            prompt: str,
            opt_strs: Tuple[str, ...],
    ) -> Union[str, PromptResult]:
        opts = [opt[0] for opt in opt_strs]
        while True:
            x = 0
            prompt_line = self.margin.lines - 1

            def _write(s: str, *, attr: int = curses.A_REVERSE) -> None:
                nonlocal x

                if x >= self.margin.cols:
                    return
                self.stdscr.insstr(prompt_line, x, s, attr)
                x += len(s)

            _write(prompt)
            _write(' [')
            for i, opt_str in enumerate(opt_strs):
                _write(opt_str[0], attr=curses.A_REVERSE | curses.A_BOLD)
                _write(opt_str[1:])
                if i != len(opt_strs) - 1:
                    _write(', ')
            _write(']?')

            if x < self.margin.cols - 1:
                s = ' ' * (self.margin.cols - x)
                self.stdscr.insstr(prompt_line, x, s, curses.A_REVERSE)
                x += 1
            else:
                x = self.margin.cols - 1
                self.stdscr.insstr(prompt_line, x, '…', curses.A_REVERSE)

            self.stdscr.move(prompt_line, x)

            key = self.get_char()
            if key.keyname == b'KEY_RESIZE':
                self.resize()
            elif key.keyname == b'^C':
                return self.status.cancelled()
            elif isinstance(key.wch, str) and key.wch in opts:
                return key.wch 
開發者ID:asottile,項目名稱:babi,代碼行數:46,代碼來源:screen.py


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