mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix the Python Console for Python3.
Replacing libgncmod-python, libgncmod-core-utils-python, and libgncmod-app-utils-python with _sw_core_utils and _sw_app_utils. The latter two are the modules that init.py wants to load and with Python3 Swig appears to no longer make them available via libgncmod. Note that there may still be some problems with actually using the console, but it at least loads at startup without complaint.
This commit is contained in:
parent
b9d2344d34
commit
4ecd9c2dd4
@ -1,5 +1,3 @@
|
||||
SET(gncmod_python_SOURCES gncmod-python.c)
|
||||
|
||||
SET(pycons_DATA
|
||||
pycons/__init__.py
|
||||
pycons/console.py
|
||||
@ -11,22 +9,6 @@ SET(pycons_DATA
|
||||
)
|
||||
|
||||
IF (WITH_PYTHON)
|
||||
|
||||
ADD_LIBRARY(gncmod-python ${gncmod_python_SOURCES})
|
||||
TARGET_LINK_LIBRARIES(gncmod-python gnc-module gnc-core-utils-python gncmod-app-utils-python
|
||||
${PYTHON_LIBRARIES} ${GLIB_LIBS}) # ${PYTHON_EXTRA_LIBS}
|
||||
TARGET_INCLUDE_DIRECTORIES(gncmod-python
|
||||
PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/core_utils ${CMAKE_SOURCE_DIR}/gnc-module ${PYTHON_INCLUDE_DIR})
|
||||
TARGET_COMPILE_OPTIONS(gncmod-python PRIVATE -DG_LOG_DOMAIN=\"gnc.python\")
|
||||
IF (APPLE)
|
||||
SET_TARGET_PROPERTIES (gncmod-python PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/gnucash")
|
||||
ENDIF()
|
||||
INSTALL(TARGETS gncmod-python
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/gnucash
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/gnucash
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
INSTALL(FILES ${pycons_DATA} DESTINATION ${CMAKE_INSTALL_DATADIR}/gnucash/python/pycons)
|
||||
INSTALL(FILES init.py DESTINATION ${CMAKE_INSTALL_DATADIR}/gnucash/python)
|
||||
|
||||
@ -35,6 +17,6 @@ ENDIF()
|
||||
ENDIF(WITH_PYTHON)
|
||||
|
||||
SET_LOCAL_DIST(pycons_DIST ${pycons_DATA})
|
||||
SET_LOCAL_DIST(python_DIST_local CMakeLists.txt gncmod-python.c init.py)
|
||||
SET_LOCAL_DIST(python_DIST_local CMakeLists.txt init.py)
|
||||
SET(python_DIST ${python_DIST_local} ${pycons_DIST} PARENT_SCOPE)
|
||||
|
||||
|
@ -1,130 +0,0 @@
|
||||
/*********************************************************************
|
||||
* gncmod-python.c
|
||||
* Python in GnuCash?! Sweet.
|
||||
*
|
||||
* Copyright (c) 2011 Andy Clayton
|
||||
*********************************************************************/
|
||||
/********************************************************************\
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
|
||||
#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);
|
||||
extern PyObject* PyInit__sw_core_utils(void);
|
||||
#else
|
||||
extern void init_sw_app_utils(void);
|
||||
extern void init_sw_core_utils(void);
|
||||
#endif
|
||||
|
||||
int
|
||||
libgncmod_python_gnc_module_init(int refcount)
|
||||
{
|
||||
/* There isn't yet a python module to init.
|
||||
PyObject *pName, *pModule;
|
||||
*/
|
||||
FILE *fp;
|
||||
gchar *pkgdatadir, *init_filename;
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
wchar_t* argv = NULL;
|
||||
#else
|
||||
char* argv = "";
|
||||
#endif
|
||||
Py_Initialize();
|
||||
PySys_SetArgv(0, &argv);
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
PyInit__sw_app_utils();
|
||||
PyInit__sw_core_utils();
|
||||
#else
|
||||
init_sw_app_utils();
|
||||
init_sw_core_utils();
|
||||
#endif
|
||||
|
||||
/* There isn't yet a python module to init.
|
||||
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;
|
||||
}
|
@ -9,7 +9,7 @@ import os
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
noisy = gnc_prefs_is_extra_enabled()
|
||||
if noisy:
|
||||
print "woop", os.path.dirname(__file__)
|
||||
print("woop", os.path.dirname(__file__))
|
||||
# Importing the console class causes SIGTTOU to be thrown if GnuCash is
|
||||
# started in the background. This causes a hang if it is not handled,
|
||||
# so ignore it for the duration
|
||||
@ -22,22 +22,22 @@ import pycons.console as cons
|
||||
signal.signal(signal.SIGTTOU, old_sigttou)
|
||||
|
||||
if noisy:
|
||||
print "Hello from python!"
|
||||
print "test", sys.modules.keys()
|
||||
print "test2", dir(_sw_app_utils)
|
||||
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 "test3", dir(gnucash_core_c)
|
||||
#print("test", dir(root), root.__class__)
|
||||
print("test3", 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)
|
||||
#print("test3", dir(acct))
|
||||
#print(acct.GetName())
|
||||
#print(acct.GetBalance())
|
||||
#print(acct.GetSplitList())
|
||||
#print("test2", dir(gnucash.gnucash_core_c))
|
||||
|
||||
class Console (cons.Console):
|
||||
""" GTK python console """
|
||||
|
@ -110,25 +110,35 @@ INSTALL(TARGETS gncmod-app-utils
|
||||
)
|
||||
|
||||
IF (WITH_PYTHON)
|
||||
ADD_LIBRARY (gncmod-app-utils-python ${SWIG_APP_UTILS_PYTHON_C})
|
||||
SET(PYEXEC_FILES sw_app_utils.py)
|
||||
ADD_LIBRARY (sw_app_utils MODULE ${SWIG_APP_UTILS_PYTHON_C})
|
||||
|
||||
TARGET_LINK_LIBRARIES(gncmod-app-utils-python gncmod-app-utils ${app_utils_ALL_LIBRARIES} ${PYTHON_LIBRARIES})
|
||||
TARGET_LINK_LIBRARIES(sw_app_utils gncmod-app-utils ${app_utils_ALL_LIBRARIES} ${PYTHON_LIBRARIES})
|
||||
SET_TARGET_PROPERTIES(sw_app_utils PROPERTIES PREFIX "_")
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES (gncmod-app-utils-python
|
||||
TARGET_INCLUDE_DIRECTORIES (sw_app_utils
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PRIVATE ${app_utils_ALL_INCLUDES} ${PYTHON_INCLUDE_DIRS}
|
||||
)
|
||||
TARGET_COMPILE_DEFINITIONS (gncmod-app-utils-python PRIVATE -DG_LOG_DOMAIN=\"gnc.app-utils\")
|
||||
TARGET_COMPILE_DEFINITIONS (sw_app_utils PRIVATE -DG_LOG_DOMAIN=\"gnc.app-utils\")
|
||||
|
||||
IF (APPLE)
|
||||
SET_TARGET_PROPERTIES (gncmod-app-utils-python PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/gnucash")
|
||||
SET_TARGET_PROPERTIES (sw_app_utils PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/gnucash")
|
||||
ENDIF()
|
||||
|
||||
INSTALL(TARGETS gncmod-app-utils-python
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/gnucash
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/gnucash
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
INSTALL(TARGETS sw_app_utils
|
||||
LIBRARY DESTINATION ${PYTHON_SYSCONFIG_OUTPUT}/gnucash
|
||||
ARCHIVE DESTINATION ${PYTHON_SYSCONFIG_OUTPUT}/gnucash
|
||||
)
|
||||
|
||||
ADD_CUSTOM_TARGET(sw-app-utils-py ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${SWIG_APP_UTILS_PYTHON_PY} ${PYTHON_SYSCONFIG_BUILD}/gnucash
|
||||
DEPENDS ${SWIG_APP_UTILS_PYTHON_C})
|
||||
|
||||
ADD_CUSTOM_TARGET(sw-app-utils-build ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR_BUILD}/gnucash/_sw_app_utils${CMAKE_SHARED_MODULE_SUFFIX} ${PYTHON_SYSCONFIG_BUILD}/gnucash
|
||||
DEPENDS sw_app_utils)
|
||||
|
||||
ENDIF()
|
||||
|
||||
|
||||
|
@ -167,27 +167,34 @@ INSTALL(TARGETS gnc-core-utils
|
||||
)
|
||||
|
||||
IF (WITH_PYTHON)
|
||||
ADD_LIBRARY (gnc-core-utils-python ${core_utils_ALL_SOURCES} ${SWIG_CORE_UTILS_PYTHON_C})
|
||||
ADD_DEPENDENCIES(gnc-core-utils-python gnc-vcs-info)
|
||||
ADD_LIBRARY (sw_core_utils MODULE ${SWIG_CORE_UTILS_PYTHON_C})
|
||||
|
||||
TARGET_LINK_LIBRARIES(gnc-core-utils-python ${core_utils_ALL_LIBRARIES} ${PYTHON_LIBRARIES})
|
||||
TARGET_LINK_LIBRARIES(sw_core_utils gnc-core-utils ${core_utils_ALL_LIBRARIES} ${PYTHON_LIBRARIES})
|
||||
SET_TARGET_PROPERTIES(sw_core_utils PROPERTIES PREFIX "_")
|
||||
|
||||
TARGET_COMPILE_DEFINITIONS(gnc-core-utils-python
|
||||
PRIVATE -DG_LOG_DOMAIN=\"gnc.core-utils\" ${GTK_MAC_CFLAGS_OTHER}
|
||||
TARGET_INCLUDE_DIRECTORIES (sw_core_utils
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PRIVATE ${core_utils_ALL_INCLUDES} ${PYTHON_INCLUDE_DIRS}
|
||||
)
|
||||
TARGET_COMPILE_DEFINITIONS (sw_core_utils PRIVATE -DG_LOG_DOMAIN=\"gnc.core-utils\")
|
||||
|
||||
IF (CORELE)
|
||||
SET_TARGET_PROPERTIES (sw_core_utils PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/gnucash")
|
||||
ENDIF()
|
||||
|
||||
INSTALL(TARGETS sw_core_utils
|
||||
LIBRARY DESTINATION ${PYTHON_SYSCONFIG_OUTPUT}/gnucash
|
||||
ARCHIVE DESTINATION ${PYTHON_SYSCONFIG_OUTPUT}/gnucash
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(gnc-core-utils-python PUBLIC ${core_utils_ALL_INCLUDES} ${PYTHON_INCLUDE_DIRS})
|
||||
|
||||
IF (MAC_INTEGRATION)
|
||||
TARGET_COMPILE_OPTIONS(gnc-core-utils-python PRIVATE ${OSX_EXTRA_COMPILE_FLAGS})
|
||||
ENDIF(MAC_INTEGRATION)
|
||||
|
||||
INSTALL(TARGETS gnc-core-utils-python
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
ADD_CUSTOM_TARGET(sw-core-utils-py ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${SWIG_CORE_UTILS_PYTHON_PY} ${PYTHON_SYSCONFIG_BUILD}/gnucash
|
||||
DEPENDS ${SWIG_CORE_UTILS_PYTHON_C})
|
||||
|
||||
ADD_CUSTOM_TARGET(sw-core-utils-build ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR_BUILD}/gnucash/_sw_core_utils${CMAKE_SHARED_MODULE_SUFFIX} ${PYTHON_SYSCONFIG_BUILD}/gnucash
|
||||
DEPENDS sw_core_utils)
|
||||
|
||||
ENDIF()
|
||||
|
||||
# No headers to install
|
||||
|
@ -360,7 +360,6 @@ gnucash/import-export/qif-imp/qif-parse.scm
|
||||
gnucash/import-export/qif-imp/qif-to-gnc.scm
|
||||
gnucash/import-export/qif-imp/qif-utils.scm
|
||||
gnucash/import-export/qif-imp/string.scm
|
||||
gnucash/python/gncmod-python.c
|
||||
gnucash/register/ledger-core/gncEntryLedger.c
|
||||
gnucash/register/ledger-core/gncEntryLedgerControl.c
|
||||
gnucash/register/ledger-core/gncEntryLedgerDisplay.c
|
||||
|
Loading…
Reference in New Issue
Block a user