While writing a script for the standalone viewer I ran into some problems. Here is a demo.
This script launches two images from the current tab:
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
cmd.deselect = false; // Prevent automatic deselection
cmd.RunCommand('Close ALLVIEWERS');
cmd.RunCommand('Show "' + tab.files(0) + '" POS=3120,0 SIZE=1200,960 NOUSEEXISTING');
cmd.RunCommand('Show "' + tab.files(1) + '" POS=3120,960 SIZE=1200,960 NOUSEEXISTING');
}
Let's analyze the two viewers:
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
cmd.deselect = false; // Prevent automatic deselection
// DOpus.viewers.Update();
cmd.RunCommand('Set UTILITY=otherlog');
DOpus.ClearOutput();
DOpus.Output('DOpus.viewers.count: ' + DOpus.viewers.count);
DOpus.Output('');
for (var eViewer = new Enumerator(DOpus.viewers); !eViewer.atEnd(); eViewer.moveNext()) {
var item = eViewer.item();
DOpus.Output('item.parenttab.path' + ': "' + item.parenttab.path + '"');
DOpus.Output('item.current' + ': "' + item.current + '"');
DOpus.Output('item.index' + ': "' + item.index + '"');
DOpus.Output('item.files.count' + ': "' + item.files.count + '"');
DOpus.Output('item.title' + ': "' + item.title + '"');
DOpus.Output('item.foreground' + ': "' + item.foreground + '"');
DOpus.Output('item.lastactive' + ': "' + item.lastactive + '"');
DOpus.Output('');
}
for (var i = 0; i < DOpus.viewers.count; i++) {
DOpus.Output('DOpus.viewers(' + i + ').parenttab.path: "' + DOpus.viewers(i).parenttab.path + '"');
DOpus.Output('DOpus.viewers(' + i + ').current: "' + DOpus.viewers(i).current + '"');
DOpus.Output('DOpus.viewers(' + i + ').index: "' + DOpus.viewers(i).index + '"');
DOpus.Output('DOpus.viewers(' + i + ').files.count: "' + DOpus.viewers(i).files.count + '"');
DOpus.Output('DOpus.viewers(' + i + ').title: "' + DOpus.viewers(i).title + '"');
DOpus.Output('DOpus.viewers(' + i + ').foreground: "' + DOpus.viewers(i).foreground + '"');
DOpus.Output('DOpus.viewers(' + i + ').lastactive: "' + DOpus.viewers(i).lastactive + '"');
DOpus.Output('');
}
}
Everything's fine, the result might look like this:
DOpus.viewers.count: 2
item.parenttab.path: "D:\test\jpg"
item.current: "D:\test\jpg\0-file-2.jpg"
item.index: "0"
item.files.count: "1"
item.title: "undefined"
item.foreground: "false"
item.lastactive: "true"
item.parenttab.path: "D:\test\jpg"
item.current: "D:\test\jpg\0-file-1.jpg"
item.index: "0"
item.files.count: "1"
item.title: "undefined"
item.foreground: "false"
item.lastactive: "false"
DOpus.viewers(0).parenttab.path: "D:\test\jpg"
DOpus.viewers(0).current: "D:\test\jpg\0-file-2.jpg"
DOpus.viewers(0).index: "0"
DOpus.viewers(0).files.count: "1"
DOpus.viewers(0).title: "undefined"
DOpus.viewers(0).foreground: "false"
DOpus.viewers(0).lastactive: "true"
DOpus.viewers(1).parenttab.path: "D:\test\jpg"
DOpus.viewers(1).current: "D:\test\jpg\0-file-1.jpg"
DOpus.viewers(1).index: "0"
DOpus.viewers(1).files.count: "1"
DOpus.viewers(1).title: "undefined"
DOpus.viewers(1).foreground: "false"
DOpus.viewers(1).lastactive: "false"
We should be able to merge the two scripts and still get the same result, right?
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
cmd.deselect = false; // Prevent automatic deselection
cmd.RunCommand('Close ALLVIEWERS');
cmd.RunCommand('Show "' + tab.files(0) + '" POS=3120,0 SIZE=1200,960 NOUSEEXISTING');
cmd.RunCommand('Show "' + tab.files(1) + '" POS=3120,960 SIZE=1200,960 NOUSEEXISTING');
// DOpus.viewers.Update();
cmd.RunCommand('Set UTILITY=otherlog');
DOpus.ClearOutput();
DOpus.Output('DOpus.viewers.count: ' + DOpus.viewers.count);
DOpus.Output('');
for (var eViewer = new Enumerator(DOpus.viewers); !eViewer.atEnd(); eViewer.moveNext()) {
var item = eViewer.item();
DOpus.Output('item.parenttab.path' + ': "' + item.parenttab.path + '"');
DOpus.Output('item.current' + ': "' + item.current + '"');
DOpus.Output('item.index' + ': "' + item.index + '"');
DOpus.Output('item.files.count' + ': "' + item.files.count + '"');
DOpus.Output('item.title' + ': "' + item.title + '"');
DOpus.Output('item.foreground' + ': "' + item.foreground + '"');
DOpus.Output('item.lastactive' + ': "' + item.lastactive + '"');
DOpus.Output('');
}
for (var i = 0; i < DOpus.viewers.count; i++) {
DOpus.Output('DOpus.viewers(' + i + ').parenttab.path: "' + DOpus.viewers(i).parenttab.path + '"');
DOpus.Output('DOpus.viewers(' + i + ').current: "' + DOpus.viewers(i).current + '"');
DOpus.Output('DOpus.viewers(' + i + ').index: "' + DOpus.viewers(i).index + '"');
DOpus.Output('DOpus.viewers(' + i + ').files.count: "' + DOpus.viewers(i).files.count + '"');
DOpus.Output('DOpus.viewers(' + i + ').title: "' + DOpus.viewers(i).title + '"');
DOpus.Output('DOpus.viewers(' + i + ').foreground: "' + DOpus.viewers(i).foreground + '"');
DOpus.Output('DOpus.viewers(' + i + ').lastactive: "' + DOpus.viewers(i).lastactive + '"');
DOpus.Output('');
}
}
Well, we don't. It looks like this:
DOpus.viewers.count: 2
item.parenttab.path: "undefined"
item.current: "undefined"
item.index: "0"
item.files.count: "0"
item.title: "undefined"
item.foreground: "false"
item.lastactive: "false"
item.parenttab.path: "undefined"
item.current: "D:\test\jpg\0-file-1.jpg"
item.index: "0"
item.files.count: "1"
item.title: "undefined"
item.foreground: "true"
item.lastactive: "true"
DOpus.viewers(0).parenttab.path: "undefined"
DOpus.viewers(0).current: "D:\test\jpg\0-file-2.jpg"
DOpus.viewers(0).index: "0"
DOpus.viewers(0).files.count: "0"
DOpus.viewers(0).title: "undefined"
DOpus.viewers(0).foreground: "true"
DOpus.viewers(0).lastactive: "true"
DOpus.viewers(1).parenttab.path: "undefined"
DOpus.viewers(1).current: "D:\test\jpg\0-file-1.jpg"
DOpus.viewers(1).index: "0"
DOpus.viewers(1).files.count: "1"
DOpus.viewers(1).title: "undefined"
DOpus.viewers(1).foreground: "false"
DOpus.viewers(1).lastactive: "false"
Ok... we can update lister objects with DOpus.listers.Update()
(docs), so maybe DOpus.viewers.Update()
works as well, although it's not mentioned in the docs.
Let's give it a try:
DOpus.viewers.count: 2
item.parenttab.path: "undefined"
item.current: "undefined"
item.index: "0"
item.files.count: "0"
item.title: "undefined"
item.foreground: "false"
item.lastactive: "false"
item.parenttab.path: "undefined"
item.current: "D:\test\jpg\0-file-1.jpg"
item.index: "0"
item.files.count: "1"
item.title: "undefined"
item.foreground: "true"
item.lastactive: "true"
DOpus.viewers(0).parenttab.path: "undefined"
DOpus.viewers(0).current: "D:\test\jpg\0-file-2.jpg"
DOpus.viewers(0).index: "0"
DOpus.viewers(0).files.count: "0"
DOpus.viewers(0).title: "undefined"
DOpus.viewers(0).foreground: "true"
DOpus.viewers(0).lastactive: "true"
DOpus.viewers(1).parenttab.path: "undefined"
DOpus.viewers(1).current: "D:\test\jpg\0-file-1.jpg"
DOpus.viewers(1).index: "0"
DOpus.viewers(1).files.count: "1"
DOpus.viewers(1).title: "undefined"
DOpus.viewers(1).foreground: "false"
DOpus.viewers(1).lastactive: "false"
A bit better, but still not completely correct.
Things I noticed while debugging:
- The results would vary after a while.
- The two enumerating methods sometimes delivered very different results.
- Opus soft crashed a few times (I am sending the mini dumps via mail)
- Occasionally the viewer stopped launching at all and Opus needed to be restarted.
- Using the script from the viewer instead of lister toolbar seemed to produce better results.
LaunchViewers.dcf (1.1 KB)
ProbeViewers.dcf (3.7 KB)
MultiShow.dcf (4.1 KB)