[JW Lua] Button press callback
Charles O. Lawrence
charlesolawrence at bellsouth.net
Wed Nov 18 03:38:02 CET 2015
Thanks very much for the explanations.
I understand about the method CreateTree(), but still do not see how to use
the FCTreeNode found in the class browser under the filter "Dialog Boxes".
There is no corresponding method in the FCCustomLuaWindow class. How is one
supposed to use FCTreeNode, if at all, or is one to always just use
AddNode()?
Similarly, how is one supposed to use FCControl, if at all, or is one to
always use the methods supplied to create the various controls?
I see how you setup the callback for the button press. What was confusing
to me was how to check which of several buttons was pressed. Normally when
you call a function, in this case mycommandhandler, which has an argument,
thecontrol, you have to pass the value of the argument to the function. It
appears that when you RegisterHandleCommand to setup the callback function,
you don't specify an argument to the callback function, rather it somehow
"magically" gets the argument, in this case the control ID, via the fact
that the definition of the function has an argument. This is strange to me.
Also, how can you define mybutton as local and yet it is in the scope of the
callback function?
Charles
-----Original Message-----
From: JWLua [mailto:jwlua-bounces at jwmusic.nu] On Behalf Of Jari Williamsson
Sent: Tuesday, November 17, 2015 6:17 PM
To: The JW Lua script plug-in. <jwlua at jwmusic.nu>
Subject: Re: [JW Lua] Button press callback
Charles,
Below is sample code for both your questions (setting up a tree control and
responding to button command in a dialog).
The control IDs are set up automatically by the "Create" methods. Get the
object from the "Create" method to manipulate the object.
Best regards,
Jari Williamsson
-----
-- Create the dialog and its controls
local str = finale.FCString()
local dialog = finale.FCCustomLuaWindow()
local mybutton = dialog:CreateButton(0, 0)
str.LuaString = "My Button"
mybutton:SetText(str)
local mytree = dialog:CreateTree(0, 30)
dialog:CreateOkButton()
dialog:CreateCancelButton()
-- Initialize the tree
str.LuaString = "Parent Tree Node"
local parentnode = mytree:AddNode(nil, true, str)
str.LuaString = "Child Item 1"
mytree:AddNode(parentnode, false, str)
str.LuaString = "Child Item 2"
mytree:AddNode(parentnode, false, str)
-- The command callback
local function mycommandhandler(thecontrol)
if thecontrol:GetControlID() == mybutton:GetControlID() then
finenv.UI():AlertInfo("The button 'mybutton' was pressed",
"Button Pressed")
end
end
-- Register the callback
dialog:RegisterHandleCommand(mycommandhandler)
if (dialog:ExecuteModal(nil) == 1) then
-- Ok button was pressed
end
-----
On 2015-11-17 21:02, Charles O. Lawrence wrote:
> Jari and JW Lua fans,
>
> I am trying to set up a FCCustomLuaWindow so that when I press a given
> button whose control ID I know, it calls a particular function to do
> something. I am struggling with the RegisterHandleCommand and how to
> pass the control ID, if that is what you do. A brief explanation of the
> procedure and/or a code sample would be greatly appreciated.
>
> Thanks,
>
> Charles
>
>
>
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>
_______________________________________________
JWLua mailing list
JWLua at jwmusic.nu
http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
More information about the JWLua
mailing list