Пример #1
0
/* (function,check_enabled,data,(char/font),shortcut_str,{sub-menu,}menu-name) */
static PyObject *PyFF_registerMenuItem(PyObject *self, PyObject *args) {
    int i, cnt;
    int flags;
    PyObject *utf8_name;

    if ( !no_windowing_ui ) {
        cnt = PyTuple_Size(args);
        if ( cnt<6 ) {
            PyErr_Format(PyExc_TypeError, "Too few arguments");
            return( NULL );
        }
        if (!PyCallable_Check(PyTuple_GetItem(args,0))) {
            PyErr_Format(PyExc_TypeError, "First argument is not callable" );
            return( NULL );
        }
        if (PyTuple_GetItem(args,1)!=Py_None &&
                !PyCallable_Check(PyTuple_GetItem(args,1))) {
            PyErr_Format(PyExc_TypeError, "Second argument is not callable" );
            return( NULL );
        }
        flags = FlagsFromTuple(PyTuple_GetItem(args,3), menuviews );
        if ( flags==-1 ) {
            PyErr_Format(PyExc_ValueError, "Unknown window for menu" );
            return( NULL );
        }
        if ( PyTuple_GetItem(args,4)!=Py_None ) {
#if PY_MAJOR_VERSION >= 3
            PyObject *obj = PyUnicode_AsUTF8String(PyTuple_GetItem(args,4));
            if ( obj==NULL )
                return( NULL );
            char *shortcut_str = PyBytes_AsString(obj);
            if ( shortcut_str==NULL ) {
                Py_DECREF( obj );
                return( NULL );
            }
            Py_DECREF( obj );
#else /* PY_MAJOR_VERSION >= 3 */
            char *shortcut_str = PyBytes_AsString(PyTuple_GetItem(args,4));
            if ( shortcut_str==NULL )
                return( NULL );
#endif /* PY_MAJOR_VERSION >= 3 */
        }
        for ( i=5; i<cnt; ++i ) {
            utf8_name = PYBYTES_UTF8(PyTuple_GetItem(args,i));
            if ( utf8_name==NULL )
                return( NULL );
            Py_DECREF(utf8_name);
        }
        if ( flags&menu_fv )
            InsertSubMenus(args,&fvpy_menu,false );
        if ( flags&menu_cv )
            InsertSubMenus(args,&cvpy_menu,true );
    }

    Py_RETURN_NONE;
}
Пример #2
0
/* (function,check_enabled,data,(char/font),shortcut_str,{sub-menu,}menu-name) */
static PyObject *PyFF_registerMenuItem(PyObject *self, PyObject *args) {
    int i, cnt;
    int flags;
    PyObject *utf8_name;

    printf("PyFF_registerMenuItem(top)\n" );
    
    if ( !no_windowing_ui ) {
	cnt = PyTuple_Size(args);
	if ( cnt<6 ) {
	    PyErr_Format(PyExc_TypeError, "Too few arguments");
return( NULL );
	}
	if (!PyCallable_Check(PyTuple_GetItem(args,0))) {
	    PyErr_Format(PyExc_TypeError, "First argument is not callable" );
return( NULL );
	}
	if (PyTuple_GetItem(args,1)!=Py_None &&
		!PyCallable_Check(PyTuple_GetItem(args,1))) {
	    PyErr_Format(PyExc_TypeError, "First argument is not callable" );
return( NULL );
	}
	flags = FlagsFromTuple(PyTuple_GetItem(args,3), menuviews );
	if ( flags==-1 ) {
	    PyErr_Format(PyExc_ValueError, "Unknown window for menu" );
return( NULL );
	}
	if ( PyTuple_GetItem(args,4)!=Py_None ) {
	    char *shortcut_str = PyString_AsString(PyTuple_GetItem(args,4));
	    if ( shortcut_str==NULL )
return( NULL );
	}
	for ( i=5; i<cnt; ++i ) {
	    utf8_name = PyString_AsEncodedObject(PyTuple_GetItem(args,i),
			"UTF-8",NULL);
	    if ( utf8_name==NULL )
return( NULL );
        printf("utf8_name: %s\n", utf8_name );
	    Py_DECREF(utf8_name);
	}
	if ( flags&menu_fv )
	    InsertSubMenus(args,&fvpy_menu_data,false );
	if ( flags&menu_cv )
	    InsertSubMenus(args,&cvpy_menu_data,true );
    }

Py_RETURN_NONE;
}