[Xfce4-commits] <thunarx-python:master> General code tidying to get tabs aligned and coding style more consistent
Adam Plumb
noreply at xfce.org
Thu May 27 18:14:05 CEST 2010
Updating branch refs/heads/master
to 122b3d1b01c1f9953a4bfa9ab42f193cc7b9024d (commit)
from 9de2a5e6ecad3f7f0c7d9bb5a8f15a28382e9598 (commit)
commit 122b3d1b01c1f9953a4bfa9ab42f193cc7b9024d
Author: Adam Plumb <adamplumb at gmail.com>
Date: Thu Jan 14 09:49:08 2010 -0500
General code tidying to get tabs aligned and coding style more consistent
src/thunarx-python-object.c | 354 ++++++++++++++++++++++---------------------
src/thunarx-python.c | 282 +++++++++++++++++++----------------
src/thunarx.override | 138 ++++++++++-------
3 files changed, 413 insertions(+), 361 deletions(-)
diff --git a/src/thunarx-python-object.c b/src/thunarx-python-object.c
index 33dc5c9..cb7a68d 100644
--- a/src/thunarx-python-object.c
+++ b/src/thunarx-python-object.c
@@ -38,7 +38,7 @@ static void
thunarx_python_object_finalize (GObject *object);
static void
thunarx_python_object_class_init (ThunarxPythonObjectClass *klass,
- gpointer class_data);
+ gpointer class_data);
@@ -47,21 +47,21 @@ static GList *thunarx_python_object_get_file_actions (ThunarxMenuProv
GtkWidget *window,
GList *files);
static GList *thunarx_python_object_get_folder_actions (ThunarxMenuProvider *provider,
- GtkWidget *window,
- ThunarxFileInfo *folder);
+ GtkWidget *window,
+ ThunarxFileInfo *folder);
static GList *thunarx_python_object_get_dnd_actions (ThunarxMenuProvider *provider,
- GtkWidget *window,
- ThunarxFileInfo *folder,
- GList *files);
+ GtkWidget *window,
+ ThunarxFileInfo *folder,
+ GList *files);
-static void thunarx_python_object_property_page_provider_iface_init (ThunarxPropertyPageProviderIface *iface);
-static GList *thunarx_python_object_get_property_pages (ThunarxPropertyPageProvider *provider,
- GList *files);
+static void thunarx_python_object_property_page_provider_iface_init (ThunarxPropertyPageProviderIface *iface);
+static GList *thunarx_python_object_get_property_pages (ThunarxPropertyPageProvider *provider,
+ GList *files);
-static void thunarx_python_object_preferences_provider_iface_init (ThunarxPreferencesProviderIface *iface);
-static GList *thunarx_python_object_get_preferences_actions (ThunarxPreferencesProvider *provider,
- GtkWidget *window);
+static void thunarx_python_object_preferences_provider_iface_init (ThunarxPreferencesProviderIface *iface);
+static GList *thunarx_python_object_get_preferences_actions (ThunarxPreferencesProvider *provider,
+ GtkWidget *window);
static void thunarx_python_object_renamer_provider_iface_init (ThunarxRenamerProviderIface *iface);
static GList *thunarx_python_object_get_renamers (ThunarxRenamerProvider *provider);
@@ -72,58 +72,64 @@ static GList *thunarx_python_object_get_renamers (ThunarxRenamerP
* the return value is called ret
*/
-#define CHECK_METHOD_NAME(self) \
- if (!PyObject_HasAttrString(self, METHOD_NAME)) \
+#define CHECK_METHOD_NAME(self) \
+ if (!PyObject_HasAttrString(self, METHOD_NAME)) \
goto beach;
-#define CHECK_OBJECT(object) \
- if (object->instance == NULL) \
- { \
- g_object_unref (object); \
- goto beach; \
- } \
+#define CHECK_OBJECT(object) \
+ if (object->instance == NULL) \
+ { \
+ g_object_unref (object); \
+ goto beach; \
+ } \
-#define CONVERT_LIST(py_files, files) \
- { \
+#define CONVERT_LIST(py_files, files) \
+ { \
GList *l; \
- py_files = PyList_New(0); \
- for (l = files; l; l = l->next) { \
- PyObject *obj = pygobject_new((GObject*)l->data); \
- PyList_Append(py_files, obj); \
- Py_DECREF(obj); \
+ py_files = PyList_New(0); \
+ for (l = files; l; l = l->next) \
+ { \
+ PyObject *obj = pygobject_new((GObject*)l->data); \
+ PyList_Append(py_files, obj); \
+ Py_DECREF(obj); \
} \
}
-#define HANDLE_RETVAL(py_ret) \
- if (!py_ret) { \
- PyErr_Print(); \
+#define HANDLE_RETVAL(py_ret) \
+ if (!py_ret) \
+ { \
+ PyErr_Print(); \
goto beach; \
- } \
- else if (py_ret == Py_None) { \
+ } \
+ else if (py_ret == Py_None) \
+ { \
goto beach; \
}
-#define HANDLE_LIST(py_ret, type, type_name) \
- { \
- Py_ssize_t i = 0; \
- if (!PySequence_Check(py_ret) || PyString_Check(py_ret)) { \
+#define HANDLE_LIST(py_ret, type, type_name) \
+ { \
+ Py_ssize_t i = 0; \
+ if (!PySequence_Check(py_ret) || PyString_Check(py_ret)) \
+ { \
PyErr_SetString(PyExc_TypeError, \
- METHOD_NAME " must return a sequence"); \
+ METHOD_NAME " must return a sequence"); \
goto beach; \
- } \
- for (i = 0; i < PySequence_Size (py_ret); i++) { \
+ } \
+ for (i = 0; i < PySequence_Size (py_ret); i++) \
+ { \
PyGObject *py_item; \
py_item = (PyGObject*)PySequence_GetItem (py_ret, i); \
- if (!pygobject_check(py_item, &Py##type##_Type)) { \
- PyErr_SetString(PyExc_TypeError, \
- METHOD_NAME \
- " must return a sequence of " \
- type_name); \
- goto beach; \
+ if (!pygobject_check(py_item, &Py##type##_Type)) \
+ { \
+ PyErr_SetString(PyExc_TypeError, \
+ METHOD_NAME \
+ " must return a sequence of " \
+ type_name); \
+ goto beach; \
} \
ret = g_list_append (ret, (type*) g_object_ref(py_item->obj)); \
- Py_DECREF(py_item); \
- } \
+ Py_DECREF(py_item); \
+ } \
}
@@ -133,29 +139,29 @@ thunarx_python_object_get_file_actions (ThunarxMenuProvider *provider,
GtkWidget *window,
GList *files)
{
- ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
- GList *ret = NULL;
- PyObject *py_ret = NULL, *py_files;
- PyGILState_STATE state = pyg_gil_state_ensure();
-
- debug_enter();
+ ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
+ GList *ret = NULL;
+ PyObject *py_ret = NULL, *py_files;
+ PyGILState_STATE state = pyg_gil_state_ensure();
+
+ debug_enter();
- CHECK_OBJECT(object);
- CHECK_METHOD_NAME(object->instance);
+ CHECK_OBJECT(object);
+ CHECK_METHOD_NAME(object->instance);
- CONVERT_LIST(py_files, files);
+ CONVERT_LIST(py_files, files);
- py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
- "(NN)", pygobject_new((GObject *)window), py_files);
+ py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
+ "(NN)", pygobject_new((GObject *)window), py_files);
- HANDLE_RETVAL(py_ret);
+ HANDLE_RETVAL(py_ret);
- HANDLE_LIST(py_ret, GtkAction, "gtk.Action");
+ HANDLE_LIST(py_ret, GtkAction, "gtk.Action");
beach:
- Py_XDECREF(py_ret);
- pyg_gil_state_release(state);
- return ret;
+ Py_XDECREF(py_ret);
+ pyg_gil_state_release(state);
+ return ret;
}
#undef METHOD_NAME
@@ -163,33 +169,33 @@ beach:
#define METHOD_NAME "get_folder_actions"
static GList *
-thunarx_python_object_get_folder_actions (ThunarxMenuProvider *provider,
- GtkWidget *window,
- ThunarxFileInfo *folder)
+thunarx_python_object_get_folder_actions (ThunarxMenuProvider *provider,
+ GtkWidget *window,
+ ThunarxFileInfo *folder)
{
- ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
- GList *ret = NULL;
- PyObject *py_ret = NULL;
- PyGILState_STATE state = pyg_gil_state_ensure();
-
- debug_enter();
+ ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
+ GList *ret = NULL;
+ PyObject *py_ret = NULL;
+ PyGILState_STATE state = pyg_gil_state_ensure();
- CHECK_OBJECT(object);
- CHECK_METHOD_NAME(object->instance);
+ debug_enter();
- py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
- "(NN)",
- pygobject_new((GObject *)window),
- pygobject_new((GObject *)folder));
-
- HANDLE_RETVAL(py_ret);
+ CHECK_OBJECT(object);
+ CHECK_METHOD_NAME(object->instance);
- HANDLE_LIST(py_ret, GtkAction, "gtk.Action");
+ py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
+ "(NN)",
+ pygobject_new((GObject *)window),
+ pygobject_new((GObject *)folder));
+
+ HANDLE_RETVAL(py_ret);
+
+ HANDLE_LIST(py_ret, GtkAction, "gtk.Action");
beach:
- Py_XDECREF(py_ret);
- pyg_gil_state_release(state);
- return ret;
+ Py_XDECREF(py_ret);
+ pyg_gil_state_release(state);
+ return ret;
}
#undef METHOD_NAME
@@ -197,37 +203,37 @@ beach:
#define METHOD_NAME "get_dnd_actions"
static GList *
-thunarx_python_object_get_dnd_actions (ThunarxMenuProvider *provider,
- GtkWidget *window,
- ThunarxFileInfo *folder,
- GList *files)
+thunarx_python_object_get_dnd_actions (ThunarxMenuProvider *provider,
+ GtkWidget *window,
+ ThunarxFileInfo *folder,
+ GList *files)
{
- ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
- GList *ret = NULL;
- PyObject *py_ret = NULL, *py_files;
- PyGILState_STATE state = pyg_gil_state_ensure();
-
- debug_enter();
+ ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
+ GList *ret = NULL;
+ PyObject *py_ret = NULL, *py_files;
+ PyGILState_STATE state = pyg_gil_state_ensure();
+
+ debug_enter();
- CHECK_OBJECT(object);
- CHECK_METHOD_NAME(object->instance);
+ CHECK_OBJECT(object);
+ CHECK_METHOD_NAME(object->instance);
- CONVERT_LIST(py_files, files);
+ CONVERT_LIST(py_files, files);
- py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
- "(NN)",
- pygobject_new((GObject *)window),
- pygobject_new((GObject *)folder),
- py_files);
+ py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
+ "(NN)",
+ pygobject_new((GObject *)window),
+ pygobject_new((GObject *)folder),
+ py_files);
- HANDLE_RETVAL(py_ret);
+ HANDLE_RETVAL(py_ret);
- HANDLE_LIST(py_ret, GtkAction, "gtk.Action");
+ HANDLE_LIST(py_ret, GtkAction, "gtk.Action");
beach:
- Py_XDECREF(py_ret);
- pyg_gil_state_release(state);
- return ret;
+ Py_XDECREF(py_ret);
+ pyg_gil_state_release(state);
+ return ret;
}
#undef METHOD_NAME
@@ -246,31 +252,31 @@ thunarx_python_object_menu_provider_iface_init (ThunarxMenuProviderIface *iface)
#define METHOD_NAME "get_property_pages"
static GList *
thunarx_python_object_get_property_pages (ThunarxPropertyPageProvider *provider,
- GList *files)
+ GList *files)
{
- ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
- PyObject *py_files, *py_ret = NULL;
- GList *ret = NULL;
- PyGILState_STATE state = pyg_gil_state_ensure();
-
- debug_enter();
+ ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
+ PyObject *py_files, *py_ret = NULL;
+ GList *ret = NULL;
+ PyGILState_STATE state = pyg_gil_state_ensure();
+
+ debug_enter();
- CHECK_OBJECT(object);
- CHECK_METHOD_NAME(object->instance);
+ CHECK_OBJECT(object);
+ CHECK_METHOD_NAME(object->instance);
- CONVERT_LIST(py_files, files);
+ CONVERT_LIST(py_files, files);
- py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
- "(N)", py_files);
+ py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
+ "(N)", py_files);
- HANDLE_RETVAL(py_ret);
+ HANDLE_RETVAL(py_ret);
- HANDLE_LIST(py_ret, ThunarxPropertyPage, "thunarx.PropertyPage");
+ HANDLE_LIST(py_ret, ThunarxPropertyPage, "thunarx.PropertyPage");
beach:
- Py_XDECREF(py_ret);
- pyg_gil_state_release(state);
- return ret;
+ Py_XDECREF(py_ret);
+ pyg_gil_state_release(state);
+ return ret;
}
#undef METHOD_NAME
@@ -280,26 +286,26 @@ beach:
static GList *
thunarx_python_object_get_renamers (ThunarxRenamerProvider *provider)
{
- ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
- PyObject *py_ret = NULL;
- GList *ret = NULL;
- PyGILState_STATE state = pyg_gil_state_ensure();
-
- debug_enter();
+ ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
+ PyObject *py_ret = NULL;
+ GList *ret = NULL;
+ PyGILState_STATE state = pyg_gil_state_ensure();
- CHECK_OBJECT(object);
- CHECK_METHOD_NAME(object->instance);
+ debug_enter();
- py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME, "");
+ CHECK_OBJECT(object);
+ CHECK_METHOD_NAME(object->instance);
- HANDLE_RETVAL(py_ret);
+ py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME, "");
+
+ HANDLE_RETVAL(py_ret);
+
+ HANDLE_LIST(py_ret, ThunarxRenamer, "thunarx.Renamer");
- HANDLE_LIST(py_ret, ThunarxRenamer, "thunarx.Renamer");
-
beach:
- Py_XDECREF(py_ret);
- pyg_gil_state_release(state);
- return ret;
+ Py_XDECREF(py_ret);
+ pyg_gil_state_release(state);
+ return ret;
}
#undef METHOD_NAME
@@ -313,8 +319,6 @@ thunarx_python_object_property_page_provider_iface_init (ThunarxPropertyPageProv
-
-
static void
thunarx_python_object_renamer_provider_iface_init (ThunarxRenamerProviderIface *iface)
{
@@ -323,33 +327,32 @@ thunarx_python_object_renamer_provider_iface_init (ThunarxRenamerProviderIface *
-
#define METHOD_NAME "get_preferences_actions"
static GList *
thunarx_python_object_get_preferences_actions (ThunarxPreferencesProvider *provider,
- GtkWidget *window)
+ GtkWidget *window)
{
- ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
- PyObject *py_ret = NULL;
- GList *ret = NULL;
- PyGILState_STATE state = pyg_gil_state_ensure();
-
- debug_enter();
+ ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
+ PyObject *py_ret = NULL;
+ GList *ret = NULL;
+ PyGILState_STATE state = pyg_gil_state_ensure();
+
+ debug_enter();
- CHECK_OBJECT(object);
- CHECK_METHOD_NAME(object->instance);
+ CHECK_OBJECT(object);
+ CHECK_METHOD_NAME(object->instance);
- py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
- "(N)", pygobject_new((GObject *)window));
+ py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
+ "(N)", pygobject_new((GObject *)window));
- HANDLE_RETVAL(py_ret);
+ HANDLE_RETVAL(py_ret);
- HANDLE_LIST(py_ret, GtkAction, "Gtk.Action");
+ HANDLE_LIST(py_ret, GtkAction, "Gtk.Action");
beach:
- Py_XDECREF(py_ret);
- pyg_gil_state_release(state);
- return ret;
+ Py_XDECREF(py_ret);
+ pyg_gil_state_release(state);
+ return ret;
}
#undef METHOD_NAME
@@ -366,28 +369,28 @@ thunarx_python_object_preferences_provider_iface_init (ThunarxPreferencesProvide
static void
thunarx_python_object_instance_init (ThunarxPythonObject *object)
{
- ThunarxPythonObjectClass *class;
- debug_enter();
+ ThunarxPythonObjectClass *class;
+ debug_enter();
- class = (ThunarxPythonObjectClass*)(((GTypeInstance*)object)->g_class);
+ class = (ThunarxPythonObjectClass*)(((GTypeInstance*)object)->g_class);
- object->instance = PyObject_CallObject(class->type, NULL);
- if (object->instance == NULL)
- PyErr_Print();
+ object->instance = PyObject_CallObject(class->type, NULL);
+ if (object->instance == NULL)
+ PyErr_Print();
}
static void
thunarx_python_object_finalize (GObject *object)
{
- debug_enter();
+ debug_enter();
- if (((ThunarxPythonObject *)object)->instance != NULL)
- Py_DECREF(((ThunarxPythonObject *)object)->instance);
+ if (((ThunarxPythonObject *)object)->instance != NULL)
+ Py_DECREF(((ThunarxPythonObject *)object)->instance);
}
static void
thunarx_python_object_class_init (ThunarxPythonObjectClass *klass,
- gpointer class_data)
+ gpointer class_data)
{
debug_enter();
@@ -401,7 +404,8 @@ thunarx_python_object_class_init (ThunarxPythonObjectClass *klass,
GType
-thunarx_python_object_get_type (ThunarxProviderPlugin *plugin, PyObject *type)
+thunarx_python_object_get_type (ThunarxProviderPlugin *plugin,
+ PyObject *type)
{
GTypeInfo *info;
const char *type_name;
@@ -450,25 +454,29 @@ thunarx_python_object_get_type (ThunarxProviderPlugin *plugin, PyObject *type)
type_name,
info, 0);
- if (PyObject_IsSubclass(type, (PyObject*)&PyThunarxPropertyPageProvider_Type)) {
+ if (PyObject_IsSubclass(type, (PyObject*)&PyThunarxPropertyPageProvider_Type))
+ {
thunarx_provider_plugin_add_interface (plugin, gtype,
THUNARX_TYPE_PROPERTY_PAGE_PROVIDER,
&property_page_provider_iface_info);
}
- if (PyObject_IsSubclass(type, (PyObject*)&PyThunarxMenuProvider_Type)) {
+ if (PyObject_IsSubclass(type, (PyObject*)&PyThunarxMenuProvider_Type))
+ {
thunarx_provider_plugin_add_interface (plugin, gtype,
THUNARX_TYPE_MENU_PROVIDER,
&menu_provider_iface_info);
}
- if (PyObject_IsSubclass(type, (PyObject*)&PyThunarxRenamerProvider_Type)) {
+ if (PyObject_IsSubclass(type, (PyObject*)&PyThunarxRenamerProvider_Type))
+ {
thunarx_provider_plugin_add_interface (plugin, gtype,
THUNARX_TYPE_RENAMER_PROVIDER,
&renamer_provider_iface_info);
}
- if (PyObject_IsSubclass(type, (PyObject*)&PyThunarxPreferencesProvider_Type)) {
+ if (PyObject_IsSubclass(type, (PyObject*)&PyThunarxPreferencesProvider_Type))
+ {
thunarx_provider_plugin_add_interface (plugin, gtype,
THUNARX_TYPE_PREFERENCES_PROVIDER,
&preferences_provider_iface_info);
diff --git a/src/thunarx-python.c b/src/thunarx-python.c
index ed524e6..d0ff2ef 100644
--- a/src/thunarx-python.c
+++ b/src/thunarx-python.c
@@ -45,22 +45,28 @@ static gboolean thunarx_python_init_pygtk (void);
static gboolean thunarx_python_init_python (void);
-
-static inline gboolean thunarx_python_init_pygobject(void)
+static inline gboolean
+thunarx_python_init_pygobject(void)
{
PyObject *gobject = PyImport_ImportModule("gobject");
- if (gobject != NULL) {
+ if (gobject != NULL)
+ {
PyObject *mdict = PyModule_GetDict(gobject);
PyObject *cobject = PyDict_GetItemString(mdict, "_PyGObject_API");
if (PyCObject_Check(cobject))
+ {
_PyGObject_API = (struct _PyGObject_Functions *)PyCObject_AsVoidPtr(cobject);
- else {
+ }
+ else
+ {
PyErr_SetString(PyExc_RuntimeError,
"could not find _PyGObject_API object");
PyErr_Print();
return FALSE;
}
- } else {
+ }
+ else
+ {
PyErr_Print();
g_warning("could not import gobject");
return FALSE;
@@ -70,22 +76,29 @@ static inline gboolean thunarx_python_init_pygobject(void)
-static inline gboolean thunarx_python_init_pygtk(void)
+static inline gboolean
+thunarx_python_init_pygtk(void)
{
PyObject *pygtk = PyImport_ImportModule("gtk._gtk");
- if (pygtk != NULL) {
+ if (pygtk != NULL)
+ {
PyObject *module_dict = PyModule_GetDict(pygtk);
PyObject *cobject = PyDict_GetItemString(module_dict, "_PyGtk_API");
if (PyCObject_Check(cobject))
+ {
_PyGtk_API = (struct _PyGtk_FunctionStruct*)
PyCObject_AsVoidPtr(cobject);
- else {
+ }
+ else
+ {
PyErr_SetString(PyExc_RuntimeError,
"could not find _PyGtk_API object");
PyErr_Print();
return FALSE;
}
- } else {
+ }
+ else
+ {
PyErr_Print();
g_warning("could not import gtk._gtk");
return FALSE;
@@ -100,72 +113,78 @@ thunarx_python_init_python (void)
{
PyObject *pygtk, *mdict, *require;
PyObject *sys_path, *tmp, *thunarx, *gtk, *pygtk_version, *pygtk_required_version;
- GModule *libpython;
- char *argv[] = { "thunarx", NULL };
-
- debug_enter();
+ GModule *libpython;
+ char *argv[] = { "thunarx", NULL };
- if (Py_IsInitialized())
- return TRUE;
+ debug_enter();
- debug ("g_module_open " PY_LIB_LOC "/libpython" PYTHON_VERSION "." G_MODULE_SUFFIX);
- libpython = g_module_open (PY_LIB_LOC "/libpython" PYTHON_VERSION "." G_MODULE_SUFFIX, 0);
- if (!libpython)
- g_warning ("g_module_open libpython failed: %s", g_module_error());
-
- debug ("Py_Initialize");
- Py_Initialize();
- if (PyErr_Occurred())
- {
- PyErr_Print();
- return FALSE;
- }
+ if (Py_IsInitialized())
+ return TRUE;
+
+ debug ("g_module_open " PY_LIB_LOC "/libpython" PYTHON_VERSION "." G_MODULE_SUFFIX);
+ libpython = g_module_open (PY_LIB_LOC "/libpython" PYTHON_VERSION "." G_MODULE_SUFFIX, 0);
+ if (!libpython)
+ g_warning ("g_module_open libpython failed: %s", g_module_error());
- debug ("PySys_SetArgv");
- PySys_SetArgv (1, argv);
- if (PyErr_Occurred())
- {
- PyErr_Print();
- return FALSE;
- }
-
- /* Sanitize sys.path */
- PyRun_SimpleString("import sys; sys.path = filter(None, sys.path)");
- if (PyErr_Occurred()) {
- PyErr_Print();
- return FALSE;
- }
+ debug ("Py_Initialize");
+ Py_Initialize();
+ if (PyErr_Occurred())
+ {
+ PyErr_Print();
+ return FALSE;
+ }
+
+ debug ("PySys_SetArgv");
+ PySys_SetArgv (1, argv);
+ if (PyErr_Occurred())
+ {
+ PyErr_Print();
+ return FALSE;
+ }
+
+ debug ("Sanitizing python sys.path");
+ PyRun_SimpleString("import sys; sys.path = filter(None, sys.path)");
+ if (PyErr_Occurred()) {
+ PyErr_Print();
+ return FALSE;
+ }
/* pygtk.require("2.0") */
debug("pygtk.require(\"2.0\")");
pygtk = PyImport_ImportModule("pygtk");
- if (!pygtk) {
+ if (!pygtk)
+ {
PyErr_Print();
return FALSE;
}
+
mdict = PyModule_GetDict(pygtk);
require = PyDict_GetItemString(mdict, "require");
PyObject_CallObject(require, Py_BuildValue("(S)", PyString_FromString("2.0")));
- if (PyErr_Occurred()) {
+ if (PyErr_Occurred())
+ {
PyErr_Print();
return FALSE;
}
/* import gobject */
- debug("init_pygobject");
- if (!thunarx_python_init_pygobject()) {
+ debug("init_pygobject");
+ if (!thunarx_python_init_pygobject())
+ {
g_warning("pygobject initialization failed");
return FALSE;
}
+
/* import gtk */
debug("init_pygtk");
- if (!thunarx_python_init_pygtk()) {
+ if (!thunarx_python_init_pygtk())
+ {
g_warning("pygtk initialization failed");
return FALSE;
}
/* gobject.threads_init() */
- debug("pyg_enable_threads");
+ debug("pyg_enable_threads");
setenv("PYGTK_USE_GIL_STATE_API", "", 0);
pyg_enable_threads();
@@ -174,7 +193,8 @@ thunarx_python_init_python (void)
mdict = PyModule_GetDict(gtk);
pygtk_version = PyDict_GetItemString(mdict, "pygtk_version");
pygtk_required_version = Py_BuildValue("(iii)", 2, 4, 0);
- if (PyObject_Compare(pygtk_version, pygtk_required_version) == -1) {
+ if (PyObject_Compare(pygtk_version, pygtk_required_version) == -1)
+ {
g_warning("PyGTK %s required, but %s found.",
PyString_AsString(PyObject_Repr(pygtk_required_version)),
PyString_AsString(PyObject_Repr(pygtk_version)));
@@ -182,20 +202,20 @@ thunarx_python_init_python (void)
return FALSE;
}
Py_DECREF(pygtk_required_version);
-
- debug("sys.path.insert(0, ...)");
- sys_path = PySys_GetObject("path");
- PyList_Insert(sys_path, 0, (tmp = PyString_FromString(THUNARX_LIBDIR "/thunarx-python")));
- Py_DECREF(tmp);
-
- g_setenv("INSIDE_THUNARX_PYTHON", "", FALSE);
- debug("import thunarx");
- thunarx = PyImport_ImportModule("thunarx");
- if (!thunarx)
- {
- PyErr_Print();
- return FALSE;
- }
+
+ debug("sys.path.insert(0, ...)");
+ sys_path = PySys_GetObject("path");
+ PyList_Insert(sys_path, 0, (tmp = PyString_FromString(THUNARX_LIBDIR "/thunarx-python")));
+ Py_DECREF(tmp);
+
+ g_setenv("INSIDE_THUNARX_PYTHON", "", FALSE);
+ debug("import thunarx");
+ thunarx = PyImport_ImportModule("thunarx");
+ if (!thunarx)
+ {
+ PyErr_Print();
+ return FALSE;
+ }
/* Extract types and interfaces from thunarx */
mdict = PyModule_GetDict(thunarx);
@@ -224,58 +244,60 @@ thunarx_python_init_python (void)
#undef IMPORT
- return TRUE;
+ return TRUE;
}
static void
-thunarx_python_load_file (ThunarxProviderPlugin *plugin, const gchar *filename)
+thunarx_python_load_file (ThunarxProviderPlugin *plugin,
+ const gchar *filename)
{
- PyObject *main_module, *main_locals, *locals, *key, *value;
- PyObject *module;
- Py_ssize_t pos = 0;
- GType new_type;
-
- main_module = PyImport_AddModule("__main__");
- if (main_module == NULL)
- {
- g_warning ("Could not get __main__");
- return;
- }
-
- main_locals = PyModule_GetDict(main_module);
- module = PyImport_ImportModuleEx((char *) filename, main_locals, main_locals, NULL);
- if (!module)
- {
- PyErr_Print();
- return;
- }
-
- locals = PyModule_GetDict(module);
-
- while (PyDict_Next(locals, &pos, &key, &value))
- {
- if (!PyType_Check(value))
- continue;
-
- if (PyObject_IsSubclass(value, (PyObject*)&PyThunarxMenuProvider_Type) ||
- PyObject_IsSubclass(value, (PyObject*)&PyThunarxPropertyPageProvider_Type) ||
- PyObject_IsSubclass(value, (PyObject*)&PyThunarxPreferencesProvider_Type) ||
- PyObject_IsSubclass(value, (PyObject*)&PyThunarxRenamerProvider_Type)) {
-
- new_type = thunarx_python_object_get_type(plugin, value);
- g_array_append_val(all_types, new_type);
- }
- }
+ PyObject *main_module, *main_locals, *locals, *key, *value;
+ PyObject *module;
+ Py_ssize_t pos = 0;
+ GType new_type;
+
+ main_module = PyImport_AddModule("__main__");
+ if (main_module == NULL)
+ {
+ g_warning ("Could not get __main__");
+ return;
+ }
+
+ main_locals = PyModule_GetDict(main_module);
+ module = PyImport_ImportModuleEx((char *) filename, main_locals, main_locals, NULL);
+ if (!module)
+ {
+ PyErr_Print();
+ return;
+ }
+
+ locals = PyModule_GetDict(module);
- debug ("python modules loaded");
+ while (PyDict_Next(locals, &pos, &key, &value))
+ {
+ if (!PyType_Check(value))
+ continue;
+
+ if (PyObject_IsSubclass(value, (PyObject*)&PyThunarxMenuProvider_Type) ||
+ PyObject_IsSubclass(value, (PyObject*)&PyThunarxPropertyPageProvider_Type) ||
+ PyObject_IsSubclass(value, (PyObject*)&PyThunarxPreferencesProvider_Type) ||
+ PyObject_IsSubclass(value, (PyObject*)&PyThunarxRenamerProvider_Type))
+ {
+ new_type = thunarx_python_object_get_type(plugin, value);
+ g_array_append_val(all_types, new_type);
+ }
+ }
+
+ debug ("python modules loaded");
}
static void
-thunarx_python_load_dir (ThunarxProviderPlugin *plugin, const char *dirname)
+thunarx_python_load_dir (ThunarxProviderPlugin *plugin,
+ const char *dirname)
{
GDir *dir;
const char *name;
@@ -283,7 +305,7 @@ thunarx_python_load_dir (ThunarxProviderPlugin *plugin, const char *dirname)
debug_enter_args("dirname=%s", dirname);
- dir = g_dir_open(dirname, 0, NULL);
+ dir = g_dir_open (dirname, 0, NULL);
if (!dir)
return;
@@ -300,15 +322,17 @@ thunarx_python_load_dir (ThunarxProviderPlugin *plugin, const char *dirname)
if (!initialized)
{
- PyObject *sys_path, *py_path;
- /* n-p python part is initialized on demand (or not
- * at all if no extensions are found) */
+ PyObject *sys_path, *py_path;
+
+ /* n-p python part is initialized on demand (or not
+ * at all if no extensions are found) */
if (!thunarx_python_init_python())
{
g_warning("thunarx_python_init_python failed");
g_dir_close(dir);
}
- /* sys.path.insert(0, dirname) */
+
+ /* sys.path.insert(0, dirname) */
sys_path = PySys_GetObject("path");
py_path = PyString_FromString(dirname);
PyList_Insert(sys_path, 0, py_path);
@@ -325,8 +349,8 @@ thunarx_python_load_dir (ThunarxProviderPlugin *plugin, const char *dirname)
G_MODULE_EXPORT void
thunar_extension_initialize (ThunarxProviderPlugin *plugin)
{
- const gchar *mismatch;
- const gchar *env_string;
+ const gchar *mismatch;
+ const gchar *env_string;
env_string = g_getenv("THUNARX_PYTHON_DEBUG");
if (env_string != NULL)
@@ -335,22 +359,22 @@ thunar_extension_initialize (ThunarxProviderPlugin *plugin)
thunarx_python_debug_keys,
thunarx_python_ndebug_keys);
env_string = NULL;
- }
+ }
- debug_enter();
+ debug_enter();
- /* verify that the thunarx versions are compatible */
- mismatch = thunarx_check_version (THUNARX_MAJOR_VERSION, THUNARX_MINOR_VERSION, THUNARX_MICRO_VERSION);
- if (G_UNLIKELY (mismatch != NULL))
+ /* verify that the thunarx versions are compatible */
+ mismatch = thunarx_check_version (THUNARX_MAJOR_VERSION, THUNARX_MINOR_VERSION, THUNARX_MICRO_VERSION);
+ if (G_UNLIKELY (mismatch != NULL))
{
- g_warning ("Version mismatch: %s", mismatch);
- return;
+ g_warning ("Version mismatch: %s", mismatch);
+ return;
}
- all_types = g_array_new(FALSE, FALSE, sizeof(GType));
-
- thunarx_provider_plugin_set_resident (plugin, TRUE);
- thunarx_python_load_dir(plugin, THUNARX_EXTENSION_DIR "/python");
+ all_types = g_array_new(FALSE, FALSE, sizeof(GType));
+
+ thunarx_provider_plugin_set_resident (plugin, TRUE);
+ thunarx_python_load_dir(plugin, THUNARX_EXTENSION_DIR "/python");
}
@@ -358,12 +382,12 @@ thunar_extension_initialize (ThunarxProviderPlugin *plugin)
G_MODULE_EXPORT void
thunar_extension_shutdown (void)
{
- debug_enter();
-
- if (Py_IsInitialized())
- Py_Finalize();
-
- g_array_free (all_types, TRUE);
+ debug_enter();
+
+ if (Py_IsInitialized())
+ Py_Finalize();
+
+ g_array_free (all_types, TRUE);
}
@@ -372,9 +396,9 @@ G_MODULE_EXPORT void
thunar_extension_list_types (const GType **types,
gint *n_types)
{
- debug_enter();
+ debug_enter();
- *types = (GType*)all_types->data;
- *n_types = all_types->len;
+ *types = (GType*)all_types->data;
+ *n_types = all_types->len;
}
diff --git a/src/thunarx.override b/src/thunarx.override
index e2e2d23..dd24652 100644
--- a/src/thunarx.override
+++ b/src/thunarx.override
@@ -25,115 +25,115 @@ headers
#include <thunarx/thunarx.h>
static PyObject *
-_glist_to_pyobject(GList *list)
+_glist_to_pyobject (GList *list)
{
GList *l;
PyObject *item, *ret;
- ret = PyList_New(0);
-
- if (ret == NULL)
- return NULL;
+ ret = PyList_New (0);
for (l = list; l != NULL; l = l->next)
{
- item = pygobject_new((GObject *)l->data);
+ item = pygobject_new ((GObject *)l->data);
if (item == NULL)
{
- Py_DECREF(ret);
+ Py_DECREF (ret);
return NULL;
}
- PyList_Append(ret, item);
- Py_DECREF(item);
+ PyList_Append (ret, item);
+ Py_DECREF (item);
}
return ret;
}
GList *
-_pyobject_to_glist(PyObject *py_items, PyTypeObject *type, gboolean *ok)
+_pyobject_to_glist (PyObject *py_items,
+ PyTypeObject *type,
+ gboolean *ok)
{
int len, i;
GList *items;
*ok = TRUE;
- len = PyList_Size(py_items);
+ len = PyList_Size (py_items);
for (i = 0; i < len; i++)
{
- PyObject *item = PyList_GetItem(py_items, i);
+ PyObject *item = PyList_GetItem (py_items, i);
- if (!pygobject_check(item, type))
+ if (!pygobject_check (item, type))
{
- char *err = g_strdup_printf("list item not a %s", type->tp_name);
+ char *err = g_strdup_printf ("list item not a %s", type->tp_name);
- PyErr_SetString(PyExc_TypeError, err);
+ PyErr_SetString (PyExc_TypeError, err);
- g_free(err);
- g_list_free(items);
+ g_free (err);
+ g_list_free (items);
*ok = FALSE;
return NULL;
}
- items = g_list_append(items, pygobject_get(item));
+ items = g_list_append (items, pygobject_get(item));
}
return items;
}
GHashTable *
-_pyobject_to_ghashtable(PyObject *py_dict, GHashTable *hashtable)
+_pyobject_to_ghashtable (PyObject *py_dict,
+ GHashTable *hashtable)
{
Py_ssize_t pos = 0;
PyObject *py_key, *py_value;
- g_return_if_fail(py_dict != NULL);
+ g_return_if_fail (py_dict != NULL);
- while(PyDict_Next(py_dict, &pos, &py_key, &py_value))
+ while (PyDict_Next (py_dict, &pos, &py_key, &py_value))
{
- if(PyString_Check(py_key) < 0)
+ if (PyString_Check (py_key) < 0)
{
PyErr_SetString (PyExc_TypeError, "key must be a string");
continue;
}
- if(PyString_Check(py_value) < 0)
+ if (PyString_Check (py_value) < 0)
{
PyErr_SetString (PyExc_TypeError, "value must be a string");
continue;
}
- g_hash_table_replace(hashtable, g_strdup(PyString_AsString(py_key)), g_strdup(PyString_AsString(py_value)));
+ g_hash_table_replace (hashtable, g_strdup (PyString_AsString (py_key)), g_strdup (PyString_AsString (py_value)));
}
return hashtable;
}
static PyObject*
-_ghashtable_to_pyobject(GHashTable *hashtable)
+_ghashtable_to_pyobject (GHashTable *hashtable)
{
GList *keys;
PyObject *dict;
gpointer *value;
- dict = PyDict_New();
+ dict = PyDict_New ();
- keys = g_hash_table_get_keys(hashtable);
- for (; keys; keys = g_list_next(keys))
+ keys = g_hash_table_get_keys (hashtable);
+ for (; keys; keys = g_list_next (keys))
{
- value = g_hash_table_lookup(hashtable, keys->data);
+ value = g_hash_table_lookup (hashtable, keys->data);
if (value)
{
- PyDict_SetItemString(dict, g_strdup((char*)keys->data), PyString_FromString((char *)value));
+ PyDict_SetItemString (dict, g_strdup ((char*)keys->data), PyString_FromString ((char *)value));
}
else
{
- PyErr_Warn(PyExc_RuntimeWarning, "hashtable contains a null value");
+ PyErr_Warn (PyExc_RuntimeWarning, "hashtable contains a null value");
}
}
- g_list_free(keys);
+ g_list_free (keys);
return dict;
}
@@ -153,7 +153,9 @@ ignore-glob
%%
override ThunarxRenamer__proxy_do_get_actions noargs
static GList*
-_wrap_ThunarxRenamer__proxy_do_get_actions(ThunarxRenamer *self, GtkWindow *window, GList *files)
+_wrap_ThunarxRenamer__proxy_do_get_actions(ThunarxRenamer *self,
+ GtkWindow *window,
+ GList *files)
{
PyGILState_STATE __py_state;
PyObject *py_self;
@@ -172,27 +174,33 @@ _wrap_ThunarxRenamer__proxy_do_get_actions(ThunarxRenamer *self, GtkWindow *wind
pyg_gil_state_release(__py_state);
return NULL;
}
+
if (window)
+ {
py_window = pygobject_new((GObject *) window);
- else {
+ }
+ else
+ {
Py_INCREF(Py_None);
py_window = Py_None;
}
GList *l;
py_files = PyList_New(0);
- for (l = files; l; l = l->next) {
- PyObject *obj = pygobject_new((GObject*)l->data);
- PyList_Append(py_files, obj);
- Py_DECREF(obj);
- }
+ for (l = files; l; l = l->next)
+ {
+ PyObject *obj = pygobject_new((GObject*)l->data);
+ PyList_Append(py_files, obj);
+ Py_DECREF(obj);
+ }
py_args = PyTuple_New(2);
PyTuple_SET_ITEM(py_args, 0, py_window);
PyTuple_SET_ITEM(py_args, 1, py_files);
py_method = PyObject_GetAttrString(py_self, "do_get_actions");
- if (!py_method) {
+ if (!py_method)
+ {
if (PyErr_Occurred())
PyErr_Print();
Py_DECREF(py_args);
@@ -200,8 +208,10 @@ _wrap_ThunarxRenamer__proxy_do_get_actions(ThunarxRenamer *self, GtkWindow *wind
pyg_gil_state_release(__py_state);
return NULL;
}
+
py_retval = PyObject_CallObject(py_method, py_args);
- if (!py_retval) {
+ if (!py_retval)
+ {
if (PyErr_Occurred())
PyErr_Print();
Py_XDECREF(py_retval);
@@ -213,7 +223,8 @@ _wrap_ThunarxRenamer__proxy_do_get_actions(ThunarxRenamer *self, GtkWindow *wind
}
Py_ssize_t i = 0;
- if (!PySequence_Check(py_retval) || PyString_Check(py_retval)) {
+ if (!PySequence_Check(py_retval) || PyString_Check(py_retval))
+ {
if (PyErr_Occurred())
PyErr_Print();
Py_XDECREF(py_retval);
@@ -223,22 +234,24 @@ _wrap_ThunarxRenamer__proxy_do_get_actions(ThunarxRenamer *self, GtkWindow *wind
pyg_gil_state_release(__py_state);
return NULL;
}
+
for (i = 0; i < PySequence_Size (py_retval); i++) {
PyGObject *py_item;
py_item = (PyGObject*)PySequence_GetItem (py_retval, i);
- if (!pygobject_check(py_item, &PyGtkAction_Type)) {
- if (PyErr_Occurred())
- PyErr_Print();
- Py_XDECREF(py_retval);
- Py_DECREF(py_method);
- Py_DECREF(py_args);
- Py_DECREF(py_self);
- pyg_gil_state_release(__py_state);
- return NULL;
+ if (!pygobject_check(py_item, &PyGtkAction_Type))
+ {
+ if (PyErr_Occurred())
+ PyErr_Print();
+ Py_XDECREF(py_retval);
+ Py_DECREF(py_method);
+ Py_DECREF(py_args);
+ Py_DECREF(py_self);
+ pyg_gil_state_release(__py_state);
+ return NULL;
}
retval = g_list_append (retval, g_object_ref(py_item->obj));
- Py_DECREF(py_item);
+ Py_DECREF(py_item);
}
Py_XDECREF(py_retval);
@@ -252,7 +265,8 @@ _wrap_ThunarxRenamer__proxy_do_get_actions(ThunarxRenamer *self, GtkWindow *wind
%%
override ThunarxRenamer__proxy_do_load noargs
static void
-_wrap_ThunarxRenamer__proxy_do_load(ThunarxRenamer *self, GHashTable *settings)
+_wrap_ThunarxRenamer__proxy_do_load(ThunarxRenamer *self,
+ GHashTable *settings)
{
PyGILState_STATE __py_state;
PyObject *py_self;
@@ -262,7 +276,8 @@ _wrap_ThunarxRenamer__proxy_do_load(ThunarxRenamer *self, GHashTable *settings)
__py_state = pyg_gil_state_ensure();
py_self = pygobject_new((GObject *) self);
- if (!py_self) {
+ if (!py_self)
+ {
if (PyErr_Occurred())
PyErr_Print();
pyg_gil_state_release(__py_state);
@@ -275,7 +290,8 @@ _wrap_ThunarxRenamer__proxy_do_load(ThunarxRenamer *self, GHashTable *settings)
PyTuple_SET_ITEM(py_args, 0, py_settings);
py_method = PyObject_GetAttrString(py_self, "do_load");
- if (!py_method) {
+ if (!py_method)
+ {
if (PyErr_Occurred())
PyErr_Print();
Py_DECREF(py_args);
@@ -295,7 +311,8 @@ _wrap_ThunarxRenamer__proxy_do_load(ThunarxRenamer *self, GHashTable *settings)
%%
override ThunarxRenamer__proxy_do_save noargs
static void
-_wrap_ThunarxRenamer__proxy_do_save(ThunarxRenamer *self, GHashTable *settings)
+_wrap_ThunarxRenamer__proxy_do_save(ThunarxRenamer *self,
+ GHashTable *settings)
{
PyGILState_STATE __py_state;
PyObject *py_self;
@@ -306,7 +323,8 @@ _wrap_ThunarxRenamer__proxy_do_save(ThunarxRenamer *self, GHashTable *settings)
__py_state = pyg_gil_state_ensure();
py_self = pygobject_new((GObject *) self);
- if (!py_self) {
+ if (!py_self)
+ {
if (PyErr_Occurred())
PyErr_Print();
pyg_gil_state_release(__py_state);
@@ -319,7 +337,8 @@ _wrap_ThunarxRenamer__proxy_do_save(ThunarxRenamer *self, GHashTable *settings)
PyTuple_SET_ITEM(py_args, 0, py_settings);
py_method = PyObject_GetAttrString(py_self, "do_save");
- if (!py_method) {
+ if (!py_method)
+ {
if (PyErr_Occurred())
PyErr_Print();
Py_DECREF(py_settings);
@@ -330,7 +349,8 @@ _wrap_ThunarxRenamer__proxy_do_save(ThunarxRenamer *self, GHashTable *settings)
}
py_ret = PyObject_CallObject(py_method, py_args);
- if (!py_ret) {
+ if (!py_ret)
+ {
if (PyErr_Occurred())
PyErr_Print();
Py_DECREF(py_method);
More information about the Xfce4-commits
mailing list