Re: Help on GObject Introspection Annotations



Thanks!

I'll add my own git example to the list:

https://github.com/tliron/pygobject-example

While there are a lot of PyGObject tutorials out there that show how to use GTK+3, there are none that show the complete loop of writing your own GObject code in C or Vala specifically for use in Python. It took me many hours to piece everything together, so I hope this simple example code will help avoid the pain for others.

In case anybody reading this is in Chicago, I will be presenting this at the ChiPy meeting on Dec 8th, 2011.

-Tal


On 12/02/2011 03:09 PM, Daniel Espinosa wrote:
I've added CC to gtk-list and gtk-developers in order to make public
these comments. Hope you make the same in the future.

I'm working to add new objects written in Vala for GDA in  the
libgda-vala branch if you want to see how to implement a library and
Unit Test in a C library and Autotools.

http://git.gnome.org/browse/libgda

2011/12/2 Tal Liron <tal liron gmail com>:
Thanks, that's good advice. Indeed, the property I am using can also access
a private field, forcing users to use the property API.

One advantage for me in using the property API is that I'm also using Vala.
In Vala, implementing properties is ridiculously easy.

I'm hoping in the future GI will support fields better. The project is
definitely evolving and adding features.

On 12/02/2011 02:32 PM, Daniel Espinosa wrote:

In GdaNumeric, we added accesors to fields in the struct.

I think you have a GObject implementation. Your way is the best: add
properties to access to fields.

GdaNumeric is a struct with some fields easy to modify directly from
Python, like the integer ones, but the string one is not handle by
Python by default because could be very different per case. Then we
added some API to access to struct members (all), and now this struct
is considered opaque.

For new implementations I recomend to hide struct definition in the
*.c and just use in the header:

typedef _MyStruct MyStruct;

This hides internal definition and forces the developer to use the
API. This way GObject Introspection will always make bindings to
modify struct fields as expected by the implementator and makes very
easy to automatically generate GIR files with the required API.

2011/12/2 Tal Liron <tal liron gmail com>:

Thanks!

I solved it in my software by wrapping fields in properties. That way C code
can still access the fields directly, while Python can use set_property().

-Tal

On 12/02/2011 01:18 PM, Daniel Espinosa wrote:

No one have sent any response message.

I've added this annotations to GdaNumeric, but GIR and Vala bindings
make no difference. Both use GdaNumeric, as declared on GDA, as a
GBoxed and use g_boxed_copy and g_boxed_free functions.

May be this help was added but not implemented jet.

2011/12/2 Tal Liron <tal liron gmail com>:

Hello Daniel, and sorry for writing to you directly, but I can't find a way
to respond to an archived message on the mailing list.

Did you ever found a solution to this issue you posted?

https://mail.gnome.org/archives/gtk-list/2011-October/msg00049.html

Thanks!

-Tal





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]