Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 63d0e15

Browse files
committed
Support draw and pause functions
1 parent ce69854 commit 63d0e15

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

matplotlibcpp.h

+32
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ namespace matplotlibcpp {
3131

3232
struct _interpreter {
3333
PyObject *s_python_function_show;
34+
PyObject *s_python_function_draw;
35+
PyObject *s_python_function_pause;
3436
PyObject *s_python_function_save;
3537
PyObject *s_python_function_figure;
3638
PyObject *s_python_function_plot;
@@ -105,6 +107,8 @@ namespace matplotlibcpp {
105107
if(!pylabmod) { throw std::runtime_error("Error loading module pylab!"); }
106108

107109
s_python_function_show = PyObject_GetAttrString(pymod, "show");
110+
s_python_function_draw = PyObject_GetAttrString(pymod, "draw");
111+
s_python_function_pause = PyObject_GetAttrString(pymod, "pause");
108112
s_python_function_figure = PyObject_GetAttrString(pymod, "figure");
109113
s_python_function_plot = PyObject_GetAttrString(pymod, "plot");
110114
s_python_function_fill_between = PyObject_GetAttrString(pymod, "fill_between");
@@ -125,6 +129,8 @@ namespace matplotlibcpp {
125129
s_python_function_tight_layout = PyObject_GetAttrString(pymod, "tight_layout");
126130

127131
if( !s_python_function_show
132+
|| !s_python_function_draw
133+
|| !s_python_function_pause
128134
|| !s_python_function_figure
129135
|| !s_python_function_plot
130136
|| !s_python_function_fill_between
@@ -146,6 +152,8 @@ namespace matplotlibcpp {
146152
) { throw std::runtime_error("Couldn't find required function!"); }
147153

148154
if ( !PyFunction_Check(s_python_function_show)
155+
|| !PyFunction_Check(s_python_function_draw)
156+
|| !PyFunction_Check(s_python_function_pause)
149157
|| !PyFunction_Check(s_python_function_figure)
150158
|| !PyFunction_Check(s_python_function_plot)
151159
|| !PyFunction_Check(s_python_function_fill_between)
@@ -651,6 +659,30 @@ namespace matplotlibcpp {
651659
Py_DECREF(res);
652660
}
653661

662+
inline void draw()
663+
{
664+
PyObject* res = PyObject_CallObject(
665+
detail::_interpreter::get().s_python_function_draw,
666+
detail::_interpreter::get().s_python_empty_tuple);
667+
668+
if (!res) throw std::runtime_error("Call to draw() failed.");
669+
670+
Py_DECREF(res);
671+
}
672+
673+
template<typename Numeric>
674+
void pause(Numeric interval)
675+
{
676+
PyObject* args = PyTuple_New(1);
677+
PyTuple_SetItem(args, 0, PyFloat_FromDouble(interval));
678+
679+
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_pause, args);
680+
if(!res) throw std::runtime_error("Call to pause() failed.");
681+
682+
Py_DECREF(args);
683+
Py_DECREF(res);
684+
}
685+
654686
inline void save(const std::string& filename)
655687
{
656688
PyObject* pyfilename = PyString_FromString(filename.c_str());

0 commit comments

Comments
 (0)