mirror of https://github.com/Gnucash/gnucash
This also renames the configure option to --enable-python. From: Andy Clayton <q3aiml@gmail.com> (with minor modifications by myself) git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20470 57a11ea4-9604-0410-9ed3-97b8803252fdpull/1/head
parent
5cbf6cbdb1
commit
1874219672
@ -1,2 +1,2 @@
|
||||
SUBDIRS = ${PYTHON_DIR} ${GTKMM_DIR}
|
||||
SUBDIRS = ${PYTHON_BINDINGS_DIR} ${GTKMM_DIR}
|
||||
DIST_SUBDIRS = python-bindings gtkmm
|
||||
|
||||
@ -0,0 +1,62 @@
|
||||
SUBDIRS = .
|
||||
#test
|
||||
|
||||
pkglib_LTLIBRARIES = libgncmod-python.la
|
||||
|
||||
libgncmod_python_la_SOURCES = \
|
||||
gncmod-python.c
|
||||
|
||||
libgncmod_python_la_LDFLAGS = -avoid-version \
|
||||
${PYTHON_LDFLAGS}
|
||||
|
||||
libgncmod_python_la_LIBADD = \
|
||||
${top_builddir}/src/gnc-module/libgnc-module.la \
|
||||
${top_builddir}/src/core-utils/libgnc-core-utils.la \
|
||||
${top_builddir}/src/app-utils/libgncmod-app-utils-python.la \
|
||||
${PYTHON_LIBS} \
|
||||
${PYTHON_EXTRA_LIBS} \
|
||||
${GLIB_LIBS}
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I${top_srcdir}/src \
|
||||
-I${top_srcdir}/src/core-utils \
|
||||
-I${top_srcdir}/src/gnc-module \
|
||||
${PYTHON_CPPFLAGS} \
|
||||
${GLIB_CFLAGS}
|
||||
|
||||
|
||||
gncpymoddir = ${GNC_SHAREDIR}/python/
|
||||
gncpymod_DATA = \
|
||||
init.py
|
||||
|
||||
if GNUCASH_SEPARATE_BUILDDIR
|
||||
#For executing test cases
|
||||
PY_FILE_LINKS = ${gncpymod_DATA}
|
||||
endif
|
||||
|
||||
.py-links:
|
||||
$(RM) -rf gnucash
|
||||
mkdir -p gnucash
|
||||
mkdir -p gnucash/python
|
||||
if GNUCASH_SEPARATE_BUILDDIR
|
||||
for X in ${PY_FILE_LINKS} ; do \
|
||||
$(LN_S) -f ${srcdir}/$$X . ; \
|
||||
done
|
||||
endif
|
||||
( cd gnucash/python; for A in $(gncpymod_DATA) ; do $(LN_S) -f ../../$$A . ; done )
|
||||
if ! OS_WIN32
|
||||
# Windows knows no "ln -s" but uses "cp": must copy every time (see bug #566567).
|
||||
touch .py-links
|
||||
endif
|
||||
|
||||
clean-local:
|
||||
$(RM) -rf gnucash
|
||||
|
||||
noinst_DATA = .py-links
|
||||
|
||||
EXTRA_DIST = ${gncpymod_DATA}
|
||||
|
||||
CLEANFILES = .py-links
|
||||
DISTCLEANFILES = ${PY_FILE_LINKS}
|
||||
|
||||
INCLUDES = -DG_LOG_DOMAIN=\"gnc.python\"
|
||||
@ -0,0 +1,96 @@
|
||||
/*********************************************************************
|
||||
* gncmod-python.c
|
||||
* Python in GnuCash?! Sweet.
|
||||
*
|
||||
* Copyright (c) 2011 Andy Clayton
|
||||
*********************************************************************/
|
||||
|
||||
#include <Python.h>
|
||||
#include "config.h"
|
||||
#include <gmodule.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "gnc-module.h"
|
||||
#include "gnc-module-api.h"
|
||||
#include "gnc-path.h"
|
||||
|
||||
GNC_MODULE_API_DECL(libgncmod_python)
|
||||
|
||||
/* version of the gnc module system interface we require */
|
||||
int libgncmod_python_gnc_module_system_interface = 0;
|
||||
|
||||
/* module versioning uses libtool semantics. */
|
||||
int libgncmod_python_gnc_module_current = 0;
|
||||
int libgncmod_python_gnc_module_revision = 0;
|
||||
int libgncmod_python_gnc_module_age = 0;
|
||||
|
||||
|
||||
char *
|
||||
libgncmod_python_gnc_module_path(void)
|
||||
{
|
||||
return g_strdup("gnucash/python");
|
||||
}
|
||||
|
||||
char *
|
||||
libgncmod_python_gnc_module_description(void)
|
||||
{
|
||||
return g_strdup("An embedded Python interpreter");
|
||||
}
|
||||
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
extern PyObject* PyInit__sw_app_utils(void);
|
||||
#else
|
||||
extern void init_sw_app_utils(void);
|
||||
#endif
|
||||
|
||||
int
|
||||
libgncmod_python_gnc_module_init(int refcount)
|
||||
{
|
||||
PyObject *pName, *pModule;
|
||||
FILE *fp;
|
||||
gchar *pkgdatadir, *init_filename;
|
||||
|
||||
Py_Initialize();
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
PyInit__sw_app_utils();
|
||||
#else
|
||||
init_sw_app_utils();
|
||||
#endif
|
||||
|
||||
/*
|
||||
pName = PyString_FromString("path/to/init.py");
|
||||
pModule = PyImport_Import(pName);
|
||||
|
||||
if (!pModule) {
|
||||
PyErr_Print();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Py_DECREF(pName);
|
||||
Py_DECREF(pModule);
|
||||
*/
|
||||
|
||||
pkgdatadir = gnc_path_get_pkgdatadir();
|
||||
init_filename = g_build_filename(pkgdatadir, "python/init.py", (char*)NULL);
|
||||
g_debug("Looking for python init script at %s", (init_filename ? init_filename : "<null>"));
|
||||
fp = fopen(init_filename, "r+");
|
||||
if (fp) {
|
||||
PyRun_SimpleFile(fp, init_filename);
|
||||
fclose(fp);
|
||||
|
||||
/* PyRun_InteractiveLoop(stdin, "foo"); */
|
||||
} else {
|
||||
g_warning("Unable to initialize Python module (unable to open %s)", init_filename);
|
||||
}
|
||||
g_free(init_filename);
|
||||
g_free(pkgdatadir);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
libgncmod_python_gnc_module_end(int refcount)
|
||||
{
|
||||
Py_Finalize();
|
||||
return TRUE;
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
import sys
|
||||
import _sw_app_utils
|
||||
from gnucash import *
|
||||
|
||||
print "Hello from python!"
|
||||
|
||||
print "test", sys.modules.keys()
|
||||
print "test2", dir(_sw_app_utils)
|
||||
|
||||
root = _sw_app_utils.gnc_get_current_root_account()
|
||||
|
||||
print "test", dir(root), root.__class__
|
||||
print "test2", dir(gnucash_core_c)
|
||||
|
||||
acct = Account(instance = root)
|
||||
|
||||
print "test3", dir(acct)
|
||||
#print acct.GetName()
|
||||
#print acct.GetBalance()
|
||||
#print acct.GetSplitList()
|
||||
|
||||
#print "test2", dir(gnucash.gnucash_core_c)
|
||||
|
||||
Loading…
Reference in new issue