Yet more python stuff

master
Yevgen Muntyan 2005-11-06 08:46:13 +00:00
parent abaf6e11ef
commit 0603085a28
12 changed files with 91 additions and 53 deletions

View File

@ -33,6 +33,7 @@ endif
EXTRA_PROGRAMS =
moo_prefix = moo
XML2H = $(srcdir)/moo/mooutils/xml2h.sh
PY2H = $(srcdir)/moo/mooutils/py2h.sh
include moo/Makefile.incl
include moo/mooutils/Makefile.incl
include moo/mooedit/Makefile.incl

View File

@ -24,7 +24,7 @@
</ignoreparts>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
<description></description>
<description/>
<secondaryLanguages>
<language>C</language>
</secondaryLanguages>
@ -54,13 +54,13 @@
<cflags>-O0 -g3 -pg</cflags>
<cxxflags>-O0 -g3 -pg</cxxflags>
<envvars/>
<topsourcedir></topsourcedir>
<cppflags></cppflags>
<ldflags></ldflags>
<ccompilerbinary></ccompilerbinary>
<cxxcompilerbinary></cxxcompilerbinary>
<f77compilerbinary></f77compilerbinary>
<f77flags></f77flags>
<topsourcedir/>
<cppflags/>
<ldflags/>
<ccompilerbinary/>
<cxxcompilerbinary/>
<f77compilerbinary/>
<f77flags/>
</debug>
<gtk-cvs>
<configargs>--enable-debug=full --enable-all-gcc-warnings=fatal --enable-developer-mode --disable-moo-module --without-python --without-mooterm --without-mooapp</configargs>
@ -200,10 +200,10 @@
<general>
<dbgshell>libtool</dbgshell>
<programargs>--g-fatal-warnings </programargs>
<gdbpath></gdbpath>
<configGdbScript></configGdbScript>
<runShellScript></runShellScript>
<runGdbScript></runGdbScript>
<gdbpath/>
<configGdbScript/>
<runShellScript/>
<runGdbScript/>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>true</floatingtoolbar>
@ -268,16 +268,16 @@
</kdevdoctreeview>
<kdevfilecreate>
<filetypes>
<type icon="source" ext="g" name="GAP source" create="template" >
<type icon="source" ext="g" create="template" name="GAP source" >
<descr>A new empty GAP source file</descr>
</type>
<type icon="source_cpp" ext="cpp" name="C++ Source" create="template" >
<type icon="source_cpp" ext="cpp" create="template" name="C++ Source" >
<descr>A new empty C++ file.</descr>
</type>
<type icon="source_h" ext="h" name="C/C++ Header" create="template" >
<type icon="source_h" ext="h" create="template" name="C/C++ Header" >
<descr>A new empty header file for C/C++.</descr>
</type>
<type icon="source_c" ext="c" name="C Source" create="template" >
<type icon="source_c" ext="c" create="template" name="C Source" >
<descr>A new empty C file.</descr>
</type>
</filetypes>
@ -304,7 +304,7 @@
</codecompletion>
<references/>
<creategettersetter>
<prefixGet></prefixGet>
<prefixGet/>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>

View File

@ -46,7 +46,7 @@
/* moo-pygtk.c */
void initmoo (void);
gboolean initmoo (void);
static MooApp *moo_app_instance = NULL;
@ -939,11 +939,16 @@ static void start_python (G_GNUC_UNUSED MooApp *app)
strv_length (app->priv->argv),
app->priv->argv);
#ifdef MOO_USE_PYGTK
initmoo ();
plugin_dirs = moo_app_get_plugin_dirs (app);
_moo_python_plugin_init (plugin_dirs);
g_strfreev (plugin_dirs);
if (initmoo ())
{
plugin_dirs = moo_app_get_plugin_dirs (app);
_moo_python_plugin_init (plugin_dirs);
g_strfreev (plugin_dirs);
}
else
{
PyErr_Print ();
}
#endif
}
else

View File

@ -6,10 +6,13 @@ moopython = $(moo_prefix)/moopython
moopython_srcdir = $(srcdir)/$(moopython)
moopython_sources = \
$(moopython)/moo-pygtk.c
$(moopython)/moo-pygtk.c \
$(moopython)/moo-mod.h
moopython_built_sources = \
$(moopython)/moo-mod.h
nodist_moopython_sources =
moopython_built_sources =
moopython_cleanfiles =
mooedit_defs_files = \
@ -20,6 +23,7 @@ mooedit_defs_files = \
# $(moopython_srcdir)/moowindow.override
moopython_extra_dist = \
$(moopython)/moo-mod.py \
$(moopython)/moo-pygtk.c \
$(moopython)/mooapp-pygtk.defs \
$(moopython)/mooapp-pygtk.override \
@ -107,10 +111,13 @@ $(moopython)/mooapp-pygtk.c: $(moopython)/mooapp-pygtk.defs $(moopython)/mooapp-
--outfilename mooapp-pygtk.c \
$(moopython_srcdir)/mooapp-pygtk.defs > $(moopython)/mooapp-pygtk.c
$(moopython)/moo-mod.h: $(moopython)/moo-mod.py
mkdir -p $(moopython)
sh $(PY2H) MOO_PY $(moopython_srcdir)/moo-mod.py > $(moopython)/moo-mod.h
if MOO_USE_PYGTK
moo_sources += $(moopython_sources)
moo_built_sources += $(moopython_bulit_sources)
moo_built_sources += $(moopython_built_sources)
moo_nodist_sources += $(nodist_moopython_sources)
moo_cleanfiles += $(moopython_cleanfiles)
endif

