@@ -47,6 +47,7 @@ struct _interpreter {
47
47
PyObject *s_python_function_legend;
48
48
PyObject *s_python_function_xlim;
49
49
PyObject *s_python_function_ion;
50
+ PyObject *s_python_function_ginput;
50
51
PyObject *s_python_function_ylim;
51
52
PyObject *s_python_function_title;
52
53
PyObject *s_python_function_axis;
@@ -160,6 +161,7 @@ struct _interpreter {
160
161
s_python_function_grid = PyObject_GetAttrString (pymod, " grid" );
161
162
s_python_function_xlim = PyObject_GetAttrString (pymod, " xlim" );
162
163
s_python_function_ion = PyObject_GetAttrString (pymod, " ion" );
164
+ s_python_function_ginput = PyObject_GetAttrString (pymod, " ginput" );
163
165
s_python_function_save = PyObject_GetAttrString (pylabmod, " savefig" );
164
166
s_python_function_annotate = PyObject_GetAttrString (pymod," annotate" );
165
167
s_python_function_clf = PyObject_GetAttrString (pymod, " clf" );
@@ -191,6 +193,7 @@ struct _interpreter {
191
193
|| !s_python_function_grid
192
194
|| !s_python_function_xlim
193
195
|| !s_python_function_ion
196
+ || !s_python_function_ginput
194
197
|| !s_python_function_save
195
198
|| !s_python_function_clf
196
199
|| !s_python_function_annotate
@@ -225,6 +228,7 @@ struct _interpreter {
225
228
|| !PyFunction_Check (s_python_function_grid)
226
229
|| !PyFunction_Check (s_python_function_xlim)
227
230
|| !PyFunction_Check (s_python_function_ion)
231
+ || !PyFunction_Check (s_python_function_ginput)
228
232
|| !PyFunction_Check (s_python_function_save)
229
233
|| !PyFunction_Check (s_python_function_clf)
230
234
|| !PyFunction_Check (s_python_function_tight_layout)
@@ -1214,6 +1218,40 @@ inline void clf() {
1214
1218
Py_DECREF (res);
1215
1219
}
1216
1220
1221
+ inline std::vector<std::array<double , 2 >> ginput (const int numClicks = 1 , const std::map<std::string, std::string>& keywords = {})
1222
+ {
1223
+ PyObject *args = PyTuple_New (1 );
1224
+ PyTuple_SetItem (args, 0 , PyLong_FromLong (numClicks));
1225
+
1226
+ // construct keyword args
1227
+ PyObject* kwargs = PyDict_New ();
1228
+ for (std::map<std::string, std::string>::const_iterator it = keywords.begin (); it != keywords.end (); ++it)
1229
+ {
1230
+ PyDict_SetItemString (kwargs, it->first .c_str (), PyUnicode_FromString (it->second .c_str ()));
1231
+ }
1232
+
1233
+ PyObject* res = PyObject_Call (
1234
+ detail::_interpreter::get ().s_python_function_ginput , args, kwargs);
1235
+
1236
+ Py_DECREF (kwargs);
1237
+ Py_DECREF (args);
1238
+ if (!res) throw std::runtime_error (" Call to ginput() failed." );
1239
+
1240
+ const size_t len = PyList_Size (res);
1241
+ std::vector<std::array<double , 2 >> out;
1242
+ out.reserve (len);
1243
+ for (size_t i = 0 ; i < len; i++) {
1244
+ PyObject *current = PyList_GetItem (res, i);
1245
+ std::array<double , 2 > position;
1246
+ position[0 ] = PyFloat_AsDouble (PyTuple_GetItem (current, 0 ));
1247
+ position[1 ] = PyFloat_AsDouble (PyTuple_GetItem (current, 1 ));
1248
+ out.push_back (position);
1249
+ }
1250
+ Py_DECREF (res);
1251
+
1252
+ return out;
1253
+ }
1254
+
1217
1255
// Actually, is there any reason not to call this automatically for every plot?
1218
1256
inline void tight_layout () {
1219
1257
PyObject *res = PyObject_CallObject (
0 commit comments