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

py_mouse.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2016 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 #include "py_commands.h"
00010 #include "VMDApp.h"
00011 #include "Mouse.h"
00012 #include "Scene.h" // needed for DISP_LIGHTS count
00013 
00014 static const char mode_doc[] =
00015 "Set the mouse behaviour in the graphics window. See help(mouse) for a list\n"
00016 "of values describing available modes\n\n"
00017 "Args:\n"
00018 "    mode (int): Mouse mode to set.\n"
00019 "    lightnum (int): Light being moved, if mode is mouse.LIGHT.";
00020 static PyObject *py_mousemode(PyObject *self, PyObject *args, PyObject *kwargs)
00021 {
00022   const char *kwlist[] = {"mode", "lightnum", NULL};
00023   int lightmode = -1;
00024   int mode;
00025 
00026   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|i:mouse.mode",
00027                                    (char**) kwlist, &mode, &lightmode))
00028     return NULL;
00029 
00030   VMDApp *app;
00031   if (!(app = get_vmdapp()))
00032     return NULL;
00033 
00034   if (mode != Mouse::LIGHT && lightmode != -1) {
00035     PyErr_SetString(PyExc_ValueError, "Mouse mode must be Mouse::LIGHT if the "
00036                     "lightnum argument is specified");
00037     return NULL;
00038   }
00039 
00040   if (mode == Mouse::LIGHT && (lightmode < 0 || lightmode >= DISP_LIGHTS)) {
00041     PyErr_Format(PyExc_ValueError, "mouse.LIGHT mode requires a valid light "
00042                  "number between 0 and %d", DISP_LIGHTS);
00043     return NULL;
00044   }
00045 
00046   if (!(app->mouse_set_mode(mode, lightmode))) {
00047     PyErr_SetString(PyExc_RuntimeError, "Unable to set mouse mode");
00048     return NULL;
00049   }
00050 
00051   Py_INCREF(Py_None);
00052   return Py_None;
00053 }
00054 
00055 
00056 static PyMethodDef methods[] = {
00057   {"mode", (PyCFunction)py_mousemode, METH_VARARGS | METH_KEYWORDS, mode_doc},
00058   {NULL, NULL}
00059 };
00060 
00061 
00062 static const char mouse_moddoc[] =
00063 "Methods for controlling the mouse behavior. Includes available mouse modes "
00064 "and the ability to set the current mouse mode.";
00065 
00066 
00067 #if PY_MAJOR_VERSION >= 3
00068 static struct PyModuleDef mousedef = {
00069   PyModuleDef_HEAD_INIT,
00070   "mouse",
00071   mouse_moddoc,
00072   -1,
00073   methods,
00074 };
00075 #endif
00076 
00077 
00078 PyObject* initmouse(void) {
00079 #if PY_MAJOR_VERSION >= 3
00080   PyObject *m = PyModule_Create(&mousedef);
00081 #else
00082   PyObject *m = Py_InitModule3("mouse", methods, mouse_moddoc);
00083 #endif
00084 
00085   PyModule_AddIntConstant(m, "ROTATE", Mouse::ROTATION);
00086   PyModule_AddIntConstant(m, "TRANSLATE", Mouse::TRANSLATION);
00087   PyModule_AddIntConstant(m, "SCALE", Mouse::SCALING);
00088   PyModule_AddIntConstant(m, "LIGHT", Mouse::LIGHT);
00089   PyModule_AddIntConstant(m, "PICK", Mouse::PICK);
00090   PyModule_AddIntConstant(m, "USERPOINT", Mouse::USERPOINT);
00091   PyModule_AddIntConstant(m, "QUERY", Mouse::QUERY);
00092   PyModule_AddIntConstant(m, "CENTER", Mouse::CENTER);
00093   PyModule_AddIntConstant(m, "LABELATOM", Mouse::LABELATOM);
00094   PyModule_AddIntConstant(m, "LABELBOND", Mouse::LABELBOND);
00095   PyModule_AddIntConstant(m, "LABELANGLE", Mouse::LABELANGLE);
00096   PyModule_AddIntConstant(m, "LABELDIHEDRAL", Mouse::LABELDIHEDRAL);
00097   PyModule_AddIntConstant(m, "MOVEATOM", Mouse::MOVEATOM);
00098   PyModule_AddIntConstant(m, "MOVERES", Mouse::MOVERES);
00099   PyModule_AddIntConstant(m, "MOVEFRAG", Mouse::MOVEFRAG);
00100   PyModule_AddIntConstant(m, "MOVEMOL", Mouse::MOVEMOL);
00101   PyModule_AddIntConstant(m, "MOVEREP", Mouse::MOVEREP);
00102   PyModule_AddIntConstant(m, "FORCEATOM", Mouse::FORCEATOM);
00103   PyModule_AddIntConstant(m, "FORCERES", Mouse::FORCERES);
00104   PyModule_AddIntConstant(m, "FORCEFRAG", Mouse::FORCEFRAG);
00105   PyModule_AddIntConstant(m, "ADDBOND", Mouse::ADDBOND);
00106 
00107   return m;
00108 }
00109 

Generated on Wed Dec 4 02:44:31 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002