diff options
author | Nalin Dahyabhai <nalin@src.gnome.org> | 2002-10-25 22:07:11 +0000 |
---|---|---|
committer | Nalin Dahyabhai <nalin@src.gnome.org> | 2002-10-25 22:07:11 +0000 |
commit | 25f084882412a537c4a3cc6993027f9707d8cc81 (patch) | |
tree | d87932bf93020b30a2d37807922d9ee53de0f55b /python | |
parent | e600d5ea308a700166c9a59e9e88e80ac7f91263 (diff) |
snip off final newlines when we're matching, they're usually not wanted.
* src/vte.c (vte_terminal_match_check_internal): snip off final newlines when
we're matching, they're usually not wanted.
* src/pty.c, src/pty.h: replace the simpler pty_open() function with a logging
version, adding the ability to specify a startup directory (Red Hat
#76529).
* src/vte.c, src/vte.h: replace the simpler fork_command() function with a
logging version, adding the ability to specify a startup directory (Red
Hat #76529).
* src/vteapp.c: modify call to handle new fork_command().
* python/vte.defs: update as above.
* python/vte.override: modify call to handle new fork_command(), adding an
optional "directory" argument.
* src/vte.c: refactor the selection code, cleaning up when selection is
cleared/started/extended (#95783). Grab focus whenever we get button
press or release or motion events.
* src/vte.c: rework how wide characters are stored to allow storing tabs
(#95958).
* python/vte.override: wrap vte_terminal_get_text() and
vte_terminal_get_text_range(). Based on patch from ha shao (#96230).
* src/vte.c, src/vte.h: add a user pointer argument to get_text callbacks
(#96230).
* src/Makefile.am: bump shared library version because we changed a public
function's signature. Take the opportunity to replace padding fields
which had previously been used up.
Diffstat (limited to 'python')
-rwxr-xr-x | python/cat.py | 13 | ||||
-rw-r--r-- | python/vte.defs | 12 | ||||
-rw-r--r-- | python/vte.override | 248 |
3 files changed, 249 insertions, 24 deletions
diff --git a/python/cat.py b/python/cat.py index ce8f553..c870299 100755 --- a/python/cat.py +++ b/python/cat.py @@ -10,9 +10,16 @@ def main_quit(object, *args): def commit_cb(object, *args): (text, length) = args - # Echo the text input by the user to stdout. - sys.stdout.write(text) - sys.stdout.flush() + # Echo the text input by the user to stdout. Note that the string's + # length isn't always going to be right. + if (0): + sys.stdout.write(text) + sys.stdout.flush() + else: + # Test the get_text() function. + for line in (string.splitfields(object.get_text(),"\n")): + if (line.__len__() > 0): + print line # Also display it. object.feed(text, length) diff --git a/python/vte.defs b/python/vte.defs index 5d44fb3..4d186e4 100644 --- a/python/vte.defs +++ b/python/vte.defs @@ -48,17 +48,7 @@ '("const-char*" "command") '("char**" "argv") '("char**" "envv") - ) -) - -(define-method fork_logged_command - (of-object "VteTerminal") - (c-name "vte_terminal_fork_logged_command") - (return-type "pid_t") - (parameters - '("const-char*" "command") - '("char**" "argv") - '("char**" "envv") + '("const-char*" "directory") '("gboolean" "lastlog") '("gboolean" "utmp") '("gboolean" "wtmp") diff --git a/python/vte.override b/python/vte.override index 76d3169..8cc2d8f 100644 --- a/python/vte.override +++ b/python/vte.override @@ -3,6 +3,7 @@ headers #include <Python.h> #include <pygtk/pygtk.h> +#include <pygobject.h> #include <gtk/gtk.h> #include "../src/vte.h" %% @@ -10,24 +11,26 @@ import gtk.gdk.Pixbuf as PyGdkPixbuf_Type import gtk.MenuShell as PyGtkMenuShell_Type import gtk.Widget as PyGtkWidget_Type %% -ignore vte_terminal_get_text -ignore vte_terminal_get_text_range -%% override vte_terminal_fork_command kwargs + static PyObject * _wrap_vte_terminal_fork_command(PyGObject * self, PyObject * args, PyObject * kwargs) { gchar **argv = NULL, **envv = NULL; - gchar *command = NULL; - static char *kwlist[] = { "command", "argv", "envv", NULL }; - PyObject *py_argv = NULL, *py_envv = NULL; + gchar *command = NULL, *directory = NULL; + static char *kwlist[] = { "command", "argv", "envv", "directory", + "loglastlog", "logutmp", "logwtmp", + NULL }; + PyObject *py_argv = NULL, *py_envv = NULL, + *loglastlog = NULL, *logutmp = NULL, *logwtmp = NULL; int i, n_args, n_envs; pid_t pid; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|sOO:fork_command", - kwlist, &command, &py_argv, - &py_envv)) { + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|sOOsOOO:fork_command", + kwlist, &command, &py_argv, &py_envv, + &directory, + &loglastlog, &logutmp, &logwtmp)) { return NULL; } @@ -67,7 +70,13 @@ _wrap_vte_terminal_fork_command(PyGObject * self, PyObject * args, } pid = vte_terminal_fork_command(VTE_TERMINAL(self->obj), - command, argv, envv); + command, argv, envv, directory, + (loglastlog != NULL) && + PyObject_IsTrue(loglastlog), + (logutmp != NULL) && + PyObject_IsTrue(logutmp), + (logwtmp != NULL) && + PyObject_IsTrue(logwtmp)); if (argv) { g_free(argv); @@ -76,3 +85,222 @@ _wrap_vte_terminal_fork_command(PyGObject * self, PyObject * args, return PyInt_FromLong(pid); } %% +override vte_terminal_get_text kwargs + +static gboolean +call_callback(VteTerminal *terminal, glong column, glong row, gpointer data) +{ + PyObject *cb, *self, *args, *result; + gboolean ret; + int i; + if (!PyArg_ParseTuple(data, "|O:call_callback", &args)) { + return FALSE; + } + args = PyList_New(0); + cb = PySequence_GetItem(args, 0); /* INCREFs */ + Py_DECREF(cb); + self = PySequence_GetItem(args, 1); /* INCREFs */ + Py_DECREF(self); + PyList_Append(args, self); + PyList_Append(args, PyInt_FromLong(column)); + PyList_Append(args, PyInt_FromLong(row)); + for (i = 2; i < PySequence_Length(args); i++) { + PyObject *item = PySequence_GetItem(args, i); + Py_DECREF(item); + PyList_Append(args, item); + } + result = PyObject_CallObject(cb, args); + ret = (result && PyObject_IsTrue(result)); + Py_DECREF(args); + Py_DECREF(result); + return ret; +} + +static gboolean +always_true(VteTerminal *terminal, glong row, glong column, gpointer data) +{ + return TRUE; +} +static PyObject * +_wrap_vte_terminal_get_text(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "callback", "attributes", "data", NULL }; + PyObject *callback = NULL, *do_attr = NULL, *data = NULL; + PyObject *callback_and_args = NULL; + GArray *attrs = NULL; + PyObject *text; + PyObject *py_attrs; + int count; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOO:terminal_get_text", + kwlist, &callback, &do_attr, &args)) { + return NULL; + } + + if (do_attr != NULL && do_attr != Py_None) { + attrs = g_array_new(FALSE, TRUE, sizeof(struct vte_char_attributes)); + } else { + attrs = NULL; + } + + if ((callback != NULL) && (callback != Py_None)) { + if (!PyCallable_Check(callback)) { + PyErr_SetString(PyExc_TypeError, "1st argument not callable."); + if (attrs) { + g_array_free(attrs, TRUE); + } + return NULL; + } + } else { + callback = NULL; + } + + if (callback != NULL) { + callback_and_args = PyList_New(0); + PyList_Append(callback_and_args, callback); + PyList_Append(callback_and_args, (PyObject*) self); + if (PyList_Check(data)) { + for (count = 0; count < PyList_Size(data); count++) { + PyList_Append(callback_and_args, PyList_GetItem(data, count)); + } + } else { + PyList_Append(callback_and_args, data); + } + } + + text = PyString_FromString(vte_terminal_get_text(VTE_TERMINAL(self->obj), + callback ? + call_callback : + always_true, + callback ? + callback_and_args : + NULL, + attrs)); + Py_XDECREF(callback_and_args); + + if (attrs) { + py_attrs = PyTuple_New(attrs->len); + for (count = 0; count < attrs->len; count++) { + struct vte_char_attributes *cht; + PyObject *py_char_attr; + PyObject *py_gdkcolor; + + cht = &g_array_index(attrs, struct vte_char_attributes, count); + py_char_attr = PyDict_New(); + PyDict_SetItemString(py_char_attr, "row", PyInt_FromLong(cht->row)); + PyDict_SetItemString(py_char_attr, "column", PyInt_FromLong(cht->column)); + + py_gdkcolor = pyg_boxed_new(GDK_TYPE_COLOR, &cht->fore, TRUE, TRUE); + PyDict_SetItemString(py_char_attr, "fore", py_gdkcolor); + py_gdkcolor = pyg_boxed_new(GDK_TYPE_COLOR, &cht->back, TRUE, TRUE); + PyDict_SetItemString(py_char_attr, "back", py_gdkcolor); + + PyDict_SetItemString(py_char_attr, "underline", + PyInt_FromLong(cht->underline)); + PyDict_SetItemString(py_char_attr, "alternate", + PyInt_FromLong(cht->alternate)); + + PyTuple_SetItem(py_attrs, count, py_char_attr); + } + g_array_free(attrs, TRUE); + return Py_BuildValue("(OO)", text, py_attrs); + } else { + return Py_BuildValue("O", text); + } +} +%% +override vte_terminal_get_text_range kwargs +static PyObject * +_wrap_vte_terminal_get_text_range(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "callback", "start_row", "start_col", "end_row", + "end_col", "attributes", "data", NULL }; + PyObject *callback = NULL, *do_attr = NULL, *data = NULL; + glong start_row, start_col, end_row, end_col; + PyObject *callback_and_args = NULL; + GArray *attrs = NULL; + PyObject *text; + PyObject *py_attrs; + int count; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|llllOOO:terminal_get_text", + kwlist, + &start_row, &start_col, &end_row, &end_col, + &callback, &do_attr, &args)) { + return NULL; + } + + if (do_attr != NULL && do_attr != Py_None) { + attrs = g_array_new(FALSE, TRUE, sizeof(struct vte_char_attributes)); + } else { + attrs = NULL; + } + + if ((callback != NULL) && (callback != Py_None)) { + if (!PyCallable_Check(callback)) { + PyErr_SetString(PyExc_TypeError, "1st argument not callable."); + if (attrs) { + g_array_free(attrs, TRUE); + } + return NULL; + } + } else { + callback = NULL; + } + + if (callback != NULL) { + callback_and_args = PyList_New(0); + PyList_Append(callback_and_args, callback); + PyList_Append(callback_and_args, (PyObject*) self); + if (PyList_Check(data)) { + for (count = 0; count < PyList_Size(data); count++) { + PyList_Append(callback_and_args, PyList_GetItem(data, count)); + } + } else { + PyList_Append(callback_and_args, data); + } + } + + text = PyString_FromString(vte_terminal_get_text_range(VTE_TERMINAL(self->obj), + start_row, start_col, + end_row, end_col, + callback ? + call_callback : + always_true, + callback ? + callback_and_args : + NULL, + attrs)); + Py_XDECREF(callback_and_args); + + if (attrs) { + py_attrs = PyTuple_New(attrs->len); + for (count = 0; count < attrs->len; count++) { + struct vte_char_attributes *cht; + PyObject *py_char_attr; + PyObject *py_gdkcolor; + + cht = &g_array_index(attrs, struct vte_char_attributes, count); + py_char_attr = PyDict_New(); + PyDict_SetItemString(py_char_attr, "row", PyInt_FromLong(cht->row)); + PyDict_SetItemString(py_char_attr, "column", PyInt_FromLong(cht->column)); + + py_gdkcolor = pyg_boxed_new(GDK_TYPE_COLOR, &cht->fore, TRUE, TRUE); + PyDict_SetItemString(py_char_attr, "fore", py_gdkcolor); + py_gdkcolor = pyg_boxed_new(GDK_TYPE_COLOR, &cht->back, TRUE, TRUE); + PyDict_SetItemString(py_char_attr, "back", py_gdkcolor); + + PyDict_SetItemString(py_char_attr, "underline", + PyInt_FromLong(cht->underline)); + PyDict_SetItemString(py_char_attr, "alternate", + PyInt_FromLong(cht->alternate)); + + PyTuple_SetItem(py_attrs, count, py_char_attr); + } + g_array_free(attrs, TRUE); + return Py_BuildValue("(OO)", text, py_attrs); + } else { + return Py_BuildValue("O", text); + } +} +%% |