Can I make the Viewer Panel Open/Close, when a media file is Selected/Deselected?

Hi folks! The name says it all. I'd like to make DOpus as efficient as possible, and am wondering if I can have it open the Viewer whenever I select a Photo or Video, then minimize it when no media files are selected?

Would this require a script or plugin? Please let me know your thoughts, and thank you so much in advance for any insight!

You could also think about the Viewerpane (eg Set VIEWPANE=Toggle) to be shown.

The selection/deselection event has to be implemented as a script. which can be captured via Dialog.WatchTab().

Hi Felix, wow-- thank you so much for the quick response! Hmmmm, I'm using trial and error right now to understand how to put that into practice. Would I start by Right-Clicking a menu bar and choosing Customize, then Right-Clicking the Viewer Pane Button, followed by Edit? Now I'm seeing the Set VIEWPANE=Toggle you'd mentioned, and if I hit Advanced, I'm now in a text box where I can add in a script, right?

Aah, actually, now I see that in the Arguments dropdown of the Advanced section, there is an option called Dialogs. And the link you shared with me seems to indicate that I can use a Dialog.WatchTab() Argument to respond to what kind of file is Selected.... Hmm, but I'm not seeing an option to choose Selected in the Arguments menu.... Soooo, I tried adding Set VIEWPANE=Toggle Dialog.WatchTab(select) to the advanced window-- no luck yet.

Am I getting warmer?

Sorry, my post might have been misleading. The first line is an internal command made to toggle the viewer pane.
Second line is script code which needs more than this line of code. I attached a simple code snippet because i found it hard to start myself with dopus coding but i wont go too deep cause it can get complicated very easily. Have a look at the docs or the forum.

function OnClick(clickData)
{
	var tab = clickData.func.sourcetab;
	var cmd = clickData.func.command;
	var dlg = clickData.func.Dlg;

	dlg.detach = true;
	dlg.template = "dialog1";
    dlg.title = "";
    dlg.create();
    dlg.show();
    dlg.watchtab(tab, "select");

	var msg;
	do
	{
		msg = dlg.GetMsg();
		
	    if (!msg.result) 
			break;

		var event = msg.event;
		var control = msg.control;
		var value = msg.value;

		if(control == "tab" && event == "select")
		{
			//If selected image open viewer with internal command
			//else close viewer
		}
	}
	while(msg);
}

I attached the button you can use for further testing.
Watchtab.dcf (2.2 KB)

Hmmm, odd... when I try and run the Watchtab.dcf file you'd shared, it tries to run this blank box, and I just get this blank box that stays open until I close it. I tried restarting to DOpus, and trying again, to no avail...

Alternatively, should I be pasting this text into the original Viewer Pane? or, is it better to add the text you'd shared with a new button?

If you want this to get a quick overview, adding the field {thumbnail} to the info tip might be an easier solution.

read this How to use buttons and scripts from this forum - Buttons/Scripts - Directory Opus Resource Centre (dopus.com)
to understand 'button scripts' and 'scripts'.

Actually this was on purpose. The way watchtab works requires a dialog. In my usecase i didnt want to have the dialog always visible. Mine is actually invisible, which i dindt copy into this snippet. In your case you might need a Button to close that dialog by itself. It took me long to understand how to work with the dialog message loop. Have a look at the corresponding docs.

Hi Ixp, thank you for the feedback! My setup does currently have the thumbnail show in this way when a file is hovered over, which is nice. I do appreciate you sharing where I need to go if I ever want to make adjustments to that.

That said, my ideal situation is still to have the viewer pane open and close based on the type of file selected...

Thank you for pointing me to this resource, Galaxy. I'll try to digest this info!

Hmmm, sadly, I still don't think I'm quite understanding. Lol... trying to follow this course of action, I just ended up messing up my Viewer button, and having to revert to the default functionality.

Just to be clear, are you saying that if I utilize the script code you'd shared with me, my DOpus should automatically open the Viewer pane when I select an image file, and close it when I deselect that file? Thank you so much for clarifying!

No. The comments i made were at the location where to put your script logic such as

		if(event == "tab" && value == "select")
		{
			tab.Update();
			if(tab.selstats.selfiles > 0)
			{
				var item = tab.selected_files(0);
				if(item.metadata == "image")
				{
					cmd.RunCommand("Show Autofilelist");
				}
			}
			else if(tab.selstats.selfiles == 0)
			{
				DOpus.viewers.lastactive.Command("close");
			}
		}

Viewer auto open close.dcf (3.4 KB)

Take a closer look at the scripting docs.

Out of curiosity I tested your script button, for the first post:
change the code

if(item.metadata == "image")
cmd.RunCommand("Show Autofilelist");
else if(tab.selstats.selfiles == 0)

to

if(item.metadata == "image" || item.metadata == "video")
cmd.RunCommand('Show "'+item+'" POS 1920,0 SIZE 960,1080');
else if(tab.selstats.selfiles == 0 && DOpus.viewers.lastactive != 0)

look at the Show internal commandShow (gpsoft.com.au)
BTW, I use seer, a quick look tool.

You don’t need to give the Show command the image path. It works on the selected file by default.

No, the viewer is already open...

I do not think it is possible to do what OP asks. Double clicking an image file to open the viewer can be done. Closing the viewer automatically does not seem possible. Using F7 to toggle viewer pane is another option. But looking at the Directory Opus scripting events (as a script would need to be run continuously) there does not seem to be one for an item has been selected or single-click on an item (same thing) also detecting that no valid items are selected to close the viewer. Please correct me if I am wrong. An interesting request.

Put this as a feature request please -
An option in Viewer/Behaviour
' Activate/de-activate viewer on image select/deselect'

The dialog.watchtab could be called at startup and when tabs are opened. Then all tabs could be monitored (not sure about performance though) for selection events. The dialog window itself can be invisible and thus the script can be run continously. And the snippet i provided was already able to open the viewer when a file was selected and closed if selection was cleared, so i dont see a reason why it shouldnt work. Or i just dont get what op asked for :sweat_smile:

Is this discussion about the viewer pane or the standalone viewer?

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Viewing_Images.htm

I'm learning scripting and I tried to make the dialog window invisible but it didn't work. . .

function OnClick(clickData)
{
	var tab = clickData.func.sourcetab;
	var cmd = clickData.func.command;
	var dlg = clickData.func.Dlg;
	
	if(!DOpus.Vars.Exists("ClickMediaOpenViewer"))
	{
	DOpus.Vars.Set("ClickMediaOpenViewer") = 1;
	} else {
	DOpus.Vars.Delete("ClickMediaOpenViewer");
	}

	dlg.detach = true;
	dlg.template = "dialog1";
    dlg.title = "OnSelect";
    dlg.create();
    //dlg.show();
	dlg.disable_window;
    dlg.watchtab(tab, "select");

	var msg;
	do
	{
		msg = dlg.GetMsg();
		//dlg.EndDlg;
		
		if(!DOpus.Vars.Exists("ClickMediaOpenViewer") && DOpus.listers.lastactive.viewpane == 1)
		{
		cmd.RunCommand("Set VIEWPANE=off");
		return
		}
		
	    if (!msg.result) 
			break;

		var event = msg.event;
		var control = msg.control;
		var value = msg.value;

		Log("Event: " + event + ", Control: " + control + ", Value: " + value);

		if(event == "tab" && value == "select")
		{
			tab.Update();
			if(tab.selstats.selfiles > 0)
			{
				var item = tab.selected_files(0);
				if(item.metadata == "image" || item.metadata == "video")
				{
				    if(DOpus.Vars.Exists("ClickMediaOpenViewer") && DOpus.listers.lastactive.viewpane == 0)
					{
					cmd.RunCommand("Set VIEWPANE=on");
					}
				}
			}
			else if(tab.selstats.selfiles == 0 && DOpus.listers.lastactive.viewpane == 1 || msg == 0)
			{
				cmd.RunCommand("Set VIEWPANE=off");
			}
		}
	}
	while(msg);
}



function Log(msg, e)
{
	DOpus.output(String(msg), e || false);
}