当前位置: 首页>>代码示例>>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;未经允许,请勿转载。