Copy link to clipboard
Copied
I'm trying to expend the functionalities of a plugin I wrote (based on the sdk samples) by adding some radio button so that the user can select 1 choice.
Meaning : Based of a "Key", the export folder and export parameters will adapted.
The last choice must be saved for the next run.
The issue is : I cannot find how to manage the fact that the number of radio buttons aren't fixed.
I tried to adapt the following code (from sample)
f:column {
spacing = f:control_spacing(),
f:radio_button {
title = "Button one",
value = LrView.bind( "selectedButton" ),
checked_value = "one",
},
f:radio_button {
title = "Button two",
value = LrView.bind( "selectedButton" ),
checked_value = "two",
},
},
In this way (as long as I found keys in the list, I add a radio button) datas are stored in a string like : key1:folder1;key2:folder2;
while true do
-- if all keys were treated, it's finished
if keys ~= '' then
return true
end
-- extract the first key
pstart= 1
pend= string.find(keys,":")
KeyM = string.sub(keys, pstart, pend-1)
-- extract the folder
pstart= pend+1
pend = string.find(keys,";")
FolderM= string.sub(keys, pstart, pend-1)
-- remove the 1st "line"
keys= string.sub(keys, posfin+1)
-- add the button the the dialog
f:radio_button {
title = FolderM,
value = LrView.bind( "selectedButton" ),
checked_value = "one",
},
end
1. I get an error : "Yielding is not allowed within a C or metamethod call". I do not really understand what this means.
2. I do not understand i
Any help is welcome
Copy link to clipboard
Copied
"Yielding is not allowed within a C or metamethod call".
This obscure error is raised when you try to call certain API functions from the main task, rather than an asynchronous task created by LrTasks. The documentation for each function indicates if it needs to be called from such a task (e.g. see catalog:createVirtualCopies()).
Copy link to clipboard
Copied
From your code fragments, it's hard to tell exactly what you're doing -- I'd have to see the entire code. But here's a template for creating a column of n radio buttons:
local buttons = {}
for i = 1, n do
table.insert (buttons, f:radio_button {...})
end
local column = f:column (buttons)
Copy link to clipboard
Copied
Thanks for the reply.
You are right, I didn't explain one important thing : I started my code from the radiobutton sample from SDK. So, the rest of the code is the standard radiobutton sample code.
To test, I just tried to do what I explained above.
I will start with your template code and give a feedback.
Thanks.
Copy link to clipboard
Copied
Ok, Thanks to you johnrellis, I came forward.
Now, I have my column of radio_buttons
But, I have another issue I can select more than one. And that not the way they should be used.
Here the part of the code (finally, I found how to insert as "code").
LrFunctionContext.callWithContext( "RadioButtons", function( context )
local buttons = {}
for i = 1, NbMembres do
table.insert (buttons,
f:radio_button {
title = NomMembre,
value = LrView.bind( "MembrePCCO" ),
checked_value = ClefMembre,
}
)
end
local props = LrBinding.makePropertyTable( context )
props.selectedButton = ClefMembre[1]
LrDialogs.presentModalDialog {
title = "Vous etes ?",
contents = column
}
end)
That's the result with multiple radiobuttons selected
Any idea what I missed ?
Copy link to clipboard
Copied
Each radio_button contains this:
value = LrView.bind( "MembrePCCO" )
But there isn't any assignment to props.MembrePCCO; instead there's this:
props.selectedButton = ClefMembre[1]
I think that should be:
props.MembrePCCO = ClefMembre[1]
Your code fragment doesn't show the construction of "column". The table "buttons" passed to f:column() needs to have the bind_to_object key assigned:
buttons.bind_to_object = props
...f:column (buttons)...
Copy link to clipboard
Copied
Thanks for the feedback.
What I forgot to mention in the first post (but you probably pointed this ) is that I'm far to be a real programmer. I just have some knowledge, but I'm curious and try to help. That's why I spend a lot of days the last weeks trying to understand lua language, based on the sample files analysis and tests by playing with the code and debugging .
To explain, the goal of this plugin (when finished) is to simplify the photo update in our photogallery for the members of my Photo club. They're regularly doing mistakes (like uploading 15Mb photos, or puting them in the wrong folder and so on... always funny )
So, what I'm trying to do is to do 3 steps in 1 click : Export to Webserver
1. Export photo based on fixed parameters
2. Transfer the photo over FTP to our website
3. Send a email to inform that new photos are available.
Steps 1 and 2 are finished and works fine !
Step 3 will be analyzed after I finished this one.
So, finally, why the radio buttons. It's a parameter (the only one) for the user. I created a combination of userkeys and destination folders for the ftp transfer.
So the meaning is that each user will :
- select he's name in the radio button list (information will be stored "somewhere")
- the plugin checks the folder associated to the userkey (datas are available in a string)
- the folder is returned to the ftp transfer function so that the photos arrives in the right folder.
I'm trying to find the good way based on the radiobutton sample, but in final, the list should be in the plugin window.
Finally, the current full code of my lua test file
-- Access the Lightroom SDK namespaces.
local LrFunctionContext = import 'LrFunctionContext'
local LrBinding = import 'LrBinding'
local LrDialogs = import 'LrDialogs'
local LrView = import 'LrView'
local LrColor = import 'LrColor'
-- Create the logger and enable the print function.
local LrLogger = import 'LrLogger'
local myLogger = LrLogger( 'Mesboutons' )
myLogger:enable( "logfile" )
local function showCustomDialogWithTransform()
LesMembres = "anm:Andre_M;bop:Boris_P;chb:Christian_B;jeb:Jean_B;jecls:Jean_C_S;jok:Joel_K;jepl:Jean_P_L;lor:Lorene_R;maf:Manuel_F;pal:Paul_L;sedep:Serge_dP;yab:Yannick_B;"
local _, NbMembres = string.gsub(LesMembres, ";", "")
local ClefMembre = {}
local NomMembre = {}
local posdeb = 0
local posfin = 0
local MesChoix = {}
local f = LrView.osFactory()
-- on extrait le nom et on sauvegarde la clef des membres
for i = 1, NbMembres do
posdeb = 1
posfin = string.find(LesMembres,":")
ClefMembre = string.sub(LesMembres, posdeb, posfin-1)
posdeb = posfin+1
posfin = string.find(LesMembres,";")
NomMembre = string.sub(LesMembres, posdeb, posfin-1)
LesMembres = string.sub(LesMembres, posfin+1)
end
LrFunctionContext.callWithContext( "RadioButtons", function( context )
local buttons = {}
for i = 1, NbMembres do
table.insert (buttons,
f:radio_button {
title = NomMembre,
value = LrView.bind( "MembrePCCO" ),
checked_value = ClefMembre,
}
)
end
local column = f:column (buttons)
local props = LrBinding.makePropertyTable( context )
props.MembrePCCO = ClefMembre[1]
local f = LrView.osFactory()
LrDialogs.presentModalDialog {
title = "Vous etes ?",
contents = column
}
end) -- end callWithContext
end
-- Now display the dialogs
showCustomDialogWithTransform()
Now, I cannot give more informations
Remember, I'm trying to find how evrything in lightroom lua works based only on reading this forum, the SDK Documentation and the sample source code.
Please don't be too angry if I'm completely wrong
Thanks anyway for the help