00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "py_commands.h"
00010 #include "VMDTkinterMenu.h"
00011 #include "VMDApp.h"
00012
00013 static PyObject *show(PyObject *self, PyObject *args) {
00014 char *name;
00015 int onoff;
00016 if (!PyArg_ParseTuple(args, (char *)"s|i", &name, &onoff))
00017 return NULL;
00018 VMDApp *app = get_vmdapp();
00019 if (PyTuple_GET_SIZE(args) > 1) {
00020 app->menu_show(name, onoff);
00021 }
00022 return Py_BuildValue("i", app->menu_status(name));
00023 }
00024
00025 static PyObject *location(PyObject *self, PyObject *args) {
00026 char *name;
00027 PyObject *loc;
00028 if (!PyArg_ParseTuple(args, (char *)"s|O", &name, &loc))
00029 return NULL;
00030 VMDApp *app = get_vmdapp();
00031 int x, y;
00032 if (PyTuple_GET_SIZE(args) > 1) {
00033
00034 if (!PyArg_ParseTuple(loc, (char *)"ii", &x, &y))
00035 return NULL;
00036 app->menu_move(name, x, y);
00037 }
00038 app->menu_location(name, x, y);
00039 return Py_BuildValue("(ii)", x, y);
00040 }
00041
00042 static PyObject *addmenu(PyObject *self, PyObject *args) {
00043 char *name;
00044 PyObject *root;
00045 if (!PyArg_ParseTuple(args, (char *)"sO", &name, &root))
00046 return NULL;
00047 VMDApp *app = get_vmdapp();
00048 VMDMenu *menu = new VMDTkinterMenu(name, root, app);
00049 if (!app->add_menu(menu)) {
00050 delete menu;
00051 PyErr_SetString(PyExc_ValueError, (char *)"Could not add menu");
00052 return NULL;
00053 }
00054 app->menu_add_extension(name,name);
00055 Py_INCREF(Py_None);
00056 return Py_None;
00057 }
00058
00059 static PyObject *registermenu(PyObject *self, PyObject *args) {
00060 char *name, *menupath=NULL;
00061 PyObject *func;
00062 if (!PyArg_ParseTuple(args, (char *)"sO|s", &name, &func, &menupath))
00063 return NULL;
00064 if (!PyCallable_Check(func)) {
00065 PyErr_SetString(PyExc_ValueError, (char *)"func argument must be callable");
00066 return NULL;
00067 }
00068 if (!menupath)
00069 menupath = name;
00070 VMDApp *app = get_vmdapp();
00071 VMDTkinterMenu *menu = new VMDTkinterMenu(name, NULL, app);
00072 if (!app->add_menu(menu)) {
00073 delete menu;
00074 PyErr_SetString(PyExc_ValueError, (char *)"Could not add menu");
00075 return NULL;
00076 }
00077 menu->register_windowproc(func);
00078 app->menu_add_extension(name,menupath);
00079 Py_INCREF(Py_None);
00080 return Py_None;
00081 }
00082
00083 static PyMethodDef methods[] = {
00084 {(char *)"add", (vmdPyMethod)addmenu, METH_VARARGS,
00085 (char *)"add(name, root) -- add to VMD extension menu"},
00086 {(char *)"register", (vmdPyMethod)registermenu, METH_VARARGS,
00087 (char *)"register(name, func, menupath) -- func returns Tk() instance"},
00088 {(char *)"show", (vmdPyMethod)show, METH_VARARGS,
00089 (char *)"show(name, onoff) -- show/hide registered window"},
00090 {(char *)"location", (vmdPyMethod)location, METH_VARARGS,
00091 (char *)"location(name, (x, y)) -- set menu location"},
00092 {NULL, NULL}
00093 };
00094
00095 void initvmdmenu() {
00096 (void) Py_InitModule((char *)"vmdmenu", methods);
00097 }
00098