[Xfce4-commits] <pyxfce:master> add wrapper for xfce_spawn_on_screen_with_child_watch .
Danny Milosavljevic
noreply at xfce.org
Fri Jan 14 20:58:01 CET 2011
Updating branch refs/heads/master
to ce3fa5e8c556e14a8127d67192484fe2f59b5595 (commit)
from df6a5c2da0203f6704379da333bfadafc837949f (commit)
commit ce3fa5e8c556e14a8127d67192484fe2f59b5595
Author: Danny Milosavljevic <dannym at xfce.org>
Date: Fri Jan 14 20:54:35 2011 +0100
add wrapper for xfce_spawn_on_screen_with_child_watch .
examples/spawn/testspawn.py | 7 +++++-
ui/spawn.override | 46 +++++++++++++++++++++++++++++++++++++++++++
ui/ui.py | 36 +++++++++++++++++++--------------
3 files changed, 73 insertions(+), 16 deletions(-)
diff --git a/examples/spawn/testspawn.py b/examples/spawn/testspawn.py
index 17bfd31..78abfc6 100644
--- a/examples/spawn/testspawn.py
+++ b/examples/spawn/testspawn.py
@@ -9,4 +9,9 @@ import xfce4.ui
import xfce4.util
import shlex
-xfce4.ui.spawn_on_screen(gtk.gdk.screen_get_default(), "/", ["xterm"], os.environ, set(["search_path"]), False, gtk.get_current_event_time(), "xterm")
+def watch(inst, status):
+ print(status)
+
+#xfce4.ui.spawn_on_screen(gtk.gdk.screen_get_default(), "/", ["xterm"], os.environ, set(["search_path"]), False, gtk.get_current_event_time(), "xterm")
+xfce4.ui.spawn_on_screen_with_child_watch(gtk.gdk.screen_get_default(), "/", ["xterm"], os.environ, set(["search_path"]), False, gtk.get_current_event_time(), "xterm", watch)
+gtk.main()
diff --git a/ui/spawn.override b/ui/spawn.override
index 2d6826a..01b0684 100644
--- a/ui/spawn.override
+++ b/ui/spawn.override
@@ -70,3 +70,49 @@ _wrap_xfce_spawn_on_screen(PyObject *self, PyObject *args, PyObject *kwargs)
return NULL;
return PyBool_FromLong(ret);
}
+%%
+override xfce_spawn_on_screen_with_child_watch kwargs
+static PyObject *
+_wrap_xfce_spawn_on_screen_with_child_watch(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "screen", "working_directory", "argv", "envp", "flags", "startup_notify", "startup_timestamp", "startup_icon_name", "callback", 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;
+ PyObject* py_callback;
+ GClosure *closure;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!sOOiiksO:spawn_on_screen", kwlist, &PyGdkScreen_Type, &screen, &working_directory, &argv, &envp, &flags, &startup_notify, &startup_timestamp, &startup_icon_name, &py_callback))
+ return NULL;
+
+ if (!PyCallable_Check(py_callback)) {
+ PyErr_SetString(PyExc_TypeError, "callback argument not callable");
+ 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);
+ closure = pyg_closure_new(py_callback, NULL, NULL);
+ ret = xfce_spawn_on_screen_with_child_watch(GDK_SCREEN(screen->obj), working_directory, c_argv, c_envp, flags, startup_notify, startup_timestamp, startup_icon_name, closure, &error);
+ /* FIXME does this leak? pygobject_watch_closure((PyObject *)self, closure); */
+ /*g_closure_set_marshal (spawn_data->closure, g_cclosure_marshal_VOID__INT);*/
+ 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 1f89115..177d267 100644
--- a/ui/ui.py
+++ b/ui/ui.py
@@ -14,21 +14,27 @@ SPAWN_STDERR_TO_DEV_NULL = 1 << 4
SPAWN_CHILD_INHERITS_STDIN = 1 << 5
SPAWN_FILE_AND_ARGV_ZERO = 1 << 6
+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
+
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))
+
+def spawn_on_screen_with_child_watch(screen, working_directory, argv, envp, flags, startup_notify, startup_timestamp, startup_icon_name, callback):
+ import _ui
+ return(_ui.spawn_on_screen_with_child_watch(screen, working_directory, argv, to_c_envp(envp), to_c_flags(flags), startup_notify, startup_timestamp, startup_icon_name, callback))
More information about the Xfce4-commits
mailing list