本文整理汇总了C++中VMDApp::color_category_item方法的典型用法代码示例。如果您正苦于以下问题:C++ VMDApp::color_category_item方法的具体用法?C++ VMDApp::color_category_item怎么用?C++ VMDApp::color_category_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VMDApp
的用法示例。
在下文中一共展示了VMDApp::color_category_item方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
static PyObject *get_colormap(PyObject *self, PyObject *args) {
char *name;
if (!PyArg_ParseTuple(args, (char *)"s", &name))
return NULL;
VMDApp *app = get_vmdapp();
int num_names = app->num_color_category_items(name);
PyObject *newdict = PyDict_New();
for (int i=0; i<num_names; i++) {
const char *key = app->color_category_item(name, i);
const char *value = app->color_mapping(name, key);
PyDict_SetItemString(newdict, (char *)key, PyString_FromString(value));
}
return newdict;
}
示例2: py_get_colormap
static PyObject* py_get_colormap(PyObject *self, PyObject *args,
PyObject *kwargs)
{
const char *kwnames[] = {"name", NULL};
PyObject *newdict = NULL;
int i, num_names;
VMDApp *app;
char *name;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:color.get_colormap",
(char**) kwnames, &name))
return NULL;
if (!(app = get_vmdapp()))
return NULL;
num_names = app->num_color_category_items(name);
if (!num_names) {
PyErr_Format(PyExc_ValueError, "Colormap '%s' does not exist", name);
return NULL;
}
if (!(newdict = PyDict_New()))
goto failure;
// Populate colormap dictionary
for (i = 0; i < num_names; i++) {
const char *key = app->color_category_item(name, i);
const char *value = app->color_mapping(name, key);
// SetItemString does correctly steal a reference.
if (PyDict_SetItemString(newdict, key, as_pystring(value)))
goto failure;
}
return newdict;
failure:
PyErr_Format(PyExc_RuntimeError, "Problem getting colormap '%s'", name);
Py_XDECREF(newdict);
return NULL;
}