Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

py_axes.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: py_axes.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.21 $       $Date: 2019/05/30 05:15:01 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *  Python Axes control interface.
00019  ***************************************************************************/
00020 
00021 #include "py_commands.h"
00022 #include "CommandQueue.h"
00023 #include "VMDApp.h"
00024 #include "Axes.h"
00025 
00026 // get_location()
00027 static char getloc_doc[] =
00028 "Get current axes location.\n\n"
00029 "Returns:\n"
00030 "    (str) Axes location, one of [OFF, ORIGIN, LOWERLEFT,\n"
00031 "        LOWERRIGHT, UPPERLEFT, UPPERRIGHT]";
00032 static PyObject *py_get_location(PyObject *self, PyObject *args) {
00033   VMDApp *app;
00034   if (!(app = get_vmdapp()))
00035     return NULL;
00036 
00037   return as_pystring(app->axes->loc_description(app->axes->location()));
00038 }
00039 
00040 
00041 // set_location(locale)
00042 static char setloc_doc[] =
00043 "Set current axes location.\n\n"
00044 "Args:\n"
00045 "    location (str): New axes location, in [OFF, ORIGIN, LOWERLEFT,\n"
00046 "        LOWERRIGHT, UPPERLEFT, UPPERRIGHT]";
00047 static PyObject *py_set_location(PyObject *self, PyObject *args, PyObject *kwargs) {
00048   char *location;
00049   const char *kwnames[] = {"location", NULL};
00050   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:axes.set_location",
00051                                    (char**) kwnames, &location))
00052     return NULL;
00053 
00054   VMDApp *app;
00055   if (!(app = get_vmdapp()))
00056     return NULL;
00057 
00058   if (!app->axes_set_location(location)) {
00059     PyErr_Format(PyExc_ValueError, "Invalid axes location '%s'", location);
00060     return NULL;
00061   }
00062 
00063   Py_INCREF(Py_None);
00064   return Py_None;
00065 }
00066 
00067 
00068 static PyMethodDef methods[] = {
00069   {"get_location", (PyCFunction)py_get_location, METH_NOARGS, getloc_doc},
00070   {"set_location", (PyCFunction)py_set_location, METH_VARARGS | METH_KEYWORDS, setloc_doc},
00071   {NULL, NULL}
00072 };
00073 
00074 
00075 static const char axes_moddoc[] =
00076 "Methods to get and set the axes location";
00077 
00078 
00079 #if PY_MAJOR_VERSION >= 3
00080 struct PyModuleDef axesdef = {
00081   PyModuleDef_HEAD_INIT,
00082   "axes",
00083   axes_moddoc,
00084   -1,
00085   methods,
00086 };
00087 #endif
00088 
00089 
00090 PyObject* initaxes(void) {
00091 
00092 #if PY_MAJOR_VERSION >= 3
00093   PyObject *m = PyModule_Create(&axesdef);
00094 #else
00095   PyObject *m = Py_InitModule3("axes", methods, axes_moddoc);
00096 #endif
00097 
00098   VMDApp *app;
00099   if (!(app = get_vmdapp()))
00100     return NULL;
00101 
00102   // Add location string constants to system
00103   PyModule_AddStringConstant(m, "OFF", app->axes->loc_description(0));
00104   PyModule_AddStringConstant(m, "ORIGIN", app->axes->loc_description(1));
00105   PyModule_AddStringConstant(m, "LOWERLEFT", app->axes->loc_description(2));
00106   PyModule_AddStringConstant(m, "LOWERRIGHT", app->axes->loc_description(3));
00107   PyModule_AddStringConstant(m, "UPPERLEFT", app->axes->loc_description(4));
00108   PyModule_AddStringConstant(m, "UPPERRIGHT", app->axes->loc_description(5));
00109 
00110   return m;
00111 }
00112 

Generated on Fri Nov 8 02:45:24 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002