r1469@localhost: muntyan | 2005-12-22 21:13:18 -0600

Moving python stuff around...
master
Yevgen Muntyan 2005-12-23 14:31:22 +00:00
parent 1a2af20723
commit cf40c4d6d0
20 changed files with 189 additions and 848 deletions

View File

@ -93,14 +93,6 @@ if MOO_OS_UNIX
libmoo_sources += $(moo_unix_sources)
endif
if !MOO_OS_CYGWIN
if MOO_BUILD_LIB
# libmoo_1_0_la_LDFLAGS = $(libmoo_ldflags)
# libmoo_1_0_la_SOURCES = $(libmoo_sources)
# nodist_libmoo_1_0_la_SOURCES = $(nodist_libmoo_sources)
endif
endif
EXTRA_DIST += \
$(moo_sources) \
$(moo_win32_sources) \
@ -109,31 +101,6 @@ $(moo_built_sources) \
$(moo_extra_dist)
##############################################################################
# moo module
#
if BUILD_PYMOO
# pyexec_LTLIBRARIES = moo.la
#
# moo_la_SOURCES = $(libmoo_sources)
# nodist_moo_la_SOURCES = $(nodist_libmoo_sources)
#
# if MOO_OS_MINGW
# mingw_flags = -no-undefined
# endif MOO_OS_MINGW
#
# moo_la_LDFLAGS = -module -avoid-version -no-undefined -export-symbols-regex "initmoo"
#
# moo_la_LIBADD = \
# $(GTK_LIBS) \
# $(XML_LIBS) \
# $(PYTHON_LDFLAGS) \
# $(PYTHON_EXTRA_LIBS)
endif BUILD_PYMOO
##############################################################################
# tests
#

View File

@ -68,9 +68,6 @@ MOO_AC_PYGTK
# pcre
MOO_AC_PCRE
# Python module
MOO_AC_MODULE
################################################################################
# Components
@ -246,7 +243,6 @@ if test x$MOO_OS_CYGWIN != "xyes"; then
echo " prefix = $mooprefix"
echo " python support = $MOO_USE_PYTHON"
echo " pygtk support = $MOO_USE_PYGTK"
echo " standalone 'moo' python module = $build_pymoo"
echo " xml support = $MOO_USE_XML"
echo
echo " editor lang files go to = $MOO_TEXT_LANG_FILES_DIR"

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/>
<cppflags/>
<ldflags/>
<ccompilerbinary/>
<cxxcompilerbinary/>
<f77compilerbinary/>
<f77flags/>
<topsourcedir></topsourcedir>
<cppflags></cppflags>
<ldflags></ldflags>
<ccompilerbinary></ccompilerbinary>
<cxxcompilerbinary></cxxcompilerbinary>
<f77compilerbinary></f77compilerbinary>
<f77flags></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>
@ -198,12 +198,12 @@
</kdevautoproject>
<kdevdebugger>
<general>
<dbgshell/>
<dbgshell></dbgshell>
<programargs>--g-fatal-warnings</programargs>
<gdbpath/>
<configGdbScript/>
<runShellScript/>
<runGdbScript/>
<gdbpath></gdbpath>
<configGdbScript></configGdbScript>
<runShellScript></runShellScript>
<runGdbScript></runGdbScript>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>true</floatingtoolbar>
@ -268,16 +268,16 @@
</kdevdoctreeview>
<kdevfilecreate>
<filetypes>
<type icon="source" ext="g" create="template" name="GAP source" >
<type icon="source" ext="g" name="GAP source" create="template" >
<descr>A new empty GAP source file</descr>
</type>
<type icon="source_cpp" ext="cpp" create="template" name="C++ Source" >
<type icon="source_cpp" ext="cpp" name="C++ Source" create="template" >
<descr>A new empty C++ file.</descr>
</type>
<type icon="source_h" ext="h" create="template" name="C/C++ Header" >
<type icon="source_h" ext="h" name="C/C++ Header" create="template" >
<descr>A new empty header file for C/C++.</descr>
</type>
<type icon="source_c" ext="c" create="template" name="C Source" >
<type icon="source_c" ext="c" name="C Source" create="template" >
<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

