GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Select/Highlight Currently Displayed Image From Image Viewer


#11

Sounds good!

Since like I said before, I’m not much of a programmer. From copying and pasting part of examples I have found, my script so far looks like this:

@script jscript Function OnClick(ByRef clickData) ViewedFile = clickData.func.viewer.current; clickData.func.command.ClearFiles(); clickData.func.command.AddFile(ViewedFile); clickData.func.command.RunCommand("Select FROMSCRIPT DESELECTNOMATCH MAKEVISIBLE"); End Function
Gives me an error:

Error at line 2, position 10 Function OnClick(ByRef clickData) ^ Expected ';' (0x800a03ec) Parse error - script aborted
I will try fixing it later once I get back home again.

However I still think that in future version of DOpus, it would be a nice and useful function to have built-in into the image viewing window without requiring new users who needs it to script it out. Would work really well with the mark/tag functions (as long as you don’t clear the current selections which I believe that is what the clickData.func.command.ClearFiles() does).


#12

Thanks Leo! o) After experimenting a bit…

“clickData.func.viewer.current” works! o) It’s tricky to always select the image in the correct tab though, since getting the last active lister and active tab, does not make sure it’s the tab the image was opened from. I assume there’s no bullet proof way to select the image in the correct tab without knowing the tab itself? If I’m correct, could you also expose a valid data.func.sourcetab object in case OnClick() is fired from the viewer toolbar? It evaluates to “0” right now. Not knowing if that’s desired behaviour?!

I thought about saving the last viewed image in a global variable, to be able to “select” it even after I’ve closed the viewer.
But this can only be done if I know when the viewer is about to close, so the variable needs to be set right before running Show VIEWERCMD=close or hitting . Unfortunately still seems to be hard wired, does it need to be? If not, then the “File -> Close” menu on the toolbar seems a good place to bind “” and inject some commands to run whenever the viewer is about to close. Does anybody not use for closing the viewer? Guess not, so it seems an important “event” for doing some automation magic.

I also noted that the key seems to be hard wired to “drag image”. is quite an important qualifier for shortcuts, I’d prefer as it meets well known adobe/photoshop standard and also clears this key for custom use. I ran into because:
I setup to select the current image and my next idea was to also close the viewer if is pressed additionally. Unfortunately it cannot be done by defining a hotkey using the key nor by testing the qualifiers string, since its hard wired nature. Did not find a setting to change that, is there?

Nonetheless, this is very promising, with some tweaks it really opens new doors! Like it! o)
This is what I ended up with for now. Very basic, since finding the correct tab is guessing, testing shift-qualifiers failed and setting global variable on closing the viewer failed as well. o) But nonetheless:

function OnClick(data){ var curItem = data.func.viewer.current; data.func.command.RunCommand('Select DESELECTNOMATCH EXACT MAKEVISIBLE "'+curItem.name+'"'); }
Btw: The “Listers” object and its methods/props do not seem to be documented, there’s only a short mention in the “DOpus” object and the description of its listers collection.


#13

Wait. I just tested that script but it does not work for me. Is it because I’m on version 11? Just to verify, I create a custom button in the image toolbar, go to advanced so that I can input a script function, and then input:

[code]@script jscript

Function OnClick(data){
var curItem = data.func.viewer.current;
data.func.command.RunCommand(‘Select DESELECTNOMATCH EXACT MAKEVISIBLE "’+curItem.name+’"’);
}[/code]
Correct right? Because it’s giving me:

