00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <string.h>
00025 #include <stdlib.h>
00026 #include <ctype.h>
00027 #include <tcl.h>
00028
00029 #include "config.h"
00030 #include "CommandQueue.h"
00031 #include "utilities.h"
00032 #include "VMDApp.h"
00033 #include "TextEvent.h"
00034
00035 int text_cmd_sleep(ClientData, Tcl_Interp *, int argc, const char *argv[]) {
00036
00037 if(argc == 2) {
00038 vmd_sleep((int) atof(argv[1]));
00039 }
00040 else {
00041 return TCL_ERROR;
00042 }
00043
00044 return TCL_OK;
00045 }
00046
00047 int text_cmd_gopython(ClientData cd, Tcl_Interp *interp,
00048 int argc, const char *argv[]) {
00049
00050 VMDApp *app = (VMDApp *)cd;
00051 CommandQueue *cmdQueue = app->commandQueue;
00052
00053 if (argc == 1) {
00054 if (!app->textinterp_change("python")) {
00055 Tcl_AppendResult(interp, "Unable to change to Python interpreter.",
00056 NULL);
00057 return TCL_ERROR;
00058 }
00059 } else if (argc == 2) {
00060
00061 if (app->textinterp_change("python")) {
00062 app->logfile_read(argv[1]);
00063 app->textinterp_change("tcl");
00064 } else {
00065 Tcl_AppendResult(interp, "Unable to change to Python interpreter.",
00066 NULL);
00067 return TCL_ERROR;
00068 }
00069 } else if (argc == 3 && !strupncmp(argv[1], "-command", CMDLEN)) {
00070
00071 if (app->textinterp_change("python")) {
00072 cmdQueue->runcommand(new PythonEvalEvent(argv[2]));
00073 app->textinterp_change("tcl");
00074 } else {
00075 Tcl_AppendResult(interp, "Unable to change to Python interpreter.",
00076 NULL);
00077 return TCL_ERROR;
00078 }
00079 } else {
00080 Tcl_AppendResult(interp, "gopython usage: \n",
00081 "gopython -- switch to python interpreter\n",
00082 "gopython <filename> -- run given file in Python interpreter\n",
00083 "gopython -command <cmd> -- execute <cmd> as literal Python command\n",
00084 NULL);
00085 return TCL_ERROR;
00086 }
00087 return TCL_OK;
00088 }
00089