[Xcb] language bindings for xcb

a r nbs.public at gmail.com
Fri May 25 16:38:43 PDT 2007


Hi Tom,

I'd do something like this:

>>> import xcb
>>> import render
>>> c = xcb.Connection()
>>> win = c.generate_id()
>>> r = c.get_render_extension() # new method, checking whether render
ext. exists
>>> r.create_picture(...) # no need to add 'c' explicitly since it can
be passed at __init__()

\R.

On 5/18/07, Thomas Hunger <hto at arcor.de> wrote:
> Hello,
>
> the following problem came up when I reactivated my old python
> bindings for xcb [1]. It is a more general problem for all
> object-oriented bindings.
>
> Each extension (e.g. render) has its own library and header file. To
> use it from c one uses pkg-config and the appropiate #include.
>
> In my bindings there is a class "Connection" which connects at
> __init__ time. Now I can use the basic functions like this:
>
> >>> import xcb
> >>> c = xcb.Connection()
> >>> win = c.generate_id()
> >>> ...
>
> The connection object in the first example cannot use e.g.
>
> >>> c.render_create_picture(...)
>
> because the connection does not now whether the render extension is
> available at all [2]. The module-source would also need all possible
> extensions installed at compile time (modules cannot be developed
> separatly).
>
> If I follow the c-model for extensions the result would be:
>
> >>> import render
> >>> render.create_picture(c, ...)
>
> meaning that the connection is passed as the first argument. The
> explicit import ensures that either the render extension module is
> available or an exception is thrown. The extension-modules can also
> be developed separatly. OTOH this is not very object oriented.
>
> Another possibility would be to override the __new__ method of the
> Connection. When __new__ is called it scans for python-xcb-modules
> and creates an attribute for each found module. Connection could then
> be used like this:
>
> >>> c.render.create_picture(...) # module render exists
>
> After all this the question is: What do you think the api should be
> like for object-oriented programming languages?
>
> Tom
>
> [1] I will put them online next week, I am not at home currently.
> [2] It is possible to do create additional render_xxx methods for
>     the connection class after an "import render" statement. This is
>     not trivial to do from c. I also think that it is not very
>     intuitive.
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xcb
>


More information about the Xcb mailing list