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

2018-08-23 Thread c . holtermann

Am 2018-08-06 16:14, schrieb John Ralls:

On Aug 6, 2018, at 5:19 AM, c.holterm...@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.holterm...@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.

Regards,
John Ralls


Hello,

I've created an experimental branch in my fork of gnucash to create swig 
python
bindings for c++ files. As suggested I started with QofSessionImpl for 
which I
have created an example file to create a file and an account. I also 
included
GncNumeric. There's no example for that yet. It's very raw. I disabled 
some errors.

It's more of a proof of concept but it's a step on the way.
https://github.com/c-holtermann/gnucash/tree/ch-python

regards,

Christoph Holtermann
___
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel


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

2018-08-23 Thread cicko
Christoph Holtermann wrote
> I'm willing to now and then do something for the python bindings. I 
> don't feel like an expert. But surely I'd like to talk and think things
> through 
> about them. Maybe someone is interested. I saw that there were some people 
> asking questions about the bindings on this list. Maybe they don't commit
> but 
> still work with the bindings. So my question remains and maybe someone has
> an 
> idea.

Christoph,

I, for example, am quite interested in accessing GnuCash via Python. So, on
first sight, Python bindings seem an interesting option.
In practice, though, I did not find much motivation to spend time on it,
unfortunately. The main reason for that is that I need my (Python) code to
run on Windows, Linux, and Android. And to run equally well.
Since the bindings are available only on Linux, that's a very limiting
factor. So I've limited my work to only reading the GnuCash data. Additional
functionality is dispersed across various small projects that keep extra
information in their own databases (i.e. Asset Allocation). This works well
on Android and I can get my Portfolio Value report or Security Analysis by
running a Python script on my phone (sounds weird, I know).
To run on all platforms I'm using Sebastien's Piecash library.
Additional step would be to add some sort of (native) GUI on all the
platforms. I've already looked into that a bit, but nothing tickles my fancy
yet.

Having the ability to write data to GnuCash would be fantastic. However, I
don't think it's going to happen on multiple platforms any time soon.
Naturally, it is possible to write to GnuCash database but that is not
exactly the same as using GnuCash's business logic.

One thing I would like to improve on next is the process of getting the
transactions from the mobile app (MoneyManagerEx for Android) into GnuCash.
Python bindings would be perfect for that, to avoid lengthy process of .qif
import. I could adapt the Android app to provide GnuCash-specific export
file, for example. But if this would work only on Linux, it would be a very
small return on the investment of time and effort. 



--
Sent from: http://gnucash.1415818.n4.nabble.com/GnuCash-Dev-f1435356.html
___
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel


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

2018-08-06 Thread c . holtermann

Am 2018-08-06 16:14, schrieb John Ralls:

On Aug 6, 2018, at 5:19 AM, c.holterm...@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.holterm...@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.

Regards,
John Ralls


John,

Thanks for the suggestion. I'll also think about what you said about the 
numerics.


regards,

Christoph Holtermann
___
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel


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

2018-08-06 Thread John Ralls


> On Aug 6, 2018, at 5:19 AM, c.holterm...@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.holterm...@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.

Regards,
John Ralls
___
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel


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

2018-08-06 Thread c . holtermann

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.holterm...@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 :-)

have a nice day !

Christoph
___
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel


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

2018-08-06 Thread Geert Janssens
Op maandag 6 augustus 2018 11:35:43 CEST schreef c.holterm...@gmx.de:
> Then you speak of c++ GncNumeric. As I understand you are moving the
> source
> from c to c++. So the python bindings need to reflect that. That sounds
> like
> another piece of work. Is there imminent need for change there ? Chances
> of
> breaking changes ?

We're indeed converting the internals of gnucash (that part we refer to as 
"libgnucash" among developers) to c++. As long as parts of gnucash as a whole 
still depend on the c interface that will continue to exist as a wrapper 
around the c++ code. So the C interface will probably still be around for a 
couple of years. So there is still quite some time available to port the 
python bindings.

I suggested this as an interesting project in my previous mail. Thinking about 
this some more it probably only makes sense when all of the objects that are 
being wrapped are converted to C++. I guess the wrapper would otherwise have 
to wrap both the C and the C++ interface to provide full functionality, which 
sounds a bit awkward.

A first experiment to get an idea of what to expect on the other hand may 
still be useful.

Regards,

Geert


___
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel


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

2018-08-06 Thread c . holtermann

Am 2018-08-06 05:32, schrieb John Ralls:

On Aug 5, 2018, at 5:17 PM, c.holterm...@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_scripts/str_methods.py)
I changed it to python3. Then I began to wonder about the 
relationshipp of

the SwigObject and the wrapping object.

In this case it's something like
'_gnc_numeric *' at 0x7f11908da840> >

and


When I have the GncNumeric object I can access the SwigObject through 
its instance property.

The other way round seems not as simple.

My method __gncnumeric__str__ overwrites the __str__ method using 
add_method.


In this method self points to the swig object. I cannot use the 
methods of GncNumeric as

it is the layer of the wrapping object.

