davidjo / gnucash_python

gnucash report writing in python
Other
3 stars 0 forks source link

alternative to gnucash_python #1

Open sdementen opened 7 years ago

sdementen commented 7 years ago

Hello, I just found your project after having written http://lists.gnucash.org/pipermail/gnucash-user/2016-October/067269.html (I am the author of piecash,https://github.com/sdementen/piecash). I thought you could be interested by this discussion.... and you may have some answers to my questions :-) kr seb

davidjo commented 7 years ago

On Wed, Oct 26, 2016 at 02:01:59AM -0700, sdementen wrote:

Hello, I just found your project after having written http://lists.gnucash.org/pipermail/gnucash-user/2016-October/067269.html (I am the author of piecash,https://github.com/sdementen/piecash). I thought you could be interested by this discussion.... and you may have some answers to my questions :-) kr seb

Hi

Interesting - although Im on the developer mailing list Im not on the user list.

Theres a long history to this - and I dont really comment as what Im doing because it doesnt seem to be something the current developers are interested in (see lots of John Ralls comments about python) - I however cant wait for re-codings (which have been going on for something like 2 years or more now) - need to do my taxes now!!.

Some time ago (this is a few years now) I did talk about trying to call python from scheme on the developer list and Geert did comment. As he says - you can already add scheme code in your .gnucash folder in config.user and that gets executed. At the time I had found scheme/python modules that allowed scheme to call python and python to call scheme. I tried to use this but it had issues with random crashing so then thought about directly using python - because gnucash is based on glib at the moment wrapping GTypes is well known - its the basis of the python libraries that wrap gtk 2 for writing GUIs in python (gtk is of course the current gnucash GUI base).

What my repository does is create pygobject wrappings for essentially 4 gnucash GTypes - GncHtml, GncHtmlWebkit, GncPlugin and GncPluginPage. This is whats needed to be able to add new report pages to the current gnucash GUI (in particular GncPluginPage). I use the standard python library ElementTree to generate HTML (you could use any HTML generator you want). Once you have the HTML I found it easier to use the GncHtmlWebkit wrapping to display the html string (I tried using the python version of webkit but had lockup issues).

There is a python module in gnucash (note this is different from the python bindings) already which reads an init.py script - I added a line to read python code from a local init script in the user .gnucash folder which is what boots the whole python report addons. (Note that as currently the GUI is in gtk you can easily add to the GUI in python using the pygtk library for your computer system).

The other is is what has been mentioned - basically all the report coding is done in scheme - options through to generation of report html string. For python I had to re-write all of the option coding in python (this is very much alpha based code).

However it does all seem to work with current version of gnucash and for me has been quite stable - reports can crash but havent had actual gnucash crash caused by the python report system for a while now.

Anyway - if you have more questions Id be happy to answer them.

I really should probably push my updates to my repository - Ive been trying to see if I can do this without any compilation - at the moment you need to compile the gobject wrappers essentially inside the gnucash source code

David

sdementen commented 7 years ago

With piecash, I took the route of a pure python binding (to avoid the compilation hell of the gnucash python bindings and support python 3). Now, I am going the route of using guile reporting infrastructure to call a python process via pipes to send the report options and retrieve the html. The report options are defined in python and a python script generates the scm file dynamically. Where I am stuck: getting in guile the name/uri of the current-book. Any clue on how to do this ?

Btw, on the user mailing list, there are a couple of threads on how to change/add reports and the global analysis/response is that "it is guile only, it is complex and it is not going to change anytime soon"

davidjo commented 7 years ago

On Wed, Oct 26, 2016 at 10:16:51AM -0700, sdementen wrote:

With piecash, I took the route of a pure python binding (to avoid the compilation hell of the gnucash python bindings and support python 3). Now, I am going the route of using guile reporting infrastructure to call a python process via pipes to send the report options and retrieve the html. The report options are defined in python and a python script generates the scm file dynamically. Where I am stuck: getting in guile the name/uri of the current-book. Any clue on how to do this ?

Btw, on the user mailing list, there are a couple of threads on how to change/add reports and the global analysis/response is that "it is guile only, it is complex and it is not going to change anytime soon"

You might want to look at pyguile - this allows scheme to call python. I had used this in 2012 to see about writing reports in python - but it hadnt been updated since 2008. However, just found there is now a github project for pyguile and it has been updated this year to work with newer pythons and newer guiles.

David

davidjo commented 7 years ago

On Wed, Oct 26, 2016 at 10:16:51AM -0700, sdementen wrote:

With piecash, I took the route of a pure python binding (to avoid the compilation hell of the gnucash python bindings and support python 3). Now, I am going the route of using guile reporting infrastructure to call a python process via pipes to send the report options and retrieve the html. The report options are defined in python and a python script generates the scm file dynamically. Where I am stuck: getting in guile the name/uri of the current-book. Any clue on how to do this ?

Im using everything - ctypes, swig and gobject wrapping - I was also trying to avoid compiling but its not possible as the gnucash GTypes dont follow some GType paradigms they ought to - the gobject introspection might allow no compiling for gobject wrapping though.

Not sure I can help - I just access the open book via either a ctypes or swig wrapping - theres a function which returns the open book object. You might want to look at the engine guile swig wrapping - it appears theres a wrap of qof_session_get_url (guile form qof-session-get-url) but I can only see it used in test .scm files.

Btw, on the user mailing list, there are a couple of threads on how to change/add reports and the global analysis/response is that "it is guile only, it is complex and it is not going to change anytime soon"

precisely - and what Ive done in my git source is a python replacement - although still not complete eg not sorted saving edited reports

David

sdementen commented 7 years ago

Hello David I have worked a bit on my alternative solution for gnucash reports in python. It is still a work in progress. You can find soem bare documentation at http://gnucash-utilities.readthedocs.io/en/develop/doc/doc.html#report-creation-linux-and-windows-python-3-x I'll be happy to have your feedback on it

davidjo commented 7 years ago

On Sun, Nov 13, 2016 at 04:03:45AM -0800, sdementen wrote:

Hello David I have worked a bit on my alternative solution for gnucash reports in python. It is still a work in progress. You can find soem bare documentation at http://gnucash-utilities.readthedocs.io/en/develop/doc/doc.html#report-creation-linux-and-windows-python-3-x I'll be happy to have your feedback on it

Looks good - is there meant to be a Jinja2 sample - didnt seem to be one for me

David

sdementen commented 7 years ago

The doc at http://gnucash-utilities.readthedocs.io/en/master/doc/doc.html#report-creation-linux-and-windows-python-3-5 is now more up-to-date.

To see an example of python report using jinja2, you can look at :