Button to change preferences option (CBR/CBZ)

Hi, guys.

This should be easy, but I don't know how to do it.

I want a button to toggle between two preferences options. I have the "Use internal picture viewer" off by default, but I would like to activate it sometimes by pressing a button (and deactivate it by pressing it again).

Thanks!

P.S: The perfect solution would be to open only CBR and CBZ files with the internal picture viewer, so I can see the next picture using the mouse scroll, and continue using a different software as default image viewer.

If you wanted a "built-in" way of doing this, you'd need an enhancement to something like Preferences / File Operations / Double-click on Files / Use internal picture viewer for to allow for conditional logic... or something similar.

However, you could try setting Settings / File Types... / Recognized images / Events / Left double-click to run the following (it's probably configured now to simply run 'show'):

[code]@ifpath:.(cbr|cbz)
show

@ifpath:else
"/system\mspaint.exe" {f}[/code]
NOTE: this works for YOUR purposes despite Opus not actually working like you'd think is correct. What I mean is that while the code above achieves the behavior you happen to want, if you flipped the logic around and tried to run a non-default action (like the call to paint.exe or some other app) if the item IS in fact located in a path that matches the .cbz wildcard, it gets ignored. I'm guessing Opus is extracting the contents of the CBR|CBZ archive to some temp folder somewhere in the background, and the wildcard pattern to the @ifset modifier isn't being applied as a result...

Oh yeah!

Replace the last line that runs "/system\mspaint.exe" {f} with the full path (in quotes to contain spaces) to whatever other program you normally want to open images - followed by the {f} code.

Thanks, dude! Unfortunately it doesn't work, dopus opens the CBR/CBZ files as compressed files, so I see the list of images and then when I open them they are just images and my default software (xnview) opens them :confused:

That's because you've got your settings backwards for how this will need to work - based on the logic goof I mentioned in Opus, which means you can't tell it do something non-default inside of CBR|CBZ archives. And it sounds like you've got your opus preferences NOT set to use the internal viewer by default, and instead have things set to open in XNView.

You'll need to configure Opus to open all images in the internal viewer by default... so in other words, enable and set that Use internal picture viewer option to all recognized pictures.

What the filetype edit I suggested then does is provide an OVERRIDE to that setting, so that Opus only does non default behavior (XNView) for files that do NOT appear to be in a CBR|CBZ archive/path.

NOTE: Opus will still open the CBR|CBZ file as an archive, but when you double-click on the images inside it, they should open in the internal viewer the way you asked.

The above should work how you asked - however, there are some ways to make it a little more slick if you would like - but there seem to be a few more unexpected behaviors from Opus in those ideas as well...

For instance, you could remove whatever default actions exist for the individual filetypes (say, CB7, CBR, and CBZ files)...

You could then create a redirect using a new Opus File Type Group, to which you would assign the 3 file extensions as members of the group, and then assign a Left double-click action that runs something like:

go newtab [ show slideshow ]
This would let you not mess with internal viewer and other settings and instead tell Opus that for those file extensions, open the archive (the go newtab command), and then uses the 'embedded commands' feature to run a subsequent command once the archive is opened (the show slideshow command inside the square brackets).

But a few issues here... once again, this runs into a limitation that perhaps GPSoft could tweak. You might notice that I'm running a go newtab command. This opens the archive in a new tab... not desirable. But if we use just a regular go command, Opus ignores the embedded commands that follow. I imagine that when support for the embedded commands was created, it was probably only expected to be used when opening new file lists (new tabs, new lister windows, etc) since the embedded command feature was created to provide a way to be sure that certain commands operated on the new file list.

So running a plain unqualified go command probably doesn't trap the embedded commands by design.

Also, in the case where you've downloaded a comic archive that contains another FOLDER inside the archive rather then the jpg images right at the root of the archive - the alternate ~smart example above wouldn't work. We'd need some scripting glue to examine what is happening inside the folder, maybe a script could do everything for you to make it smart and smooth.

Drag this into Preferences / Toolbars / Scripts and it should do what you want:

ShowForComics.vbs.txt (472 Bytes)

[code]Function OnInit(initData)
initData.name = "ShowForComics"
initData.desc = "Divert double-clicks to internal viewer inside comic archives"
initData.version = "1.0"
initData.default_enable = true
End Function

Function OnDoubleClick(doubleClickData)
Set folderTest = DOpus.FSUtil.NewWild("*.(cbr|cbz|cb7)")
If (folderTest.match( doubleClickData.tab.path )) Then
OnDoubleClick = "Show LISTSIBLINGS"
Else
OnDoubleClick = False
End If
End Function[/code]

More intelligence, like checking that it's really inside an archive and not a folder that happens to have ".cbr" as parts of its name, or like checking the type of file that has been double-clicked, is left as an exercise. :slight_smile:

Doesn't seem to work here... something wrong with the wild match, it never never catches it.

Checking it out now...

It's because the script is running before we've opened the archive into the new path... so the doubleClickData.tab.path is evaluated as the parent folder OF the archive.

I'll tweak it and add in a check for sub-dirs as well.

The script changes what happens when you double-click an image file while inside a .CBZ (etc.) archive.

If you want to change what happens when you double-click the archive itself, that would need something slightly different, but is still possible.

Ah, yeah. That works fine - sorry. Had a different idea for scripting. Post shortly...

Ok, Christmas Eve family festivities complete!

Here's what I had in mind for a script with a bit more coverage than Leo's excellent starter script, simply based on being familiar with digital comics, from the scripts opening comments:

[quote="steje"]The purpose of this script is to help Opus treat comic book archives with a user configurable file extension (commonly .cb7, .cbr, or .cbz) similar to how dedicated comic archive readers work, where double-clicking on the archive itself automatically starts displaying the comic book images inside the archive - but in this case, using Opus' internal picture viewer.

For the script to work, Opus must ALREADY be configured to treat files with these extensions as archives (7zip, RAR, and ZIP respectively)...

The script also forces the use of the internal picture viewer when double clicking on images inside either an archive (if you've browsed inside it as a folder) or a real folder that has an extension which matches one from the configurable list of archive file extensions.

There is also an option to configure the list of image file extensions that the script will handle inside of archives and archive extension folders...

In addition to this primary behavior, the script also provides an option to specify a qualifier key that you can use when double-clicking on the comic archives to control if the script should do it's job or not. By default, this option is set to "none".

NOTE: the script has logic to handle the fairly common tendency for some comic book archives to contain a single child folder at the root of the archive, which in turn contains the comic images. If there are MULTIPLE items inside the archive root in addition to that single child folder, then it's not clear what the "right" thing to do is.

If this turns out to be the case, the script will NOT attempt to figure something out and will instead just open the archive as normal - like a folder, at which point a variation on Leo's original code for the request that generated this script will still let the Opus internal picture viewer open any images you double click on once you've found them manually inside the archive.

Either way, this also helps in case you want to have another application than Opus handle opening images outside of comic archives, but still like the Opus internal picture viewer for simple viewing and scrolling through comic book images...[/quote]

How to install and use it?:
The script is provided here as an Opus Script Package... which in turn is actually a zip file with the VBScript that does the work packaged inside.

ShowForComics.osp (2.56 KB)
It can be installed by either manually copying the OSP file to the /dopusdata\Script AddIns folder, or via drag-and-drop into the Preferences / Toolbars / Scripts page. As shown in the screenshot below, as well as mentioned above, the script has a set of configurable options:



Oh - and Happy Holidays!

Sorry guys, Holidays got in the way. That works really well steje, thank you very much! :slight_smile:

Wasn't expecting any replies during the brunt of the holidays :slight_smile:... but sure, no problem. I'm using this myself now as well, so thank YOU for raising the idea again (it has come up in the past from digital comic fans, but I think before we had scripting in Opus).

Going to upload a new version tomorrow... with a new name and some other changes, such as support for not just the qualifier key to ENABLE the scripts behavior, but also for support of a qualifier key to DISABLE the scripts behavior, and run whatever you want as the default action (in my case, to open the archive like normal using the 'Go FROMSEL' command).

And... thanks to Leo for the starter idea.

I only piped up after he posted his excellently simple starter script because I wanted to share a version that opened images inside of comic archives automatically after double-clicking the archive, rather than having to still browse INTO the archive and again double-click on the images.

It works but I get some errors, by the way:

ShowForComics: Error at line 97, position 4 ShowForComics: Object doesn't support this property or method: 'doubleClickData.item.is_dir' (0x800a01b6) ShowForComics: Error at line 97, position 4 ShowForComics: Object doesn't support this property or method: 'doubleClickData.item.is_dir' (0x800a01b6)

That's really odd... there shouldn't be any dependency for the use of that property that DOESN'T get satisfied that could cause that error.

Can you say what exactly you were double clicking on when that error gets thrown?

I've made some other changes (and renamed the script) and am posting it to the Script Buttons & Add-Ins forum... Please delete the current script package and install the new one. You will need to reset any script configuration options.

I couldn't find it in the forum, did you post it?

Sorry - holidays, and some other scripting stuff got in the way.

I'll upload it tomorrow after updating 2 other previous scripts that some folks asked for some enhancements on.

Can you say what exactly you were double clicking on when that 'doubleClickData.item.is_dir' error was thrown? Can you reproduce it?