r1249@localhost: muntyan | 2005-12-03 15:28:37 -0600

Some random stuff here and there
This commit is contained in:
Yevgen Muntyan 2005-12-04 16:23:10 +00:00
parent ba6e78e21a
commit 671210ac4b
9 changed files with 143 additions and 99 deletions

View File

@ -113,6 +113,30 @@ class StringArg(ArgType):
' Py_INCREF(Py_None);\n' +
' return Py_None;')
class StrvArg(ArgType):
def write_param(self, ptype, pname, pdflt, pnull, info):
if pdflt:
if pdflt != 'NULL': raise TypeError("Only NULL is supported as a default char** value")
info.varlist.add('char', '**' + pname + ' = ' + pdflt)
else:
info.varlist.add('char', '**' + pname)
info.arglist.append(pname)
if pnull:
info.add_parselist('O&', ['moo_pyobject_to_strv', '&' + pname], [pname])
else:
info.add_parselist('O&', ['moo_pyobject_to_strv_no_null', '&' + pname], [pname])
def write_return(self, ptype, ownsreturn, info):
if ownsreturn:
# have to free result ...
info.varlist.add('char', '**ret')
info.varlist.add('PyObject', '*py_ret')
info.codeafter.append(' py_ret = moo_strv_to_pyobject (ret);' +
' g_strfreev (ret);' +
' return py_ret;')
else:
info.varlist.add('char', '**ret')
info.codeafter.append(' return moo_strv_to_pyobject (ret);')
class UCharArg(ArgType):
# allows strings with embedded NULLs.
def write_param(self, ptype, pname, pdflt, pnull, info):
@ -860,6 +884,9 @@ matcher.register('gchar-const*', arg)
matcher.register('string', arg)
matcher.register('static_string', arg)
arg = StrvArg()
matcher.register('strv', arg)
arg = UCharArg()
matcher.register('unsigned-char*', arg)
matcher.register('const-guchar*', arg)

View File

@ -55,6 +55,12 @@
(release-func "moo_term_profile_free")
)
(define-pointer TermLine
(in-module "Moo")
(c-name "MooTermLine")
(gtype-id "MOO_TYPE_TERM_LINE")
)
;; Enumerations and flags ...
@ -388,11 +394,11 @@
(define-method fork_command
(of-object "MooTerm")
(c-name "moo_term_fork_command")
(return-type "gboolean")
(return-type "none")
(parameters
'("const-MooTermCommand*" "cmd")
'("const-char*" "working_dir")
'("char**" "envp")
'("const-char*" "working_dir" (null-ok) (default "NULL"))
'("strv" "envp" (null-ok) (default "NULL"))
'("GError**" "error")
)
)
@ -400,25 +406,41 @@
(define-method fork_command_line
(of-object "MooTerm")
(c-name "moo_term_fork_command_line")
(return-type "gboolean")
(return-type "none")
(parameters
'("const-char*" "cmd_line")
'("const-char*" "working_dir")
'("char**" "envp")
'("const-char*" "working_dir" (null-ok) (default "NULL"))
'("strv" "envp" (null-ok) (default "NULL"))
'("GError**" "error")
)
(docstring "fork_command_line(cmd, [working_dir, env]) -> None. Starts process in the terminal\n"
"\n"
"cmd - command line\n"
"working_dir - working directory for new process\n"
"env - sequence of strings representing environment variables \n"
"for new process, in format 'VARIABLE=value'\n"
"\n"
"Raises gobject.GError on error.")
)
(define-method fork_argv
(of-object "MooTerm")
(c-name "moo_term_fork_argv")
(return-type "gboolean")
(return-type "none")
(parameters
'("char**" "argv")
'("const-char*" "working_dir")
'("char**" "envp")
'("strv" "argv")
'("const-char*" "working_dir" (null-ok) (default "NULL"))
'("strv" "envp" (null-ok) (default "NULL"))
'("GError**" "error")
)
(docstring "fork_argv(cmd, [working_dir, env]) -> None. Starts process in the terminal\n"
"\n"
"argv - sequence of command line arguments\n"
"working_dir - working directory for new process\n"
"env - sequence of strings representing environment variables \n"
"for new process, in format 'VARIABLE=value'\n"
"\n"
"Raises gobject.GError on error.")
)
(define-method child_alive
@ -579,8 +601,8 @@
(parameters
'("const-char*" "name")
'("const-MooTermCommand*" "cmd")
'("char**" "envp")
'("const-char*" "working_dir")
'("strv" "env" (null-ok) (default "NULL"))
'("const-char*" "working_dir" (null-ok) (default "NULL"))
)
)
@ -705,8 +727,8 @@
(is-constructor-of "MooTermCommand")
(return-type "MooTermCommand*")
(parameters
'("const-char*" "cmd_line")
'("char**" "argv")
'("const-char*" "cmd_line" (null-ok) (default "NULL"))
'("strv" "argv" (null-ok) (default "NULL"))
)
)
@ -716,12 +738,6 @@
(return-type "MooTermCommand*")
)
(define-method free
(of-object "MooTermCommand")
(c-name "moo_term_command_free")
(return-type "none")
)
;; From mootermbuffer.h