1
moo/moopython/moo-mod.py Normal file
View File

@ -0,0 +1 @@
from _moo import *

View File

@ -19,9 +19,10 @@
#include <pygobject.h> /* _PyGObjectAPI lives here */
#include <pygtk/pygtk.h>
#include <glib.h>
#include "moopython/moo-mod.h"
void initmoo (void);
gboolean initmoo (void);
void moo_utils_mod_init (PyObject *moo_mod);
void moo_edit_mod_init (PyObject *moo_mod);
void moo_term_mod_init (PyObject *moo_mod);
@ -48,43 +49,44 @@ static PyObject *moo_detailed_version (void)
}
static PyMethodDef moo_functions[] = {
static PyMethodDef _moo_functions[] = {
{NULL, NULL, 0, NULL}
};
static char *moo_module_doc = (char*)"moo module.";
static char *_moo_module_doc = (char*)"_moo module.";
#define mod_init(class) \
{ \
class##_mod_init (moo_module); \
class##_mod_init (_moo_module); \
if (PyErr_Occurred ()) \
{ \
PyErr_Print (); \
PyErr_SetString (PyExc_RuntimeError, \
"error in " #class \
"_mod_init"); \
return; \
} \
return FALSE; \
}
void initmoo (void)
static void
func_init_pygobject (void)
{
PyObject *moo_module;
init_pygobject ();
init_pygtk ();
}
moo_module = Py_InitModule3 ((char*)"moo", moo_functions, moo_module_doc);
gboolean
initmoo (void)
{
PyObject *_moo_module, *code, *moo_mod;
if (PyErr_Occurred ()) {
PyErr_Print ();
PyErr_SetString (PyExc_RuntimeError, "could not create 'moo' module");
return;
}
func_init_pygobject ();
PyModule_AddObject (moo_module, (char*)"version", moo_version());
PyModule_AddObject (moo_module, (char*)"detailed_version", moo_detailed_version());
if (PyErr_Occurred ())
return FALSE;
_moo_module = Py_InitModule3 ((char*) "_moo", _moo_functions, _moo_module_doc);
if (PyErr_Occurred ())
return FALSE;
PyModule_AddObject (_moo_module, (char*)"version", moo_version());
PyModule_AddObject (_moo_module, (char*)"detailed_version", moo_detailed_version());
#ifdef MOO_BUILD_UTILS
mod_init (moo_utils);
@ -98,4 +100,17 @@ void initmoo (void)
#ifdef MOO_BUILD_APP
mod_init (moo_app);
#endif
code = Py_CompileString (MOO_PY, "moo.py", Py_file_input);
if (!code)
return FALSE;
moo_mod = PyImport_ExecCodeModule ((char*) "moo", code);
Py_DECREF (code);
if (!moo_mod)
return FALSE;
return TRUE;
}

View File

@ -14,7 +14,7 @@ modulename moo
import gtk.Window as PyGtkWindow_Type
import gtk.Widget as PyGtkWidget_Type
import gobject.GObject as PyGObject_Type
import moo.UIXML as PyMooUIXML_Type
import _moo.UIXML as PyMooUIXML_Type
%%
ignore-glob
*_get_type

View File

@ -23,8 +23,8 @@ import gtk.TextTagTable as PyGtkTextTagTable_Type
import gtk.TextTag as PyGtkTextTag_Type
import gtk.gdk.Pixbuf as PyGdkPixbuf_Type
import gobject.GObject as PyGObject_Type
import moo.Window as PyMooWindow_Type
import moo.UIXML as PyMooUIXML_Type
import _moo.Window as PyMooWindow_Type
import _moo.UIXML as PyMooUIXML_Type
%%
ignore-glob
*_get_type

View File

@ -30,7 +30,7 @@ modulename moo
import gtk.Widget as PyGtkWidget_Type
import gtk.Adjustment as PyGtkAdjustment_Type
import gobject.GObject as PyGObject_Type
import moo.Window as PyMooWindow_Type
import _moo.Window as PyMooWindow_Type
%%
ignore-glob
*_get_type

View File

@ -28,7 +28,7 @@ void moo_utils_add_constants (PyObject *module,
%%
modulename moo.utils
modulename moo
%%
import gtk.Window as PyGtkWindow_Type
import gtk.Widget as PyGtkWidget_Type

View File

@ -266,6 +266,7 @@ nodist_mooutils_sources = \
mooutils_extra_dist = \
$(mooutils_python_sources) \
$(mooutils)/moomarshals.list \
$(mooutils)/py2h.sh \
$(mooutils)/xml2h.sh
mooutils_built_sources = \

8
moo/mooutils/py2h.sh Normal file
View File

@ -0,0 +1,8 @@
if [ x$2 = x ]; then
echo usage: "$0 <var_name> <file_name>"
exit 1
fi
echo "static const char *$1 = \"\""
sed 's/"/\\"/g' $2 | sed 's/\\/\\\\/g' | sed 's/^\(.*\)$/"\1\\n"/'
echo ";"