Python is back

This commit is contained in:
Yevgen Muntyan 2010-04-17 23:29:31 -07:00
parent a89cee4eda
commit 7a7b3b5c68
118 changed files with 480 additions and 209 deletions

View File

@ -20,6 +20,8 @@ ENDIF(WIN32 AND EXISTS "$ENV{GTKDIR}")
MOO_ADD_COMPILE_DEFINITIONS(RELEASE -DG_DISABLE_CAST_CHECKS -DG_DISABLE_ASSERT)
MOO_ADD_COMPILER_FLAGS(GCC WIN32 -mms-bitfields)
FIND_PACKAGE(MooPython)
PKG_CHECK_MODULES(LIBXML2 REQUIRED libxml-2.0)
LIST(APPEND MOO_DEP_LIBS ${LIBXML2_LIBRARIES})
INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIRS})

View File

@ -162,7 +162,7 @@ ENDMACRO(MOO_ADD_COMPILE_DEFINITIONS)
# DEBUG
#
MOO_ADD_COMPILE_DEFINITIONS(DEBUG -DMOO_DEBUG -DDEBUG -D_DEBUG)
MOO_ADD_COMPILE_DEFINITIONS(DEBUG -DMOO_DEBUG -DDEBUG)
###########################################################################

View File

@ -7,6 +7,30 @@ IF(ENABLE_NLS)
ENDIF(NOT GETTEXT_FOUND)
ENDIF(ENABLE_NLS)
MACRO(MOO_TRANSFORM_INI_FILES outvar)
FOREACH(_moo_ini_in_in_file ${ARGN})
SET(_moo_ini_in_in_file_abs ${CMAKE_CURRENT_SOURCE_DIR}/${_moo_ini_in_in_file})
STRING(REPLACE ".ini.in.in" ".ini.in" _moo_ini_in_file ${_moo_ini_in_in_file})
SET(_moo_ini_in_file ${CMAKE_CURRENT_BINARY_DIR}/${_moo_ini_in_file})
CONFIGURE_FILE(${_moo_ini_in_in_file} ${_moo_ini_in_file})
STRING(REPLACE ".ini.in.in" ".ini" _moo_ini_file ${_moo_ini_in_in_file})
SET(_moo_ini_file ${_moo_ini_file})
LIST(APPEND ${outvar} ${CMAKE_CURRENT_BINARY_DIR}/${_moo_ini_file})
IF(ENABLE_NLS)
ADD_CUSTOM_COMMAND(OUTPUT ${_moo_ini_file}
COMMAND ${INTLTOOL_MERGE_COMMAND} -d -u -c ${CMAKE_BINARY_DIR}/po/.intltool-merge-cache ${CMAKE_SOURCE_DIR}/po ${_moo_ini_in_file} ${_moo_ini_file}
DEPENDS ${_moo_ini_in_file})
ELSE(ENABLE_NLS)
ADD_CUSTOM_COMMAND(OUTPUT ${_moo_ini_file}
COMMAND ${MOO_CMAKE_COMMAND} -D MOO_OS_BSD=${MOO_OS_BSD}
-D INPUT_FILE=${_moo_ini_in_file}
-D OUTPUT_FILE=${_moo_ini_file}
-P ${CMAKE_SOURCE_DIR}/moo/mooutils/moo-intltool-merge.cmake
DEPENDS ${_moo_ini_in_file})
ENDIF(ENABLE_NLS)
ENDFOREACH(_moo_ini_in_in_file)
ENDMACRO(MOO_TRANSFORM_INI_FILES)
MACRO(MOO_ADD_MSG_CATALOG catalogname dir)
IF(ENABLE_NLS)
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${dir})
@ -36,13 +60,17 @@ IF(ENABLE_NLS)
FIND_FILE(${var} ${script})
ENDIF(NOT "${var}")
ENDMACRO(_MOO_FIND_INTLTOOL_VAR)
_MOO_FIND_INTLTOOL_VAR(INTLTOOL_UPDATE intltool-update)
_MOO_FIND_INTLTOOL_VAR(INTLTOOL_EXTRACT intltool-extract)
_MOO_FIND_INTLTOOL_VAR(INTLTOOL_MERGE intltool-merge)
CONFIGURE_FILE(${MOO_SOURCE_DIR}/plat/win32/intltool-wrapper.bat.in ${MOO_BINARY_DIR}/intltool-wrapper.bat)
SET(INTLTOOL_UPDATE_COMMAND ${MOO_BINARY_DIR}/intltool-wrapper.bat)
FOREACH(_moo_i18n_tool update extract merge)
STRING(TOUPPER ${_moo_i18n_tool} _moo_i18n_TOOL)
_MOO_FIND_INTLTOOL_VAR(INTLTOOL_${_moo_i18n_TOOL} intltool-${_moo_i18n_tool})
SET(__MOO_INTLTOOL_SCRIPT ${INTLTOOL_${_moo_i18n_TOOL}})
CONFIGURE_FILE(${MOO_SOURCE_DIR}/plat/win32/intltool-wrapper.bat.in ${MOO_BINARY_DIR}/intltool-${_moo_i18n_tool}-wrapper.bat)
SET(INTLTOOL_${_moo_i18n_TOOL}_COMMAND ${MOO_BINARY_DIR}/intltool-${_moo_i18n_tool}-wrapper.bat)
ENDFOREACH(_moo_i18n_tool)
ELSE(WIN32)
FIND_PROGRAM(INTLTOOL_UPDATE_COMMAND intltool-update)
FIND_PROGRAM(INTLTOOL_MERGE_COMMAND intltool-merge)
FIND_PROGRAM(INTLTOOL_EXTRACT_COMMAND intltool-extract)
ENDIF(WIN32)
SET(MOO_PO_DIR ${MOO_SOURCE_DIR}/po)

