Jump if double event with else statement?

If you have a question or need help, this is the place to be.
Post Reply
jachin99
Experienced User
Posts: 646
Joined: Sat Feb 13, 2016 8:39 pm

Jump if double event with else statement?

Post by jachin99 » Sun May 24, 2020 3:52 pm

I would like to tell eventghost to perform a given action if an event occurs twice within a given period of time. I can already do this via the jump if double event plugin however, I would like to perform a different action if my same event only occurs once within the same time period. I plan to use this for a few remote key presses but I'm not sure if a plugin already exists that can accomplish this, or how I would go about scripting it. Thanks.

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

Re: Jump if double event with else statement?

Post by kgschlosser » Mon May 25, 2020 10:03 pm

Code: Select all

# how long you want to wait until the second event comes in.
wait_time = 1.0

def do():
    # event you are going to trigger if only a single event came in
    # you will then run whatever actions you need to have run from this event
    eg.TriggerEvent(prefix='run.some', suffix='other.task')
    eg.globals.task = None

task = getattr(eg.globals, 'task', None)
if task is not None:
    eg.Scheduler.CancelTask(task)
    eg.globals.task = None
else:
    # since this is the first time around for the event we want to start the timer
    # and stop the rest of the macro from running and exit the script.
    eg.globals.task = eg.Scheduler.AddShortTask(wait_time, do)
    eg.StopMacro()
    eg.Exit()


# place any actions you want to have run if the event comes in 2 times after this script.
If you like the work I have been doing then feel free to Image

jachin99
Experienced User
Posts: 646
Joined: Sat Feb 13, 2016 8:39 pm

Re: Jump if double event with else statement?

Post by jachin99 » Tue May 26, 2020 2:59 am

Alright, here is my first shot at filling things in. I'm not sure if I filled out the prefix, and suffix just right but I'm trying to call a specific action from a plugin, and not a macro like the current jump if double event. If I need to create a macro to jump to then thats fine also but I want to make sure I call it correctly. I want skip back .7 seconds if pressed once, and if my button is pressed twice, I want to rewind normally. Thanks. I'll keep trying this also to see if I can figure it out on my own.

Code: Select all

# how long you want to wait until the second event comes in.
wait_time = .75

def do():
    # event you are going to trigger if only a single event came in
    # you will then run whatever actions you need to have run from this event
    eg.TriggerEvent(prefix='eg.plugins', suffix='XBMC2.Seek(-07)')
    eg.globals.task = None

task = getattr(eg.globals, 'task', None)
if task is not None:
    eg.Scheduler.CancelTask(task)
    eg.globals.task = None
else:
    # since this is the first time around for the event we want to start the timer
    # and stop the rest of the macro from running and exit the script.
    eg.globals.task = eg.Scheduler.AddShortTask(wait_time, do)
    eg.StopMacro()
    eg.Exit()
    eg.plugins.XBMC2.Rewind()
    

# place any actions you want to have run if the event comes in 2 times after this script.
I get this error when I run the script above
23:04:10 TypeError: unbound method AddShortTask() must be called with Scheduler instance as first argument (got float instance instead)

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

Re: Jump if double event with else statement?

Post by kgschlosser » Tue May 26, 2020 4:54 pm

ooopsie my bad..



it's eg.scheduler not eg.Scheduler.

also this statement is never going to run

Code: Select all

    eg.plugins.XBMC2.Rewind()
If you like the work I have been doing then feel free to Image

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

Re: Jump if double event with else statement?

Post by kgschlosser » Tue May 26, 2020 5:00 pm

This is how the script is intended to work.


if the event comes in the script will run. If there is no scheduled task then that means that this is the first time within the .7 seconds an event has come in. So it will make the timer and then exit the macro and exit the script. If the scheduled time on the timer expires it will trigger the event and reset everything to start from the beginning again.

So if a second event comes in within that 0.7 seconds it is going to cancel the running timer and then it will allow the maco to continue running as normal. so any actions you want to have run if there are 2 events you wil add them as usual after the python script. any actions you want to have run if only a single event takes place you want to put those in they own macro and put the event in that that happens when the timer expires.


the eg.StopMacro() you see in the script does what it says. It stops the macro from running. the eg.Exit() does exactly what it states. it exists the script right then and there. nothing after it is going to run.
If you like the work I have been doing then feel free to Image

jachin99
Experienced User
Posts: 646
Joined: Sat Feb 13, 2016 8:39 pm

Re: Jump if double event with else statement?

Post by jachin99 » Wed May 27, 2020 3:58 pm

Alright, I'm not getting any errors now but I don't understand the e.TriggerEvent statement because I haven't worked with prefix or suffix. I'm not entirely sure how to fill these out so you might have to bear with me a little here. The macro I want to fire on single presses looks like this in the log

Code: Select all

Replay
   XBMC2: SmallStepBack
This is what I have built so far for my script, which doesn't throw any errors but it doesn't look like it will work either.

Code: Select all

# how long you want to wait until the second event comes in.
wait_time = 1.0

def do():
    # event you are going to trigger if only a single event came in
    # you will then run whatever actions you need to have run from this event
    eg.TriggerEvent(prefix='', suffix='Replay')
    eg.globals.task = None

task = getattr(eg.globals, 'task', None)
if task is not None:
    eg.scheduler.CancelTask(task)
    eg.globals.task = None
