Sebastian asked if I could detect when an external editor has made changes to the file in the script editor. It's often the case that the scientist has two editors going, one because it is what they are used to and the autoplot editor to get the execute button.
I was looking at the WatchService object today and tried to hook it up to detect external changes. This works fine on my desktop, but needs to be tested on other platforms. Also it appears to fail on Armond's machine.
Here's a standard procedure to verify:
1. run autoplot, bring up the script tab.
2. make a new script, save it to a local folder. (We should test on both network and physical drives)
3. bring up an external editor with the saved file.
4. append "#trivial change" to the file and save.
5. the dialog should appear in Autoplot's script editor.
Kristoff pointed out that there's something wrong on WIndows, where it seems to respond to its own save as if someone else had modified the file. Here is the log when working correctly on Linux:
11.10.050: == Executing Script ==
10.047: closing watcher
10.046: pausing before restarting watcher
00.050: restarting watcher
00.050: ENTRY org.virbo.autoplot.scriptconsole.restartWatcher /home/jbf/foo.jy /home/jbf/foo.jy
00.049: RETURN org.virbo.autoplot.scriptconsole.restartWatcher /home/jbf/foo.jy /home/jbf/foo.jy (1ms)
00.049: start watch event loop on /home/jbf
00.045: restarting watcher
00.045: ENTRY org.virbo.autoplot.scriptconsole.restartWatcher /home/jbf/foo.jy /home/jbf/foo.jy
00.001: watch service was closed: sun.nio.fs.LinuxWatchService@4b51cf0f
00.000: RETURN org.virbo.autoplot.scriptconsole.restartWatcher /home/jbf/foo.jy /home/jbf/foo.jy (45ms)
00.000: start watch event loop on /home/jbf
I've kludged in a 10 second wait between when the file is written and when it starts to monitor again.
Last edit: Jeremy Faden 2015-11-11
If two Autoplots have the same script running, the second will post the "changed" message each time the first runs the script. This is because it's tweaking the timestamp, and no contents are changing.
This works properly.
I noticed this may not work when the filesystem is a network drive. (Linux, /home/jbf/project/, on spot7).
This has caused enough headaches that I'm going to change the logic so that if the editor is not dirty (saved), then the script will automatically reload with the new version of the file. About half of the people scripting don't use the editor for scripting, but it's a nice reference and shouldn't bother the person if they aren't using it to make changes.
This should also fix problems with double-warnings and things people have seen on other platforms.