View File

@ -54,60 +54,6 @@ _wrap_moo_term_new (PyGObject *self, PyObject *args, PyObject *kwargs)
return 0;
}
%%
override moo_term_fork_command_line kwargs
static PyObject *
_wrap_moo_term_fork_command_line (PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {(char*)"cmd", (char*)"working_dir", (char*)"env", NULL};
const char *cmd = NULL;
const char *working_dir = NULL;
char **env = NULL;
GError *error = NULL;
if (!PyArg_ParseTupleAndKeywords (args, kwargs, (char*) "s|sO&:Term.fork_command_line",
kwlist, &cmd, &working_dir,
moo_pyobject_to_strv, &env))
return NULL;
if (working_dir)
g_print ("working_dir: %s\n", working_dir);
moo_term_fork_command_line (MOO_TERM (self->obj), cmd,
working_dir, env, &error);
g_strfreev (env);
if (pyg_error_check (&error))
return NULL;
return_None;
}
%%
override moo_term_fork_argv kwargs
static PyObject *
_wrap_moo_term_fork_argv (PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {(char*)"argv", (char*)"working_dir", (char*)"env", NULL};
const char *working_dir = NULL;
char **argv = NULL;
char **env = NULL;
GError *error = NULL;
if (!PyArg_ParseTupleAndKeywords (args, kwargs, (char*) "O&|sO&:Term.fork_argv",
kwlist, moo_pyobject_to_strv, &argv,
&working_dir, moo_pyobject_to_strv, &env))
return NULL;
moo_term_fork_argv (MOO_TERM (self->obj), argv,
working_dir, env, &error);
g_strfreev (env);
g_strfreev (argv);
if (pyg_error_check (&error))
return NULL;
return_None;
}
%%
override moo_term_copy_clipboard kwargs
static PyObject *
_wrap_moo_term_copy_clipboard (PyGObject *self, PyObject *args, PyObject *kwargs)
@ -275,3 +221,14 @@ _wrap_moo_term_get_screen_size (PyGObject *self)
moo_term_get_screen_size (MOO_TERM (self->obj), &columns, &rows);
return Py_BuildValue ((char*) "(ii)", columns, rows);
}
%%
override moo_term_command_copy noargs
static PyObject *
_wrap_moo_term_command_copy (PyObject *self)
{
MooTermCommand *ret;
ret = moo_term_command_copy (pyg_boxed_get (self, MooTermCommand));
return pyg_boxed_new (MOO_TYPE_TERM_COMMAND, ret, FALSE, TRUE);
}

View File

