예제 #1
0
			raise NotImplementedError ()
		else:
			info.varlist.add("gchar", "**ret")
			info.codeafter.append("    if (ret) {\n"
					      "        guint size = g_strv_length(ret);\n"
					      "        PyObject *py_ret = PyTuple_New(size);\n"
					      "        gint i;\n"
					      "        for (i = 0; i < size; i++)\n"
					      "            PyTuple_SetItem(py_ret, i,\n"
					      "                PyString_FromString(ret[i]));\n"
					      "        return py_ret;\n"
					      "    }\n"
					      "    return PyTuple_New (0);\n")


matcher.register('GstClockTime', UInt64Arg())
matcher.register('GstElementFactoryListType', UInt64Arg())
matcher.register('GstClockTimeDiff', Int64Arg())
matcher.register('xmlNodePtr', XmlNodeArg())
matcher.register('xmlDocPtr', XmlDocArg())
matcher.register('GstCaps', GstCapsArg()) #FIXME: does this work?
matcher.register('GstCaps*', GstCapsArg()) #FIXME: does this work?
matcher.register('const-GstCaps*', GstCapsArg())
matcher.register('GstIterator*', GstIteratorArg())

arg = PointerArg('gpointer', 'G_TYPE_POINTER')
matcher.register('GstClockID', arg)

for typename in ["GstPlugin", "GstStructure", "GstTagList", "GError", "GstDate", "GstSegment"]:
	matcher.register_reverse(typename, GBoxedParam)
	matcher.register_reverse_ret(typename, GBoxedReturn)
예제 #2
0
        info.varlist.add('cairo_matrix_t', '*'+pname)
        info.add_parselist('O', ['&py_'+pname], [pname])
        info.arglist.append(pname)
        info.codebefore.append (self.before % { 'name' : pname, 'namecopy' : 'NULL' })


    def write_return(self, ptype, ownsreturn, info):
        info.varlist.add('cairo_matrix_t', '*ret')
        info.codeafter.append('    if (ret)\n'
                              '        return PycairoMatrix_FromMatrix(ret);\n'
                              '    else {\n'
                              '        Py_INCREF(Py_None);\n'
                              '        return Py_None;\n'
                              '    }');

matcher.register('cairo_matrix_t*', CairoMatrixArg())


class CairoParam(reversewrapper.Parameter):
    def get_c_type(self):
        return self.props.get('c_type').replace('const-', 'const ')
    def convert_c2py(self):
        self.wrapper.add_declaration("PyObject *py_%s;" % self.name)
        self.wrapper.write_code(
            code=('py_%s = PycairoContext_FromContext(cairo_reference(%s), NULL, NULL);' %
                  (self.name, self.name)),
            cleanup=("Py_DECREF(py_%s);" % self.name))
        self.wrapper.add_pyargv_item("py_%s" % self.name)

matcher.register_reverse("cairo_t*", CairoParam)
예제 #3
0
		if ownsreturn:
			raise NotImplementedError ()
		else:
			info.varlist.add("gchar", "**ret")
			info.codeafter.append("    if (ret) {\n"
					      "        guint size = g_strv_length(ret);\n"
					      "        PyObject *py_ret = PyTuple_New(size);\n"
					      "        gint i;\n"
					      "        for (i = 0; i < size; i++)\n"
					      "            PyTuple_SetItem(py_ret, i,\n"
					      "                PyString_FromString(ret[i]));\n"
					      "        return py_ret;\n"
					      "    }\n"
					      "    return PyTuple_New (0);\n")

matcher.register('GstClockTime', UInt64Arg())
matcher.register('GstClockTimeDiff', Int64Arg())
matcher.register('xmlNodePtr', XmlNodeArg())
matcher.register('xmlDocPtr', XmlDocArg())
matcher.register('GstCaps', GstCapsArg()) #FIXME: does this work?
matcher.register('GstCaps*', GstCapsArg()) #FIXME: does this work?
matcher.register('const-GstCaps*', GstCapsArg())
matcher.register('GstIterator*', GstIteratorArg())

arg = PointerArg('gpointer', 'G_TYPE_POINTER')
matcher.register('GstClockID', arg)

for typename in ["GstPlugin", "GstStructure", "GstTagList", "GError", "GstDate", "GstSegment"]:
	matcher.register_reverse(typename, GBoxedParam)
	matcher.register_reverse_ret(typename, GBoxedReturn)
예제 #4
0
from argtypes import ArgType, IntArg, matcher

matcher.register('index', IntArg())


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;')
예제 #5
0
        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);')


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)
예제 #6
0
            code=('py_%s = PycairoContext_FromContext(cairo_reference(%s), NULL, NULL);' %
                  (self.name, self.name)),
            cleanup=("Py_DECREF(py_%s);" % self.name))
        self.wrapper.add_pyargv_item("py_%s" % self.name)

matcher.register_reverse("cairo_t*", CairoParam)

class CairoSurfaceArg(ArgType):

    before = ('    %(name)s = &((PycairoSurface*)(py_%(name)s))->surface;\n')

    def write_param(self, ptype, pname, pdflt, pnull, info):
        info.varlist.add('PyObject', '*py_' + pname)
        info.varlist.add('cairo_surface_t', '*'+pname)
        info.add_parselist('O', ['&py_'+pname], [pname])
        info.arglist.append(pname)
        info.codebefore.append (self.before % { 'name' : pname, 'namecopy' : 'NULL' })


    def write_return(self, ptype, ownsreturn, info):
        info.varlist.add('cairo_surface_t', '*ret')
        info.codeafter.append('    if (ret)\n'
                              '        return PycairoSurface_FromSurface(ret, NULL);\n'
                              '    else {\n'
                              '        Py_INCREF(Py_None);\n'
                              '        return Py_None;\n'
                              '    }');

matcher.register('cairo_surface_t*', CairoSurfaceArg())

예제 #7
0
        else:
            info.varlist.add("gchar", "**ret")
            info.codeafter.append(
                "    if (ret) {\n"
                "        guint size = g_strv_length(ret);\n"
                "        PyObject *py_ret = PyTuple_New(size);\n"
                "        gint i;\n"
                "        for (i = 0; i < size; i++)\n"
                "            PyTuple_SetItem(py_ret, i,\n"
                "                PyString_FromString(ret[i]));\n"
                "        return py_ret;\n"
                "    }\n"
                "    return PyTuple_New (0);\n")


matcher.register('GstClockTime', UInt64Arg())
matcher.register('GstClockTimeDiff', Int64Arg())
matcher.register('xmlNodePtr', XmlNodeArg())
matcher.register('xmlDocPtr', XmlDocArg())
matcher.register('GstCaps', GstCapsArg())  #FIXME: does this work?
matcher.register('GstCaps*', GstCapsArg())  #FIXME: does this work?
matcher.register('const-GstCaps*', GstCapsArg())
matcher.register('GstIterator*', GstIteratorArg())

arg = PointerArg('gpointer', 'G_TYPE_POINTER')
matcher.register('GstClockID', arg)

for typename in [
        "GstPlugin", "GstStructure", "GstTagList", "GError", "GstDate",
        "GstSegment"
]:
예제 #8
0
파일: argtypes_m.py 프로젝트: cmotc/medit
from argtypes import ArgType, IntArg, matcher

matcher.register('index', IntArg())

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: