eg.TriggerEvent Help needed please

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
loveleejohn
Experienced User
Posts: 124
Joined: Thu Dec 10, 2015 12:09 am

eg.TriggerEvent Help needed please

Post by loveleejohn » Tue May 09, 2017 9:03 pm

Hi everyone. eg.TriggerEvent is firing my custom made events in the log but the associated subsequent events in the macro are not firing for some odd reason. Any ideas what could be wrong?
Windows 10
eg.0.5

For example, I have the following python script in the first macro.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc2">
    <Action XML_Guid="{F638F799-3DF6-4B0C-A075-24BFF189E310}">
        EventGhost.PythonScript(u"eg.scheduler.AddTask(3, eg.TriggerEvent, 'startweathernow-pt2')")
    </Action>
</EventGhost>
And I am correctly seeing an event in the log titled Main.startweathernow-pt2

However, after the event appears in the log, no further actions are occurring. Any hints?

User avatar
kgschlosser
Site Admin
Posts: 4204
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: eg.TriggerEvent Help needed please

Post by kgschlosser » Tue May 09, 2017 11:31 pm

need a better breakdown. of what is suppose to happen.
you are saying that you are seeing the event in the log. then the xml data you posted is functioning properly. because the event is getting triggered. now if you have not associated that event to something then all it is going to do is show the event.
If you like the work I have been doing then feel free to Image

loveleejohn
Experienced User
Posts: 124
Joined: Thu Dec 10, 2015 12:09 am

Re: eg.TriggerEvent Help needed please

Post by loveleejohn » Wed May 10, 2017 1:13 am

kgschlosser wrote:need a better breakdown. of what is suppose to happen.
you are saying that you are seeing the event in the log. then the xml data you posted is functioning properly. because the event is getting triggered. now if you have not associated that event to something then all it is going to do is show the event.
Sorry for the lack of clarity kg.

Here's the first macro:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc2">
    <Macro Name="Weather-initializer" XML_Guid="{C308BF87-29F6-480D-BC5F-04303ACCFF53}" Expanded="True">
        <Event Name="weatheron-Pt1" XML_Guid="{43049A2E-8845-4930-BB8D-DD81E612B809}" />
        <Action XML_Guid="{F638F799-3DF6-4B0C-A075-24BFF189E310}">
            EventGhost.PythonScript(u"eg.scheduler.AddTask(1, eg.TriggerEvent, 'startweathernow-pt2')")
        </Action>
    </Macro>
</EventGhost>


And here's the second macro that is supposed to be triggered by the previous macro.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc2">
    <Macro Name="Weather-part two" XML_Guid="{0ABC445F-1F3D-48B9-B089-921EE887AB9E}" Expanded="True">
        <Event Name="startweathernow-pt2" XML_Guid="{DD4B4B48-E9D4-474C-AAE5-3CCEA54A7A7F}" />
        <Action XML_Guid="{F638F799-3DF6-4B0C-A075-24BFF189E310}">
            EventGhost.PythonScript(u'print "Success"')
        </Action>
    </Macro>
</EventGhost>


The problem is that the event for the second macro is clearly appearing in the log as Main.startweathernow-pt2 but nothing is being printed in the log area. This just started happening today by the way. I have not made any major changes in the program that I can recall. :?

User avatar
kgschlosser
Site Admin
Posts: 4204
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: eg.TriggerEvent Help needed please

Post by kgschlosser » Wed May 10, 2017 4:40 am

well i am going to ask you a question.. and lets see if you can figure it out.


what is the event that is being triggered?
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4204
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: eg.TriggerEvent Help needed please

Post by kgschlosser » Wed May 10, 2017 4:41 am

and don't leave to big a red mark on your forehead
If you like the work I have been doing then feel free to Image

loveleejohn
Experienced User
Posts: 124
Joined: Thu Dec 10, 2015 12:09 am

Re: eg.TriggerEvent Help needed please

Post by loveleejohn » Wed May 10, 2017 11:36 am

kgschlosser wrote:well i am going to ask you a question.. and lets see if you can figure it out.


what is the event that is being triggered?
Well I thought it was the event that is named "startweathernow-pt2" isn't it? And I thought that this event would be followed by the python script that prints "success" since it is is the second macro. Am I way off in left field again? Lol. If I am it would be very confusing since I have a very extensive script that worked like this in the previous version of Eventghost.

loveleejohn
Experienced User
Posts: 124
Joined: Thu Dec 10, 2015 12:09 am

Re: eg.TriggerEvent Help needed please

Post by loveleejohn » Wed May 10, 2017 12:34 pm