@ -15,10 +15,6 @@
#include "config.h"
#endif
#ifdef MOO_USE_PYTHON
#include "moopython/moopython.h"
#endif
#define WANT_MOO_APP_CMD_CHARS
#include "mooapp/mooapp-private.h"
#include "mooapp/mooappinput.h"
@ -27,6 +23,7 @@
#include "mooedit/mooeditor.h"
#include "mooedit/mooplugin.h"
#include "mooedit/plugins/mooeditplugins.h"
#include "moopython/moopython.h"
#include "mooutils/moomarshals.h"
#include "mooutils/moocompat.h"
#include "mooutils/moodialogs.h"
@ -42,10 +39,6 @@
#endif
/* moo-pygtk.c */
gboolean initmoo (void);
static MooApp *moo_app_instance = NULL;
static MooAppInput *moo_app_input = NULL;
static MooAppOutput *moo_app_output = NULL;
@ -75,8 +68,6 @@ struct _MooAppPrivate {
char *tmpdir;
gboolean use_python_console;
gboolean new_app;
char **open_files;
};
@ -127,11 +118,8 @@ static void moo_app_set_description (MooApp *app,
static void all_editors_closed (MooApp *app);
static void start_python (MooApp *app);
static void start_io (MooApp *app);
#ifdef MOO_USE_PYTHON
static void execute_selection (MooEditWindow *window);
#endif
static GObjectClass *moo_app_parent_class;
@ -176,7 +164,6 @@ enum {
PROP_RUN_OUTPUT,
PROP_USE_EDITOR,
PROP_USE_TERMINAL,
PROP_USE_PYTHON_CONSOLE,
PROP_OPEN_FILES,
PROP_NEW_APP
};
@ -296,14 +283,6 @@ moo_app_class_init (MooAppClass *klass)
TRUE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class,
PROP_USE_PYTHON_CONSOLE,
g_param_spec_boolean ("use-python-console",
"use-python-console",
"use-python-console",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class,
PROP_OPEN_FILES,
g_param_spec_pointer ("open-files",
@ -505,10 +484,6 @@ moo_app_set_property (GObject *object,
app->priv->use_terminal = g_value_get_boolean (value);
break;
case PROP_USE_PYTHON_CONSOLE:
app->priv->use_python_console = g_value_get_boolean (value);
break;
case PROP_NEW_APP:
app->priv->new_app = g_value_get_boolean (value);
break;
@ -672,7 +647,6 @@ moo_app_get_rc_file_name (MooApp *app)
}
#ifdef MOO_USE_PYTHON
void
moo_app_python_execute_file (G_GNUC_UNUSED GtkWindow *parent_window)
{
@ -753,7 +727,7 @@ moo_app_python_run_string (MooApp *app,
g_return_val_if_fail (string != NULL, FALSE);
g_return_val_if_fail (moo_python_running (), FALSE);
res = moo_python_run_string (string, FALSE);
res = moo_python_run_string (string);
if (res)
{
@ -767,23 +741,6 @@ moo_app_python_run_string (MooApp *app,
}
}
static guint strv_length (char **argv)
{
guint len = 0;
char **c;
if (!argv)
return 0;
for (c = argv; *c != NULL; ++c)
++len;
return len;
}
#endif /* !MOO_USE_PYTHON */
MooEditor *moo_app_get_editor (MooApp *app)
{
g_return_val_if_fail (MOO_IS_APP (app), NULL);
@ -969,8 +926,9 @@ moo_app_init_real (MooApp *app)
app);
plugin_dirs = moo_app_get_plugin_dirs (app);
moo_set_plugin_dirs (plugin_dirs);
moo_plugin_init_builtin ();
moo_plugin_read_dirs (plugin_dirs);
moo_plugin_read_dirs ();
g_strfreev (plugin_dirs);
g_free (lang_dir);
@ -986,7 +944,6 @@ moo_app_init_real (MooApp *app)
}
#endif /* __WIN32__ && MOO_BUILD_TERM */
start_python (app);
start_io (app);
return TRUE;
@ -997,63 +954,27 @@ exit:
}
#ifdef MOO_USE_PYTHON
static void
reload_python_plugins (void)
{
_moo_python_plugin_reload ();
}
static void
add_python_plugin_actions (MooApp *app)
{
MooUIXML *xml;
MooWindowClass *klass;
klass = g_type_class_ref (MOO_TYPE_EDIT_WINDOW);
moo_window_class_new_action (klass, "ReloadPythonPlugins",
"name", "Reload Python Plugins",
"label", "Reload Python Plugins",
"icon-stock-id", GTK_STOCK_REFRESH,
"closure-callback", reload_python_plugins,
NULL);
xml = moo_app_get_ui_xml (app);
moo_ui_xml_add_item (xml, moo_ui_xml_new_merge_id (xml),
"ToolsMenu", "ReloadPythonPlugins",
"ReloadPythonPlugins", -1);
g_type_class_unref (klass);
}
#endif /* MOO_USE_PYTHON */
static void
start_python (G_GNUC_UNUSED MooApp *app)
{
#ifdef MOO_USE_PYTHON
if (app->priv->run_python)
{
G_GNUC_UNUSED char **plugin_dirs;
moo_python_start (strv_length (app->priv->argv),
app->priv->argv);
#ifdef MOO_USE_PYGTK
if (initmoo ())
{
plugin_dirs = moo_app_get_plugin_dirs (app);
_moo_python_plugin_init (plugin_dirs);
g_strfreev (plugin_dirs);
add_python_plugin_actions (app);
}
else
{
moo_PyErr_Print ();
}
#endif
}
#endif /* !MOO_USE_PYTHON */
}
// static void
// add_python_plugin_actions (MooApp *app)
// {
// MooUIXML *xml;
// MooWindowClass *klass;
//
// klass = g_type_class_ref (MOO_TYPE_EDIT_WINDOW);
// moo_window_class_new_action (klass, "ReloadPythonPlugins",
// "name", "Reload Python Plugins",
// "label", "Reload Python Plugins",
// "icon-stock-id", GTK_STOCK_REFRESH,
// "closure-callback", reload_python_plugins,
// NULL);
//
// xml = moo_app_get_ui_xml (app);
// moo_ui_xml_add_item (xml, moo_ui_xml_new_merge_id (xml),
// "ToolsMenu", "ReloadPythonPlugins",
// "ReloadPythonPlugins", -1);
//
// g_type_class_unref (klass);
// }
static void
@ -1182,11 +1103,6 @@ static void moo_app_quit_real (MooApp *app)
moo_app_output = NULL;
}
#ifdef MOO_USE_PYTHON
if (moo_python_running ())
moo_python_shutdown ();
#endif
list = g_slist_copy (app->priv->terminals);
for (l = list; l != NULL; l = l->next)
moo_window_close (MOO_WINDOW (l->data));
@ -1428,7 +1344,6 @@ static void install_editor_actions (MooApp *app)
install_actions (app, MOO_TYPE_EDIT_WINDOW);
#ifdef MOO_USE_PYTHON
moo_window_class_new_action (klass, "ExecuteSelection",
"name", "Execute Selection",
"label", "_Execute Selection",
@ -1437,7 +1352,6 @@ static void install_editor_actions (MooApp *app)
"accel", "<shift><alt>Return",
"closure-callback", execute_selection,
NULL);
#endif /* !MOO_USE_PYTHON */
g_type_class_unref (klass);
}
@ -1621,7 +1535,6 @@ GType moo_app_info_get_type (void)
}
#ifdef MOO_USE_PYTHON
static void execute_selection (MooEditWindow *window)
{
MooEdit *edit;
@ -1642,7 +1555,6 @@ static void execute_selection (MooEditWindow *window)
g_free (text);
}
}
#endif
void
@ -1706,14 +1618,12 @@ moo_app_exec_cmd_real (MooApp *app,
switch (code)
{
#ifdef MOO_USE_PYTHON
case MOO_APP_CMD_PYTHON_STRING:
moo_app_python_run_string (app, data);
break;
case MOO_APP_CMD_PYTHON_FILE:
moo_app_python_run_file (app, data);
break;
#endif
case MOO_APP_CMD_OPEN_FILE:
moo_app_open_file (app, data);

View File

@ -19,6 +19,7 @@
#include "mooedit/mooplugin.h"
#include "mooedit/moopluginprefs-glade.h"
#include "mooedit/plugins/mooeditplugins.h"
#include "moopython/mooplugin-python.h"
#include "mooutils/mooprefsdialog.h"
#include "mooutils/moostock.h"
#include <string.h>
@ -31,6 +32,7 @@ typedef struct {
MooEditor *editor;
GSList *list; /* MooPlugin* */
GHashTable *names;
char **dirs;
} PluginStore;
static PluginStore *plugin_store = NULL;
@ -821,11 +823,30 @@ moo_plugin_read_dir (const char *path)
}
void
moo_plugin_read_dirs (char **dirs)
char **
moo_get_plugin_dirs (void)
{
for ( ; dirs && *dirs; ++dirs)
moo_plugin_read_dir (*dirs);
plugin_store_init ();
return g_strdupv (plugin_store->dirs);
}
void
moo_set_plugin_dirs (char **dirs)
{
plugin_store_init ();
g_strfreev (plugin_store->dirs);
plugin_store->dirs = g_strdupv (dirs);
}
void
moo_plugin_read_dirs (void)
{
char **d;
plugin_store_init ();
for (d = plugin_store->dirs; d && *d; ++d)
moo_plugin_read_dir (*d);
}
@ -840,10 +861,6 @@ _moo_window_attach_plugins (MooEditWindow *window)
for (l = plugin_store->list; l != NULL; l = l->next)
plugin_attach_win (l->data, window);
#ifdef MOO_USE_PYGTK
_moo_python_attach_win (window);
#endif
}
@ -858,10 +875,6 @@ _moo_window_detach_plugins (MooEditWindow *window)
for (l = plugin_store->list; l != NULL; l = l->next)
plugin_detach_win (l->data, window);
#ifdef MOO_USE_PYGTK
_moo_python_detach_win (window);
#endif
}
@ -878,10 +891,6 @@ _moo_doc_attach_plugins (MooEditWindow *window,
for (l = plugin_store->list; l != NULL; l = l->next)
plugin_attach_doc (l->data, window, doc);
#ifdef MOO_USE_PYGTK
_moo_python_attach_doc (window, doc);
#endif
}
@ -898,10 +907,6 @@ _moo_doc_detach_plugins (MooEditWindow *window,
for (l = plugin_store->list; l != NULL; l = l->next)
plugin_detach_doc (l->data, window, doc);
#ifdef MOO_USE_PYGTK
_moo_python_detach_doc (window, doc);
#endif
}
@ -909,12 +914,15 @@ void
moo_plugin_init_builtin (void)
{
#ifndef __WIN32__
moo_find_plugin_init ();
_moo_find_plugin_init ();
#if GTK_CHECK_VERSION(2,6,0)
moo_file_selector_plugin_init ();
_moo_file_selector_plugin_init ();
#endif
#endif
moo_active_strings_plugin_init ();
_moo_active_strings_plugin_init ();
#ifdef MOO_USE_PYGTK
_moo_python_plugin_init ();
#endif
}

