Display two pictures side by side in Standalone viewer

If you are a photographer who does a lot of detailed photo-editing, it is extremely useful to be be able to view the before and after results of your efforts without the fag of having to have two Photoshop windows open.

The little script here will do just that. You select the two images you want to compare and they appear next to each other in separate Standalone viewer windows

I have attached a Close button to the toolbar of my Standalone Viewer, which closes both windows and brings the latest Lister to the front

Two Images In Viewer.dcf (2.8 KB)

Close.dcf (829 Bytes)

To get the two viewer windows next to each other you will have to experiment with the minimum width window of the viewer to suit your video set-up. Although those who are much better at scripts that I am will no doubt be able to discover the right co-ordinate of the first window and place the second widow close to that co-ordinate.

Also depending on your video set-up you may need to edit line 34 of the script to set the left co-ordinate of the second window. (Unless you are clever enough to get the system to work it out for you)

I have found this little script saves me so much time.

4 Likes

Thanks for the inspiration!

A bit of feedback:

  • The first picture always gets loaded twice. Delete the first ClickData.Func.command.Run to take care of this.

  • To have more control over the viewers, add SIZE to the Show command.

  • There is a slightly easier way to address the selected files :wink:

Function OnClick(ByRef clickData)
    If clickData.func.sourcetab.selected_files.count <> 2 Then
        Msgbox "Please select two files."
        Exit Function
    End If

    For Each v in DOpus.Viewers
        v.Command("close")
    Next

    ClickData.Func.Command.AddLine("Show """ & ClickData.Func.sourcetab.selected_files(0) & """ POS 3120,0 SIZE 1200,960 NOUSEEXISTING")
    ClickData.Func.Command.AddLine("Show """ & ClickData.Func.sourcetab.selected_files(1) & """ POS 3120,960 SIZE 1200,960 NOUSEEXISTING")
    ClickData.Func.Command.Run
End Function

@Ixp
Yes. I realised that the first picture was getting loaded twice, but I haven't had time to post a correction.

I take your point about the control of the viewer window, but as I use the feature solely for comparing before and after edits in portraits, I have found that if I set the viewer to FIT EVERY PICTURE and then give each picture a fixed width, it is ideal.

What would be nice would be to display the first viewer window, get the value of it top right co-ordinates and use them to display the second window, but as you will have gathered, writing VB is like drawing teeth for me, so I can't work out how to do it.

That's why I added SIZE. It refers to the size of the viewers, not the pictures.

If your monitor was 1600x1200, you would use POS 0,0 SIZE 800,1200 for left viewer and POS 800,0 SIZE 800,1200 for the right one.

@Ixp
Your solution seems to give a neater solution most of the time. Thanks for the tip. I have to say I find this a very handy feature to have.

Up to now, on a single-monitor sysem I've just been opening two instances of the standalone viewer and flicking between their full-screen windows to compare. But maybe I'll give this a spin...

Here is a new version of the View Two Images button, with a correction to the problem of displaying an extra picture and the positioning suggestions from Ixp

Compare Images In Viewer.dcf (3.1 KB)

Here is a new version of the View Two images macro. It contains far more robust error checking, but the functionality is the same. Feel free to adapt to your needs.

Compare Images In Viewer.dcf (4.0 KB)

Close.dcf (829 Bytes)

3 Likes

Auden, I really like the button. Thanks very much.

1 Like

Thanks for the buttons, auden.

Based on my testing, adding this line

@disablenosel:numfiles=2,type=grp:images

to the Modifiers list can ensure the button is only clickable when exactly 2 image files are selected.

This would eliminate the need for this section in the script:

'Error trap in case  the user does NOT choose TWO images to display
   numpics = clickData.func.sourcetab.selected_files.count
   numpics = CStr(numpics)
   If clickData.func.sourcetab.selected_files.count = 0 Then
   msgbox "You have NOT selected any files",16, "NO FILE SELECTED"
   Exit Function
   End If
    If clickData.func.sourcetab.selected_files.count = 1 Then
   msgbox "You have ONLY selected ONE file",16, "NO FILE SELECTED"
   Exit Function
   End If
   If clickData.func.sourcetab.selected_files.count <> 2 Then
      Msgbox "You have selected " + numpics + " Files. SELECT ONLY  TWO",16, "FILE SELECTION ERROR"
	  		ClickData.Func.Command.AddLine("Select NONE")
			ClickData.Func.command.Run
	  Exit Function
	  End If

On the other hand, I would also like to make the Close button only enabled when there are open viewers (i.e. DOpus.Viewers is not empty), but so far I have no clue how to check that with a modifier. If anyone has any idea how to achieve that, please let me know. :slight_smile:

1 Like

You could set a variable via the OnActivateLister event and react to it in the button.

BTW, people who like these buttons often also like this add-in: ShowMulti (Launch multiple viewers).

Thanks for the quick reply!

On that first page you referred to, I found OnViewerEvent, which seems more suitable for my need here.

So I added this background script to keep track of the number of open viewers at any moment:

// Called when an event takes place in the standalone viewer
function OnViewerEvent(viewerEventData)
{
    if (viewerEventData.event == "create") {
	    if (!DOpus.Vars.Exists("viewerOpen")) {
			DOpus.Vars.Set("viewerOpen", 1);
		} else{
	     	DOpus.Vars.Set("viewerOpen", DOpus.Vars.Get("viewerOpen") + 1);
		}
    } else if (viewerEventData.event == "destroy" && DOpus.Vars.Exists("viewerOpen") && DOpus.Vars.Get("viewerOpen") > 0) {
        DOpus.Vars.Set("viewerOpen", DOpus.Vars.Get("viewerOpen") - 1);
    }
}

and this button script:

@disableif:=($glob:viewerOpen==0)
Close ALLVIEWERS

Now the button would indeed be disabled when no viewer is open, and when any viewer is open, it will be enabled. However, immediately after I click the button to close all viewers, the button remains enabled, unless I, well, perform some actions, like switching the active tab, selecting another file, deselecting the current file, etc. Only then will the button be disabled again. It's as if there is a delay in the state of the global variables from the button's perspective.

Do you know what's going on here? I tried adding @toggle:update which seems a bit relevant, but it didn't help.

(I guess another way to tackle this would be to let the button disable itself after closing all viewers, as an one-off action, but I haven't been able to find such a command.)

Thanks in advance!

I'd store DOpus.viewers.count in this variable. Then you can use more events to update it without worrying about keeping track of opening/closing viewers.

Adding

cmd.UpdateToggle();

could help with timely updates.

Thanks! Adding that line did the trick.

For some reason the number in DOpus.viewers.count seems off on my end. When two viewers are open, it shows 2, but when no viewer is open, it shows 1. Since I already having a working version of the scripts, I'll keep them as is for now.