Esempio n. 1
0
 def keyname(ch):
     _ensure_initialised()
     if ch < 0:
         raise error("invalid key number")
     knp = lib.keyname(ch)
     if knp == ffi.NULL:
         return ""
     return ffi.string(knp)
Esempio n. 2
0
 def keyname(ch):
     _ensure_initialised()
     if ch < 0:
         raise error("invalid key number")
     knp = lib.keyname(ch)
     if knp == ffi.NULL:
         return ""
     return ffi.string(knp)
Esempio n. 3
0
def _setup():
    for name in ['ERR', 'OK', 'KEY_MIN', 'KEY_MAX',
                 'A_ATTRIBUTES', 'A_NORMAL', 'A_STANDOUT', 'A_UNDERLINE',
                 'A_REVERSE', 'A_BLINK', 'A_DIM', 'A_BOLD', 'A_ALTCHARSET',
                 'A_PROTECT', 'A_CHARTEXT', 'A_COLOR',
                 'COLOR_BLACK', 'COLOR_RED', 'COLOR_GREEN', 'COLOR_YELLOW',
                 'COLOR_BLUE', 'COLOR_MAGENTA', 'COLOR_CYAN', 'COLOR_WHITE',
                 ]:
        _copy_to_globals(name)

    if not lib._m_NetBSD:
        _copy_to_globals('A_INVIS')

    for name in ['A_HORIZONTAL', 'A_LEFT', 'A_LOW', 'A_RIGHT', 'A_TOP',
                 'A_VERTICAL',
                 ]:
        if hasattr(lib, name):
            _copy_to_globals(name)

    if lib._m_NCURSES_MOUSE_VERSION:
        for name in ["BUTTON1_PRESSED", "BUTTON1_RELEASED", "BUTTON1_CLICKED",
                     "BUTTON1_DOUBLE_CLICKED", "BUTTON1_TRIPLE_CLICKED",
                     "BUTTON2_PRESSED", "BUTTON2_RELEASED", "BUTTON2_CLICKED",
                     "BUTTON2_DOUBLE_CLICKED", "BUTTON2_TRIPLE_CLICKED",
                     "BUTTON3_PRESSED", "BUTTON3_RELEASED", "BUTTON3_CLICKED",
                     "BUTTON3_DOUBLE_CLICKED", "BUTTON3_TRIPLE_CLICKED",
                     "BUTTON4_PRESSED", "BUTTON4_RELEASED", "BUTTON4_CLICKED",
                     "BUTTON4_DOUBLE_CLICKED", "BUTTON4_TRIPLE_CLICKED",
                     "BUTTON_SHIFT", "BUTTON_CTRL", "BUTTON_ALT",
                     "ALL_MOUSE_EVENTS", "REPORT_MOUSE_POSITION",
                     ]:
            _copy_to_globals(name)

    if not lib._m_NetBSD:
        for key in range(lib.KEY_MIN, lib.KEY_MAX):
            key_n = lib.keyname(key)
            if key_n == ffi.NULL:
                continue
            key_n = ffi.string(key_n)
            if key_n == b"UNKNOWN KEY":
                continue
            if not isinstance(key_n, str):   # python 3
                key_n = key_n.decode()
            key_n = key_n.replace('(', '').replace(')', '')
            globals()[key_n] = key
Esempio n. 4
0
    def getkey(self, *args):
        if len(args) == 0:
            val = lib.wgetch(self._win)
        elif len(args) == 2:
            val = lib.mvwgetch(self._win, *args)
        else:
            raise error("getkey requires 0 or 2 arguments")

        if val == lib.ERR:
            raise error("no input")
        elif val <= 255:
            return chr(val)
        else:
            # XXX: The following line is different if `__NetBSD__` is defined.
            val = lib.keyname(val)
            if val == ffi.NULL:
                return ""
            return ffi.string(val)
Esempio n. 5
0
    def getkey(self, *args):
        if len(args) == 0:
            val = lib.wgetch(self._win)
        elif len(args) == 2:
            val = lib.mvwgetch(self._win, *args)
        else:
            raise error("getkey requires 0 or 2 arguments")

        if val == lib.ERR:
            raise error("no input")
        elif val <= 255:
            return chr(val)
        else:
            # XXX: The following line is different if `__NetBSD__` is defined.
            val = lib.keyname(val)
            if val == ffi.NULL:
                return ""
            return ffi.string(val)
Esempio n. 6
0
def _setup():
    for name in [
            'ERR',
            'OK',
            'KEY_MIN',
            'KEY_MAX',
            'A_ATTRIBUTES',
            'A_NORMAL',
            'A_STANDOUT',
            'A_UNDERLINE',
            'A_REVERSE',
            'A_BLINK',
            'A_DIM',
            'A_BOLD',
            'A_ALTCHARSET',
            'A_PROTECT',
            'A_CHARTEXT',
            'A_COLOR',
            'COLOR_BLACK',
            'COLOR_RED',
            'COLOR_GREEN',
            'COLOR_YELLOW',
            'COLOR_BLUE',
            'COLOR_MAGENTA',
            'COLOR_CYAN',
            'COLOR_WHITE',
    ]:
        _copy_to_globals(name)

    if not lib._m_NetBSD:
        _copy_to_globals('A_INVIS')

    for name in [
            'A_HORIZONTAL',
            'A_LEFT',
            'A_LOW',
            'A_RIGHT',
            'A_TOP',
            'A_VERTICAL',
    ]:
        if hasattr(lib, name):
            _copy_to_globals(name)

    if lib._m_NCURSES_MOUSE_VERSION:
        for name in [
                "BUTTON1_PRESSED",
                "BUTTON1_RELEASED",
                "BUTTON1_CLICKED",
                "BUTTON1_DOUBLE_CLICKED",
                "BUTTON1_TRIPLE_CLICKED",
                "BUTTON2_PRESSED",
                "BUTTON2_RELEASED",
                "BUTTON2_CLICKED",
                "BUTTON2_DOUBLE_CLICKED",
                "BUTTON2_TRIPLE_CLICKED",
                "BUTTON3_PRESSED",
                "BUTTON3_RELEASED",
                "BUTTON3_CLICKED",
                "BUTTON3_DOUBLE_CLICKED",
                "BUTTON3_TRIPLE_CLICKED",
                "BUTTON4_PRESSED",
                "BUTTON4_RELEASED",
                "BUTTON4_CLICKED",
                "BUTTON4_DOUBLE_CLICKED",
                "BUTTON4_TRIPLE_CLICKED",
                "BUTTON_SHIFT",
                "BUTTON_CTRL",
                "BUTTON_ALT",
                "ALL_MOUSE_EVENTS",
                "REPORT_MOUSE_POSITION",
        ]:
            _copy_to_globals(name)

    if not lib._m_NetBSD:
        for key in range(lib.KEY_MIN, lib.KEY_MAX):
            key_n = lib.keyname(key)
            if key_n == ffi.NULL:
                continue
            key_n = ffi.string(key_n)
            if key_n == b"UNKNOWN KEY":
                continue
            if not isinstance(key_n, str):  # python 3
                key_n = key_n.decode()
            key_n = key_n.replace('(', '').replace(')', '')
            globals()[key_n] = key
Esempio n. 7
0
def _setup():
    for name in [
        "ERR",
        "OK",
        "KEY_MIN",
        "KEY_MAX",
        "A_ATTRIBUTES",
        "A_NORMAL",
        "A_STANDOUT",
        "A_UNDERLINE",
        "A_REVERSE",
        "A_BLINK",
        "A_DIM",
        "A_BOLD",
        "A_ALTCHARSET",
        "A_PROTECT",
        "A_CHARTEXT",
        "A_COLOR",
        "COLOR_BLACK",
        "COLOR_RED",
        "COLOR_GREEN",
        "COLOR_YELLOW",
        "COLOR_BLUE",
        "COLOR_MAGENTA",
        "COLOR_CYAN",
        "COLOR_WHITE",
    ]:
        _copy_to_globals(name)

    if not lib._m_NetBSD:
        _copy_to_globals("A_INVIS")

    for name in ["A_HORIZONTAL", "A_LEFT", "A_LOW", "A_RIGHT", "A_TOP", "A_VERTICAL"]:
        if hasattr(lib, name):
            _copy_to_globals(name)

    if lib._m_NCURSES_MOUSE_VERSION:
        for name in [
            "BUTTON1_PRESSED",
            "BUTTON1_RELEASED",
            "BUTTON1_CLICKED",
            "BUTTON1_DOUBLE_CLICKED",
            "BUTTON1_TRIPLE_CLICKED",
            "BUTTON2_PRESSED",
            "BUTTON2_RELEASED",
            "BUTTON2_CLICKED",
            "BUTTON2_DOUBLE_CLICKED",
            "BUTTON2_TRIPLE_CLICKED",
            "BUTTON3_PRESSED",
            "BUTTON3_RELEASED",
            "BUTTON3_CLICKED",
            "BUTTON3_DOUBLE_CLICKED",
            "BUTTON3_TRIPLE_CLICKED",
            "BUTTON4_PRESSED",
            "BUTTON4_RELEASED",
            "BUTTON4_CLICKED",
            "BUTTON4_DOUBLE_CLICKED",
            "BUTTON4_TRIPLE_CLICKED",
            "BUTTON_SHIFT",
            "BUTTON_CTRL",
            "BUTTON_ALT",
            "ALL_MOUSE_EVENTS",
            "REPORT_MOUSE_POSITION",
        ]:
            _copy_to_globals(name)

    if not lib._m_NetBSD:
        for key in range(lib.KEY_MIN, lib.KEY_MAX):
            key_n = lib.keyname(key)
            if key_n == ffi.NULL:
                continue
            key_n = ffi.string(key_n)
            if key_n == b"UNKNOWN KEY":
                continue
            if not isinstance(key_n, str):  # python 3
                key_n = key_n.decode()
            key_n = key_n.replace("(", "").replace(")", "")
            globals()[key_n] = key