PDA

View Full Version : How to make a Lua Script execute a Macro?



piratao2
February 16th, 2007, 04:12 AM
Ok, I've opened this new thread since I thought the original one did not have the correct title.

http://www.promixis.com/forums/showthread.php?t=16245

I'm building my own GML file to support:
Winamp
Zoom Player
Windows Operations (Mouse, Keyboard)
TVedia
*maybe I add more later.

I want to have a OSD Menu to choose what application to start and once started, I want the group of commands for that application to be enabled and the others disabled. This will be triggered with a button on the X10 remote UR81A and the X10 RF receiver MR26A.
I have all configured and now I'm working on the OSD Menu, which needs to enable/disable groups based on which option was choosen by the user on the OSD menu.
My doubt for now is how I can do to make the response from the OSD menu trigger the related macro on girder. I've created some macros for each of the options of the OSD menu and each of these macros will do the necessary actions to enable an application and disable the others. The problem is how to relate the option choosen on the OSD menu with the macros I've already created.

Any ideas, examples? Please I'm stuck on this, have searched but it looks nobody uses this approach...

This is the current OSD menu code that I want to change as mentioned in the previous post.




--[[

OSD Menu example

:New ({Modifiers})

Modifiers is a table containing modifications to the base class (see osd.lua). The example below specifies a callback function.

:Initialize ()

Setups up the menu

:Show (ForceToTopOfScreen,Title,{Table of items})


--]]


local function ShowResult (number,text)

osd.StatusMessage ("Processando\n"..text)
if number == 1 then -- launch app 1

--[[ HERE I WOULD LIKE TO CALL A MACRO THAT WILL DISABLE
SOME GROUPS AND ENABLE OTHERS, OPEN THE RELATED
APPLICATION, SET FOCUS, ETC
]]

elseif number == 2 then

--[[ HERE I WOULD LIKE TO CALL A MACRO THAT WILL DISABLE
SOME GROUPS AND ENABLE OTHERS, OPEN THE RELATED
APPLICATION, SET FOCUS, ETC
]]

elseif number == 3 then

--[[ HERE I WOULD LIKE TO CALL A MACRO THAT WILL DISABLE
SOME GROUPS AND ENABLE OTHERS, OPEN THE RELATED
APPLICATION, SET FOCUS, ETC
]]

elseif number == 4 then


--[[ HERE I WOULD LIKE TO CALL A MACRO THAT WILL DISABLE
SOME GROUPS AND ENABLE OTHERS, OPEN THE RELATED
APPLICATION, SET FOCUS, ETC
]]

else

--[[ HERE I WOULD LIKE TO CALL A MACRO THAT WILL DISABLE
SOME GROUPS AND ENABLE OTHERS, OPEN THE RELATED
APPLICATION, SET FOCUS, ETC
]]

end


end

local menu = osd.Classes.Menu:New ({Callback = ShowResult})

menu:Initialize ()

menu:Show (true,"Menu Principal",{"1-Winamp","2-Zoom Player","3-Windows Media Player","4-TVedia Portal (default)",})




Thanks in advance.

blubberhoofd
February 16th, 2007, 07:59 AM
Hi,

seems to me like you could generate events instead of directly executing a macro


gir.TriggerEvent("whatever", 18)

Promixis
February 16th, 2007, 09:04 AM
Just attach an eventstring that matches 'whatever' to the macro you want to execute.

blubberhoofd
February 16th, 2007, 01:22 PM
@Mike

lol, thanx for completing my sugestion ;)

piratao2
March 14th, 2007, 08:57 AM
Hello all, sorry for the late responses but I was very busy at work and I was not able to take the time to look here... Anyway thanks for you responses!

I must admit that I'm a newbie with Girder and I would be gratefull if you direct me on how to create an eventstring that could do what I want to do. I tried to understand this on the help file, but I don't know if I'm looking on the right thing on it.

Maybe if you give me some examples I could get it myself... I don't see how an eventstring is able to: DISABLE SOME GROUPS AND ENABLE OTHERS, OPEN THE RELATED APPLICATION, SET FOCUS, ETC


Thanks in advance.

Ron
March 14th, 2007, 09:05 AM
Best thing to do is read the manual on how Girder works.

the short of it is this:

There are 2 entities in girder. Actions and Events. Events trigger Actions. Actions can do a lot of things including enabling groups, set focus etc.

To hook an event to an action you open the log window, make the event happen and then drag and drop that event on top of the action.