Error at line 1, position 23 Function OnClick(data){ ^ Invalid character (0x800a0408) Parse error - script aborted

If without “@script jscript”, it would give:

Error at line 3, position 10 Function OnClick(data){ ^ Expected ';' (0x800a03ec) Parse error - script aborted


#14

Viewer scripting requires the Opus 12 beta.


#15

My 2nd try using my previous script resulted in:

[code]@script jscript

function OnClick(clickData) {

ViewedImage = null;
ViewedImage = clickData.func.viewer.current;

dlg = clickData.func.Dlg;
dlg.message = "The Viewed Image Is '" + ViewedImage.name + "' - " + ViewedImage.size.fmt;
dlg.buttons = "Select It|Cancel";
dlg.icon = "info";
dlg.title = "Viewed Image";

if (dlg.Show() == 1) {
    clickData.func.command.ClearFiles();
    clickData.func.command.AddFile(ViewedImage);
    clickData.func.command.RunCommand("Select FROMSCRIPT DESELECTNOMATCH MAKEVISIBLE");
}
else {
    clickData.func.command.deselect = false;
}

}[/code]

Gave me this error:

Error at line 6, position 5 'func.viewer.current' is null or not an object (0x800a138f)

Aaargh! I don’t know what I’m doing!


#16

Ah! So that’s the problem. I opened this thread in the first place asking if it’s possible to do it in Opus 11. Apparently that’s a clear no.


#17

In the Opus 11 viewer, Edit > Tag File (Ctrl+T) is the closest thing to what you want:

The Tag File command is useful when you want to vet a collection of images - you can step through them one at a time in the viewer, and use the Tag File command (or press Ctrl+T) to tag the images you want to keep. This has the effect of putting the parent Lister into Checkbox mode; images you tag will be automatically checked for later processing.


#18

Great so now I’m a bit worried. The reason is I bought Opus back sometime in November or December so not really sure whether I would be eligible for an update to 12 once it comes out.

On an unrelated note, is just me but you can’t edit your posts in this forum?

Oh. I just saw a new post right as I submit my post.

[quote=“leo”]In the Opus 11 viewer, Edit > Tag File (Ctrl+T) is the closest thing to what you want:

The Tag File command is useful when you want to vet a collection of images - you can step through them one at a time in the viewer, and use the Tag File command (or press Ctrl+T) to tag the images you want to keep. This has the effect of putting the parent Lister into Checkbox mode; images you tag will be automatically checked for later processing.[/quote]
Yes I found out about this feature earlier today this but not exactly ideal for my situation. Whatever I guess I will just have to continue to use that for now.


#19

I think the standalone viewer knows which folder tab (if any) opened it, so we could probably expose that as a property. But there’s no guaranteeing the viewer was opened via a lister, though, nor that the folder tab it opened from still exists or is still in the right folder, so there will always be cases where the script might have to search through the other listers/tabs and/or open a new one.

[quote]I thought about saving the last viewed image in a global variable, to be able to “select” it even after I’ve closed the viewer.
But this can only be done if I know when the viewer is about to close[/quote]
An OnViewerClose event might make sense.

Shift only affects the left mouse button, and would only drag if you had the button set to Select Clipboard Region.

It’s been the case for about 10-15 years and nobody has complained. :slight_smile:

Space advances to the next image, which is much more common with image viewers, so I don’t think using it to toggle dragging would be a good idea.

Shift should only change what the mouse buttons do and should not affect hotkeys.

A Ctrl-Shift-G hotkey should work, and does here. I set one to run “Help ABOUT” and pushing it in the viewer opened the About dialog. The default config has Ctrl+Shift+S (Save As) hotkey, which is also working here.

Making a Ctrl-G hotkey check if Shift is held down should not work since the Ctrl-G hotkey should not be run if shift is held down (same in a lister).

It’s just a collection of Lister objects. How collections work depends on the scripting language. We document the Lister objects it contains, but not the collection itself as collections are part of the scripting language.

We document our own custom collection-like objects (Vector, Set, and so on) which are used in a few places instead of native collections, since they’re part of Opus, but not the native ones. Since documentation on Windows scripting is so bad, maybe we could provide a page with collection examples in JScript and VBScript. (Of course, we can’t document collections for all the other languages people might install.)


#20

See the FAQs, bottom section. :slight_smile:


#21

Agree, however the “guess” case then is the exception and not the regular case. So a valid sourcetab would render things robust and designful (what a nice word you have here? o).

I agree, but what about the nearest thing, binding to the “Show VIEWERCMD=close” entry on the toolbar?

Checked: I indeed have “left mouse” set to be “Select Clipboard Region”, changed it to run a blank command -> still works as “Select Clipboard Region”. Bugglet? Entering a dummy command or “//” fixes that.

I guess without the option and intent to define custom hotkeys, it’s quite clear that nobody really tried and complained, hu? o)

Many users and software companys think different about that I guess. is the first thing I press, because so many do it that way. It’s similar to the thing it seems. Why can’t be connected to the “Show VIEWERCMD=next” command from the toolbar so it’s consistent with other key definitions and available for customization?
I see that some additional preferences controls/options would be necessary to setup the keys people like to use for dragging, selecting region etc., but you also did that for mousebuttons so you are obviously aware of different user preferences here. Using or any other non-qualifying key is probably harder to code to be used for dragging etc., but you can make it! o)

Tested again and confirmed. Regular hotkeys work, testing qualifiers does not. Don’t remember how things behaved in a regular lister, if that is equal as you say, then fine - something we seem to get along with. o)