View File

@ -195,7 +195,9 @@ const char *moo_plugin_description (MooPlugin *plugin);
const char *moo_plugin_author (MooPlugin *plugin);
const char *moo_plugin_version (MooPlugin *plugin);
void moo_plugin_read_dirs (char **dirs);
char **moo_get_plugin_dirs (void);
void moo_set_plugin_dirs (char **dirs);
void moo_plugin_read_dirs (void);
void moo_plugin_init_builtin (void);
void _moo_window_attach_plugins (MooEditWindow *window);
@ -204,12 +206,6 @@ void _moo_doc_attach_plugins (MooEditWindow *window,
MooEdit *doc);
void _moo_doc_detach_plugins (MooEditWindow *window,
MooEdit *doc);
void _moo_python_attach_win (MooEditWindow *window);
void _moo_python_detach_win (MooEditWindow *window);
void _moo_python_attach_doc (MooEditWindow *window,
MooEdit *doc);
void _moo_python_detach_doc (MooEditWindow *window,
MooEdit *doc);
void _moo_plugin_attach_prefs (GtkWidget *prefs_dialog);

View File

@ -942,7 +942,7 @@ MOO_PLUGIN_DEFINE_FULL (AS, as,
gboolean
moo_active_strings_plugin_init (void)
_moo_active_strings_plugin_init (void)
{
return moo_plugin_register (as_plugin_get_type ());
}

View File

@ -1158,7 +1158,7 @@ MOO_PLUGIN_DEFINE_FULL (FileSelector, file_selector,
gboolean
moo_file_selector_plugin_init (void)
_moo_file_selector_plugin_init (void)
{
return moo_plugin_register (file_selector_plugin_get_type ());
}

View File

@ -20,15 +20,15 @@ G_BEGIN_DECLS
#ifndef __WIN32__
gboolean moo_find_plugin_init (void);
gboolean _moo_find_plugin_init (void);
#if GTK_CHECK_VERSION(2,6,0)
gboolean moo_file_selector_plugin_init (void);
gboolean _moo_file_selector_plugin_init (void);
#endif
#endif
gboolean moo_active_strings_plugin_init (void);
gboolean _moo_active_strings_plugin_init (void);
G_END_DECLS

View File

@ -909,7 +909,7 @@ MOO_PLUGIN_DEFINE_FULL (Find, find,
gboolean
moo_find_plugin_init (void)
_moo_find_plugin_init (void)
{
return moo_plugin_register (find_plugin_get_type ());
}

View File

@ -6,15 +6,15 @@ moopython = $(moo_prefix)/moopython
moopython_srcdir = $(srcdir)/$(moopython)
moopython_sources = \
$(moopython)/moopython.c \
$(moopython)/moopython.h \
$(moopython)/moopython-utils.c \
$(moopython)/moopython-utils.h \
$(moopython)/mooplugin-python.c \
$(moopython)/mooplugin-python.h
moo_sources += \
$(moopython)/moopython.c \
$(moopython)/moopython.h
if MOO_USE_PYGTK
moo_sources += $(moopython_sources)
endif
moo_extra_dist += $(moopython_sources)

View File

@ -22,131 +22,90 @@
#include "moopython/mooplugin-python.h"
#include "moopython/moopython-utils.h"
#include "moopython/moopython.h"
#include "moopython/pygtk/moo-pygtk.h"
#include "mooedit/mooplugin-macro.h"
#define PLUGIN_SUFFIX ".py"
typedef enum {
HOOK_NEW_WINDOW = 0,
HOOK_CLOSE_WINDOW,
HOOK_NEW_DOC,
HOOK_CLOSE_DOC,
HOOK_LAST
} HookType;
typedef struct {
HookType type;
PyObject *callback;
PyObject *data;
} Hook;
typedef struct _MooPyPluginData MooPyPluginData;
typedef struct {
char **dirs;
GHashTable *hook_ids;
GSList *hooks[HOOK_LAST];
int last_id;
GSList *plugins; /* MooPyPluginInfo* */
} MooPythonPlugin;
static MooPythonPlugin python_plugin;
static PyObject *main_mod;
static Hook *hook_new (HookType type,
PyObject *callback,
PyObject *data);
static void hook_free (Hook *hook);
static PyObject *moo_python_plugin_add_hook (MooPythonPlugin *plugin,
HookType type,
PyObject *callback,
PyObject *data);
static void moo_python_plugin_remove_hook (MooPythonPlugin *plugin,
int id);
static void moo_py_plugin_delete (MooPyPluginData *data);
static void
call_hooks (MooPythonPlugin *plugin,
MooEditWindow *window,
MooEdit *doc,
HookType type)
static MooPyObject*
run_string (const char *str)
{
GSList *l;
PyObject *py_win, *py_doc;
PyObject *dict;
g_return_val_if_fail (str != NULL, NULL);
dict = PyModule_GetDict (main_mod);
return (MooPyObject*) PyRun_String (str, Py_file_input, dict, dict);
}
g_return_if_fail (!window || MOO_IS_EDIT_WINDOW (window));
g_return_if_fail (!doc || MOO_IS_EDIT (doc));
g_return_if_fail (type < HOOK_LAST);
py_win = pygobject_new (G_OBJECT (window));
py_doc = doc ? pygobject_new (G_OBJECT (doc)) : NULL;
static MooPyObject*
run_file (gpointer fp,
const char *filename)
{
PyObject *dict;
g_return_val_if_fail (fp != NULL && filename != NULL, NULL);
dict = PyModule_GetDict (main_mod);
return (MooPyObject*) PyRun_File (fp, filename, Py_file_input, dict, dict);
}
for (l = plugin->hooks[type]; l != NULL; l = l->next)
static MooPyObject*
incref (MooPyObject *obj)
{
if (obj)
{
PyObject *result;
Hook *hook = l->data;
PyTuple_SET_ITEM (hook->data, 0, py_win);
if (py_doc)
PyTuple_SET_ITEM (hook->data, 1, py_doc);
result = PyObject_Call (hook->callback, hook->data, NULL);
PyTuple_SET_ITEM (hook->data, 0, NULL);
if (py_doc)
PyTuple_SET_ITEM (hook->data, 1, NULL);
if (result)
{
Py_DECREF (result);
}
else
{
PyErr_Print ();
}
Py_INCREF ((PyObject*) obj);
}
Py_XDECREF (py_win);
Py_XDECREF (py_doc);
return obj;
}
static void
decref (MooPyObject *obj)
{
if (obj)
{
Py_DECREF ((PyObject*) obj);
}
}
static void
err_print (void)
{
PyErr_Print ();
}
void
_moo_python_attach_win (MooEditWindow *window)
static gboolean
moo_python_api_init (void)
{
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
call_hooks (&python_plugin, window, NULL, HOOK_NEW_WINDOW);
}
static MooPyAPI moo_py_api = {
incref, decref, err_print,
run_string, run_file
};
g_return_val_if_fail (!moo_python_running(), FALSE);
moo_python_init (&moo_py_api);
void
_moo_python_detach_win (MooEditWindow *window)
{
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
call_hooks (&python_plugin, window, NULL, HOOK_CLOSE_WINDOW);
}
Py_Initialize ();
main_mod = PyImport_AddModule ((char*)"__main__");
Py_XINCREF ((PyObject*) main_mod);
void
_moo_python_attach_doc (MooEditWindow *window,
MooEdit *doc)
{
g_return_if_fail (!window || MOO_IS_EDIT_WINDOW (window));
g_return_if_fail (MOO_IS_EDIT (doc));
call_hooks (&python_plugin, window, doc, HOOK_NEW_DOC);
}
void
_moo_python_detach_doc (MooEditWindow *window,
MooEdit *doc)
{
g_return_if_fail (!window || MOO_IS_EDIT_WINDOW (window));
g_return_if_fail (MOO_IS_EDIT (doc));
call_hooks (&python_plugin, window, doc, HOOK_CLOSE_DOC);
return TRUE;
}
@ -228,196 +187,42 @@ moo_python_plugin_read_dir (const char *path)
static void
moo_python_plugin_read_dirs (char **dirs)
moo_python_plugin_read_dirs ()
{
for ( ; dirs && *dirs; ++dirs)
moo_python_plugin_read_dir (*dirs);
}
char **d;
char **dirs = moo_get_plugin_dirs ();
for (d = dirs; d && *d; ++d)
moo_python_plugin_read_dir (*d);
void
_moo_python_plugin_init (char **dirs)
{
if (!python_plugin.hook_ids)
python_plugin.hook_ids = g_hash_table_new (g_direct_hash, g_direct_equal);
if (python_plugin.dirs)
g_strfreev (python_plugin.dirs);
python_plugin.dirs = g_strdupv (dirs);
moo_python_plugin_read_dirs (dirs);
}
void
_moo_python_plugin_reload (void)
{
char **dirs = python_plugin.dirs;
python_plugin.dirs = NULL;
_moo_python_plugin_deinit ();
_moo_python_plugin_init (dirs);
g_strfreev (dirs);
}
static void
prepend_id (gpointer id,
G_GNUC_UNUSED gpointer hook,
GSList **list)
gboolean
_moo_python_plugin_init (void)
{
*list = g_slist_prepend (*list, id);
if (!moo_python_api_init ())
return FALSE;
if (!_moo_pygtk_init ())
return FALSE;
moo_python_plugin_read_dirs ();
return TRUE;
}
void
_moo_python_plugin_deinit (void)
{
GSList *ids = NULL, *l;
g_return_if_fail (python_plugin.hook_ids != NULL);
g_hash_table_foreach (python_plugin.hook_ids, (GHFunc) prepend_id, &ids);
for (l = ids; l != NULL; l = l->next)
moo_python_plugin_remove_hook (&python_plugin, GPOINTER_TO_INT (l->data));
g_hash_table_destroy (python_plugin.hook_ids);
python_plugin.hook_ids = NULL;
g_slist_free (ids);
/* XXX */
g_slist_foreach (python_plugin.plugins, (GFunc) moo_py_plugin_delete, NULL);
g_slist_free (python_plugin.plugins);
python_plugin.plugins = NULL;
}
static PyObject*
moo_python_plugin_add_hook (MooPythonPlugin *plugin,
HookType type,
PyObject *callback,
PyObject *data)
{
int id = ++plugin->last_id;
Hook *hook = hook_new (type, callback, data);
plugin->hooks[type] = g_slist_prepend (plugin->hooks[type], hook);
g_hash_table_insert (plugin->hook_ids, GINT_TO_POINTER (id), hook);
return_Int (id);
}
PyObject*
_moo_python_plugin_hook (const char *event,
PyObject *callback,
PyObject *data)
{
PyObject *result;
if (!strcmp (event, "new-window"))
result = moo_python_plugin_add_hook (&python_plugin, HOOK_NEW_WINDOW, callback, data);
else if (!strcmp (event, "close-window"))
result = moo_python_plugin_add_hook (&python_plugin, HOOK_CLOSE_WINDOW, callback, data);
else if (!strcmp (event, "new-doc"))
result = moo_python_plugin_add_hook (&python_plugin, HOOK_NEW_DOC, callback, data);
else if (!strcmp (event, "close-doc"))
result = moo_python_plugin_add_hook (&python_plugin, HOOK_CLOSE_DOC, callback, data);
else
return_TypeErr ("invalid event type");
return result;
}
static Hook*
hook_new (HookType type,
PyObject *callback,
PyObject *data)
{
int data_len, extra = 0, i;
Hook *hook = g_new0 (Hook, 1);
hook->type = type;
hook->callback = callback;
Py_INCREF (callback);
data_len = data ? PyTuple_GET_SIZE (data) : 0;
switch (type)
{
case HOOK_NEW_WINDOW:
case HOOK_CLOSE_WINDOW:
extra = 1;
break;
case HOOK_NEW_DOC:
case HOOK_CLOSE_DOC:
extra = 2;
break;
case HOOK_LAST:
g_return_val_if_reached (NULL);
}
hook->data = PyTuple_New (data_len + extra);
for (i = 0; i < data_len; ++i)
{
PyTuple_SET_ITEM (hook->data, i + extra,
PyTuple_GET_ITEM (data, i));
Py_INCREF (PyTuple_GET_ITEM (data, i));
}
return hook;
}
static void
moo_python_plugin_remove_hook (MooPythonPlugin *plugin,
int id)
{
Hook *hook;
g_return_if_fail (id > 0);
hook = g_hash_table_lookup (plugin->hook_ids, GINT_TO_POINTER (id));
g_return_if_fail (hook != NULL);
plugin->hooks[hook->type] = g_slist_remove (plugin->hooks[hook->type], hook);
g_hash_table_remove (plugin->hook_ids, GINT_TO_POINTER (id));
hook_free (hook);
}
static void
hook_free (Hook *hook)
{
if (hook)
{
int i, extra = 0;
switch (hook->type)
{
case HOOK_NEW_WINDOW:
case HOOK_CLOSE_WINDOW:
extra = 1;
break;
case HOOK_NEW_DOC:
case HOOK_CLOSE_DOC:
extra = 2;
break;
case HOOK_LAST:
g_critical ("%s: oops", G_STRLOC);
extra = 0;
break;
}
for (i = 0; i < extra; ++i)
{
PyTuple_SET_ITEM (hook->data, i, Py_None);
Py_INCREF (Py_None);
}
Py_XDECREF (hook->callback);
Py_XDECREF (hook->data);
g_free (hook);
}
}
/***************************************************************************/
/* Python plugins
*/
@ -596,10 +401,10 @@ moo_py_plugin_finalize (GObject *object)
}
PyObject*
_moo_python_plugin_register (PyObject *py_plugin_type,
PyObject *py_win_plugin_type,
PyObject *py_doc_plugin_type)
gpointer
_moo_python_plugin_register (gpointer py_plugin_type,
gpointer py_win_plugin_type,
gpointer py_doc_plugin_type)
{
char *plugin_type_name = NULL;
static GTypeInfo plugin_type_info;
@ -607,9 +412,9 @@ _moo_python_plugin_register (PyObject *py_plugin_type,
int i;
g_return_val_if_fail (py_plugin_type != NULL, NULL);
g_return_val_if_fail (PyType_Check (py_plugin_type), NULL);
g_return_val_if_fail (!py_win_plugin_type || PyType_Check (py_win_plugin_type), NULL);
g_return_val_if_fail (!py_doc_plugin_type || PyType_Check (py_doc_plugin_type), NULL);
g_return_val_if_fail (PyType_Check ((PyObject*) py_plugin_type), NULL);
g_return_val_if_fail (!py_win_plugin_type || PyType_Check ((PyObject*) py_win_plugin_type), NULL);
g_return_val_if_fail (!py_doc_plugin_type || PyType_Check ((PyObject*) py_doc_plugin_type), NULL);
for (i = 0; i < 1000; ++i)
{
@ -627,9 +432,9 @@ _moo_python_plugin_register (PyObject *py_plugin_type,
class_data->py_plugin_type = py_plugin_type;
class_data->py_win_plugin_type = py_win_plugin_type;
class_data->py_doc_plugin_type = py_doc_plugin_type;
Py_XINCREF (py_plugin_type);
Py_XINCREF (py_win_plugin_type);
Py_XINCREF (py_doc_plugin_type);
Py_XINCREF ((PyObject*) py_plugin_type);
Py_XINCREF ((PyObject*) py_win_plugin_type);
Py_XINCREF ((PyObject*) py_doc_plugin_type);
plugin_type_info.class_size = sizeof (MooPyPluginClass);
plugin_type_info.class_init = (GClassInitFunc) moo_py_plugin_class_init;

View File

@ -15,22 +15,16 @@
#ifndef __MOO_PLUGIN_PYTHON_H__
#define __MOO_PLUGIN_PYTHON_H__
#include <Python.h>
#include "mooedit/mooplugin.h"
#include <glib.h>
G_BEGIN_DECLS
void _moo_python_plugin_init (char **dirs);
void _moo_python_plugin_deinit (void);
void _moo_python_plugin_reload (void);
gboolean _moo_python_plugin_init (void);
PyObject *_moo_python_plugin_hook (const char *event,
PyObject *callback,
PyObject *data);
PyObject *_moo_python_plugin_register (PyObject *plugin_type,
PyObject *win_plugin_type,
PyObject *doc_plugin_type);
gpointer _moo_python_plugin_register (gpointer py_plugin_type,
gpointer py_win_plugin_type,
gpointer py_doc_plugin_type);
G_END_DECLS

View File

@ -11,255 +11,12 @@
* See COPYING file that comes with this distribution.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <Python.h>
#ifdef MOO_USE_PYGTK
#define NO_IMPORT_PYGOBJECT
#include <pygobject.h>
#endif
#include <glib.h>
#include <stdio.h>
#include "moopython/moopython.h"
#include "mooutils/moocompat.h"
static gboolean running;
MooPyAPI *_moo_py_api = NULL;
static MooPyAPI moo_py_api;
static PyObject *main_mod;
static MooPythonLogFunc log_in_func;
static MooPythonLogFunc log_out_func;
static MooPythonLogFunc log_err_func;
static gpointer log_func_data;
gboolean
moo_python_running (void)
void moo_python_init (MooPyAPI *api)
{
return running;
}
void
moo_python_shutdown (void)
{
g_return_if_fail (running);
Py_XDECREF (main_mod);
_moo_py_api = NULL;
running = FALSE;
}
static MooPyObject*
run_string (const char *str,
gboolean silent)
{
PyObject *dict;
g_return_val_if_fail (str != NULL, NULL);
if (!silent && log_in_func)
log_in_func (str, -1, log_func_data);
dict = PyModule_GetDict (main_mod);
return (MooPyObject*) PyRun_String (str, Py_file_input, dict, dict);
}
static MooPyObject*
run_file (gpointer fp,
const char *filename)
{
PyObject *dict;
g_return_val_if_fail (fp != NULL && filename != NULL, NULL);
dict = PyModule_GetDict (main_mod);
return (MooPyObject*) PyRun_File (fp, filename, Py_file_input, dict, dict);
}
static void
set_log_func (MooPythonLogFunc in,
MooPythonLogFunc out,
MooPythonLogFunc err,
gpointer data)
{
log_in_func = in;
log_out_func = out;
log_err_func = err;
log_func_data = data;
}
static void
write_log (int kind,
const char *text,
int len)
{
char *freeme = NULL;
const char *write_text;
g_return_if_fail (kind == 2 || kind == 3);
g_return_if_fail (text != NULL);
if (!len)
return;
if (len > 0)
{
freeme = g_strndup (text, len);
write_text = freeme;
}
else
{
write_text = text;
}
if (kind == 2)
{
if (log_out_func)
log_out_func (write_text, -1, log_func_data);
else
fprintf (stdout, "%s", write_text);
}
if (kind == 3)
{
if (log_err_func)
log_err_func (write_text, -1, log_func_data);
else
fprintf (stderr, "%s", write_text);
}
g_free (freeme);
}
#define WRITE_LOG "_write_log"
static PyObject*
write_log_meth (G_GNUC_UNUSED PyObject *self,
PyObject* args)
{
int kind;
const char *string;
if (PyArg_ParseTuple(args, (char*)"is:" WRITE_LOG, &kind, &string))
{
write_log (kind, string, -1);
}
else
{
g_critical (WRITE_LOG ": incorrect parameters passed");
PyErr_Clear ();
}
Py_INCREF(Py_None);
return Py_None;
}
static void
init_logger (void)
{
PyObject *fun, *res;
const char *script;
static PyMethodDef meth = {(char*) WRITE_LOG, write_log_meth, METH_VARARGS, (char*) WRITE_LOG};
fun = PyCFunction_New (&meth, main_mod);
g_return_if_fail (fun != NULL);
if (PyModule_AddObject (main_mod, (char*) WRITE_LOG, fun))
{
Py_DECREF (fun);
return;
}
script =
"import sys\n"
"class __Logger:\n"
" def __init__ (self, t):\n"
" self.kind = t\n"
" def write (self, data):\n"
" " WRITE_LOG " (self.kind, data)\n"
"sys.stdout = __Logger (2)\n"
"sys.stderr = __Logger (3)\n";
res = (PyObject*) run_string (script, TRUE);
if (res)
{
Py_DECREF (res);
}
else
{
g_critical ("%s: error in Logger initialization", G_STRLOC);
g_critical ("%s", script);
PyErr_Print ();
}
}
static MooPyObject*
incref (MooPyObject *obj)
{
if (obj)
{
Py_INCREF ((PyObject*) obj);
}
return obj;
}
static void
decref (MooPyObject *obj)
{
if (obj)
{
Py_DECREF ((PyObject*) obj);
}
}
static void
err_print (void)
{
PyErr_Print ();
}
gboolean
moo_python_start (int argc,
char **argv)
{
g_return_val_if_fail (!running, FALSE);
if (argc)
Py_SetProgramName (argv[0]);
Py_Initialize ();
if (argc)
PySys_SetArgv (argc, argv);
main_mod = PyImport_AddModule ((char*)"__main__");
Py_XINCREF ((PyObject*) main_mod);
_moo_py_api = &moo_py_api;
moo_py_api.incref = incref;
moo_py_api.decref = decref;
moo_py_api.err_print = err_print;
moo_py_api.set_log_func = set_log_func;
moo_py_api.run_string = run_string;
moo_py_api.run_file = run_file;
init_logger ();
running = TRUE;
return TRUE;
_moo_py_api = api;
}

View File

@ -18,50 +18,33 @@
G_BEGIN_DECLS
typedef struct _MooPyAPI MooPyAPI;
typedef struct _MooPyObject MooPyObject;
typedef void (*MooPythonLogFunc) (const char *text,
int len,
gpointer data);
struct _MooPyAPI {
MooPyObject* (*incref) (MooPyObject *obj);
void (*decref) (MooPyObject *obj);
void (*err_print) (void);
MooPyObject* (*incref) (MooPyObject *obj);
void (*decref) (MooPyObject *obj);
void (*err_print) (void);
void (*set_log_func)(MooPythonLogFunc in,
MooPythonLogFunc out,
MooPythonLogFunc err,
gpointer data);
MooPyObject* (*run_string) (const char *str,
gboolean silent);
MooPyObject* (*run_file) (gpointer fp,
const char *filename);
MooPyObject* (*run_string) (const char *str);
MooPyObject* (*run_file) (void *fp,
const char *filename);
};
extern MooPyAPI *_moo_py_api;
void moo_python_init (MooPyAPI *api);
gboolean moo_python_start (int argc,
char **argv);
void moo_python_shutdown (void);
gboolean moo_python_running (void);
#define moo_python_running() (_moo_py_api != NULL)
void _moo_python_plugin_init (char **dirs);
void _moo_python_plugin_deinit (void);
void _moo_python_plugin_reload (void);
#define moo_Py_INCREF _moo_py_api->incref
#define moo_Py_DECREF _moo_py_api->decref
#define moo_PyErr_Print _moo_py_api->err_print
#define moo_Py_INCREF _moo_py_api->incref
#define moo_Py_DECREF _moo_py_api->decref
#define moo_PyErr_Print _moo_py_api->err_print
#define moo_python_set_log_func _moo_py_api->set_log_func
#define moo_python_run_string _moo_py_api->run_string
#define moo_python_run_file _moo_py_api->run_file
#define moo_python_run_string _moo_py_api->run_string
#define moo_python_run_file _moo_py_api->run_file
G_END_DECLS

View File

@ -59,7 +59,7 @@ func_init_pygobject (void)
}
gboolean
initmoo (void)
_moo_pygtk_init (void)
{
PyObject *_moo_module, *code, *moo_mod;

View File

@ -24,7 +24,7 @@ extern PyMethodDef _moo_term_functions[];
extern PyMethodDef _moo_edit_functions[];
extern PyMethodDef _moo_app_functions[];
gboolean initmoo (void);
gboolean _moo_pygtk_init (void);
gboolean _moo_utils_mod_init (void);
gboolean _moo_edit_mod_init (void);

View File

@ -1,12 +1,3 @@
(define-function hook
(c-name "moo_python_plugin_hook")
(return-type "guint")
(parameters
'("const-char*" "event")
'("const-char*" "dummy")
)
)
(define-function plugin_register
(c-name "moo_python_plugin_register")
(return-type "none")

View File

@ -60,9 +60,6 @@ int _medit_parse_options (const char *const program_name,
#define STR_HELP_LOG "\
-l, --log[=FILE] Show debug output or write it to FILE\n"
#define STR_HELP_LOG_PYTHON "\
-p, --log-python Redirect output to python console\n"
#define STR_HELP_VERSION "\
--version Display version information and exit\n"
@ -72,7 +69,6 @@ int _medit_parse_options (const char *const program_name,
#define STR_HELP "\
-n, --new-app Run new instance of application\n\
-l, --log[=FILE] Show debug output or write it to FILE\n\
-p, --log-python Redirect output to python console\n\
--version Display version information and exit\n\
-h, --help Display this help text and exit\n"
@ -84,11 +80,6 @@ char _medit_opt_new_app;
char _medit_opt_log;
#endif
#ifdef MOO_USE_PYTHON
/* Set to 1 if option --log-python (-p) has been specified. */
char _medit_opt_log_python;
#endif
/* Set to 1 if option --version has been specified. */
char _medit_opt_version;
@ -105,18 +96,12 @@ const char *_medit_arg_log;
int _medit_parse_options (const char *const program_name, const int argc, char **const argv)
{
static const char *const optstr__new_app = "new-app";
#ifdef MOO_USE_PYTHON
static const char *const optstr__log_python = "log-python";
#endif
static const char *const optstr__version = "version";
static const char *const optstr__help = "help";
int i = 0;
_medit_opt_new_app = 0;
#ifdef __WIN32__
_medit_opt_log = 0;
#endif
#ifdef MOO_USE_PYTHON
_medit_opt_log_python = 0;
#endif
_medit_opt_version = 0;
_medit_opt_help = 0;
@ -161,26 +146,10 @@ int _medit_parse_options (const char *const program_name, const int argc, char *
#ifdef __WIN32__
if (strncmp (option + 1, "og", option_len - 1) == 0)
{
if (option_len < 3)
goto error_long_opt_ambiguous;
_medit_arg_log = argument;
_medit_opt_log = 1;
break;
}
#endif
#ifdef MOO_USE_PYTHON
if (strncmp (option + 1, optstr__log_python + 1, option_len - 1) == 0)
{
if (option_len <= 3)
goto error_long_opt_ambiguous;
if (argument != 0)
{
option = optstr__log_python;
goto error_unexpec_arg_long;
}
_medit_opt_log_python = 1;
break;
}
#endif
goto error_unknown_long_opt;
case 'n':
@ -210,9 +179,6 @@ int _medit_parse_options (const char *const program_name, const int argc, char *
error_unknown_long_opt:
fprintf (stderr, STR_ERR_UNKNOWN_LONG_OPT, program_name, option);
return -1;
error_long_opt_ambiguous:
fprintf (stderr, STR_ERR_LONG_OPT_AMBIGUOUS, program_name, option);
return -1;
error_unexpec_arg_long:
fprintf (stderr, STR_ERR_UNEXPEC_ARG_LONG, program_name, option);
return -1;
@ -241,11 +207,6 @@ int _medit_parse_options (const char *const program_name, const int argc, char *
case 'n':
_medit_opt_new_app = 1;
break;
#ifdef MOO_USE_PYTHON
case 'p':
_medit_opt_log_python = 1;
break;
#endif
default:
fprintf (stderr, STR_ERR_UNKNOWN_SHORT_OPT, program_name, *option);
return -1;
@ -266,9 +227,6 @@ static void usage (void)
g_print ("%s", STR_HELP_NEW_APP);
#ifdef __WIN32__
g_print ("%s", STR_HELP_LOG);
#endif
#ifdef MOO_USE_PYTHON
g_print ("%s", STR_HELP_LOG_PYTHON);
#endif
g_print ("%s", STR_HELP_VERSION);
g_print ("%s", STR_HELP_HELP);
@ -286,7 +244,6 @@ int main (int argc, char *argv[])
int opt_remain;
MooUIXML *xml;
MooEditor *editor;
G_GNUC_UNUSED gboolean use_python_console = FALSE;
gtk_init (&argc, &argv);
// gdk_window_set_debug_updates (TRUE);
@ -320,19 +277,11 @@ int main (int argc, char *argv[])
}
#endif
#ifdef MOO_USE_PYTHON
if (_medit_opt_log_python)
use_python_console = TRUE;
#endif
app = g_object_new (MOO_TYPE_APP,
"argv", argv,
"short-name", "medit",
"full-name", "medit",
"description", "medit is a text editor",
#ifdef MOO_USE_PYTHON
"use-python-console", use_python_console,
#endif
"open-files", argv + opt_remain,
"new-app", (gboolean) _medit_opt_new_app,
NULL);

View File

@ -33,9 +33,6 @@ int _medit_parse_options (const char *const program_name,
n new-app "Run new instance of application"
#ifdef __WIN32__
l log "[=FILE] Show debug output or write it to FILE" optarg
#endif
#ifdef MOO_USE_PYTHON
p log-python "Redirect output to python console"
#endif
version "Display version information and exit" return
h help "Display this help text and exit" return
@ -52,9 +49,6 @@ static void usage (void)
g_print ("%s", STR_HELP_NEW_APP);
#ifdef __WIN32__
g_print ("%s", STR_HELP_LOG);
#endif
#ifdef MOO_USE_PYTHON
g_print ("%s", STR_HELP_LOG_PYTHON);
#endif
g_print ("%s", STR_HELP_VERSION);
g_print ("%s", STR_HELP_HELP);
@ -72,7 +66,6 @@ int main (int argc, char *argv[])
int opt_remain;
MooUIXML *xml;
MooEditor *editor;
G_GNUC_UNUSED gboolean use_python_console = FALSE;
gtk_init (&argc, &argv);
// gdk_window_set_debug_updates (TRUE);
@ -106,19 +99,11 @@ int main (int argc, char *argv[])
}
#endif
#ifdef MOO_USE_PYTHON
if (_medit_opt_log_python)
use_python_console = TRUE;
#endif
app = g_object_new (MOO_TYPE_APP,
"argv", argv,
"short-name", "medit",
"full-name", "medit",
"description", "medit is a text editor",
#ifdef MOO_USE_PYTHON
"use-python-console", use_python_console,
#endif
"open-files", argv + opt_remain,
"new-app", (gboolean) _medit_opt_new_app,
NULL);