mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 13:47:32 +08:00
Merge pull request #6707 from tech2077:master
This commit is contained in:
commit
c7fc9dc42f
@ -1268,6 +1268,52 @@ static PyObject *pycvCreateTrackbar(PyObject*, PyObject *args)
|
||||
ERRWRAP2(createTrackbar(trackbar_name, window_name, value, count, OnChange, Py_BuildValue("OO", on_change, Py_None)));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static void OnButtonChange(int state, void *param)
|
||||
{
|
||||
PyGILState_STATE gstate;
|
||||
gstate = PyGILState_Ensure();
|
||||
|
||||
PyObject *o = (PyObject*)param;
|
||||
PyObject *args;
|
||||
if(PyTuple_GetItem(o, 1) != NULL)
|
||||
{
|
||||
args = Py_BuildValue("(iO)", state, PyTuple_GetItem(o,1));
|
||||
}
|
||||
else
|
||||
{
|
||||
args = Py_BuildValue("(i)", state);
|
||||
}
|
||||
|
||||
PyObject *r = PyObject_Call(PyTuple_GetItem(o, 0), args, NULL);
|
||||
if (r == NULL)
|
||||
PyErr_Print();
|
||||
Py_DECREF(args);
|
||||
PyGILState_Release(gstate);
|
||||
}
|
||||
|
||||
static PyObject *pycvCreateButton(PyObject*, PyObject *args, PyObject *kw)
|
||||
{
|
||||
const char* keywords[] = {"buttonName", "onChange", "userData", "buttonType", "initialButtonState", NULL};
|
||||
PyObject *on_change;
|
||||
PyObject *userdata = NULL;
|
||||
char* button_name;
|
||||
int button_type = 0;
|
||||
bool initial_button_state = false;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|Oii", (char**)keywords, &button_name, &on_change, &userdata, &button_type, &initial_button_state))
|
||||
return NULL;
|
||||
if (!PyCallable_Check(on_change)) {
|
||||
PyErr_SetString(PyExc_TypeError, "onChange must be callable");
|
||||
return NULL;
|
||||
}
|
||||
if (userdata == NULL) {
|
||||
userdata = Py_None;
|
||||
}
|
||||
|
||||
ERRWRAP2(createButton(button_name, OnButtonChange, Py_BuildValue("OO", on_change, userdata), button_type, initial_button_state));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -1300,6 +1346,7 @@ static int convert_to_char(PyObject *o, char *dst, const char *name = "no_name")
|
||||
static PyMethodDef special_methods[] = {
|
||||
#ifdef HAVE_OPENCV_HIGHGUI
|
||||
{"createTrackbar", pycvCreateTrackbar, METH_VARARGS, "createTrackbar(trackbarName, windowName, value, count, onChange) -> None"},
|
||||
{"createButton", (PyCFunction)pycvCreateButton, METH_VARARGS | METH_KEYWORDS, "createButton(buttonName, onChange [, userData, buttonType, initialButtonState]) -> None"},
|
||||
{"setMouseCallback", (PyCFunction)pycvSetMouseCallback, METH_VARARGS | METH_KEYWORDS, "setMouseCallback(windowName, onMouse [, param]) -> None"},
|
||||
#endif
|
||||
{NULL, NULL},
|
||||
|
Loading…
Reference in New Issue
Block a user