eg.TriggerEvent Help needed please

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
User avatar
kgschlosser
Site Admin
Posts: 4034
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: eg.TriggerEvent Help needed please

Post by kgschlosser » Fri May 12, 2017 12:43 pm

Ok so in the actual dialog. I get ya. The payload couldn't be done because of the dynamic nature of it. And it would also slow down event generation due to the excessive searching. But the new event dialog I do agree. We have been working on a better event dialog and plugin devs can list all of the events that their plugin can generate along with a nice description of the event. I have been working on dynamically adding events to this as well. The thing is it has become a project that has grown. Because right now EG revolves around wx.TreeItems and no specific Main container so to speak. And with Events being the core of everything I have been making an event the core container. It holds all of the macros it runs. As well as the last payload data and last time it ran. Also it runs in its own thread. I have a working version of this. It's still a little rough so maybe in EG 0.6. It's been very difficult to make this work. Because it is 100% backwards compatable with plugins. None of the EG API changes which was extremely difficult. So your idea of putting separate fields for prefix and suffix is a great idea. And will most likely end up being used. But it could be upwards of a year or so out.
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 » Sun May 14, 2017 5:30 pm

Thanks for the explanation on how this works kg! I'll just remember to insert "Main." as the prefix to my events from now on and remove this prefix when triggering the event. Now please don't go changing it again in 0.6!! :lol:

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

Re: eg.TriggerEvent Help needed please

Post by kgschlosser » Mon May 15, 2017 12:42 pm

I didn't change it. That was done before I was helping with the code. And in my opinion it is a bug. So I will take a look see at the original code and see what has been changed. And if I can fix it. I will.
If you like the work I have been doing then feel free to Image

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

Re: eg.TriggerEvent Help needed please

Post by kgschlosser » Mon May 15, 2017 12:56 pm

But with you I want you to start supplying prefix's to any event you are triggering yourself. And structure the event identical to your tree hiarchy for where the event is going to. Meaning I have a folder called TV I. There I have folders for the manufacturer so call one of the folders Samsung. Now I have multiple Samsung TVs so you can either use the room it's in or the model. I chose to use the model. So next folder is UN55D8000 then the subfolder for button category so Power and then the off and on macros.

So you have

TV/Samsung/UN55D8000/Power/On

Swap out the / for a . And you have the event to use for triggering the tv to turn on. Now since I am not dependant on a payload. I will put in the payload the structure for where the event originated from. This makes it really simple to track events.

So when triggering events use the prefix='prefix', suffix='suffix', payload='payload'

This makes it really simple to read. You will understand this more later on down The road when you have to change an old script you wrote. Or even when asking someone for help. It helps them when they are reading it.
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 » Mon May 15, 2017 8:51 pm

kgschlosser wrote:So you have

TV/Samsung/UN55D8000/Power/On

Swap out the / for a . And you have the event to use for triggering the tv to turn on. Now since I am not dependant on a payload. I will put in the payload the structure for where the event originated from. This makes it really simple to track events.

So when triggering events use the prefix='prefix', suffix='suffix', payload='payload'

This makes it really simple to read. You will understand this more later on down The road when you have to change an old script you wrote. Or even when asking someone for help. It helps them when they are reading it.
Whoa!! Wait a minute! You mean the "." represents nested folder structures? :o Or is it just my wishful thinking that is making me jump the gun again? Lol. That would be very easy to remember if that is what you meant.

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

Re: eg.TriggerEvent Help needed please

Post by kgschlosser » Tue May 16, 2017 6:28 am

ok since Jump was not able to be used in the past from code. i would trigger events in order to get other macros to run.

so what i would do is the event name would be the same as the folder structure i used. they don't correlate in any way for the purposes of EG. it was for my own identification of where to find the macro that had that event in it. and the payload i would set to where the event was triggered from.



I only did this so i could trace things that were happening. so as an example

say this is my tree layout

Code: Select all


parent_folder--
    child_folder--
        grandchild_folder--
            macro--
                event
                pythonscript eg.TriggerEvent(prefix='friend_folder', suffix='friend_macro', payload='parent_folder/child_folder/grandchild_folder/macro')

friend_folder--
    friend_macro
        event ('friend_folder.friend_macro')
        action
so in the example above some event comes in that runs macro. in the python script there is an eg.TriggerEvent that is used to run friend_macro.
so what i do is i set the prefix and suffix accordingly so that when the event runs it will have the same names that i used for the location of the macro that is going to be run. and the payload i set to be the same names of where the macro that caused the event to be triggered is located)

I did this because my tree has many thousands of items. and trying to hunt things down really sucked. and the issue with using a Jump is that at the time it could not be run from a python script. but also it would tell you where it was jumping to. but if you went to that location there was no identifier as to where a jump was coming from. the use of triggerevent solved this problem for me. because when the event got triggered it would have the location of the running python script informing me where that macro was located.


if you want i can make up a simple tree which you can load and that might help you understand a little better.
If you like the work I have been doing then feel free to Image

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

Re: eg.TriggerEvent Help needed please

Post by kgschlosser » Tue May 16, 2017 6:36 am

here i made up a simple little example it will run when EG starts.
but you can look at the event and also look at the way i did my naming convention
Attachments
naming_example.egtree
(1.54 KiB) Downloaded 87 times
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 » Fri Sep 01, 2017 6:31 pm

Shame on me! Sorry for missing these replies kg! Thanks a million for taking the time to share your example with me.

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

Re: eg.TriggerEvent Help needed please

Post by kgschlosser » Fri Sep 01, 2017 8:19 pm

uh huh. it's ok i am used to it.
If you like the work I have been doing then feel free to Image

User avatar
Luca Brasi
Experienced User
Posts: 262
Joined: Sat Oct 11, 2008 12:39 pm

Re: eg.TriggerEvent Help needed please

Post by Luca Brasi » Sun Sep 17, 2017 9:38 am

Hi,

after using TriggerEvent as you described above I noticed recently that the plugin for that has changed (I'm on 5 RC4). It has this delay setting now.
And if I copy it with python I will get

Code: Select all

eg.plugins.EventGhost.TriggerEvent(u'ThisistheString', 0.0)
How does the above logic fit into that?
I tried...

Code: Select all

eg.plugins.EventGhost.TriggerEvent('prefixtext', 'suffixtext', 'payloadtext', 0.0)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: __call__() takes at most 3 arguments (5 given)
Win10 x64 Prof. / Eventghost latest / MCE Plugin / MCE RC6 Receiver / Logitech Harmony Hub / MediaPortal / kodi

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

Re: eg.TriggerEvent Help needed please

Post by kgschlosser » Sun Sep 17, 2017 2:46 pm

that is because the eg.plugins.Eventghost.TriggerEvent is not the same as eg.TriggerEvent. the first is a plugin which does not have concessions for a prefix or payload but instead allows you to set an optional timer.
If you like the work I have been doing then feel free to Image

User avatar
Luca Brasi
Experienced User
Posts: 262
Joined: Sat Oct 11, 2008 12:39 pm

Re: eg.TriggerEvent Help needed please

Post by Luca Brasi » Sun Sep 17, 2017 3:17 pm

Ok, thanks for clearing that up.
Win10 x64 Prof. / Eventghost latest / MCE Plugin / MCE RC6 Receiver / Logitech Harmony Hub / MediaPortal / kodi

Post Reply