[GNC-dev] Python: About Wrapping SWIG Objects (GncNumeric)

John Ralls jralls at ceridwen.us
Mon Aug 6 10:14:23 EDT 2018

> On Aug 6, 2018, at 5:19 AM, c.holtermann at gmx.de wrote:
> Am 2018-08-06 11:35, schrieb Geert Janssens:
>> Op maandag 6 augustus 2018 05:32:27 CEST schreef John Ralls:
>>> > On Aug 5, 2018, at 5:17 PM, c.holtermann at gmx.de wrote:
>>> >
>>> > Hello,
>>> >
>>> > after some time I get back to the gnucash python bindings.
>>> >
>>> > I worked on a str method for GncNumeric. It's in the example_script
>>> > dir
>>> > (https://github.com/Gnucash/gnucash/blob/maint/bindings/python/example_sc
>>> > ripts/str_methods.py) I changed it to python3.
>> I read at the beginning of this file you chose to implement it as an example
>> script which - if found useful - could be added to gnucash_core.
>> You have my blessing to include it in gnucash_core :)
>>> > Well I found it interesting to think these things through. Maybe someone
>>> > can tell me about the mysterious "later on" in the cited comment. At this
>>> > point I find it useful to have a way from the instance to the wrapping
>>> > object through some kind of link as I suggested in the patch to
>>> > function_class.
>>> Christoph,
>>> The person who wrote the first two lines of that, Mark Jenkins, was the
>>> original source of the Python bindings. He was never a regular dev, he just
>>> got 16 patches committed between 2007 and 2012, 10 of which touched the
>>> python bindings. Your history with them is almost as long as his--in fact
>>> you have *12* commits--and pretty much no one else has done anything
>>> serious with them.
>> Hopefully Mark is still around on the list to clarify.
>>> In other words, if anyone knows, it’s you!
>> True :)
>>> Just to add some more confusion, there’s now a C++ class GncNumeric that
>>> handles the actual implementation of many of the gnc_numeric.* functions. I
>>> believe that SWIG can’t see it, only the C wrapper functions are exposed to
>>> SWIG.
>> It would be a very useful experiment to wrap the C++ GncNumeric class directly
>> rather than it's c wrapper gnc_numeric_xxx. Python doesn't need the c
>> compatibility layer it represents.
>> Geert
> Geert,
> unfortunately your mail went to my spam folder for whatever reason. Trying to
> do C++ bindings for python sounds very interesting. I'd like to try that when
> I find the time for a simple example type. I don't know if GncNumeric would
> be a good candidate. I'll have a look at it. Thanks for the blessing :-)

Python has its own rational numbers so the only thing the Python bindings need is a way to convert to-and-from that to GncNumeric for communicating with the rest of the GnuCash API.

I suggest QofSession as the first C++ class to play with SWIGing. It’s fairly simple and using it is the first step in using the bindings.

John Ralls

More information about the gnucash-devel mailing list