Help with patching Tropy 1.16

I’m trying to patch Tropy 1.16 to integrate it with ScanTailor Advanced, among other things. For my archive folders, I do the following:

  • I use ScanTailor to clean up my images (creating .tiff files in ./out folder).
  • I use Tesseract for batch OCR reading (creating .txt files in ./ocr folder).
  • I use R to create a .json file with a Tropy Item: the archive folder in question, containing the .tiff images from ScanTailor with per-image metadata containing the path to source image and to the OCR file.

When it comes to patching Tropy’s source code, I have added buttons to Tropy’s toolbar (next to link and unlink buttons), and have created a handle that can open a fixed path .txt file when clicking the OCR button (as a test).

What I haven’t been able to figure out – I have never worked with Java Script – is how to retrieve metadata from the currently viewed photo; in my case, for example the metadata field “ocr”. I would like to do something like: electron.shell.openPath(ocrPath), where ocrPath is retrieved from metadata.

I would be very grateful if someone could give me guidance in how to access metadata.

This depends a lot on the context, but in general there’s a full ‘state’ object that holds all the information used by the UI. You can explore the current state object in the dev console by accessing tropy.state().

To get the metadata of the active photo, you first need the photos id: tropy.state().nav.photo. This id can be used to access the photo’s metadata at tropy.state().metadata[photoId]. These are only the photo-level fields though. To get at the current item-level metadata you’d have to use the active item ids at tropy.state().nav.items instead.

1 Like

Excellent, works perfectly. Thanks!

1 Like