Skip to content

Conversation

@rotdrop
Copy link

@rotdrop rotdrop commented May 24, 2025

The idea is to be able to use the percentage function with a python function callback. Maybe a little bit hacky as SWIG was not designed for these kind of things (i.e. callbacks from the target language back to Python are difficult to achieve with SWIG).

Usage:

...
percentageCallback =  gnucash_core_c.qof_percentage_func(lambda a, b: print(a, b) if a else print(b))
...
gnucash_core_c.qof_session_load(inputSession, percentageFunc)
...

Complete "save-as" script is here https://github.com/rotdrop/gnucash-python/blob/main/src/save-as.py

The idea is to be able to use the percentage function with a python
function callback. Maybe a little bit hacky as SWIG was not designed for
these kind of things (i.e. callbacks from the target language back to
Python are difficult to achieve with SWIG).

Signed-off-by: Claus-Justus Heine <[email protected]>
Copy link
Member

@jralls jralls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clever.

Needs a test to go with it.

@rotdrop
Copy link
Author

rotdrop commented May 28, 2025

Very clever.

Needs a test to go with it.

The credits go actually to

https://gist.github.com/sterin/32b5c7c42a177dacf455

Test would also need to be written for my other PR #2090, I'll try to have a look at it ...

@rotdrop rotdrop requested a review from jralls May 28, 2025 08:05
@rotdrop rotdrop force-pushed the feature/expose-percentage-callback-to-python branch from eecabdc to e7e3b55 Compare May 28, 2025 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants