PDA

View Full Version : Scroll through buttons on a page using Girder



jsl
June 17th, 2009, 04:05 PM
I've got a somewhat convoluted process I'm trying to set up, but I haven't figured out the easiest way to do it. I want to use Girder to scan through the buttons on my NR pages and then trigger a chosen button. The buttons I have created are laid out in a grid on each page and have 3 states (normal, selected, activated). I've created a Macro in Girder that uses Girder states to change the button's state, but I haven't figured out a way to easily have Girder "press" the button.

It seems like I should be able to write something in Lua in NetRemote that I can trigger from Girder to do both the scanning and activating, but I'm not sure where to start. Any ideas?

Thanks,
John

Rob H
June 17th, 2009, 11:25 PM
You could perhaps use NetRemote.RunLua() to execute a bit of code in NetRemote, although any errors will not be reported back to Girder, and may not appear in NRD's Lua console - you might be able to see them in DebugView though.

Once you have found an element using NetRemote.GetElementByName() you can use various methods of the element object - see the help in NRD for more information on this. You can certainly press and release a button that way - btw do make sure that if you use Lua to press a button that you also release it.

jsl
June 18th, 2009, 11:49 AM
Thanks for the reply Rob.
Because all of the buttons are on a fixed grid, could I select a button by position instead of name? That way, I could just have Girder send the x & y coordinates for the button I want. I see the GetPosition function, but it looks like it gives the position of an element, not get an element based on position. Is there another way?
Thanks,
John

Rob H
June 18th, 2009, 03:47 PM
Are you using individual buttons or a looped frame?

You pretty much have to find an element by name or path, although you could maybe iterate over the children of a page looking for a button that matches the position

jsl
June 18th, 2009, 05:23 PM
I'm using individual buttons. How would I iterate over the children of a page looking for a button that matches the position? (I'm still getting the hang of lua)
Thanks,
John

Rob H
June 18th, 2009, 10:21 PM
You would use something like (untested code)


function FindElementFromElementsAt(elements, x, y)
for id, element in pairs(elements) do
if element:IsShowing() then
local left, top = element:GetPosition(abs)
local width, height = element:GetSize()
if (x >= left and x <= left + width) and (y >= top and y <= top + height) then
local typeId, typeName = element:GetType()
if typeName == 'frame' then
return FindElementFromElementsAt(element:GetChildren(), x, y)
else
return element
end
end
end
end
return nil
end

function FindElementAt(x, y)
local page = NetRemote.GetCurrentPage()
return FindElementInElementsAt(page:GetElements(), x, y)
end

jsl
June 18th, 2009, 11:16 PM
Thanks for the code Rob. I'll work through it tomorrow and try to get a handle on it.

I appreciate the help.
John

jsl
July 1st, 2009, 02:02 PM
I finally got a chance to get back to this, and I've still got a lot of questions. It looks like you have things starting at the top left part of the page. The buttons that I want to scan through start at x=0, y=20. How would I take that into account? Also, I do have a few pages that deviate from this standard and have either a bunch of smaller buttons or have some buttons missing. Any ideas of how to handle that? Finally, what should the syntax of the ButtonDown and ButtonUp be and how should I call all of this in Girder?

Sorry to be a little clueless on this. I appreciate the help,
John