Added support for string and GObject GSList's; moo_boxed_slist_to_pyobject()
This commit is contained in:
parent
7bd0745ae8
commit
105e546bbf
@ -111,6 +111,71 @@ 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);\n' +
|
||||
' g_strfreev (ret);\n' +
|
||||
' return py_ret;')
|
||||
else:
|
||||
info.varlist.add('char', '**ret')
|
||||
info.codeafter.append(' return moo_strv_to_pyobject (ret);')
|
||||
|
||||
class StringSListArg(ArgType):
|
||||
def write_return(self, ptype, ownsreturn, info):
|
||||
if ownsreturn:
|
||||
# have to free result ...
|
||||
info.varlist.add('GSList', '*ret')
|
||||
info.varlist.add('PyObject', '*py_ret')
|
||||
info.codeafter.append(' py_ret = moo_string_slist_to_pyobject (ret);\n' +
|
||||
' g_slist_foreach (ret, (GFunc) g_free, NULL);\n' +
|
||||
' g_slist_free (ret);\n' +
|
||||
' return py_ret;')
|
||||
else:
|
||||
info.varlist.add('GSList', '*ret')
|
||||
info.codeafter.append(' return moo_string_slist_to_pyobject (ret);')
|
||||
|
||||
class ObjectSListArg(ArgType):
|
||||
def write_return(self, ptype, ownsreturn, info):
|
||||
if ownsreturn:
|
||||
# have to free result ...
|
||||
info.varlist.add('GSList', '*ret')
|
||||
info.varlist.add('PyObject', '*py_ret')
|
||||
info.codeafter.append(' py_ret = moo_object_slist_to_pyobject (ret);\n' +
|
||||
' g_slist_foreach (ret, (GFunc) g_object_unref, NULL);\n' +
|
||||
' g_slist_free (ret);\n' +
|
||||
' return py_ret;')
|
||||
else:
|
||||
info.varlist.add('GSList', '*ret')
|
||||
info.codeafter.append(' return moo_object_slist_to_pyobject (ret);')
|
||||
|
||||
class NoRefObjectSListArg(ArgType):
|
||||
def write_return(self, ptype, ownsreturn, info):
|
||||
if ownsreturn:
|
||||
# have to free result ...
|
||||
info.varlist.add('GSList', '*ret')
|
||||
info.varlist.add('PyObject', '*py_ret')
|
||||
info.codeafter.append(' py_ret = moo_object_slist_to_pyobject (ret);\n' +
|
||||
' g_slist_free (ret);\n' +
|
||||
' return py_ret;')
|
||||
else:
|
||||
info.varlist.add('GSList', '*ret')
|
||||
info.codeafter.append(' return moo_object_slist_to_pyobject (ret);')
|
||||
|
||||
class UCharArg(ArgType):
|
||||
# allows strings with embedded NULLs.
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
@ -927,6 +992,16 @@ matcher.register('gchar-const*', arg)
|
||||
matcher.register('string', arg)
|
||||
matcher.register('static_string', arg)
|
||||
|
||||
arg = StrvArg()
|
||||
matcher.register('strv', arg)
|
||||
|
||||
arg = StringSListArg()
|
||||
matcher.register('string-slist', arg)
|
||||
arg = ObjectSListArg()
|
||||
matcher.register('object-slist', arg)
|
||||
arg = NoRefObjectSListArg()
|
||||
matcher.register('no-ref-object-slist', arg)
|
||||
|
||||
arg = UCharArg()
|
||||
matcher.register('unsigned-char*', arg)
|
||||
matcher.register('const-guchar*', arg)
|
||||
|
@ -140,11 +140,13 @@ PyObject *moo_gvalue_to_pyobject (const GValue *val)
|
||||
}
|
||||
|
||||
|
||||
typedef PyObject *(*PtrToPy) (gpointer ptr);
|
||||
typedef PyObject *(*PtrToPy) (gpointer ptr,
|
||||
gpointer data);
|
||||
|
||||
static PyObject*
|
||||
slist_to_pyobject (GSList *list,
|
||||
PtrToPy func)
|
||||
slist_to_pyobject (GSList *list,
|
||||
PtrToPy func,
|
||||
gpointer data)
|
||||
{
|
||||
int i;
|
||||
GSList *l;
|
||||
@ -154,7 +156,7 @@ slist_to_pyobject (GSList *list,
|
||||
|
||||
for (i = 0, l = list; l != NULL; l = l->next, ++i)
|
||||
{
|
||||
PyObject *item = func (l->data);
|
||||
PyObject *item = func (l->data, data);
|
||||
|
||||
if (!item)
|
||||
{
|
||||
@ -172,7 +174,7 @@ slist_to_pyobject (GSList *list,
|
||||
PyObject*
|
||||
moo_object_slist_to_pyobject (GSList *list)
|
||||
{
|
||||
return slist_to_pyobject (list, (PtrToPy) pygobject_new);
|
||||
return slist_to_pyobject (list, (PtrToPy) pygobject_new, NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -188,7 +190,24 @@ string_to_pyobject (gpointer str)
|
||||
PyObject*
|
||||
moo_string_slist_to_pyobject (GSList *list)
|
||||
{
|
||||
return slist_to_pyobject (list, string_to_pyobject);
|
||||
return slist_to_pyobject (list, (PtrToPy) string_to_pyobject, NULL);
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
boxed_to_pyobject (gpointer boxed,
|
||||
gpointer type)
|
||||
{
|
||||
return pyg_boxed_new (GPOINTER_TO_SIZE (type), boxed, TRUE, TRUE);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
moo_boxed_slist_to_pyobject (GSList *list,
|
||||
GType type)
|
||||
{
|
||||
g_return_val_if_fail (g_type_is_a (type, G_TYPE_BOXED), NULL);
|
||||
return slist_to_pyobject (list, boxed_to_pyobject,
|
||||
GSIZE_TO_POINTER (type));
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,6 +35,8 @@ int moo_pyobject_to_strv_no_null (PyObject *obj,
|
||||
|
||||
PyObject *moo_object_slist_to_pyobject (GSList *list);
|
||||
PyObject *moo_string_slist_to_pyobject (GSList *list);
|
||||
PyObject *moo_boxed_slist_to_pyobject (GSList *list,
|
||||
GType type);
|
||||
|
||||
PyObject *moo_gvalue_to_pyobject (const GValue *val);
|
||||
|
||||
|
@ -92,6 +92,16 @@
|
||||
)
|
||||
)
|
||||
|
||||
(define-object TextStyleScheme
|
||||
(in-module "Moo")
|
||||
(parent "GObject")
|
||||
(c-name "MooTextStyleScheme")
|
||||
(gtype-id "MOO_TYPE_TEXT_STYLE_SCHEME")
|
||||
(fields
|
||||
'("char*" "name")
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
(define-boxed Lang
|
||||
(in-module "Moo")
|
||||
@ -676,7 +686,8 @@
|
||||
(define-method get_sections
|
||||
(of-object "MooLangMgr")
|
||||
(c-name "moo_lang_mgr_get_sections")
|
||||
(return-type "GSList*")
|
||||
(return-type "string-slist")
|
||||
(caller-owns-return "t")
|
||||
)
|
||||
|
||||
(define-method get_lang_for_file
|
||||
@ -715,33 +726,12 @@
|
||||
)
|
||||
)
|
||||
|
||||
(define-method get_context
|
||||
(of-object "MooLangMgr")
|
||||
(c-name "moo_lang_mgr_get_context")
|
||||
(return-type "MooContext*")
|
||||
(parameters
|
||||
'("const-char*" "lang_name")
|
||||
'("const-char*" "ctx_name")
|
||||
)
|
||||
)
|
||||
|
||||
(define-method list_schemes
|
||||
(of-object "MooLangMgr")
|
||||
(c-name "moo_lang_mgr_list_schemes")
|
||||
(return-type "GSList*")
|
||||
)
|
||||
|
||||
(define-method get_style
|
||||
(of-object "MooLangMgr")
|
||||
(c-name "moo_lang_mgr_get_style")
|
||||
(return-type "MooTextStyle*")
|
||||
(parameters
|
||||
'("const-char*" "lang_name")
|
||||
'("const-char*" "style_name")
|
||||
'("MooTextStyleScheme*" "scheme")
|
||||
)
|
||||
)
|
||||
|
||||
(define-method get_active_scheme
|
||||
(of-object "MooLangMgr")
|
||||
(c-name "moo_lang_mgr_get_active_scheme")
|
||||
@ -1256,9 +1246,9 @@
|
||||
)
|
||||
)
|
||||
|
||||
(define-method apply_scheme
|
||||
(define-method set_scheme
|
||||
(of-object "MooTextView")
|
||||
(c-name "moo_text_view_apply_scheme")
|
||||
(c-name "moo_text_view_set_scheme")
|
||||
(return-type "none")
|
||||
(parameters
|
||||
'("MooTextStyleScheme*" "scheme")
|
||||
|
@ -447,10 +447,16 @@ _wrap_moo_editor_create_instance (void)
|
||||
return ret;
|
||||
}
|
||||
%%
|
||||
override moo_editor_get_session noargs
|
||||
override moo_lang_mgr_get_available_langs noargs
|
||||
static PyObject *
|
||||
_wrap_moo_editor_get_session (PyGObject *self)
|
||||
_wrap_moo_lang_mgr_get_available_langs (PyGObject *self)
|
||||
{
|
||||
MooEditSession *ret = moo_editor_get_session (MOO_EDITOR(self->obj));
|
||||
return pyg_boxed_new (MOO_TYPE_EDIT_SESSION, ret, FALSE, TRUE);
|
||||
GSList *list;
|
||||
PyObject *result;
|
||||
|
||||
list = moo_lang_mgr_get_available_langs (MOO_LANG_MGR (pygobject_get (self)));
|
||||
result = moo_boxed_slist_to_pyobject (list, MOO_TYPE_LANG);
|
||||
|
||||
g_slist_free (list);
|
||||
return result;
|
||||
}
|
||||
|
@ -324,6 +324,7 @@
|
||||
(define-function plugin_get_dirs
|
||||
(c-name "moo_plugin_get_dirs")
|
||||
(return-type "strv")
|
||||
(caller-owns-return "t")
|
||||
)
|
||||
|
||||
(define-function plugin_read_dirs
|
||||
|
@ -100,6 +100,14 @@
|
||||
(parent "GtkVBox")
|
||||
(c-name "MooPrefsDialogPage")
|
||||
(gtype-id "MOO_TYPE_PREFS_DIALOG_PAGE")
|
||||
(fields
|
||||
'("char*" "label")
|
||||
'("GdkPixbuf*" "icon")
|
||||
'("char*" "icon_stock_id")
|
||||
'("MooGladeXML*" "xml")
|
||||
'("GSList*" "widgets")
|
||||
'("gboolean" "auto_apply")
|
||||
)
|
||||
)
|
||||
|
||||
(define-object Window
|
||||
@ -107,6 +115,12 @@
|
||||
(parent "GtkWindow")
|
||||
(c-name "MooWindow")
|
||||
(gtype-id "MOO_TYPE_WINDOW")
|
||||
(fields
|
||||
'("GtkAccelGroup*" "accel_group")
|
||||
'("GtkWidget*" "menubar")
|
||||
'("GtkWidget*" "toolbar")
|
||||
'("GtkWidget*" "vbox")
|
||||
)
|
||||
)
|
||||
|
||||
(define-object MenuAction
|
||||
@ -804,7 +818,7 @@
|
||||
(define-method get_widget
|
||||
(of-object "MooGladeXML")
|
||||
(c-name "moo_glade_xml_get_widget")
|
||||
(return-type "gpointer")
|
||||
(return-type "GtkWidget*")
|
||||
(parameters
|
||||
'("const-char*" "id")
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user