piratao2
March 14th, 2007, 09:44 AM
Ok, so, if my menu is setup to trigger an event, I can then just hook it to an action or a macro, right?
But how to create a custom event in Lua script?

Thanks.

Ron
March 14th, 2007, 10:51 AM
custom event: see post #2

piratao2
March 14th, 2007, 10:58 AM
ahh ok! Thanks! I will try to play with it later and I will post here the results.

piratao2
March 14th, 2007, 03:17 PM
OK, I've added the custom event to the menu code. And then I have hooked up this custom event to the macro that I want to execute when Winamp is choosen on the menu.
Looking on the log, I see that the custom event is triggered once I choose Winamp from the menu, but the macro which is assigned to that custom event is not executed.

The menu code is a scripting object that is inside another macro, called CHOOSEAPP. This macro is executed when the menu button is pressed on my remote. The purpose of this macro is to close opened applications if any and depending on the application that is choosen, the macro should call another macro. The problem, like I said is that the menu code is triggering an event that is assigned to another macro, called ENABLEWINAMP and for an unknown reason, the macro ENABLEWINAMP does not run.

Please review the code below and let me know about any tip you may have.




local function ShowResult (number,text)

--osd.StatusMessage ("Processando\n"..text)
if number == 1 then -- launch app 1

gir.TriggerEvent ('WINAMP123',18)

elseif number == 2 then

gir.TriggerEvent ('ZOOMPLAYER123',18)

elseif number == 3 then

gir.TriggerEvent ('WMP123',18)

elseif number == 4 then

gir.TriggerEvent ('TVEDIA123',18)

else
-- win.close ('windowsmediaplayer.exe',nil,nil,nil)
end


end

local menu = osd.Classes.Menu:New ({Callback = ShowResult})

menu:Initialize ()

menu:Show (true,"Menu Principal",{"1-Winamp","2-Zoom Player","3-Windows Media Player","4-TVedia Portal (default)",})



Thanks in advance.

Ron
March 14th, 2007, 03:21 PM
Do you have the event exactly right? Check that it is a 'Girder Event'. Best thing to do is to trigger the event with the log open and then drag and drop that event on top of the action, then you'll be sure that it will match next time it happens.

piratao2
March 14th, 2007, 07:38 PM
Do you have the event exactly right? Check that it is a 'Girder Event'. Best thing to do is to trigger the event with the log open and then drag and drop that event on top of the action, then you'll be sure that it will match next time it happens.

Thanks Ron, but it is just exactly what I've made, based on the previous recommendation on this thread.
And I'm sure it is not running the ENABLEWINAMP macro because I've created just a simple OSD on this macro to test if it would work. When I right click the ENABLEWINAMP macro, and click Test, it shows the OSD. But when I test the CHOOSEAPP macro, this CHOOSEAPP shows on the log that it is triggering the custom event, but this custom event does not trigger the actions (CHOOSEAPP macro) that are assigned to it.

Please help me since I'm stuck at this. Once it is resolved, I think it will be very easy to do the rest. I've attached my gml for you to take a look on it Look at the folder (group) called Windows. You will see the macros I'm creating and mentioning. All the other stuff will be used later once I start to assign actions to events from my remote controller. The main purpose of this gml is to be able to use it for launching either standalone apps or TVedia.




Thanks in advance!

piratao2
March 15th, 2007, 08:54 AM
Ok, I've noticed why it was not responding. Actually even the CHOOSEAPP macro would not respond to my remote. The reason was that I was using a GML that I downloaded for TVEDIA and that GML had a Windows Conditional to make it respond to events only when TVEDIA is active. Anyway thanks for all the help.
Then I'll try to go ahead with my GML and see if I'm able to finish it soon...

I would like to hear from you if the way I'm planning to do is really good... Since my media computer is also the only computer on the house (means it used on the console), I don't want to put TVedia on the boot. I want to use Girder to launch TVedia only when I need it or optionally open Winamp, Zoom Player and Windows Media Player.
What I've planned is to have a macro that will allow me to choose what application I need to launch. Once the menu appears, the mouse control is disabled and only the keys up, down and enter are enabled, this is for chosing an app from the menu.
Then, once an app is choosen, the group for that application is enabled and then when the menu button is pressed on the remote controller, the menu appears again...
The mouse control through the remote controller will be enabled depending if it is needed on an app.

This is my plan, What you think? Any suggestions???