It is currently Sat Jul 06, 2024 7:30 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: I'm in need of an example
PostPosted: Mon Aug 24, 2015 5:39 pm  (#1) 
Offline
GimpChat Member
User avatar

Joined: Aug 13, 2015
Posts: 312
Location: Somewhere between lost and found.
I am writing a pygtk app that exists partially in the form of GIMP plugins. The app and most of the plugins have their own pygtk UI. I need to give them a progress bar independent of the one in gimp or gimps python plugin UI.

I see there is a procedure called gimp-process-install which is supposed to handle registering a callback function to be triggered by gimp's script/plugin processor, but it only seems to accept a single callback function.

The c code in libgimp shows handling for four callback functions, which would make sense due to initializing a progress bar, updating a progress bar, finalizing a progress bar, and the fourth is for handling failures. But I cannot seem to find the code for the python bindign to this method.

Does anyone know where such code is located in the GIMP sources, or of a python app which implements an external/seperate progress bar so I can digest it and spit out my own custom handler?

_________________
The answer was 42. The question is long forgotten. The computer that solved it is now destroyed.
The MK-2 has been built. Should this be the next question?
(Solve if you can ... ;) )
Image


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: I'm in need of an example
PostPosted: Mon Aug 24, 2015 9:29 pm  (#2) 
Offline
GimpChat Member
User avatar

Joined: Aug 13, 2015
Posts: 312
Location: Somewhere between lost and found.
found it
Now my c++ is quite rusty, but if I read this right, it is simply looking for a series of keyword arguments in the form of:
start=some_function, end=some_other_function, text=another_one,value=yet_another

or
some_function, some_other_function, another_one, yet_another


But as I said my C++ is quite rusty, so it's still under review...

pygimp_progress_install(PyObject *self, PyObject *args, PyObject *kwargs)
{
    GimpProgressVtable vtable = { 0, };
    const gchar *ret;
    ProgressData *pdata;
    static char *kwlist[] = { "start", "end", "text", "value", "data", NULL };

    pdata = g_new0(ProgressData, 1);

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOO|O:progress_install",
                                     kwlist,
                                     &pdata->start, &pdata->end,
                                     &pdata->text, &pdata->value,
                                     &pdata->user_data))
        goto cleanup;

#define PROCESS_FUNC(n) G_STMT_START {                                  \
    if (!PyCallable_Check(pdata->n)) {                                  \
        PyErr_SetString(pygimp_error, #n "argument must be callable");  \
        goto cleanup;                                                   \
    }                                                                   \
    Py_INCREF(pdata->n);                                                \
} G_STMT_END

    PROCESS_FUNC(start);
    PROCESS_FUNC(end);
    PROCESS_FUNC(text);
    PROCESS_FUNC(value);

    Py_XINCREF(pdata->user_data);

#undef PROCESS_FUNC

    vtable.start     = pygimp_progress_start;
    vtable.end       = pygimp_progress_end;
    vtable.set_text  = pygimp_progress_text;
    vtable.set_value = pygimp_progress_value;

    ret = gimp_progress_install_vtable(&vtable, pdata);

    if (!ret) {
        PyErr_SetString(pygimp_error,
                        "error occurred while installing progress functions");

        Py_DECREF(pdata->start);
        Py_DECREF(pdata->end);
        Py_DECREF(pdata->text);
        Py_DECREF(pdata->value);

        goto cleanup;
    }

    return PyString_FromString(ret);

cleanup:
    g_free(pdata);
    return NULL;
}

The call to PyArg_ParseTupleAndKeywords is an internal system call of the python interpreter. It's function is just as it's name says, to parse tuples and kw arguments.

Time for some experimentation....(I wont bother finding the source for the interpreter to check it out...)

_________________
The answer was 42. The question is long forgotten. The computer that solved it is now destroyed.
The MK-2 has been built. Should this be the next question?
(Solve if you can ... ;) )
Image


Top
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group