To access these methods I used to instantiate a 
GncNumeric(instance=self) as a temporary self.

But that seems not right as this probably already exists.

I wondered if I could know about the wrapping object when I had the 
instance only. I did not

find a way. I stumbled over an interesting comment in
https://github.com/Gnucash/gnucash/blob/69fef8277fde56e7d2df700b21c63c19c115852a/bindings/python/function_class.py#L50

# why reimpliment __new__? Because later on we're going to
# use new to avoid creating new instances when existing instances
# already exist with the same __instance value, or equivalent 
__instance

# values, where this is desirable...

I did not find "later on". But if that works I can safely do 
GncNumeric(instance=self) as it

would reuse the existing GncNumeric object.

But nevertheless I wondered if we could put a link to the GncNumeric 
in the Swig Level. I tried

it:
https://github.com/c-holtermann/gnucash/commit/a6c2adf7d29c4367728a4fa920307ee595eefa5a
(link to my fork)

Interstingly some Swig objects can be added to and some others not. 
GncNumeric works while

QofSession doesn't. So I made it a try block for now.

Having done that I can get to the GncNumeric (sort of higher self) 
from the Swig object:

https://github.com/c-holtermann/gnucash/commit/2f35b550709ad4131aca0e7309f6bb4b0f984b84

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.

In other words, if anyone knows, it’s you!

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.

Regards,
John Ralls


John,

thank you for the insights and the friendly words. I like the python 
bindings
for gnucash and use them to feed my bank data to gnucash using a 
webscraping
script that fetches a CSV for me which I can then import using the 
bindings.
This has worked quite well for me for years. At some point in time 
gnucash
wouldn't build due to some segmentation error. The system was working 
but I
only now came back to compile gnucash again when I made a big system 
update.


I'm willing to now and then do something for the python bindings. I 
don't feel
like an expert. But surely I'd like to talk and think things through 
about
them. Maybe someone is interested. I saw that there were some people 
asking
questions about the bindings on this list. Maybe they don't commit but 
still
work with the bindings. So my question remains and maybe someone has an 
idea.
I will continue to think about it anyway (depending on the time I can 
spare

on this project :-).

I thought I will look through the python bindings and see if all files 
are

compatible with python3. Thanks to you developers who made that step for
the bindings ! I suppose some of the example scripts are not yet 
converted.
The information in the wiki should reflect the step to python3. I'll try 
to

have a look at that.

Then you speak of c++ GncNumeric. As I understand you are moving the 
source
from c to c++. So the python bindings need to reflect that. That sounds 
like
another piece of work. Is there imminent need for change there ? Chances 
of

breaking changes ?

regards,

Christoph Holtermann
___
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel


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

2018-08-06 Thread Geert Janssens
Op maandag 6 augustus 2018 05:32:27 CEST schreef John Ralls:
> > On Aug 5, 2018, at 5:17 PM, c.holterm...@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


___
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel


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

2018-08-05 Thread John Ralls


> On Aug 5, 2018, at 5:17 PM, c.holterm...@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_scripts/str_methods.py)
> I changed it to python3. Then I began to wonder about the relationshipp of
> the SwigObject and the wrapping object.
> 
> In this case it's something like
>  '_gnc_numeric *' at 0x7f11908da840> >
> and
> 
> 
> When I have the GncNumeric object I can access the SwigObject through its 
> instance property.
> The other way round seems not as simple.
> 
> My method __gncnumeric__str__ overwrites the __str__ method using add_method.
> 
> In this method self points to the swig object. I cannot use the methods of 
> GncNumeric as
> it is the layer of the wrapping object.
> 
> To access these methods I used to instantiate a GncNumeric(instance=self) as 
> a temporary self.
> But that seems not right as this probably already exists.
> 
> I wondered if I could know about the wrapping object when I had the instance 
> only. I did not
> find a way. I stumbled over an interesting comment in
> https://github.com/Gnucash/gnucash/blob/69fef8277fde56e7d2df700b21c63c19c115852a/bindings/python/function_class.py#L50
> 
> # why reimpliment __new__? Because later on we're going to
> # use new to avoid creating new instances when existing instances
> # already exist with the same __instance value, or equivalent __instance
> # values, where this is desirable...
> 
> I did not find "later on". But if that works I can safely do 
> GncNumeric(instance=self) as it
> would reuse the existing GncNumeric object.
> 
> But nevertheless I wondered if we could put a link to the GncNumeric in the 
> Swig Level. I tried
> it:
> https://github.com/c-holtermann/gnucash/commit/a6c2adf7d29c4367728a4fa920307ee595eefa5a
> (link to my fork)
> 
> Interstingly some Swig objects can be added to and some others not. 
> GncNumeric works while
> QofSession doesn't. So I made it a try block for now.
> 
> Having done that I can get to the GncNumeric (sort of higher self) from the 
> Swig object:
> https://github.com/c-holtermann/gnucash/commit/2f35b550709ad4131aca0e7309f6bb4b0f984b84
> 
> 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.

In other words, if anyone knows, it’s you!

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.

Regards,
John Ralls

___
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel