Commit 74ae1df9 authored by hkrishna's avatar hkrishna

updating web client and adding ability to record & write python state

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@21858 18c085ea-50e0-402c-830e-de6fd14e8384
parent c8d0c25c
/// requires jQuery to work..
var debugTextArea = document.getElementById("debugTextArea");
function debug(message)
{
debugTextArea.value += message + "\n";
debugTextArea.scrollTop = debugTextArea.scrollHeight;
}
function showAllClasses()
{
// $.each(viewerApi, function(key,value)
// {
// debug("key: " + key + " " + viewerState.get(key).typename);
// });
}
function inspectClass()
{
// var key = document.getElementById("inspect").value;
// debug("api: " + JSON.stringify(viewerState.get(key)));
// debug("data: " + JSON.stringify(viewerState.get(key)));
}
function clearScreen()
{
debugTextArea.value = "";
debugTextArea.scrollTop = debugTextArea.scrollHeight;
}
function AttributeSubject()
{
......@@ -78,6 +48,9 @@ function AttributeSubject()
return typename;
}
this.toString = function() {
return JSON.stringify(api) + "\n" + JSON.stringify(data);
}
this.registerCallback = function(cb) {
callbackList.push(cb);
}
......@@ -514,7 +487,7 @@ function VisItProxy()
}
catch(err)
{
alert(data);
//alert(data);
return;
}
......
......@@ -528,7 +528,7 @@ static pthread_mutex_t mutex;
static pthread_cond_t received_sync_from_viewer;
static bool waitingForViewer = false;
static ObserverToCallback *synchronizeCallback = 0;
#define THREAD_INIT() { pthread_attr_init(&thread_atts); }
#define THREAD_INIT() pthread_attr_init(&thread_atts)
#define MUTEX_CREATE() pthread_mutex_init(&mutex, NULL)
#define MUTEX_DESTROY() pthread_mutex_destroy(&mutex)
#define MUTEX_LOCK() pthread_mutex_lock(&mutex)
......@@ -3356,7 +3356,7 @@ OpenClientHelper(PyObject *self, PyObject *args, int componentNumber)
PyErr_Clear();
}
if(componentNumber == 2)
else if(componentNumber == 2)
{
clientName = "CLI";
program = "visit";
......@@ -3386,6 +3386,11 @@ OpenClientHelper(PyObject *self, PyObject *args, int componentNumber)
return NULL;
}
}
else
{
VisItErrorFunc(OCEError);
return NULL;
}
}
else
{
......@@ -15881,27 +15886,84 @@ visit_exec_client_method(void *data)
for(size_t i = 0; i < code.size(); ++i)
{
char *buf = NULL;
// Handle ClientMethod specially if we're not in a local namespace.
if(strncmp(code[i].c_str(), "ClientMethod(", 13) == 0)
{
if(!localNameSpace)
/// hktodo: remove this raw input abstraction,
/// currently I want this separated from regular interpret logic
if(code[i].find("raw:") == 0) {
std::ostringstream c;
c << "exec(\"" << code[i].substr(4) << "\")"; /// remove the prefix
PyRun_SimpleString(c.str().c_str());
}
else {
// Handle ClientMethod specially if we're not in a local namespace.
if(strncmp(code[i].c_str(), "ClientMethod(", 13) == 0)
{
if(!localNameSpace)
{
int len = code[i].size() + 6 + 1;
buf = new char[len];
SNPRINTF(buf, len, "visit.%s", code[i].c_str());
}
}
if(buf == NULL)
{
int len = code[i].size() + 6 + 1;
int len = code[i].size() + 1;
buf = new char[len];
SNPRINTF(buf, len, "visit.%s", code[i].c_str());
strcpy(buf, code[i].c_str());
}
PyRun_SimpleString(buf);
delete [] buf;
}
if(buf == NULL)
{
int len = code[i].size() + 1;
buf = new char[len];
strcpy(buf, code[i].c_str());
}
PyRun_SimpleString(buf);
delete [] buf;
}
}
else if(m->GetMethodName() == "WriteState")
{
std::string command = "";
std::string result = "";
command += "import cStringIO\n";
command += "__tmpOut__ = cStringIO.StringIO()\n";
command += "WriteScript(__tmpOut__)\n";
command += "__tmpOut__.seek(0)\n";
command += "__tmpRes__ = __tmpOut__.read()\n";
command += "__tmpOut__.close()\n";
PyRun_SimpleString(command.c_str());
PyObject* mod = PyImport_AddModule("__main__");
PyObject* dict = PyModule_GetDict(mod);
PyObject* key = PyString_FromString("__tmpRes__");
PyObject* res = PyDict_GetItem(dict, key);
result = PyString_AsString(res);
// Send the macro to the clients.
if(result.size() > 0)
{
//if(onNewThread)
GetViewerProxy()->SetXferUpdate(true);
// We don't want to get here re-entrantly so disable the client
// method observer temporarily.
clientMethodObserver->SetUpdate(false);
stringVector args;
args.push_back(result);
ClientMethod *newM = GetViewerState()->GetClientMethod();
newM->ClearArgs();
newM->SetMethodName("AcceptRecordedMacro");
newM->SetStringArgs(args);
newM->Notify();
//if(onNewThread)
GetViewerProxy()->SetXferUpdate(false);
}
}
if(acquireLock)
VisItUnlockPythonInterpreter(myThreadState);
......@@ -16011,6 +16073,7 @@ ExecuteClientMethod(ClientMethod *method, bool onNewThread)
info->DeclareMethod("MacroStart", "");
info->DeclareMethod("MacroPause", "");
info->DeclareMethod("MacroEnd", "");
info->DeclareMethod("WriteState", "");
info->SelectAll();
// If onNewThread is true then we got into this method on the 2nd
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment