• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

SDK: How to select all text in LrView window?

Participant ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

An absolute beginner in LR SDK is searching for advise how to tweak and improve an existing plugin.

Background:

There is a beautiful plugin available on Github to visualize focus points as well as display EXIF metadata for a given photo. The metadata displayed is a bit inconvenient to use, because you can't search the text inside the window, and if you want to copy the entire information to a text editor you have to do this separately for the two columns, ie tag names and values. "Select all" in the context menu applies only to the active column. See attached image.

 

Ambition:

Of course, it would be perfect to have a means to search the text directly inside the window but I guess this might too difficult, at least I'm unable to do at this point. 

I would be already happy if I could tweak the existing code so that it's possible to select all text in Metadata display at once, so it can be easily copied to a text editor for further investigation.

 

Question:

The Metadata dialog of this plugin is currently implemented as 

 

LrView
   scrolled_view
      row  

         col1=static_text, col2=static_text

 

I would very much appreciate any suggestions how this could be reorganized so that it would be possible to select and copy the entire text in the window at once.

TOPICS
SDK

Views

470

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

As you're discovering, the SDK doesn't give fine-grained control over a plugin's user-interface components.  Some ideas:

 

- Add a button "Show as Text" that opens a scrolled_vew() containing an edit_field() with the "value" property set to the desired text and the "property height_in_lines" set to the number of lines in the text.  When the user first clicks in that field, all the text will be selected, making it easy to copy it to the clip board.  

 

You could add an incremental search field at the top of this window, an edit_field() with the "immediate" property true and the "value" property bound to a property value using LrView.bind().  That property value has an observer function attached to it that gets called any time the user types in the edit_field(), and the observer function changes the text value displayed in the window to those lines containing the string the user has typed.   While this wouldn't take more than a dozen or so lines of code, it invokes a number of different SDK modules -- the Lightroom Classic Programmer's Guide explains the concepts.

 

- Add a button "Copy to Clipboard" that sets the operating-system clipboard to contain the desired text.  You'll have to use LrTasks.execute() to run a utility for setting the clipboard from a temporary text file written by the plugin.  Use "pbcopy" on Mac and "clip" on Windows. 

 

- Add a button "Open in Editor" which writes the desired text to a .txt file and then opens the .txt file in the current default app for editing text files.  See here for the SDK idiom that does that:

https://community.adobe.com/t5/lightroom-classic/developing-a-publish-plugin-some-api-questions/m-p/... 

 

[Use the blue reply button under the first post to ensure replies sort properly.]

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Thank you so much for this valuable information, John!

I guess it will take me some time to go through this, understand, put the pieces together and then modify the plugin code so that it supports the desired behaviour. My programming skills have become quite rusty, so even if this exercise is walk in the park for most of you, it's a real challenge for me 😉

 

Anyway, you have shown me four ways to accomplish my goal, so hopefully I can manage to get at least one of them  to work  🙂

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

@johnrellis  Thanks to your excellent advice I have been able to make some progress.

The "open in editor" feature was pretty easy; the text file already existed since the plugin is using it (exiftool output file) to fill the two arrays (columns for labels and values) with data.

Anyway, having spent some time to understand the plugin code and SDK concepts, I had the ambition to go further and add the incremental search as well.

 

I have implemented the additional UI elements plus the oberver infrastructure. Next step would be implementing the filtering and its application in the dialog. This is where I got stuck. To me, it's not clear how the filtered lines/columns would get updated and visible at the UI.

The dialog is constucted as follows:

 

result = LrDialogs.presentModalDialog {
  title = "Metadata display",
  ...
  contents = contents

 

whith

 

local contents = f:column {
  spacing = f:label_spacing(),
  bind_to_object = properties,
  findwhat,    -- entry field for incremental search
  scrollView   -- scrolled view of the two columns for labels & values
}

 

 and 

 

local scrollView = f:scrolled_view {
  f:row {
    f:static_text {
      title = column1,
      ..
    },
    f:static_text {
      title = column2,
      ..
    }
    .. 
  },
  ..
}

 

where column1 and column2 hold the actual data (EXIF labels and values).

 

Just modifying column1 and column2 doesn't seem to have an effect on the dialog window.

Is there any way to directly access and modify the data that is used by the dialog?
Or do I need to recreate the "contents" data structure or even make another call to presentModalDialog during the observer function? (which would impact the edit field as well).

I would be very thankful for your suggestions how to proceed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

You'll need to bind the "title" properties of the static_texts:

    f:static_text {
      title = LrView.bind "column1"

 Then you assign the current value of that property by doing:

properties.column1 = ...string containing the labels...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

Perfect! 

 

With this hint I was able to complete the implemention of the incremental filter.

I can't believe that I managed to get these improvements done, and only within a few hours. Thank you so much for guiding me, really appreciate.

 

Some more testing, code polishing & documentation, then I'll check with the author if he wants to integrate these changes so everyone could benefit from it.

 

Just one more question: are you using a source code debugger for LR plugins, can you recommend one?

 

I was positively surprised how easy this went for me. The LUA compiler doesn't catch everything, but gives many good hints in case of improper code. Having a debugger eases and speeds up things, though.

 

Best regards

Karsten

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

LATEST

"Are you using a source code debugger for LR plugins, can you recommend one?"

 

Two options:

 

- My Lightroom Debugging Toolkit for Lightroom is lightweight and specialized for debugging LR plugins.

 

- The Zero Brane IDE is full-featured IDE for Lua. It isn't fully aware of how LR handles tasks and stack tracing, though.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines