From 56441aabda9b2c480bf3a832af7226359974875f Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Tue, 23 Aug 2011 21:20:15 +0000 Subject: [PATCH] Add qof queries to python bindings and set PYTHON_PATH in gnucash-env Patch by Hendrik van Antwerpen git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21215 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/base-typemaps.i | 24 +++++++++++++++++++ src/bin/overrides/Makefile.am | 3 ++- src/bin/overrides/gnucash-env.in | 3 +++ .../python-bindings/gnucash_business.py | 2 +- src/optional/python-bindings/gnucash_core.i | 7 ++++++ src/optional/python-bindings/gnucash_core.py | 12 ++++++++++ 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/base-typemaps.i b/src/base-typemaps.i index def02a173c..199dd3d168 100644 --- a/src/base-typemaps.i +++ b/src/base-typemaps.i @@ -136,6 +136,28 @@ typedef char gchar; } } +%typemap(in) GSList *, QofQueryParamList * { + $1 = NULL; + /* Check if is a list */ + if (PyList_Check($input)) { + int i; + int size = PyList_Size($input); + for (i = size-1; i >= 0; i--) { + PyObject *o = PyList_GetItem($input, i); + if (PyString_Check(o)) { + $1 = g_slist_prepend($1,PyString_AsString(PyList_GetItem($input, i))); + } else { + PyErr_SetString(PyExc_TypeError, "list must contain strings"); + g_slist_free($1); + return NULL; + } + } + } else { + PyErr_SetString(PyExc_TypeError, "not a list"); + return NULL; + } +} + %typemap(out) GList *, CommodityList *, SplitList *, AccountList *, LotList *, MonetaryList *, PriceList *, EntryList * { guint i; @@ -158,6 +180,8 @@ typedef char gchar; PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p_GNCLot, 0)); else if (GNC_IS_PRICE(data)) PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p_GNCPrice, 0)); + else if (GNC_IS_INVOICE(data)) + PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncInvoice, 0)); else if (GNC_IS_ENTRY(data)) PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncEntry, 0)); else if ($1_descriptor == $descriptor(MonetaryList *)) diff --git a/src/bin/overrides/Makefile.am b/src/bin/overrides/Makefile.am index 61900d98b4..bacbede52c 100644 --- a/src/bin/overrides/Makefile.am +++ b/src/bin/overrides/Makefile.am @@ -35,7 +35,8 @@ gnucash-env: gnucash-env.in ${top_builddir}/config.status Makefile -e 's#@-GNC_SCM_INSTALL_DIR-@#${GNC_SCM_INSTALL_DIR}#g' \ -e 's#@-GNC_LIB_INSTALLDIR-@#${libdir}#' \ -e 's#@-GNC_PKGLIB_INSTALLDIR-@#${pkglibdir}#g' \ - -e 's#@-GNC_SCRIPT_OVERRIDE_DIR-@#${gncoverridedir}#g' + -e 's#@-GNC_SCRIPT_OVERRIDE_DIR-@#${gncoverridedir}#g' \ + -e 's#@-GNC_PYTHON_DIR-@#${pythondir}#g' mv $@.tmp $@ chmod u+x $@ CLEANFILES += gnucash-env diff --git a/src/bin/overrides/gnucash-env.in b/src/bin/overrides/gnucash-env.in index 0bf2d0856c..cb71444b0e 100644 --- a/src/bin/overrides/gnucash-env.in +++ b/src/bin/overrides/gnucash-env.in @@ -18,9 +18,12 @@ EXTRA_LIBS="${EXTRA_LIBS}:@-GNC_PKGLIB_INSTALLDIR-@" LD_LIBRARY_PATH="${EXTRA_LIBS}:${LD_LIBRARY_PATH}" DYLD_LIBRARY_PATH="${EXTRA_LIBS}:${DYLD_LIBRARY_PATH}" +PYTHONPATH="${PYTHONPATH}:@-GNC_PYTHON_DIR-@" + export GNC_MODULE_PATH export GUILE_LOAD_PATH export LD_LIBRARY_PATH export DYLD_LIBRARY_PATH +export PYTHONPATH exec "$@" diff --git a/src/optional/python-bindings/gnucash_business.py b/src/optional/python-bindings/gnucash_business.py index f944117d38..bc1eae2071 100644 --- a/src/optional/python-bindings/gnucash_business.py +++ b/src/optional/python-bindings/gnucash_business.py @@ -42,7 +42,7 @@ from gnucash_core_c import GNC_OWNER_CUSTOMER, GNC_OWNER_JOB, \ GNC_PAYMENT_CASH, GNC_PAYMENT_CARD, \ GNC_DISC_PRETAX, GNC_DISC_SAMETIME, GNC_DISC_POSTTAX, \ GNC_TAXINCLUDED_YES, GNC_TAXINCLUDED_NO, GNC_TAXINCLUDED_USEGLOBAL, \ - GNC_AMT_TYPE_VALUE, GNC_AMT_TYPE_PERCENT + GNC_AMT_TYPE_VALUE, GNC_AMT_TYPE_PERCENT, GNC_ID_INVOICE import datetime diff --git a/src/optional/python-bindings/gnucash_core.i b/src/optional/python-bindings/gnucash_core.i index bafbada539..af9a07d15f 100644 --- a/src/optional/python-bindings/gnucash_core.i +++ b/src/optional/python-bindings/gnucash_core.i @@ -54,6 +54,8 @@ #include "qofutil.h" #include "qofid.h" #include "guid.h" +#include "qofquery.h" +#include "qofquerycore.h" #include "gnc-module/gnc-module.h" #include "engine/gnc-engine.h" #include "Transaction.h" @@ -93,6 +95,10 @@ %include +%include + +%include + /* SWIG doesn't like this macro, so redefine it to simply mean const */ #define G_CONST_RETURN const %include @@ -201,6 +207,7 @@ %init %{ qof_log_init(); qof_init(); +qof_query_init(); gnc_module_system_init(); char * no_args[1] = { NULL }; gnc_engine_init(0, no_args); diff --git a/src/optional/python-bindings/gnucash_core.py b/src/optional/python-bindings/gnucash_core.py index 4456446cb2..b768ca9344 100644 --- a/src/optional/python-bindings/gnucash_core.py +++ b/src/optional/python-bindings/gnucash_core.py @@ -655,3 +655,15 @@ guid_dict = { } methods_return_instance(GUID, guid_dict) +#Query +from gnucash_core_c import \ + QOF_QUERY_AND, \ + QOF_QUERY_OR, \ + QOF_QUERY_NAND, \ + QOF_QUERY_NOR, \ + QOF_QUERY_XOR + +class Query(GnuCashCoreClass): + pass + +Query.add_constructor_and_methods_with_prefix('qof_query_', 'create') \ No newline at end of file