Miguel wrote:
I am not familiar with doevents()
Sorry, that's a VB function that allows a function to release its hold on the system while system events are processed. Without it, in VB, mouse events and such can't be processed. The same problem occurs in browsers (on a PC at least):
for(var i=0;i<1;){}locks the browser. But with VB you can get around that with the equivalent, but with a "doevents()":
do
GLOBALFLAG=true
...
doevents()loop until GLOBALFLAG
Here, doevents() might allow an event to trigger that changes GLOBALFLAG
Anyway, you can't do that in JavaScript. So we must use setTimeout() and let the calling function return.
By the way, I was experimenting, and now I see that
document.jmol.script()
just signals "Jmol executing script" and then returns. Only after the calling function JS later returns does the script continue. Thus:
function testit(){
NOW=new Date()
document.jmol.script("show file")
document.jmol.script("select *;color green")
MYDATA+=((new Date())-NOW)+": TESTING"
}function showmsg(n,what){
//message callback
MYDATA+="\n"+((new Date())-NOW)+": "+what+"\n"
}produces:
10: Jmol executing script ...
30: Jmol executing script ... 30: TESTING 50: 19 atoms selected
60: Script completed
So two scripts are starting, the function continues, but only the second script actually executes. This is a real drag--that if a script command is given while another is executing, the second is just plain lost.
From this I see that it would not be possible to have a .script() function return a buffer that includes what has been output as a result of that script. In fact, the return happens long before the script ever actually runs.
Here's something like what you are talking about, I think:
MsgQueue="" NOW=new Date()
function showmsg(n,what){
//message callback
MsgQueue+="\n"+((new Date())-NOW)+": "+what+"\n"
}function testit(){
//called by a button press
MsgQueue=""
NOW=new Date()
document.jmol.script("show file")
document.jmol.script("delay 3;select *;color green")
MsgQueue+=((new Date())-NOW)+": TESTING"
PollJmol()
}function PollJmol(){
if(MsgQueue.indexOf("Script completed")>0){
document.info.msg.value=MsgQueue
return
}
setTimeout("PollJmol()",10)
}except that I am using the callback still to set a JavaScript variable MsgQueue instead of some internal Java variable document.jmol.MsgQueue. It's a bit more complicated to set something like this up, but I don't see why it couldn't be done. This outputs after about 3 seconds:
10: Jmol executing script ...
10: Jmol executing script ... 20: TESTING 3045: 19 atoms selected
3055: Script completed
(The page running this is http://www.stolaf.edu/people/hansonr/jmol/test/polling.htm)
I also experimented with scriptButton. Does anyone use this? It seems to me the button callback should be at the END of the sequence (upon completion) not at the beginning.
Enough!
Bob
-- Robert M. Hanson, [EMAIL PROTECTED], 507-646-3107 Professor of Chemistry, St. Olaf College 1520 St. Olaf Ave., Northfield, MN 55057 mailto:[EMAIL PROTECTED] http://www.stolaf.edu/people/hansonr
------------------------------------------------------- The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt _______________________________________________ Jmol-developers mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jmol-developers
