Example #1
0
def test_library_with_signatures():
    errcheck = mock.Mock(name='errcheck')
    signatures = dict(XFree=([c_void_p], c_int, errcheck))
    library = util.load_library('X11', signatures)
    assert library
    assert isinstance(library, CDLL)
    assert library.XFree.argtypes == [c_void_p]
    assert library.XFree.restype == c_int
    assert library.XFree.errcheck is errcheck
Example #2
0
def test_library_with_signatures():
    errcheck = mock.Mock(name='errcheck')
    signatures = dict(XFree=([c_void_p], c_int, errcheck))
    library = util.load_library('X11', signatures)
    assert library
    assert isinstance(library, CDLL)
    assert library.XFree.argtypes == [c_void_p]
    assert library.XFree.restype == c_int
    assert library.XFree.errcheck is errcheck
Example #3
0

SIGNATURES = dict(
    XIQueryVersion=([xlib.Display_p, c_int_p, c_int_p], xlib.Status),
    XIQueryDevice=([xlib.Display_p, c_int, c_int_p], XIDeviceInfo_p),
    XIFreeDeviceInfo=([XIDeviceInfo_p], None),
    XIListProperties=([xlib.Display_p, c_int, c_int_p], xlib.Atom_p),
    XIGetProperty=([xlib.Display_p, c_int, xlib.Atom, c_long, c_long,
                    xlib.Bool, xlib.Atom, xlib.Atom_p, c_int_p,
                    c_ulong_p, c_ulong_p, POINTER(c_byte_p)], xlib.Status),
    XIChangeProperty=([xlib.Display_p, c_int, xlib.Atom, xlib.Atom,
                       c_int, c_int, c_byte_p, c_int], None),
    )


libXi = load_library('Xi', SIGNATURES)


# add libXi functions under pythonic names and with pythonic api to
# top-level namespace
def query_version(display, expected_version):
    """
    Query the server-side XInput version.

    ``display`` is a :class:`~synaptiks._bindings.xlib.Display_p` providing the
    server connection, ``expected_version`` a tuple ``(major, minor)`` with the
    expected version.  Both components are integers.

    Return a tuple ``(matched, actual_version)``.  ``matched`` is ``True``,
    if the server-side version is at least the ``expected_version``,
    ``False`` otherwise.  ``actual_version`` is a ``(major, minor)`` tuple
Example #4
0

SIGNATURES = dict(
    XFree=([c_void_p], c_int),
    XOpenDisplay=([c_char_p], Display_p),
    XCloseDisplay=([Display_p], c_int),
    XFlush=([Display_p], c_int),
    XInternAtom=([Display_p, c_char_p, Bool], Atom),
    XGetAtomName=([Display_p, Atom], c_void_p, _convert_x11_char_p),
    XQueryKeymap=([Display_p, c_char * 32], c_int),
    XGetModifierMapping=([Display_p], XModifierKeymap_p),
    XFreeModifiermap=([XModifierKeymap_p], c_int),
    )


libX11 = load_library('X11', SIGNATURES)


open_display = libX11.XOpenDisplay
close_display = libX11.XCloseDisplay
flush = libX11.XFlush


# add libX11 functions to top-level namespace under pythonic names
def free(ptr):
    """
    Free the given pointer using ``XFree``.

    Unlike ``XFree`` this function is safe for use with a ``NULL`` pointer.
    """
    if ptr:
Example #5
0
def test_load_library_not_existing():
    with pytest.raises(ImportError) as exc_info:
        util.load_library('doesNotExist')
    assert str(exc_info.value) == 'No library named doesNotExist'
Example #6
0
def test_load_library_no_signatures():
    library = util.load_library('X11')
    assert library
    assert isinstance(library, CDLL)
Example #7
0

SIGNATURES = dict(
    XRecordQueryVersion=([xlib.Display_p, c_int_p, c_int_p], xlib.Status),
    XRecordAllocRange=([], XRecordRange_p, None),
    XRecordCreateContext=([xlib.Display_p, c_int, XRecordClientSpec_p, c_int,
                           POINTER(XRecordRange_p), c_int], XRecordContext),
    XRecordFreeContext=([xlib.Display_p, XRecordContext], xlib.Status),
    XRecordEnableContext=([xlib.Display_p, XRecordContext,
                           XRecordInterceptProc, xlib.XPointer], xlib.Status),
    XRecordDisableContext=([xlib.Display_p, XRecordContext], xlib.Status),
    XRecordFreeData=([XRecordInterceptData_p], None),
    )


libXtst = load_library('Xtst', SIGNATURES)


def query_version(display):
    """
    Query the xrecord version available on the given ``display``.

    ``display`` is an X11 display connection
    (e.g. :class:`~synaptiks._bindings.xlib.Display_p` or
    :class:`~synaptiks.qx11.QX11Display`).

    Return a tuple ``(success, version)``.  ``success`` is a boolean flag
    inidicating, whether XRecord is available on the given display.
    ``version`` is a tuple ``(major, minor)``, where ``major`` and ``minor``
    are integers holding the corresponding component of the XRecord version
    number.
Example #8
0
        return None


SIGNATURES = dict(
    XFree=([c_void_p], c_int),
    XOpenDisplay=([c_char_p], Display_p),
    XCloseDisplay=([Display_p], c_int),
    XFlush=([Display_p], c_int),
    XInternAtom=([Display_p, c_char_p, Bool], Atom),
    XGetAtomName=([Display_p, Atom], c_void_p, _convert_x11_char_p),
    XQueryKeymap=([Display_p, c_char * 32], c_int),
    XGetModifierMapping=([Display_p], XModifierKeymap_p),
    XFreeModifiermap=([XModifierKeymap_p], c_int),
)

libX11 = load_library('X11', SIGNATURES)

open_display = libX11.XOpenDisplay
close_display = libX11.XCloseDisplay
flush = libX11.XFlush


# add libX11 functions to top-level namespace under pythonic names
def free(ptr):
    """
    Free the given pointer using ``XFree``.

    Unlike ``XFree`` this function is safe for use with a ``NULL`` pointer.
    """
    if ptr:
        libX11.XFree(ptr)
Example #9
0
def test_load_library_not_existing():
    with pytest.raises(ImportError) as exc_info:
        util.load_library('doesNotExist')
    assert str(exc_info.value) == 'No library named doesNotExist'
Example #10
0
def test_load_library_no_signatures():
    library = util.load_library('X11')
    assert library
    assert isinstance(library, CDLL)