Exemplo n.º 1
0
static PyObject* py_get_colorlist(PyObject *self, PyObject *args)
{

  PyObject *newlist = NULL, *newtuple = NULL;
  int i, j, listlen;
  const char *name;
  float col[3];
  VMDApp *app;

  if (!(app = get_vmdapp()))
    return NULL;

  listlen = app->num_regular_colors();
  if (!(newlist = PyList_New(listlen)))
    goto failure;

  for (i = 0; i < listlen; i++) {

    name = app->color_name(i);
    if (!app->color_value(name, col, col+1, col+2))
      goto failure;

    if (!(newtuple = PyTuple_New(3)))
      goto failure;

    for (j = 0; j < 3; j++) {
      PyTuple_SET_ITEM(newtuple, j, PyFloat_FromDouble(col[j]));
      if (PyErr_Occurred())
        goto failure;
    }

    PyList_SET_ITEM(newlist, i, newtuple);
    if (PyErr_Occurred())
      goto failure;

  }
  return newlist;

failure:
  PyErr_SetString(PyExc_RuntimeError, "Problem getting color list");
  Py_XDECREF(newlist);
  Py_XDECREF(newtuple);
  return NULL;
}
Exemplo n.º 2
0
static PyObject *get_colors(PyObject *self, PyObject *args) {
  if (!PyArg_ParseTuple(args, (char *)""))
    return NULL;
  
  VMDApp *app = get_vmdapp();
  PyObject *newdict = PyDict_New();
  for (int i=0; i<app->num_regular_colors(); i++) {
    float col[3];
    const char *name = app->color_name(i);
    if (!app->color_value(name, col, col+1, col+2)) {
      PyErr_SetString(PyExc_ValueError, (char *) 
        "Unable to get color definition");
      return NULL;
    }
    PyObject *newtuple = PyTuple_New(3);
    for (int j=0; j<3; j++)
      PyTuple_SET_ITEM(newtuple, j, PyFloat_FromDouble(col[j]));
    PyDict_SetItemString(newdict, (char *)name, newtuple);
  }
  return newdict;
}