Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

[SOLVED] Possibility to listen to events within a plugin?

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

[SOLVED] Possibility to listen to events within a plugin?

Post by Sem;colon »

Hello,

What IÔÇÖm trying to do is to listen for some specific events in the EventGhost log and trigger actions, just like the default macros in EventGhost but from within a plugin.

Does anyone know if thatÔÇÖs possible and how to do it?

Thank you!
Last edited by Sem;colon on Thu Aug 07, 2014 9:38 pm, edited 3 times in total.
If you like my work, Image me a drink :wink:
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Possibility to listen to events within a plugin?

Post by Pako »

Sem;colon wrote:Does anyone know if thatÔÇÖs possible and how to do it?
Yes, it is of course possible.
You can look for example at MediaPlayerClassic plugin, how it's done.
Search for keywords eg.Bind and eg.Unbind.
Pay particular attention to the return value of "True" !

Pako
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Possibility to listen to events within a plugin?

Post by Sem;colon »

I see, thank you!

How would I do it if I want to use wildcards?

something like:
eg.Bind("Process.Created.*", myFunction)
?
If you like my work, Image me a drink :wink:
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Possibility to listen to events within a plugin?

Post by Pako »

Sem;colon wrote:How would I do it if I want to use wildcards?
This should work as you do in your example.
But be careful, do not forget, that the wildcard can only be used as a prefix or as a second suffix (as you do in your example).

Pako
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Possibility to listen to events within a plugin?

Post by Sem;colon »

Pako wrote:This should work as you do in your example.
Are you sure? Because this example didn't work for me as I tried it...
If you like my work, Image me a drink :wink:
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Possibility to listen to events within a plugin?

Post by Pako »

Sem;colon wrote:Are you sure? Because this example didn't work for me as I tried it...
I'm sorry, you're right. It can not work.
See EventGhostEvent.py, lines 124-127.

Pako
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Possibility to listen to events within a plugin?

Post by Sem;colon »

hmm, any Idea how I can accomplish that?
If you like my work, Image me a drink :wink:
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Possibility to listen to events within a plugin?

Post by Pako »

At the moment I have no idea.
You can refine your intentions?

Pako
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Possibility to listen to events within a plugin?

Post by Sem;colon »

Sure,

What I'm trying to do is to write a plugin that forwards events from one Eventghost to another one with the possibility to set a filter e.g. only events with a specific Prefix.

Pako, I guess you did something similar in the Log redirector, right?
I was trying to find how you did it, but it's really hard to find if you don't know exactly what you are looking for..
If you like my work, Image me a drink :wink:
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Possibility to listen to events within a plugin?

Post by Pako »

Sem;colon wrote:Pako, I guess you did something similar in the Log redirector, right?
Yes, it is may be the right direction.
Earlier it was done differently (I think LogRedirector), but when phlox did EventGhost Application Control Plugin, it had to be changed.
The key word is eg.log.AddLogListener and the function, that you need is a WriteLine.
I think it will be good to read topic EventGhost Application Control Plugin.

Pako
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Possibility to listen to events within a plugin?

Post by Sem;colon »

That works!
thank you very much! :)
If you like my work, Image me a drink :wink:
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: [SOLVED] Possibility to listen to events within a plugin

Post by Sem;colon »

... I have to recall the SOLVED, as I noticed that it's sill not doing what I want it to.

I can get now the "event" like it is displayed in the log but I can't really work with the payload as comes as string along with the other parts of the event.
So at the moment I can only forward the event string, that's not what I wanted..

Anyway, I took a look at the Log class in EventGhost and realised that this is not very difficult to get when just extending that class a bit.
I attached a modified version of that class where I added an "eventListener" in addition to the "logListener".

This could probably be useful to others as well!
Attachments
Log.py
(8.52 KiB) Downloaded 175 times
Last edited by Sem;colon on Fri Aug 08, 2014 4:55 pm, edited 1 time in total.
If you like my work, Image me a drink :wink:
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: [SOLVED] Possibility to listen to events within a plugin

Post by Pako »

Sem;colon wrote:I attached a modified version ...
It appears that the original version is attached.

Pako
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: [SOLVED] Possibility to listen to events within a plugin

Post by Sem;colon »

You're right, looks like a uploaded the wrong file - I corrected it!
If you like my work, Image me a drink :wink:
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: [SOLVED] Possibility to listen to events within a plugin

Post by Pako »

Hi Sem;colon !
I looked at your solution. I have to admit, I do not get it.
How should it work?
To me it seems that the payload you get exactly the same way as before.

BTW:
Yesterday I was on a family outing. We went early and came back late.
We were in Dresden. We do not have it too far (about 110 Km).

Pako
Post Reply