Isn’t “Listers” your collection? When reading through the docs of the DOpus object, it tells me there is Listers.Update() and Listers.LastActive() method, so it’s not entirely native and probably worth its own section? Just thinking, because I was looking for LastActive() exactly and expected to find “Listers” or something, then pulled up the search and found things to be mentioned elsewhere only.


#22

See the FAQs, bottom section. :slight_smile:[/quote]
:blush:

Anyway, I took the dive and finally upgraded to the Opus 12 beta. And yeah all those script including mine works!! So happy now. :smiley:

Thank you leo, tbone, and leo! Anyway I will continue to silently follow this thread since it looks like tbone wants to add some more smartness or function to it. Well I will also do some more exploration with the scripting functions.

Last note, does Directory Opus has a lock on any other files outside of its install directory? Because I noticed that every single time I upgrade it, I had to restart the computer. I already check using tools to make sure there are no locks on any files in the install directory and to make sure the tray icon for Opus is closed. Yet it still required a restart. I had tried simply running it and ignoring the restart message but it does not work. It’s a tad annoying at times especially when you have many important programs opened.


#23

Somewhat off-topic for this thread, but it is not Opus locking files outside of Opus; it is Windows and other programs locking Opus’s files. There is no reliable way to replace a DLL which other programs have loaded as a shell extension or hook, other than rebooting.

The shell / desktop / taskbar can be restarted these days (although doing so often crashes other tools that don’t expect it), but isn’t the only thing that locks the DLLs, and there’s usually some program or other that doesn’t support automated restarting. Microsoft didn’t think ahead to provide a mechanism to request unload & replacement of shell extensions and similar DLLs.


#24

In the next beta we’ll add the command Show VIEWERCMD selectfile which will hard-code this function in (select the currently viewed file in the original tab).

For scripting, we’ll also fix it so qualifiers are passed through to the OnClick function when run from the viewer, and make the source tab handle available as suggested above.


#25

Nice to hear you go 2-way here, fully supporting command and scripting. o) Anything up regarding the keyboard things?

What happened to your avatar Leo? Are you serious? o) I just got used to the “new” one with the face! o)


#26

Hmm, now that you’ve mentioned it… :slight_smile:


#27

Over in the german forum, a user wants to refresh the list of images the viewer determined when it opened.
Kundal came up with this and it’s reported to work. o) “F5” in the viewer to refresh the list is something I also thought of, so very nice! o)

function OnClick(data){ var curItem = data.func.viewer.current; data.func.command.RunCommand('Select DESELECTNOMATCH EXACT MAKEVISIBLE "'+curItem.name+'"'); data.func.command.RunCommand("Show VIEWERCMD=close"); data.func.command.RunCommand("Show LISTSIBLINGS"); }
Now it would be nice to know if the viewer in fullscreen mode or not, when re-opening it.
I digged through the release notes and found following syntax (mentioned in conjunction with @ifset only though).
It does not work, it always gives “false”, is it me doing something wrong or is it expected to not work the way I thought?


#28

IsSet takes one or two arguments.

If only one argument is given, it assumes you’re testing arguments to the Set command. (This used to be the only thing IsSet could do, and the only way to call it.) So IsSet(“Show VIEWERCMD=fullscreen”) is effectively testing Set SHOW VIEWERCMD=fullscreen (which won’t work, of course).

If two arguments are given, the first is the command and the second is the arguments to test.

Here’s how to do it (verified working with 12.0.4):

var isFull = data.func.command.IsSet(“Show”,“VIEWERCMD=fullscreen”);


#29

Ok, that works indeed! o)
Adding “FULLSCREEN” or not to the “Show” command only makes a difference if “Preferences / Viewer / Appearance / Auto-size viewer window” is not enabled or at least not set to open fullscreen. I had that enabled, so a missing “FULLSCREEN” switch would still re-open the viewer in fullscreen mode. To get around that, I disabled that option and added “FULLSCREEN” to the "Show … " command in the double-click filetype definition for images. Will see how that might effect other situations I currently can’t think of, but for now, working nicely. o)

Thank you! o)


#30

[quote=“jon”]In the next beta we’ll add the command Show VIEWERCMD selectfile which will hard-code this function in (select the currently viewed file in the original tab).

For scripting, we’ll also fix it so qualifiers are passed through to the OnClick function when run from the viewer, and make the source tab handle available as suggested above.[/quote]
Oh! Sorry somehow I missed this post. Anyway thank you very much for this function! It’s awesome! :smiley: :thumbsup: