1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
// Reflect brush setting and input information from libmypaint into Python.
// This probably isn't the best way of doing this,
// given that we have SWIG to hand.
// It does ensure that the human-readable fields are translated, however.
// I am OK with this.
#include "brushsettings.hpp"
#include <mypaint-brush-settings.h>
PyObject *
get_libmypaint_brush_settings()
{
PyObject* result = PyList_New(0);
if (! result) {
PyErr_SetString(PyExc_MemoryError, "Unable to create result list");
return NULL;
}
for (int i = 0; i < MYPAINT_BRUSH_SETTINGS_COUNT; ++i) {
MyPaintBrushSetting id = (MyPaintBrushSetting) i;
const MyPaintBrushSettingInfo *inf = mypaint_brush_setting_info(id);
if (! inf) {
PyErr_SetString(PyExc_RuntimeError,
"Unable to get brush setting from libmypaint");
break;
}
PyObject *inf_dict = Py_BuildValue(
"{s:s,s:s,s:b,s:f,s:f,s:f,s:s}",
"cname", inf->cname,
"name", mypaint_brush_setting_info_get_name(inf),
"constant", inf->constant,
"min", inf->min,
"default", inf->def,
"max", inf->max,
"tooltip", mypaint_brush_setting_info_get_tooltip(inf)
);
if (! inf_dict) {
PyErr_SetString(PyExc_MemoryError, "Unable to create item dict");
break;
}
PyList_Append(result, inf_dict);
}
return result;
}
PyObject *
get_libmypaint_brush_inputs()
{
PyObject* result = PyList_New(0);
if (! result) {
PyErr_SetString(PyExc_MemoryError, "Unable to create result list");
return NULL;
}
for (int i = 0; i < MYPAINT_BRUSH_INPUTS_COUNT; ++i) {
MyPaintBrushInput id = (MyPaintBrushInput) i;
const MyPaintBrushInputInfo *inf = mypaint_brush_input_info(id);
if (! inf) {
PyErr_SetString(PyExc_RuntimeError,
"Unable to get brush input info from libmypaint");
break;
}
PyObject *inf_dict = Py_BuildValue(
"{s:s,s:f,s:f,s:f,s:f,s:f,s:s,s:s}",
"name", inf->cname,
"hard_min", inf->hard_min,
"soft_min", inf->soft_min,
"normal", inf->normal,
"hard_max", inf->hard_max,
"soft_max", inf->soft_max,
"dname", mypaint_brush_input_info_get_name(inf),
"tooltip", mypaint_brush_input_info_get_tooltip(inf)
);
if (! inf_dict) {
PyErr_SetString(PyExc_MemoryError, "Unable to create item dict");
break;
}
PyList_Append(result, inf_dict);
}
return result;
}
|