@ -128,12 +128,10 @@
)
(define-boxed UINode
(define-pointer UINode
(in-module "Moo")
(c-name "MooUINode")
(gtype-id "MOO_TYPE_UI_NODE")
(copy-func "moo_ui_node_ref")
(release-func "moo_ui_node_unref")
)
(define-boxed PaneLabel

View File

@ -697,3 +697,15 @@ moo_term_line_get_text (MooTermLine *line,
return g_string_free (text, FALSE);
}
GType
moo_term_line_get_type (void)
{
static GType type = 0;
if (!type)
type = g_pointer_type_register_static ("MooTermLine");
return type;
}

View File

@ -22,6 +22,8 @@ G_BEGIN_DECLS
typedef struct _MooTermCell MooTermCell;
typedef struct _MooTermLine MooTermLine;
#define MOO_TYPE_TERM_LINE (moo_term_line_get_type ())
#define MOO_TERM_EMPTY_CHAR ' '
#define MOO_TERM_ZERO_ATTR {0, 0, 0}
@ -35,6 +37,8 @@ typedef struct _MooTermLine MooTermLine;
(a1__).background == (a2__).background))
GType moo_term_line_get_type (void) G_GNUC_CONST;
guint moo_term_line_len (MooTermLine *line);
gunichar moo_term_line_get_char (MooTermLine *line,
guint index_);

View File

@ -2455,22 +2455,13 @@ moo_ui_xml_finalize (GObject *object)
}
static gpointer
ptr_copy (gpointer boxed)
{
return boxed;
}
GType
moo_ui_node_get_type (void)
{
static GType type = 0;
if (!type)
type = g_boxed_type_register_static ("MooUINode",
(GBoxedCopyFunc) ptr_copy,
(GBoxedFreeFunc) ptr_copy);
type = g_pointer_type_register_static ("MooUINode");
return type;
}

View File

@ -23,15 +23,14 @@
#endif
PyObject *moo_strv_to_pyobject (char **strv)
PyObject *
moo_strv_to_pyobject (char **strv)
{
PyObject *result;
guint len, i;
if (!strv)
{
return_None;
}
len = g_strv_length (strv);
result = PyTuple_New (len);
@ -46,6 +45,35 @@ PyObject *moo_strv_to_pyobject (char **strv)
}
static char **
moo_pyobject_to_strv_no_check (PyObject *seq,
int len)
{
#define CACHE_SIZE 10
static char **cache[CACHE_SIZE];
static guint n;
int i;
char **ret;
g_strfreev (cache[n]);
cache[n] = ret = g_new (char*, len + 1);
ret[len] = NULL;
for (i = 0; i < len; ++i)
{
PyObject *item = PySequence_ITEM (seq, i);
ret[i] = g_strdup (PyString_AS_STRING (item));
}
if (++n == CACHE_SIZE)
n = 0;
return ret;
#undef CACHE_SIZE
}
int moo_pyobject_to_strv (PyObject *obj, char ***dest)
{
int len, i;
@ -86,19 +114,27 @@ int moo_pyobject_to_strv (PyObject *obj, char ***dest)
}
}
*dest = g_new (char*, len + 1);
(*dest)[len] = NULL;
for (i = 0; i < len; ++i)
{
PyObject *item = PySequence_ITEM (obj, i);
(*dest)[i] = g_strdup (PyString_AS_STRING (item));
}
*dest = moo_pyobject_to_strv_no_check (obj, len);
return TRUE;
}
int
moo_pyobject_to_strv_no_null (PyObject *obj,
char ***dest)
{
if (obj == Py_None)
{
PyErr_SetString (PyExc_TypeError,
"argument must be a sequence, not None");
return FALSE;
}
return moo_pyobject_to_strv (obj, dest);
}
PyObject *moo_gvalue_to_pyobject (const GValue *val)
{
return pyg_value_as_pyobject (val, TRUE);

View File

@ -25,10 +25,13 @@ PyObject *moo_py_object_ref (PyObject *obj);
void moo_py_object_unref (PyObject *obj);
GType moo_py_object_get_type (void) G_GNUC_CONST;
PyObject *moo_strv_to_pyobject (char **strv);
/* result may not be freed */
int moo_pyobject_to_strv (PyObject *obj,
char ***dest);
int moo_pyobject_to_strv_no_null (PyObject *obj,
char ***dest);
PyObject *moo_object_slist_to_pyobject (GSList *list);
PyObject *moo_string_slist_to_pyobject (GSList *list);