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.
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.
Parsing Events
Parsing Events
Hi,
I'm wondering if it is possible to do the following:
1) Receive an event from TCP, it shows up as TCP.<event name>
2) Take that received event and cut out portions of the string and then do a conditional jump to other actions.
What I am trying to do is receive a TCP event that has a channel number that I am using to change channels on a set top box via USBUIRT. When I send the event for channels greater than a single digit, I receive something like TCP.12 (This is what gets sent by the MediaPortal software). When I receive it in EventGhost, I need to be able to send to my Set Top Box the IR code for 1 and then for 2. I can either go and create 53 seperate events for my channels and create 53 different IR codes to be sent or take that TCP.12, parse out the 1 and jump to an action called 1 (which sends the 1 IR code) and then do the same for the 2 code.
Make sense? Possible?
Thanks.
I'm wondering if it is possible to do the following:
1) Receive an event from TCP, it shows up as TCP.<event name>
2) Take that received event and cut out portions of the string and then do a conditional jump to other actions.
What I am trying to do is receive a TCP event that has a channel number that I am using to change channels on a set top box via USBUIRT. When I send the event for channels greater than a single digit, I receive something like TCP.12 (This is what gets sent by the MediaPortal software). When I receive it in EventGhost, I need to be able to send to my Set Top Box the IR code for 1 and then for 2. I can either go and create 53 seperate events for my channels and create 53 different IR codes to be sent or take that TCP.12, parse out the 1 and jump to an action called 1 (which sends the 1 IR code) and then do the same for the 2 code.
Make sense? Possible?
Thanks.
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
With some scripting you can do nearly everything. 
Make a macro that gets triggered on all needed events. You can use a wildcard so you can name the event-item "TCP.*" to get every event from this plugin.
Next add a Python script like this:
This will generate events like "SendNumber0", "SendNumber1", ... for every digit in your event.
Make a macro that gets triggered on all needed events. You can use a wildcard so you can name the event-item "TCP.*" to get every event from this plugin.
Next add a Python script like this:
Code: Select all
# get the event
event = eg.EventString
parts = event.split(".")
value = parts[-1]
if value.isdigit():
# iterate over every digit
for digit in value:
# send an event for the digit
eg.TriggerEvent("SendNumber" + digit)Sweet,
That's exactly what I'm trying to do...I guess no is a good a time as any to pick up Python.
[EDIT] Is there documentation on what's available within EventGhost API to call from a Python script? For instance you have the eg.EventString to get the EventString. I'm assuming that this comes from the main EventGhost "class"
Thanks!
That's exactly what I'm trying to do...I guess no is a good a time as any to pick up Python.
[EDIT] Is there documentation on what's available within EventGhost API to call from a Python script? For instance you have the eg.EventString to get the EventString. I'm assuming that this comes from the main EventGhost "class"
Thanks!
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
No, and actually the next release will change many names and access-pathes to simplify the interface. I might write some wiki entry about the most important things, if the 0.3.1 is released.falkyre wrote:[EDIT] Is there documentation on what's available within EventGhost API to call from a Python script? For instance you have the eg.EventString to get the EventString. I'm assuming that this comes from the main EventGhost "class"
Thanks!
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
Thanks again for the script. I'm getting close to the final solution. I tried it out and am running into this problem.
I send the event into EventGhost. I see that it's received in the log window. It shows up TCP.101 ['127.0.0.1']. However, the scriupt does not get fired off. I have a macro that contains an event called TCP.* and then the script but it never automatically makes it there. If I high lite the macro where the script is and then press the execute button, it runs fine. But it doesn't run automatically. Am I doing something wrong?
Also, in the Python script, I'm trying to get output into the log window using eg.notice("some string") but it's not showing up. Is there something else I need to do?
Thanks!
I send the event into EventGhost. I see that it's received in the log window. It shows up TCP.101 ['127.0.0.1']. However, the scriupt does not get fired off. I have a macro that contains an event called TCP.* and then the script but it never automatically makes it there. If I high lite the macro where the script is and then press the execute button, it runs fine. But it doesn't run automatically. Am I doing something wrong?
Also, in the Python script, I'm trying to get output into the log window using eg.notice("some string") but it's not showing up. Is there something else I need to do?
Thanks!
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
Congratulation, you found another bug. 
I just tried it and I also found that EG has a problem with the TCP-plugin and wildcard-matching. Actually every plugin with additional data carried with the event like the ['127.0.0.1'] generates this problem. Will be fixed in 0.3.1. Currently you can only use full-qualified events or the wildcard "*" that matches every event from every plugin.
eg.notice() is for debugging purposes only, so its output is disabled when the debug-mode is disabled.
To get output to the logger simply use Python's builtin "print" statement, like:
I just tried it and I also found that EG has a problem with the TCP-plugin and wildcard-matching. Actually every plugin with additional data carried with the event like the ['127.0.0.1'] generates this problem. Will be fixed in 0.3.1. Currently you can only use full-qualified events or the wildcard "*" that matches every event from every plugin.
eg.notice() is for debugging purposes only, so its output is disabled when the debug-mode is disabled.
To get output to the logger simply use Python's builtin "print" statement, like:
Code: Select all
print eg.EventString- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
You don't need to download the source separatly, because every installer and updater already includes it.
It wouldn't make much sense to try to fix 0.3.0, as the source has changed to much on the way to 0.3.1.
You can try a pre-release of 0.3.1 I just uploaded:
[Link outdated]
But since I'm a bit in the middle of refactoring, you might encounter many other bugs.
As allways:
Make a backup of your XML before you update and place it at a safe place.
It wouldn't make much sense to try to fix 0.3.0, as the source has changed to much on the way to 0.3.1.
You can try a pre-release of 0.3.1 I just uploaded:
[Link outdated]
But since I'm a bit in the middle of refactoring, you might encounter many other bugs.
As allways:
Make a backup of your XML before you update and place it at a safe place.
Last edited by Bitmonster on Mon Jul 03, 2006 3:57 pm, edited 1 time in total.
Hiya!
I'm playing with the wildcards for the pre-release (I realize that's it a prerelease) and have come across something.
If I do TCP.*. it works fine. However, this captures all events with TCP. Is it possible to allow for the wildcard to be anywhere in a string. For instance, if I'm sending different groups of messages, I want to be able to do different things. Here's what I mean:
I receive TCP.Channel.*, then I know I want to send the IR codes for the changing channels as the example script you showed me previously. However, if I receive TCP.Guide, then I know that I want to send the Guide IR code.
Right now, I can only do TCP.* and it always get sent to the script. I suppose that I can add some extra scripting to handle these situations but it would be nice if the wildcard could be anywhere in the event string and match on that.
Sooo, any pointers where I could look in the code
for the wildcard handling?
Thanks!
[EDIT]
Ok, I've tried a few things and it looks like I can have both the TCP.Guide and TCP.* but the problem is that both get called (which I guess is not a problem as the script ignores the event message if it doesn't have digits in it anyways). Just adding some more input. I still think that being able to parse the string with the wildcard anywhere in the string would be valuable for someone that doesn't do a lot of scripting.
I'm playing with the wildcards for the pre-release (I realize that's it a prerelease) and have come across something.
If I do TCP.*. it works fine. However, this captures all events with TCP. Is it possible to allow for the wildcard to be anywhere in a string. For instance, if I'm sending different groups of messages, I want to be able to do different things. Here's what I mean:
I receive TCP.Channel.*, then I know I want to send the IR codes for the changing channels as the example script you showed me previously. However, if I receive TCP.Guide, then I know that I want to send the Guide IR code.
Right now, I can only do TCP.* and it always get sent to the script. I suppose that I can add some extra scripting to handle these situations but it would be nice if the wildcard could be anywhere in the event string and match on that.
Sooo, any pointers where I could look in the code
Thanks!
[EDIT]
Ok, I've tried a few things and it looks like I can have both the TCP.Guide and TCP.* but the problem is that both get called (which I guess is not a problem as the script ignores the event message if it doesn't have digits in it anyways). Just adding some more input. I still think that being able to parse the string with the wildcard anywhere in the string would be valuable for someone that doesn't do a lot of scripting.
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
This will currently not work, because EG is not 'comparing' every event in the tree with the current eventstring. It stores the tree-events in a dictionary and 'accesses' them more or less directly, because this is much faster.
You find the related code in eg/ActionThread.py (ActionThread.HandleEvent).
Currently you can just compare the eventstring in your script and do a quick exit, if it doesn't match.
It would be possible to add an additional special list of wildcarded events, that are compared all one by one. I will have to think about it...
You find the related code in eg/ActionThread.py (ActionThread.HandleEvent).
Currently you can just compare the eventstring in your script and do a quick exit, if it doesn't match.
It would be possible to add an additional special list of wildcarded events, that are compared all one by one. I will have to think about it...