I am new to EventGhost and Python but have used them successsfully to control "my living room" but I am stuck.
Where do I find answers to the following:
1 How do I call an EventGhost macro from an EventGhost hosted Python script?
2 How do I call the Event Ghost function ShowOSD and other functions from an EventGhost hosted Python script?
Call EventGhost macros and functions from a Python script
-
- Posts: 15
- Joined: Fri Sep 26, 2008 4:45 pm
Re: Call EventGhost macros and functions from a Python script
A little example:
Have a look at Wiki: http://www.eventghost.org/wiki/Scripting
Tip: Create a Macro/Action, copy it (Strg-c) and paste (Strg-v) it into the script editor. This should help you to find out how to use EG-Actions in scripts.
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1486">
<Macro Name="<Unbenanntes Makro>" Expanded="True">
<Action>
EventGhost.PythonScript(u'eg.globals.whatever = "Just a simple test"\n')
</Action>
<Action>
EventGhost.PythonScript(u'eg.plugins.EventGhost.ShowOSD(u\'{eg.globals.whatever}\', u\'0;-32;0;0;0;700;0;0;0;0;3;2;1;34;Arial\', (0, 202, 0), (0, 0, 0), 4, (0, 0), 0, 3.0, False)\neg.plugins.EventGhost.Wait(2.0)\neg.TriggerEvent("MyEvent")\n')
</Action>
</Macro>
</EventGhost>
Tip: Create a Macro/Action, copy it (Strg-c) and paste (Strg-v) it into the script editor. This should help you to find out how to use EG-Actions in scripts.
-
- Posts: 15
- Joined: Fri Sep 26, 2008 4:45 pm
Re: Call EventGhost macros and functions from a Python script
Thanks for your helpful response. I understand your answer to my second question but my first question remains unresolved - If I create an EventGhost macro named XYZ, how do I just call/execute XYZ from a Phython script in another macro in the same xml file without replicating the contents of XYZ?
Thanks
Thanks
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: Call EventGhost macros and functions from a Python script
1) You can use Action "Jump" with (or without) option "and return after execution"
2) Try this example (Script 1 must be called as the first):Pako
2) Try this example (Script 1 must be called as the first):
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1486">
<Folder Name="TEST 2 scripts" Expanded="True">
<Macro Name="Python Script 1" Expanded="True">
<Action>
EventGhost.PythonScript(u"def myScript(txt):\n print txt\neg.globals.myProcedure=myScript\n#test:\neg.globals.myProcedure('Text 1')")
</Action>
</Macro>
<Macro Name="Python Script 2" Expanded="True">
<Action>
EventGhost.PythonScript(u"eg.globals.myProcedure('Text 2')")
</Action>
</Macro>
</Folder>
</EventGhost>
-
- Posts: 15
- Joined: Fri Sep 26, 2008 4:45 pm
Re: Call EventGhost macros and functions from a Python script
Pako,
Thank you that helps a little but what I want to do would be like this with your example:
<Folder Name="TEST 2 scripts" Expanded="True"><Macro Name="Python Script 1" Expanded="True"><Action>EventGhost.PythonScript(u"def myScript(txt):\n print txt\neg.globals.myProcedure=myScript\n#test:\neg.globals.myProcedure('Text 1')")</Action></Macro><Macro Name="Python Script 2" Expanded="True"><Action>EventGhost.PythonScript(u'eg.EventGhost.Macro."Python Script 1"')</Action></Macro></Folder></EventGhost>
Here all I want is to repeat execution of macro "Python Script 1" by a call from the macro "Python Script 2" but this and other permutations do not compile.
Thanks
Peter
Thank you that helps a little but what I want to do would be like this with your example:
<Folder Name="TEST 2 scripts" Expanded="True"><Macro Name="Python Script 1" Expanded="True"><Action>EventGhost.PythonScript(u"def myScript(txt):\n print txt\neg.globals.myProcedure=myScript\n#test:\neg.globals.myProcedure('Text 1')")</Action></Macro><Macro Name="Python Script 2" Expanded="True"><Action>EventGhost.PythonScript(u'eg.EventGhost.Macro."Python Script 1"')</Action></Macro></Folder></EventGhost>
Here all I want is to repeat execution of macro "Python Script 1" by a call from the macro "Python Script 2" but this and other permutations do not compile.
Thanks
Peter