@@ -36,6 +36,7 @@ struct _interpreter {
36
36
PyObject *s_python_function_pause;
37
37
PyObject *s_python_function_save;
38
38
PyObject *s_python_function_figure;
39
+ PyObject *s_python_function_fignum_exists;
39
40
PyObject *s_python_function_plot;
40
41
PyObject *s_python_function_quiver;
41
42
PyObject *s_python_function_semilogx;
@@ -142,6 +143,7 @@ struct _interpreter {
142
143
s_python_function_draw = PyObject_GetAttrString (pymod, " draw" );
143
144
s_python_function_pause = PyObject_GetAttrString (pymod, " pause" );
144
145
s_python_function_figure = PyObject_GetAttrString (pymod, " figure" );
146
+ s_python_function_fignum_exists = PyObject_GetAttrString (pymod, " fignum_exists" );
145
147
s_python_function_plot = PyObject_GetAttrString (pymod, " plot" );
146
148
s_python_function_quiver = PyObject_GetAttrString (pymod, " quiver" );
147
149
s_python_function_semilogx = PyObject_GetAttrString (pymod, " semilogx" );
@@ -177,6 +179,7 @@ struct _interpreter {
177
179
|| !s_python_function_draw
178
180
|| !s_python_function_pause
179
181
|| !s_python_function_figure
182
+ || !s_python_function_fignum_exists
180
183
|| !s_python_function_plot
181
184
|| !s_python_function_quiver
182
185
|| !s_python_function_semilogx
@@ -211,6 +214,7 @@ struct _interpreter {
211
214
|| !PyFunction_Check (s_python_function_draw)
212
215
|| !PyFunction_Check (s_python_function_pause)
213
216
|| !PyFunction_Check (s_python_function_figure)
217
+ || !PyFunction_Check (s_python_function_fignum_exists)
214
218
|| !PyFunction_Check (s_python_function_plot)
215
219
|| !PyFunction_Check (s_python_function_quiver)
216
220
|| !PyFunction_Check (s_python_function_semilogx)
@@ -845,6 +849,23 @@ inline long figure(long number = -1)
845
849
return figureNumber;
846
850
}
847
851
852
+ inline bool fignum_exists (long number)
853
+ {
854
+ // Make sure interpreter is initialised
855
+ detail::_interpreter::get ();
856
+
857
+ PyObject *args = PyTuple_New (1 );
858
+ PyTuple_SetItem (args, 0 , PyLong_FromLong (number));
859
+ PyObject *res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_fignum_exists , args);
860
+ if (!res) throw std::runtime_error (" Call to fignum_exists() failed." );
861
+
862
+ bool ret = PyObject_IsTrue (res);
863
+ Py_DECREF (res);
864
+ Py_DECREF (args);
865
+
866
+ return ret;
867
+ }
868
+
848
869
inline void figure_size (size_t w, size_t h)
849
870
{
850
871
const size_t dpi = 100 ;
0 commit comments