Taking this one step further, I tried this with a Jump action and it worked as expected and triggered the second macro which then printed "Success" in the log. Still not sure why the pyhton script is not triggering the second action. :(

loveleejohn
Experienced User
Posts: 124
Joined: Thu Dec 10, 2015 12:09 am

Re: eg.TriggerEvent Help needed please

Post by loveleejohn » Wed May 10, 2017 12:37 pm

So I've tried grabbing the python code for the jump action to try to decipher what was happening but it seems that the jump action uses xml ids to jump which is an entirely different beasts... While the jump action can be used as a workaround, that would not really explain what's going wrong so back to the drawing board or the head banging board for that matter. lolz...

loveleejohn
Experienced User
Posts: 124
Joined: Thu Dec 10, 2015 12:09 am

Re: eg.TriggerEvent Help needed please

Post by loveleejohn » Wed May 10, 2017 12:48 pm

Ok.... I need a flamethrower and a ton of gasoline! I think I've figured out the difference now... In the previous version of eventghost I could not name an event with "Main." as a prefix because when I went to trigger the event, eventghost would automagically add an additional "Main." prefix so the log would show "Main.Main.nameofmyevent". To avoid this all of my events had simple names with no prefix and everything worked as expected. In 0.5rc it seems that this behavior has changed and one now has to name the event with a prefix of "Main." when the event is created but I am now curious as to how this prefix might affect the phython script because I do not have the "Main." prefix in the script... Let's see.

loveleejohn
Experienced User
Posts: 124
Joined: Thu Dec 10, 2015 12:09 am

Re: eg.TriggerEvent Help needed please

Post by loveleejohn » Wed May 10, 2017 12:53 pm

Hmmm... either I've stumbled onto a bug or perhaps the more likely explanation is that I have no idea what I am doing.... :lol: One way or the other, here's what I've observed... When I add a prefix of "Main." in the python script, eventghost attempts to fire an event called "Main.Main.myeventname" as can be seen in the log. This occurs when my event is named "Main.nameofmyevent" and also when my event is named "nameofmyevent". Could this possibly be a bug or perhaps there is a sophisticated graduate level reason for this behavior. Lol. Regardless, for newbs like me, keep this in mind as you try to write a python script that triggers an event until we hear back from the mavericks. :)

User avatar
yokel22
Experienced User
Posts: 251
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: eg.TriggerEvent Help needed please

Post by yokel22 » Wed May 10, 2017 2:29 pm

Okay, you seem to have figured out what kg was alluding to. The event your triggering is "Main.startweathernow-pt2", this is because of how the "trigger event" action applies the prefix "Main". The event you want to trigger your macro is "startweathernow-pt2", clearly not a match. The easiest way to avoid these kinds of errors is to trigger the event, then drag it onto your macro.

To override the suffix of "Main", you can do the same trigger event with this python script.

Code: Select all

import time

# wait time until you want event to be triggered, in seconds. 
time.sleep(5)

# trigger event
eg.TriggerEvent(prefix="startweathernow", suffix="pt2", payload=None) 
Or a better way.

Code: Select all

# time in seconds
sec = 5.0

# function to trigger event
def event ():
 eg.TriggerEvent(prefix="startweathernow", suffix="pt2", payload=None) 

# Schedule event for time set
eg.scheduler.AddTask(sec, event)
I kinda think the triggerevent action should be setup with prefix & payload overrides to avoid confusion amongst newbies.
Last edited by yokel22 on Wed May 10, 2017 8:00 pm, edited 1 time in total.

loveleejohn
Experienced User
Posts: 124
Joined: Thu Dec 10, 2015 12:09 am

Re: eg.TriggerEvent Help needed please

Post by loveleejohn » Wed May 10, 2017 4:11 pm

yokel22 wrote:Okay, you seem to have figured out what kg was alluding to. The event your triggering is "Main.startweathernow-pt2", this is because of how the "trigger event" action applies the prefix "Main". The event you want to trigger your macro is "startweathernow-pt2", clearly not a match. The easiest way to avoid these kinds of errors is to trigger the event, then drag it onto your macro.

To override the suffix of "Main", you can do the same trigger event with this python script.

Code: Select all

import time

# wait time until you want event to be triggered, in seconds. 
time.sleep(5)

# trigger event
eg.TriggerEvent(prefix="startweathernow", suffix="pt2", payload="NA") 
I kinda think the triggerevent action should be setup with prefix & payload overrides to avoid confusion amongst newbies.
Hey there yokel22! Thanks for the feedback. I especially agree with the last sentence of your comment. Hopefully this might make it to the next release. That said, this issue seems to be more than just a matter of not adding Main as a prefix to the Macro since this was not needed in the previous version in a very extensive sequence of macros that I had built in the 0.4.1r1722 version. In that version all of my macros had trigger events that did not start with the "Main." prefix and worked with no issue at all. In fact when I used the "Main." prefix in 0.4.1r1722 the log would show "Main.Main.nameofmyevent" and this was why I removed the "Main." prefix from all of my event triggers in that release. When I updated to the 0.5 release the macros stopped working and that's what prompted me to begin this thread. So I guess what I am saying is that the requirement of the prefix appears to be a new thing in 0.5 and since I had no idea of this, this is likely what caused my macros to stop working.

User avatar
kgschlosser
Site Admin
Posts: 4204
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: eg.TriggerEvent Help needed please

Post by kgschlosser » Thu May 11, 2017 12:46 am

ok brief rundown of why the behavior has changed.. this is due to the use of fnmatch case. which is used for wild carding events.

TriggerEvent has default values associated with it.

Code: Select all

TriggerEvent(suffix, prefix='Main', Payload=None)
either you can put the items in the same order which you see above..

Code: Select all

TriggerEvent('MySuffix', 'MyPrefix', 'MyPayload')
which i find less readable because of the order of them and the fact that not all of your events will be names like that.

so instead of using it in a positional manner. you can use keywords

Code: Select all

TriggerEvent(prefix='MyPrefix', suffix='MySuffix', payload='MyPayload')
I personally like the last method better. even tho it is a hell of a lot more typing. it's easier to read.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4204
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: eg.TriggerEvent Help needed please

Post by kgschlosser » Thu May 11, 2017 12:50 am

yokel22 wrote:I kinda think the triggerevent action should be setup with prefix & payload overrides to avoid confusion amongst newbies.
explain what you mean by this. Ya have me curious
If you like the work I have been doing then feel free to Image

User avatar
yokel22
Experienced User
Posts: 251
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: eg.TriggerEvent Help needed please

Post by yokel22 » Fri May 12, 2017 5:08 am

I just always thought it's be nice to give access to the other parameters of eg.Event. Meaning simple textCtrl inputs for event.prefix & event.payload. Maybe a placeholder of "Main" for the prefix, so it doesn't catch new folks of guard.

Post Reply