View File

@ -0,0 +1,52 @@
MOO_OPTION(MOO_ENABLE_PYTHON TRUE "Enable Python" HEADER TRUE)
SET(PYTHON_DEV_FOUND FALSE)
MACRO(MOO_GET_PYTHON_SYSCONFIG_VAR var value error)
SET(${error} FALSE)
EXECUTE_PROCESS(COMMAND "${PYTHON_EXECUTABLE}" -c "import distutils.sysconfig; print distutils.sysconfig.get_config_vars('${var}')[0]"
RESULT_VARIABLE _moo_gpsv_result
OUTPUT_VARIABLE _moo_gpsv_output
ERROR_VARIABLE _moo_gpsv_error
OUTPUT_STRIP_TRAILING_WHITESPACE)
IF(_moo_gpsv_result EQUAL 0)
SET(${value} "${_moo_gpsv_output}")
ELSE(_moo_gpsv_result EQUAL 0)
SET(${error} TRUE)
ENDIF(_moo_gpsv_result EQUAL 0)
ENDMACRO(MOO_GET_PYTHON_SYSCONFIG_VAR)
IF(MOO_ENABLE_PYTHON)
PKG_CHECK_MODULES(PYGTK pygtk-2.0)
IF(PYGTK_FOUND)
_MOO_GET_PKG_CONFIG_VARIABLE(PYGTK_DEFS_DIR defsdir pygtk-2.0)
_MOO_GET_PKG_CONFIG_VARIABLE(PYGTK_CODEGEN_DIR codegendir pygtk-2.0)
MOO_GET_PYTHON_SYSCONFIG_VAR("INCLUDEPY" _moo_fp_includepy _moo_fp_error)
IF(NOT _moo_fp_error)
MOO_GET_PYTHON_SYSCONFIG_VAR("VERSION" _moo_fp_pyversion _moo_fp_error)
ENDIF(NOT _moo_fp_error)
IF(NOT _moo_fp_error AND WIN32)
MOO_GET_PYTHON_SYSCONFIG_VAR("prefix" _moo_fp_pyprefix _moo_fp_error)
ENDIF(NOT _moo_fp_error AND WIN32)
IF(NOT _moo_fp_error)
SET(PYTHON_LIBRARIES "python${_moo_fp_pyversion}")
FILE(TO_CMAKE_PATH "${_moo_fp_includepy}" PYTHON_INCLUDE_DIRS)
FILE(TO_CMAKE_PATH "${_moo_fp_pyprefix}/libs" PYTHON_LIBRARY_DIRS)
SET(PYTHON_DEV_FOUND TRUE)
ENDIF(NOT _moo_fp_error)
ENDIF(PYGTK_FOUND)
ENDIF(MOO_ENABLE_PYTHON)
MOO_DEBUG(STATUS "PYTHON_DEV_FOUND = ${PYTHON_DEV_FOUND}")
IF(PYTHON_DEV_FOUND)
MOO_DEBUG(STATUS "PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
MOO_DEBUG(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
MOO_DEBUG(STATUS "PYTHON_LIBRARY_DIRS = ${PYTHON_LIBRARY_DIRS}")
LIST(APPEND MOO_DEP_LIBS ${PYTHON_LIBRARIES})
LINK_DIRECTORIES(${PYTHON_LIBRARY_DIRS} ${PYGTK_LIBRARY_DIRS})
ELSE(PYTHON_DEV_FOUND)
SET(MOO_ENABLE_PYTHON FALSE)
ENDIF(PYTHON_DEV_FOUND)
# -%- strip:true, indent-width:2 -%-

View File

@ -1,53 +0,0 @@
INCLUDE(plugins/CMakeLists.cmake)
SET(MOOMOD_SOURCES
moo-mod.c
moopython-api.h
moopython-utils.h
moopython-utils.c
moopython-loader.h
moopython-loader.c
)
SET(PYMOO_SOURCES
moopython-mod.c
moopython-pygtkmod.h
moopython-api.h
moopython-loader.h
moopython-loader.c
moopython-utils.h
moopython-utils.c
)
SET(MOOPYTHON_SOURCES
moopython-builtin.h
moopython-builtin.c
moopython-api.h
moopython-loader.h
moopython-loader.c
moopython-utils.h
moopython-utils.c
)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/pygtk
${CMAKE_CURRENT_BINARY_DIR}/pygtk
${PYTHON_INCLUDE_PATH}
${PYGTK_INCLUDE_DIRS}
)
IF(WIN32 AND MOO_BUILD_SHARED_LIB)
ADD_DEFINITIONS(-DMOO_PYTHON_MODULE_DLL_NAME=\"pymoo.dll\")
ENDIF(WIN32 AND MOO_BUILD_SHARED_LIB)
INCLUDE(pygtk/CMakeLists.cmake)
IF(MOO_BUILD_SHARED_LIB)
MOO_ADD_LIBRARY(moomod MODULE ${MOOPYGTK_SOURCES})
MOO_ADD_LIBRARY(pymoo MODULE)
TARGET_LINK_LIBRARIES(moomod moo ${PYGTK_LIBRARIES} ${PYTHON_LIBRARIES})
ELSE(MOO_BUILD_SHARED_LIB)
MOO_ADD_LIBRARY(moopython ${MOOMOD_SOURCES} ${MOOPYGTK_SOURCES})
ENDIF(MOO_BUILD_SHARED_LIB)
# -%- strip:true -%-

View File

@ -1,114 +0,0 @@
SET(MOOPYGTK_SOURCES
pygtk/moo-pygtk.c
pygtk/moo-pygtk.h
pygtk/mooapp-mod.h
pygtk/mooedit-mod.h
pygtk/mooutils-mod.h
pygtk/moo-mod.h
)
SET(mooedit_defs_files
pygtk/mooeditor.defs
pygtk/mooplugin.defs
pygtk/moocommand.defs
)
SET(mooutils_defs_files
pygtk/moofileview.defs
pygtk/moopaned.defs
)
SET(mooutils_override_files
pygtk/moopaned.override
)
IF(WIN32)
SET(codegen_platform --platform win32)
ELSE(WIN32)
SET(codegen_platform)
ENDIF(WIN32)
SET(codegen_files
codegen/codegen.py
codegen/argtypes.py
codegen/argtypes_m.py
codegen/reversewrapper.py
)
GET_FILENAME_COMPONENT(_moo_abs_srcdir ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE)
SET(codegen_script ${_moo_abs_srcdir}/codegen/codegen.py)
SET(codegen ${PYTHON_EXECUTABLE} ${codegen_script} ${codegen_platform} --pygtk-version=${PYGTK_MINOR_VERSION})
pygtk/mooutils-pygtk.c: pygtk/mooutils-pygtk.defs pygtk/mooutils-pygtk.override $(mooutils_override_files) $(mooutils_defs_files) $(codegen_files)
mkdir -p pygtk
$(codegen) --prefix _moo_utils
--load-types $(srcdir)/codegen/argtypes_m.py
--register $(PYGTK_DEFS_DIR)/gtk-types.defs
--register $(PYGTK_DEFS_DIR)/gdk-types.defs
--override $(srcdir)/pygtk/mooutils-pygtk.override
--outfilename pygtk/mooutils-pygtk.c
$(srcdir)/pygtk/mooutils-pygtk.defs > $@.tmp &&
mv $@.tmp $@
pygtk/mooapp-pygtk.c: pygtk/mooapp-pygtk.defs pygtk/mooapp-pygtk.override $(codegen_files)
mkdir -p pygtk
$(codegen) --prefix _moo_app
--load-types $(srcdir)/codegen/argtypes_m.py
--register $(PYGTK_DEFS_DIR)/gtk-types.defs
--register $(PYGTK_DEFS_DIR)/gdk-types.defs
--register $(srcdir)/pygtk/mooutils-pygtk.defs
--override $(srcdir)/pygtk/mooapp-pygtk.override
--outfilename pygtk/mooapp-pygtk.c
$(srcdir)/pygtk/mooapp-pygtk.defs > $@.tmp &&
mv $@.tmp $@
pygtk/mooedit-pygtk.c: pygtk/mooedit-pygtk.defs pygtk/mooedit-pygtk.override $(mooedit_defs_files) $(codegen_files)
mkdir -p pygtk
$(codegen) --prefix _moo_edit
--load-types $(srcdir)/codegen/argtypes_m.py
--register $(PYGTK_DEFS_DIR)/gtk-types.defs
--register $(PYGTK_DEFS_DIR)/gdk-types.defs
--register $(srcdir)/pygtk/mooutils-pygtk.defs
--override $(srcdir)/pygtk/mooedit-pygtk.override
--outfilename pygtk/mooedit-pygtk.c
$(srcdir)/pygtk/mooedit-pygtk.defs > $@.tmp &&
mv $@.tmp $@
PY2H = $(srcdir)/../mooutils/py2h.sh
pygtk/%-mod.h: $(srcdir)/pygtk/%-mod.py $(PY2H)
mkdir -p pygtk
$(SHELL) $(PY2H) `echo $* | tr '[a-z]' '[A-Z]'`_PY $(srcdir)/pygtk/$*-mod.py > $@.tmp &&
mv $@.tmp $@
FOREACH(_moo_comp utils edit app)
STRING(TOUPPER ${_moo_comp} _moo_COMP)
MOO_ADD_GENERATED_FILE(
${CMAKE_CURRENT_BINARY_DIR}/pygtk/moo${_moo_comp}-pygtk.stamp
${CMAKE_CURRENT_BINARY_DIR}/pygtk/moo${_moo_comp}-pygtk.c
${MOO_${_moo_COMP}_PYGTK_COMMAND}
DEPENDS pygtk/moo${_moo_comp}-pygtk.defs pygtk/moo${_moo_comp}-pygtk.override ${codegen_files})
ENDFOREACH(_moo_comp)
# noinst_LTLIBRARIES += libmoopygtk.la
#
# libmoopygtk_la_SOURCES = $(moopygtk_sources)
# nodist_libmoopygtk_la_SOURCES = $(nodist_moopygtk_sources)
# libmoopygtk_la_LIBADD =
#
# libmoopygtk_la_CFLAGS =
# -Ipygtk
# $(MOO_CFLAGS)
# $(MOO_W_NO_WRITE_STRINGS)
# $(MOO_W_NO_UNUSED)
# $(PYTHON_INCLUDES)
# $(PYGTK_CFLAGS)
#
# libmoopygtk_la_CXXFLAGS =
# -Ipygtk
# $(MOO_CXXFLAGS)
# $(MOO_W_NO_WRITE_STRINGS)
# $(MOO_W_NO_UNUSED)
# $(PYTHON_INCLUDES)
# $(PYGTK_CFLAGS)
# -%- strip: true -%-

View File

@ -6,9 +6,14 @@ IF(MOO_ENABLE_UNIT_TESTS AND NOT WIN32)
ADD_DEFINITIONS(-DSRCDIR="${CMAKE_SOURCE_DIR}/medit")
ENDIF(MOO_ENABLE_UNIT_TESTS AND NOT WIN32)
IF(MOO_ENABLE_PYTHON)
SET(moopythonlib moopython)
ENDIF(MOO_ENABLE_PYTHON)
SET(MEDIT_SOURCES mem-debug.h run-tests.h parse.h main.c)
SET(medit_libs
meditplugins
${moopythonlib}
moousertools
mooapp
smclient
@ -29,6 +34,10 @@ ADD_EXECUTABLE(medit WIN32 ${MEDIT_SOURCES})
TARGET_LINK_LIBRARIES(medit ${medit_libs} ${MOO_DEP_LIBS})
INSTALL(TARGETS medit DESTINATION ${BINDIR})
IF(MOO_ENABLE_PYTHON)
ADD_DEPENDENCIES(medit python-plugins-ini)
ENDIF(MOO_ENABLE_PYTHON)
FIND_PACKAGE(MooDesktopFile)
MOO_INSTALL_DESKTOP_FILE(medit.desktop.in)

View File

@ -16,8 +16,8 @@
#include <config.h>
#include "mooapp/mooapp.h"
#include "mooedit/mooplugin.h"
#ifdef MOO_PYTHON_BUILTIN
#include "moopython/moopython-builtin.h"
#ifdef MOO_ENABLE_PYTHON
#include "plugins/moopython/moopython-builtin.h"
#endif
#include "mooutils/mooi18n.h"
#include "mooutils/mooutils-fs.h"
@ -66,11 +66,12 @@ MOO_DEFINE_TYPE_STATIC (MeditApp, medit_app, MOO_TYPE_APP)
static void
medit_app_init_plugins (G_GNUC_UNUSED MooApp *app)
{
#ifdef MOO_PYTHON_BUILTIN
#ifdef MOO_ENABLE_PYTHON
_moo_python_builtin_init ();
#endif
moo_plugin_init_builtin ();
moo_plugin_read_dirs ();
_moo_user_tools_plugin_init ();
}
static void

View File

@ -0,0 +1,38 @@
# INPUT_FILE, OUTPUT_FILE
FIND_PROGRAM(GSED gsed)
IF(GSED)
SET(SED_PROGRAM ${GSED} -r)
ELSEIF(MOO_OS_BSD)
SET(SED_PROGRAM sed -E)
ELSE(GSED)
SET(SED_PROGRAM sed -r)
ENDIF(GSED)
MACRO(DO_FILE)
SET(COMMAND ${SED_PROGRAM} ${ARGN} "${INPUT_FILE}")
EXECUTE_PROCESS(COMMAND ${COMMAND}
RESULT_VARIABLE result
ERROR_VARIABLE error
OUTPUT_FILE "${OUTPUT_FILE}.tmp")
IF(NOT result EQUAL 0)
MESSAGE(FATAL_ERROR "Command ${COMMAND} failed: ${error}")
ENDIF(NOT result EQUAL 0)
FILE(RENAME "${OUTPUT_FILE}.tmp" "${OUTPUT_FILE}")
ENDMACRO(DO_FILE)
MACRO(DO_XML)
DO_FILE(-e "s@<_@<@g" -e "s@</_@</@g")
ENDMACRO(DO_XML)
MACRO(DO_DESKTOP)
DO_FILE(-e "s@^_(\\w+)=@\\1=@g")
ENDMACRO(DO_DESKTOP)
IF("${INPUT_FILE}" MATCHES ".*[.]xml[.]in$")
DO_XML()
ELSEIF("${INPUT_FILE}" MATCHES ".*[.](desktop|ini)[.]in$")
DO_DESKTOP()
ELSE("${INPUT_FILE}" MATCHES ".*[.]xml[.]in$")
MESSAGE(FATAL_ERROR "Unknown file type: ${INPUT_FILE}")
ENDIF("${INPUT_FILE}" MATCHES ".*[.]xml[.]in$")

View File

@ -1,4 +1,4 @@
set INTLTOOL_UPDATE=${INTLTOOL_UPDATE}
set INTLTOOL_EXTRACT=${INTLTOOL_EXTRACT}
set INTLTOOL_MERGE=${INTLTOOL_MERGE}
${PERL_EXECUTABLE} ${INTLTOOL_UPDATE} %* || exit /b %errorlevel%
${PERL_EXECUTABLE} ${__MOO_INTLTOOL_SCRIPT} %* || exit /b %errorlevel%

View File

@ -66,6 +66,8 @@ MOO_GEN_GXML(
MOO_ADD_LIBRARY(meditplugins)
# ADD_SUBDIRECTORY(moopython)
IF(MOO_ENABLE_PYTHON)
ADD_SUBDIRECTORY(moopython)
ENDIF(MOO_ENABLE_PYTHON)
# -%- strip:true -%-

View File

@ -16,10 +16,11 @@
#include <config.h>
#include "mooeditplugins.h"
void initmoo (void);
void
moo_plugin_init_builtin (void)
{
_moo_user_tools_plugin_init ();
_moo_file_selector_plugin_init ();
_moo_file_list_plugin_init ();
_moo_find_plugin_init ();

View File

@ -0,0 +1,166 @@
ADD_SUBDIRECTORY(plugins)
SET(MOOMOD_SOURCES
moo-mod.c
moopython-api.h
moopython-utils.h
moopython-utils.c
moopython-loader.h
moopython-loader.c
)
SET(PYMOO_SOURCES
moopython-mod.c
moopython-pygtkmod.h
moopython-api.h
moopython-loader.h
moopython-loader.c
moopython-utils.h
moopython-utils.c
)
SET(MOOPYTHON_SOURCES
moopython-builtin.h
moopython-builtin.c
moopython-api.h
moopython-loader.h
moopython-loader.c
moopython-utils.h
moopython-utils.c
)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/pygtk
${CMAKE_CURRENT_BINARY_DIR}/pygtk
${PYTHON_INCLUDE_DIRS}
${PYGTK_INCLUDE_DIRS}
)
ADD_DEFINITIONS(${PYTHON_DEFINITIONS} ${PYGTK_DEFINITIONS})
SET(MOOPYGTK_SOURCES
pygtk/moo-pygtk.c
pygtk/moo-pygtk.h
pygtk/mooapp-mod.h
pygtk/mooedit-mod.h
pygtk/mooutils-mod.h
pygtk/mooapp-mod.c
pygtk/mooedit-mod.c
pygtk/mooutils-mod.c
pygtk/moo-mod.h
)
SET(mooedit_defs_files
pygtk/mooeditor.defs
pygtk/mooplugin.defs
pygtk/moocommand.defs
)
SET(mooutils_defs_files
pygtk/moofileview.defs
pygtk/moopaned.defs
)
SET(mooutils_override_files
pygtk/moopaned.override
)
IF(WIN32)
SET(codegen_platform --platform win32)
ELSE(WIN32)
SET(codegen_platform)
ENDIF(WIN32)
SET(codegen_files
codegen/codegen.py
codegen/argtypes.py
codegen/argtypes_m.py
codegen/reversewrapper.py
)
GET_FILENAME_COMPONENT(_moo_abs_srcdir ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE)
SET(codegen_script ${_moo_abs_srcdir}/codegen/codegen.py)
SET(codegen ${PYTHON_EXECUTABLE} ${codegen_script} ${codegen_platform})
SET(MOO_UTILS_CODEGEN_ARGS
)
SET(MOO_EDIT_CODEGEN_ARGS
--register ${_moo_abs_srcdir}/pygtk/mooutils-pygtk.defs
)
SET(MOO_APP_CODEGEN_ARGS
--register ${_moo_abs_srcdir}/pygtk/mooutils-pygtk.defs
--register ${_moo_abs_srcdir}/pygtk/mooedit-pygtk.defs
)
SET(MOO_PY2H ${_moo_abs_srcdir}/py2h.py)
MACRO(MOO_GEN_MOD_H _moo_comp)
STRING(TOUPPER "${_moo_comp}" _moo_COMP)
MOO_ADD_GENERATED_FILE(
${CMAKE_CURRENT_BINARY_DIR}/pygtk/moo${_moo_comp}-mod.h.stamp
${CMAKE_CURRENT_BINARY_DIR}/pygtk/moo${_moo_comp}-mod.h
COMMAND ${CMAKE_COMMAND} -E make_directory pygtk
COMMAND ${PYTHON_EXECUTABLE} ${MOO_PY2H}
${_moo_abs_srcdir}/pygtk/moo${_moo_comp}-mod.py
${CMAKE_CURRENT_BINARY_DIR}/pygtk/moo${_moo_comp}-mod.h
MOO${_moo_COMP}_PY
DEPENDS pygtk/moo${_moo_comp}-mod.py ${MOO_PY2H})
ENDMACRO(MOO_GEN_MOD_H)
MOO_GEN_MOD_H("")
FOREACH(_moo_comp utils edit app)
STRING(TOUPPER ${_moo_comp} _moo_COMP)
MOO_GEN_MOD_H(${_moo_comp})
MOO_ADD_GENERATED_FILE(
${CMAKE_CURRENT_BINARY_DIR}/pygtk/moo${_moo_comp}-pygtk.stamp
${CMAKE_CURRENT_BINARY_DIR}/pygtk/moo${_moo_comp}-pygtk.c
COMMAND ${CMAKE_COMMAND} -E make_directory pygtk
COMMAND ${codegen}
--prefix _moo_${_moo_comp}
--load-types ${_moo_abs_srcdir}/codegen/argtypes_m.py
--register ${PYGTK_DEFS_DIR}/gtk-types.defs
--register ${PYGTK_DEFS_DIR}/gdk-types.defs
${MOO_${_moo_COMP}_CODEGEN_ARGS}
--override ${_moo_abs_srcdir}/pygtk/moo${_moo_comp}-pygtk.override
--outfile pygtk/moo${_moo_comp}-pygtk.c.tmp
--outfilename pygtk/moo${_moo_comp}-pygtk.c
${_moo_abs_srcdir}/pygtk/moo${_moo_comp}-pygtk.defs
COMMAND ${CMAKE_COMMAND} -E copy_if_different pygtk/moo${_moo_comp}-pygtk.c.tmp pygtk/moo${_moo_comp}-pygtk.c
COMMAND ${CMAKE_COMMAND} -E remove pygtk/moo${_moo_comp}-pygtk.c.tmp
COMMAND ${CMAKE_COMMAND} -E touch pygtk/moo${_moo_comp}-pygtk.stamp
DEPENDS pygtk/moo${_moo_comp}-pygtk.defs
pygtk/moo${_moo_comp}-pygtk.override
${moo${_moo_comp}_override_files}
${moo${_moo_comp}_defs_files}
${codegen_files})
ENDFOREACH(_moo_comp)
# noinst_LTLIBRARIES += libmoopygtk.la
#
# libmoopygtk_la_SOURCES = $(moopygtk_sources)
# nodist_libmoopygtk_la_SOURCES = $(nodist_moopygtk_sources)
# libmoopygtk_la_LIBADD =
#
# libmoopygtk_la_CFLAGS =
# -Ipygtk
# $(MOO_CFLAGS)
# $(MOO_W_NO_WRITE_STRINGS)
# $(MOO_W_NO_UNUSED)
# $(PYTHON_INCLUDES)
# $(PYGTK_CFLAGS)
#
# libmoopygtk_la_CXXFLAGS =
# -Ipygtk
# $(MOO_CXXFLAGS)
# $(MOO_W_NO_WRITE_STRINGS)
# $(MOO_W_NO_UNUSED)
# $(PYTHON_INCLUDES)
# $(PYGTK_CFLAGS)
INCLUDE_DIRECTORIES(${MOO_SOURCE_DIR})
MOO_ADD_LIBRARY(moopython ${MOOPYTHON_SOURCES} ${MOOPYGTK_SOURCES})
# -%- strip:true, indent-width:2 -%-

View File

@ -12,8 +12,6 @@ import override
import reversewrapper
import warnings
pygtk_version = 6
class Coverage(object):
def __init__(self, name):
self.name = name
@ -74,6 +72,8 @@ class FileOutput:
self.filename = filename
else:
self.filename = self.fp.name
if sys.platform == 'win32':
self.filename = self.filename.replace('\\', '/')
# handle writing to the file, and keep track of the line number ...
def write(self, str):
self.fp.write(str)
@ -154,7 +154,7 @@ class Wrapper:
getter_tmpl = (
'static PyObject *\n'
'%(funcname)s(PyObject *self, void *closure)\n'
'%(funcname)s(PyObject *self, G_GNUC_UNUSED void *closure)\n'
'{\n'
'%(varlist)s'
' ret = %(field)s;\n'
@ -181,8 +181,8 @@ class Wrapper:
noconstructor = (
'static int\n'
'pygobject_no_constructor(PyObject *self, PyObject *args, '
'PyObject *kwargs)\n'
'pygobject_no_constructor(PyObject *self, G_GNUC_UNUSED PyObject *args, '
'G_GNUC_UNUSED PyObject *kwargs)\n'
'{\n'
' gchar buf[512];\n'
'\n'
@ -195,7 +195,7 @@ class Wrapper:
function_tmpl = (
'static PyObject *\n'
'_wrap_%(cname)s(PyObject *self%(extraparams)s)\n'
'_wrap_%(cname)s(G_GNUC_UNUSED PyObject *self%(extraparams)s)\n'
'{\n'
'%(varlist)s'
'%(parseargs)s'
@ -234,7 +234,7 @@ class Wrapper:
constructor_tmpl = None
method_tmpl = None
def __init__(self, parser, objinfo, overrides, fp=FileOutput(sys.stdout)):
def __init__(self, parser, objinfo, overrides, fp):
self.parser = parser
self.objinfo = objinfo
self.overrides = overrides
@ -397,7 +397,6 @@ class Wrapper:
data = self.overrides.override(funcname)
self.write_function(funcname, data)
self.objinfo.has_new_constructor_api = (
pygtk_version >= 8 and
self.objinfo.typecode in
self.overrides.newstyle_constructors)
else:
@ -405,7 +404,7 @@ class Wrapper:
# new-style constructores :P
property_based = getattr(self,
'write_property_based_constructor',
None) and pygtk_version >= 8
None)
if property_based:
if (len(constructor.params) == 0 or
isinstance(constructor.params[0],
@ -947,7 +946,7 @@ class GObjectWrapper(Wrapper):
'%(codeafter)s\n'
'}\n\n'
)
def __init__(self, parser, objinfo, overrides, fp=FileOutput(sys.stdout)):
def __init__(self, parser, objinfo, overrides, fp):
Wrapper.__init__(self, parser, objinfo, overrides, fp)
if self.objinfo:
self.castmacro = string.replace(self.objinfo.typecode,
@ -986,8 +985,8 @@ class GObjectWrapper(Wrapper):
## just like the constructor is inheritted, we should
# inherit the new API compatibility flag
self.objinfo.has_new_constructor_api = (
pygtk_version >= 8 and parent.has_new_constructor_api)
elif self.objinfo.parent == 'GObject' and pygtk_version >= 8:
parent.has_new_constructor_api)
elif self.objinfo.parent == 'GObject':
self.objinfo.has_new_constructor_api = True
return '0'
@ -1328,7 +1327,7 @@ class GPointerWrapper(GBoxedWrapper):
return substdict
class SourceWriter:
def __init__(self, parser, overrides, prefix, fp=FileOutput(sys.stdout)):
def __init__(self, parser, overrides, prefix, fp):
self.parser = parser
self.overrides = overrides
self.prefix = prefix
@ -1656,12 +1655,13 @@ usage = 'usage: codegen.py [-o overridesfile] [-p prefix] defsfile'
def main(argv):
o = override.Overrides()
prefix = 'pygtk'
outfile = None
outfilename = None
errorfilename = None
opts, args = getopt.getopt(argv[1:], "o:p:r:t:D:I:",
["override=", "prefix=", "register=", "outfilename=",
["override=", "prefix=", "register=", "outfile=", "outfilename=",
"load-types=", "errorfilename=", "py_ssize_t-clean",
"platform=", "pygtk-version="])
"platform="])
defines = {} # -Dkey[=val] options
py_ssize_t_clean = False
for opt, arg in opts:
@ -1675,17 +1675,14 @@ def main(argv):
p.startParsing()
register_types(p)
del p
elif opt == '--outfile':
outfile = arg
elif opt == '--outfilename':
outfilename = arg
elif opt == '--errorfilename':
errorfilename = arg
elif opt == '--platform':
sys.platform = arg
elif opt == '--pygtk-version':
global pygtk_version
pygtk_version = int(arg)
if pygtk_version < 8:
defines['pygtk-2.6'] = '1'
elif opt in ('-t', '--load-types'):
globals = {}
execfile(arg, globals)
@ -1712,7 +1709,11 @@ def main(argv):
p.startParsing()
register_types(p)
sw = SourceWriter(p, o, prefix, FileOutput(sys.stdout, outfilename))
if outfile is None:
fp = sys.stdout
else:
fp = open(outfile, 'w')
sw = SourceWriter(p, o, prefix, FileOutput(fp, outfilename))
sw.write(py_ssize_t_clean)
functions_coverage.printstats()

View File

@ -20,6 +20,12 @@
#define NO_IMPORT_PYGOBJECT
#include "pygobject.h"
#include <string.h>
#include <stdlib.h>
#ifdef __WIN32__
#include <fcntl.h>
#include <io.h>
#endif
#include <glib/gstdio.h>
#include "moopython/moopython-loader.h"
#include "mooutils/mooutils-misc.h"
@ -103,20 +109,89 @@ sys_path_add_plugin_dirs (void)
}
/* Python doesn't like \r characters in the text passed to Py_CompileString() */
static char *
get_text_contents (const char *path)
{
#if 1 && defined(__WIN32__)
int fd = -1;
GIOChannel *io = NULL;
GString *content = NULL;
GString *buffer = NULL;
gsize terminator_pos;
char *contents = NULL;
GIOStatus status;
if ((fd = g_open (path, _O_RDONLY | _O_BINARY, 0)) == -1)
{
moo_warning ("could not read file '%s'", path);
goto out;
}
io = g_io_channel_win32_new_fd (fd);
if (!io)
{
moo_critical ("oops");
goto out;
}
content = g_string_new (NULL);
buffer = g_string_new (NULL);
while ((status = g_io_channel_read_line_string (io, buffer, &terminator_pos, NULL)) == G_IO_STATUS_NORMAL)
{
g_string_append_len (content, buffer->str, terminator_pos);
if (buffer->len > terminator_pos)
g_string_append_len (content, "\n", 1);
}
if (status == G_IO_STATUS_ERROR)
{
moo_warning ("error reading file '%s'", path);
goto out;
}
contents = g_string_free (content, FALSE);
content = NULL;
out:
if (content)
g_string_free (content, TRUE);
if (buffer)
g_string_free (buffer, TRUE);
if (io)
{
g_io_channel_shutdown (io, FALSE, NULL);
g_io_channel_unref (io);
}
if (fd != -1)
close (fd);
return contents;
#else
char *content = NULL;
GError *error = NULL;
if (!g_file_get_contents (path, &content, NULL, &error))
{
moo_warning ("could not read file '%s': %s", path, error->message);
g_error_free (error);
return NULL;
}
else
{
return content;
}
#endif
}
static PyObject *
do_load_file (const char *path)
{
PyObject *mod = NULL;
PyObject *code;
char *modname = NULL, *content = NULL;
GError *error = NULL;
if (!g_file_get_contents (path, &content, NULL, &error))
{
g_warning ("could not read file '%s': %s", path, error->message);
g_error_free (error);
if (!(content = get_text_contents (path)))
return NULL;
}
modname = g_strdup_printf ("moo_module_%08x", g_random_int ());
code = Py_CompileString (content, path, Py_file_input);
@ -160,7 +235,7 @@ do_load_file (const char *path)
PyErr_Restore(type, value, traceback);
}
g_warning ("error when loading file '%s'", path);
g_printerr ("error when loading file '%s'", path);
PyErr_Print ();
goto out;
}

View File

@ -54,7 +54,7 @@ void _moo_py_init_print_funcs (void);
/* avoid strict aliasing warnings */
#define return_True return PyBool_FromLong (TRUE)
#define return_False return PyBool_FromLong (FALSE)
#define return_Bool(v) return PyBool_FromLong ((v) && TRUE)
#define return_Bool(v) return PyBool_FromLong ((v) != 0)
#define return_Int(v) return PyInt_FromLong (v)

View File

@ -0,0 +1,26 @@
SET(moopython_pluginsdir ${MOO_PLUGINS_DIR})
SET(plugins_libdir ${MOO_PLUGINS_DIR}/lib)
SET(plugins
terminal.py
python.py
pycmd.py
)
SET(INI_IN_IN_FILES
terminal.ini.in.in
python.ini.in.in
pycmd.ini.in.in
)
IF(NOT WIN32)
LIST(APPEND plugins terminal.py)
LIST(APPEND INI_IN_IN_FILES terminal.ini.in.in)
ENDIF(NOT WIN32)
MOO_TRANSFORM_INI_FILES(INI_FILES ${INI_IN_IN_FILES})
ADD_CUSTOM_TARGET(python-plugins-ini DEPENDS ${INI_IN_IN_FILES})
INSTALL(FILES ${INI_FILES} ${plugins} DESTINATION ${moopython_pluginsdir})
INSTALL(FILES lib/pyconsole.py lib/insert_date_and_time.py DESTINATION ${plugins_libdir})
INSTALL(FILES medit/__init__.py medit/runpython.py DESTINATION ${plugins_libdir}/medit)

37
plugins/moopython/py2h.py Normal file
View File

@ -0,0 +1,37 @@
#! /usr/bin/python
import sys
import filecmp
import shutil
input = sys.argv[1]
output = sys.argv[2]
tmp_output = output + '.tmp'
varname = sys.argv[3]
outfile = open(tmp_output, 'w')
print >> outfile, '/* -*- C -*- */'
print >> outfile, 'static const char %s [] = ""' % (varname,)
for line in open(input):
if line.endswith('\n'):
line = line[:-1]
print >> outfile, '"' + line.replace('"', '\\"') + '\\n"'
print >> outfile, ';'
outfile.close()
docopy = False
try:
docopy = not filecmp.cmp(tmp_output, output)
except:
docopy = True
if docopy:
shutil.copyfile(tmp_output, output)
open(output + '.stamp', 'w').write('stamp\n')
try:
os.remove(tmp_output)
except:
pass

Some files were not shown because too many files have changed in this diff Show More