Call EventGhost macros and functions from a Python script

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
peterlloyd
Posts: 15
Joined: Fri Sep 26, 2008 4:45 pm

Call EventGhost macros and functions from a Python script

Post by peterlloyd » Tue Nov 25, 2008 6:43 pm

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?

User avatar
topix
Experienced User
Posts: 441
Joined: Sat May 05, 2007 3:43 pm
Location: Germany
Contact:

Re: Call EventGhost macros and functions from a Python script

Post by topix » Wed Nov 26, 2008 7:44 pm

A little example:

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>
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.

peterlloyd
Posts: 15
Joined: Fri Sep 26, 2008 4:45 pm

Re: Call EventGhost macros and functions from a Python script

Post by peterlloyd » Thu Nov 27, 2008 8:21 pm

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

User avatar
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

Post by Pako » Thu Nov 27, 2008 8:55 pm

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):

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>
Pako

peterlloyd
Posts: 15
Joined: Fri Sep 26, 2008 4:45 pm

Re: Call EventGhost macros and functions from a Python script

Post by peterlloyd » Mon Dec 01, 2008 3:38 am

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

Post Reply