Working example of kvp acess in Python

David Osguthorpe david.osguthorpe at gmail.com
Tue Jun 10 11:24:59 EDT 2014


On Mon, Jun 09, 2014 at 12:53:38AM +0200, Christoph Holtermann wrote:
> Hello,
> 
> for my python latex invoice script I tried to access the owners data. I tried
> to work my way to it and came across the kvp system. I made a rude
> path through there with a working example to access the companies data.
> 
> If someone is interested in clarifying the swig qof_instance and kvp_frame
> stuff for python it would be nice to cooperate.
> 
> My branch on github about this is
> https://github.com/c-holtermann/gnucash/tree/python-kvp
> 

Hi

I have been working with the python bindings but all my knowledge is from my human introspection
of the existing code

I have worked on adding the budget - as you have done you add the include files to the
swig interface file gnucash_core.i and most objects get a base swig interface

My analysis shows that the bindings then wrap the raw swig objects inside more pythonic classes
using GnuCashCoreClass as the base object

so eg in your your case you might want to define     class KvpFrame(GnuCashCoreClass):

you then add methods by calling the add_methods function

eg

KvpFrame.add_methods_with_prefix('kvp_frame_')

where any c function that starts with the string kvp_frame_ gets added to the class
This does add all methods that begin with this string - the only methods you can actually
use in the class though are those where the C kvpframe structure is the first argument

if methods return special objects the should use methods_return_instances
to add the return object type

I have messed a little with the Kvp stuff - one problem is that it tends to return multiple
types which is not so easy to handle - may have to follow the GList typemap as defined
in base-typemaps.i

David


More information about the gnucash-devel mailing list