else:
    # since this is the first time around for the event we want to start the timer
    # and stop the rest of the macro from running and exit the script.
    eg.plugins.XBMC2.Rewind()
    eg.globals.task = eg.scheduler.AddShortTask(wait_time, do)
    eg.StopMacro()
    eg.Exit()


# place any actions you want to have run if the event comes in 2 times after this script.

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

Re: Jump if double event with else statement?

Post by kgschlosser » Wed May 27, 2020 10:00 pm

an event is broken down into 2 sections a prefix and a suffix.

the prefix is typically say a plugin name and the suffix is any additional information to be added to the event string.
So when you get an event in the log for changing the volume on your PC you get
System.Volume

where System is the plugin name and Volume is what has changed.

eg.TriggerEvent(prefix='System', suffix='Volume')

if you wanted to you could do this
eg.TriggerEvent('Volume')
but the event that is going to appear is going to be

Main.Volume


I will make you an example you can paste into EG and run to see how it works.
If you like the work I have been doing then feel free to Image

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

Re: Jump if double event with else statement?

Post by kgschlosser » Wed May 27, 2020 10:12 pm

Here is the example code. copy the code below and paste it directly into your tree in EG. you can do this by right clicking on the pc icon at the top of your tree and clicking on paste.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc6">
    <Folder Name="Example" XML_Guid="{2AE115E5-4C79-450A-B9E7-027A0486B4EF}" Expanded="True">
        <Macro Name="runs with event Main.Event1" XML_Guid="{B3AF2A40-7C2C-49A9-B392-4F4CE30F38DB}" Expanded="True">
            <Event Name="Main.Event1" XML_Guid="{FEADFD07-6F45-459E-B993-37BC85C7DA3C}" />
            <Action XML_Guid="{9D06DD38-5E3D-4D07-BDAA-E9267AF44E4A}">
                EventGhost.PythonScript(u"# how long you want to wait until the second event comes in.\nwait_time = 1.0\n\ndef do():\n    # event you are going to trigger if only a single event came in\n    # you will then run whatever actions you need to have run from this event\n    eg.TriggerEvent('Event2')\n    eg.globals.task = None\n\ntask = getattr(eg.globals, 'task', None)\nif task is not None:\n    eg.scheduler.CancelTask(task)\n    eg.globals.task = None\nelse:\n    # since this is the first time around for the event we want to start the timer\n    # and stop the rest of the macro from running and exit the script.\n    eg.globals.task = eg.scheduler.AddShortTask(wait_time, do)\n    eg.StopMacro()\n    eg.Exit()\n\n\n# place any actions you want to have run if the event comes in 2 times after this script.")
            </Action>
            <Action XML_Guid="{AF1563F9-DECE-4D70-9E26-E8E232F50452}">
                EventGhost.ShowOSD(u'Double Event', u'0;-96;0;0;0;700;0;0;0;0;3;2;1;34;Arial', (58, 252, 24), (0, 0, 0), 4, (0, 0), 0, 3.0, None)
            </Action>
        </Macro>
        <Macro Name="runs with Main.Event2" XML_Guid="{EF61DE6B-1AD0-4110-81B5-E5DBB640F778}" Expanded="True">
            <Event Name="Main.Event2" XML_Guid="{69CE3F91-A2A1-4BD2-8689-3114FEB54CDF}" />
            <Action XML_Guid="{AF1563F9-DECE-4D70-9E26-E8E232F50452}">
                EventGhost.ShowOSD(u'Single Event', u'0;-96;0;0;0;700;0;0;0;0;3;2;1;34;Arial', (58, 252, 24), (0, 0, 0), 4, (0, 0), 0, 3.0, None)
            </Action>
        </Macro>
        <Macro Name="RUN TESTS" XML_Guid="{A735297C-3C03-4ADF-AF79-09DAD07DF4E3}" Expanded="True">
            <Action Name="Single Event" XML_Guid="{7E719766-6285-4181-8933-324BCB6AC665}">
                EventGhost.PythonScript(u"eg.TriggerEvent('Event1')")
            </Action>
            <Action Name="Double Event" XML_Guid="{BDA29791-2A16-4F3E-BD10-A3FC4FCC5DE0}">
                EventGhost.PythonScript(u"eg.TriggerEvent('Event1')\neg.TriggerEvent('Event1')")
            </Action>
        </Macro>
    </Folder>
</EventGhost>

it is going to create a folder in your tree called Example. in that folder you will find a macro called RUN TESTS. in that macro are going to be 2 scripts. run the first script and wait. you will get an OSD that is going to pop up. then sun the second script and you will see a completely different OSD pop up.
If you like the work I have been doing then feel free to Image

jachin99
Experienced User
Posts: 646
Joined: Sat Feb 13, 2016 8:39 pm

Re: Jump if double event with else statement?

Post by jachin99 » Sun May 31, 2020 12:20 am

Kevin, it looks like that XML folder you gave me will work great. It also kind of gave me a new look at how to solve problems but I'm still trying to wrap my head around exactly how it works.

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

Re: Jump if double event with else statement?

Post by kgschlosser » Sun May 31, 2020 3:44 am

LOL OK no worries. Let me try and explain it a different way. I think I am going to resory to drawing some pictures as It will be easier to do.
If you like the work I have been doing then feel free to Image

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

Re: Jump if double event with else statement?

Post by kgschlosser » Sun May 31, 2020 4:03 am

i sent you a PM
If you like the work I have been doing then feel free to Image

Post Reply