[Xfce4-commits] <pyxfce:master> add wrapper for spawn_on_screen .

Danny Milosavljevic noreply at xfce.org
Fri Jan 14 20:16:01 CET 2011


Updating branch refs/heads/master
         to 13a5eb594a7b02efe624495b3c3e84fb9bb0157e (commit)
       from 3fb5079dcc88ead31f5b9291a09170bab856b026 (commit)

commit 13a5eb594a7b02efe624495b3c3e84fb9bb0157e
Author: Danny Milosavljevic <dannym at xfce.org>
Date:   Fri Jan 14 20:12:09 2011 +0100

    add wrapper for spawn_on_screen .

 ui/spawn.override |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 ui/ui.py          |   27 +++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/ui/spawn.override b/ui/spawn.override
index a7ffb6b..2d6826a 100644
--- a/ui/spawn.override
+++ b/ui/spawn.override
@@ -4,9 +4,21 @@
 %%
 headers
 #include "pygobject.h"
+#include <stdlib.h>
 #include <gtk/gtk.h>
 #include <libxfce4ui/libxfce4ui.h>
 
+static char** PyStringList_AsStrv(PyObject* argv) { /* does NOT copy */
+	int c_argc;
+	char** c_argv;
+	int i;
+	c_argc = PySequence_Length(argv);
+	c_argv = (char**) g_malloc0_n(c_argc + 1, sizeof(char*));
+	for(i = 0; i < c_argc; ++i)
+		c_argv[i] = strdup(PyString_AsString(PyList_GetItem(argv, i)));
+	return(c_argv);
+}
+
 %%
 include
 %%
@@ -22,3 +34,39 @@ ignore-glob
 %%
 ignore-win32
 %%
+override xfce_spawn_on_screen kwargs
+static PyObject *
+_wrap_xfce_spawn_on_screen(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+    static char *kwlist[] = { "screen", "working_directory", "argv", "envp", "flags", "startup_notify", "startup_timestamp", "startup_icon_name", NULL };
+    PyGObject *screen;
+    char *working_directory, *startup_icon_name;
+    char** c_argv;
+    char** c_envp;
+    PyObject* argv;
+    PyObject* envp;
+    int flags, startup_notify, ret;
+    unsigned long startup_timestamp;
+    GError *error = NULL;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!sOOiiks:spawn_on_screen", kwlist, &PyGdkScreen_Type, &screen, &working_directory, &argv, &envp, &flags, &startup_notify, &startup_timestamp, &startup_icon_name))
+        return NULL;
+
+    if(!PySequence_Check(argv)) {
+        PyErr_SetObject(PyExc_TypeError, argv);
+        return NULL;
+    }
+    if(!PySequence_Check(envp)) {
+        PyErr_SetObject(PyExc_TypeError, envp);
+        return NULL;
+    }
+    c_envp = PyStringList_AsStrv(envp);
+    c_argv = PyStringList_AsStrv(argv);
+    ret = xfce_spawn_on_screen(GDK_SCREEN(screen->obj), working_directory, c_argv, c_envp, flags, startup_notify, startup_timestamp, startup_icon_name, &error);
+    g_strfreev(c_envp);
+    g_strfreev(c_argv);
+    
+    if (pyg_error_check(&error))
+        return NULL;
+    return PyBool_FromLong(ret);
+}
diff --git a/ui/ui.py b/ui/ui.py
index dc52da3..1f89115 100644
--- a/ui/ui.py
+++ b/ui/ui.py
@@ -5,3 +5,30 @@ from _ui import *
 def spawn_command_line(*args, **kwargs):
 	import gtk
 	return(spawn_command_line_on_screen(gtk.gdk.screen_get_default(), *args, **kwargs))
+
+SPAWN_LEAVE_DESCRIPTORS_OPEN = 1 << 0
+SPAWN_DO_NOT_REAP_CHILD      = 1 << 1
+SPAWN_SEARCH_PATH            = 1 << 2
+SPAWN_STDOUT_TO_DEV_NULL     = 1 << 3
+SPAWN_STDERR_TO_DEV_NULL     = 1 << 4
+SPAWN_CHILD_INHERITS_STDIN   = 1 << 5
+SPAWN_FILE_AND_ARGV_ZERO     = 1 << 6
+
+def spawn_on_screen(screen, working_directory, argv, envp, flags, startup_notify, startup_timestamp, startup_icon_name):
+	def to_c_envp(source):
+		if hasattr(source, "items"):
+			return ["%s=%s" % (key, value) for key, value in source.items()]
+		else:
+			return source
+	def to_c_flags(source):
+		if isinstance(source, int):
+			return(source)
+		else:
+			result = 0
+			bits = ["leave_descriptors_open", "do_not_reap_child", "search_path", "stdout_to_dev_null", "stderr_to_dev_null", "child_inherits_stdin", "file_and_argv_zero"]
+			for i, name in enumerate(bits):
+				if name in source:
+					result |= 1 << i
+			return result
+	import _ui
+	return(_ui.spawn_on_screen(screen, working_directory, argv, to_c_envp(envp), to_c_flags(flags), startup_notify, startup_timestamp, startup_icon_name))



More information about the Xfce4-commits mailing list