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.
toggle a command (on/off)
toggle a command (on/off)
hi there,
i am new to EG, but i have been using girder for a number of years.
I have a simple question - i want an event to toggle between 2 different actions (on/off) every time i press it.
i have and macro with 2 actions in it (on/off) - in girder i used to assign an event to both of them and then use 'state' to tell whitch one of them sould be activated.
im sure the answer is somewere in the 'add action' window, but i cant find it. I have also tried google to no avail.
i hope somebody in here can send me in the right direction.
br
Brille
i am new to EG, but i have been using girder for a number of years.
I have a simple question - i want an event to toggle between 2 different actions (on/off) every time i press it.
i have and macro with 2 actions in it (on/off) - in girder i used to assign an event to both of them and then use 'state' to tell whitch one of them sould be activated.
im sure the answer is somewere in the 'add action' window, but i cant find it. I have also tried google to no avail.
i hope somebody in here can send me in the right direction.
br
Brille
Re: toggle a command (on/off)
What's stopping you from making the flip-flop logic yourself?
I used the keyboard plugin and F12 button as the event for testing, but you can change that to whatever you want. You can simply copy & paste the examples into EG.
A quick example using the enable exclusive action, this is probably the most useful (in most cases) and easiest way:
-jinxdone
I used the keyboard plugin and F12 button as the event for testing, but you can change that to whatever you want. You can simply copy & paste the examples into EG.
A quick example using the enable exclusive action, this is probably the most useful (in most cases) and easiest way:
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1194">
<Folder Name="myaction" Expanded="True">
<Macro Name="Show OSD: Hello" id="2586" Expanded="True">
<Event Name="Keyboard.F12" />
<Action>
EventGhost.ShowOSD(u'Hello', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 0, (0, 0), 0, 3.0, False)
</Action>
<Action>
EventGhost.EnableExclusive(XmlIdLink(2588))
</Action>
</Macro>
<Macro Name="Show OSD: World" id="2588" Enabled="False" Expanded="True">
<Event Name="Keyboard.F12" />
<Action Name="Show OSD: World">
EventGhost.ShowOSD(u'World', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 0, (0, 0), 0, 3.0, False)
</Action>
<Action>
EventGhost.EnableExclusive(XmlIdLink(2586))
</Action>
</Macro>
</Folder>
</EventGhost>Re: toggle a command (on/off)
Here's an example of some python commands that pretty much do the same thing as the other example but this time using the jump action. You can do a conditional jump based on the eg.result variable's value with the jump if last action successful / unsuccessful selection.
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1194">
<Folder Name="myaction2" Expanded="True">
<Macro Name="Show OSD: Hello" id="2607" Expanded="True">
<Action>
EventGhost.ShowOSD(u'Hello', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 0, (0, 0), 0, 3.0, False)
</Action>
<Action>
EventGhost.PythonCommand(u'mystate = False')
</Action>
</Macro>
<Macro Name="Show OSD: World" id="2611" Expanded="True">
<Action Name="Show OSD: World">
EventGhost.ShowOSD(u'World', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 0, (0, 0), 0, 3.0, False)
</Action>
<Action Name="mystate = True">
EventGhost.PythonCommand(u'mystate = True')
</Action>
</Macro>
<Macro Name="logic" Expanded="True">
<Event Name="Keyboard.F12" />
<Action>
EventGhost.PythonCommand(u'if mystate: eg.result = True')
</Action>
<Action>
EventGhost.NewJumpIf(XmlIdLink(2607), 0, False)
</Action>
<Action>
EventGhost.NewJumpIf(XmlIdLink(2611), 2, False)
</Action>
</Macro>
</Folder>
</EventGhost>Re: toggle a command (on/off)
Here's another example using a simple python script and the eg.TriggerEvent() python command. You could obviously make the logic script as complex as you wish even though this one is very simple.
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1194">
<Folder Name="myaction3" Expanded="True">
<Macro Name="Show OSD: Hello" Expanded="True">
<Event Name="Main.hello" />
<Action>
EventGhost.ShowOSD(u'Hello', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 0, (0, 0), 0, 3.0, False)
</Action>
<Action>
EventGhost.PythonCommand(u'mystate = False')
</Action>
</Macro>
<Macro Name="Show OSD: World" Expanded="True">
<Event Name="Main.world" />
<Action Name="Show OSD: World">
EventGhost.ShowOSD(u'World', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 0, (0, 0), 0, 3.0, False)
</Action>
<Action Name="mystate = True">
EventGhost.PythonCommand(u'mystate = True')
</Action>
</Macro>
<Macro Name="logic" Expanded="True">
<Action>
EventGhost.PythonScript(u"if eg.globals.mystate:\n eg.TriggerEvent('hello')\nelse:\n eg.TriggerEvent('world')")
</Action>
<Event Name="Keyboard.F12" />
</Macro>
</Folder>
</EventGhost>Re: toggle a command (on/off)
brille
There are not States/Variables that can be created using the GUI... wish it did.
So IF you must have persistent (cross session) states you will need to script and save a states in the config.
If you want to simply do a toggle without persistence you can do this in the GUI per my example On/Off toggle in the attached jpg. Basically it checkes to see if the window exists. It jumps out based on the answer or continues to the next jump (which could be replaced with the 2nd command)... I have bacially created an If/Then since EG does not have If/Then (unfortunately).
EG is a great tool though it is not the easiest to get used to if you are accustomed to standard programming logic - unless you are good with python so you can bypass the EG shortcomings. Thankfully we have some great plugin writers that are filling many of the gaps... overall EG cannot be beat (I've used Girder5
)
There are not States/Variables that can be created using the GUI... wish it did.
So IF you must have persistent (cross session) states you will need to script and save a states in the config.
If you want to simply do a toggle without persistence you can do this in the GUI per my example On/Off toggle in the attached jpg. Basically it checkes to see if the window exists. It jumps out based on the answer or continues to the next jump (which could be replaced with the 2nd command)... I have bacially created an If/Then since EG does not have If/Then (unfortunately).
EG is a great tool though it is not the easiest to get used to if you are accustomed to standard programming logic - unless you are good with python so you can bypass the EG shortcomings. Thankfully we have some great plugin writers that are filling many of the gaps... overall EG cannot be beat (I've used Girder5
setup... XBMC, W7MC for DVR & Live OTA TV, JRMC for multi-zone audio, EG, MiCasaVerde Vera3, USB-UIRT IR receiver, Harmony remote, 5.2 home theater system
Re: toggle a command (on/off)
Yep. Actually, what Livin is doing is probably the most useful way of approaching this. It'd always be the best option if you can get the current state information from somewhere else. For example from some X10 devices you can ask what the current state is.
-jinxdone
-jinxdone
Re: toggle a command (on/off)
hi there both of you.
Thanks a lot for your replies.
I am not starting/stopping something on the computer so i am afriad i cannot use Livins example - i am already doing it with and other application - so its a good idea.
I am sending an on or off command to a tellstick dongle (RF-transmitter for lights control).
I have tried to use the 'F12' example that you (jinxdone) postet, but i get a number of error messages - i have never done this before and i am proberly making some mistakes.
i have made:
i) a new folder called myaction2
ii) a new macro called Show OSD: Hello
iii) i put a keyboard event in the macro: Keyboard.F12
iv) i added an action: Show OSD: World
v) i added a python script with the code that jinxdone postet.
when i run the scirpt (F5) i get this error: "17:19:17 TypeError: 'NoneType' object is not callable"
what am i doing wrong? (proberly more than one thing...)
thanks a lot for your time.
br brille
Thanks a lot for your replies.
I am not starting/stopping something on the computer so i am afriad i cannot use Livins example - i am already doing it with and other application - so its a good idea.
I am sending an on or off command to a tellstick dongle (RF-transmitter for lights control).
I have tried to use the 'F12' example that you (jinxdone) postet, but i get a number of error messages - i have never done this before and i am proberly making some mistakes.
i have made:
i) a new folder called myaction2
ii) a new macro called Show OSD: Hello
iii) i put a keyboard event in the macro: Keyboard.F12
iv) i added an action: Show OSD: World
v) i added a python script with the code that jinxdone postet.
when i run the scirpt (F5) i get this error: "17:19:17 TypeError: 'NoneType' object is not callable"
what am i doing wrong? (proberly more than one thing...)
thanks a lot for your time.
br brille
Re: toggle a command (on/off)
Well, you should have the macros in your config tree somewhat like they are in the attached picture, right?
The problem you are probably having is that the mystate variable which I used does not exist. To initialize it run one of the "mystate = False" actions by hand. After this they should work, just trigger the event assigned to one of the examples (in my case I used Keyboard.F12 but you change the events to whatever you want). If you copied & pasted more than one of the examples it's a good idea to leave only one of them enabled, just like in the attached pic I only have the myaction3 folder enabled. It may get a little confusing if you run all three at the same time.
Hopefully you have more luck now. Just experiment with it for a while I'm sure you can see how each example should work.
PS. The first example doesn't need the mystate variable because it uses the "Enable exclusive" actions, which simply enable/disable the macros.
The problem you are probably having is that the mystate variable which I used does not exist. To initialize it run one of the "mystate = False" actions by hand. After this they should work, just trigger the event assigned to one of the examples (in my case I used Keyboard.F12 but you change the events to whatever you want). If you copied & pasted more than one of the examples it's a good idea to leave only one of them enabled, just like in the attached pic I only have the myaction3 folder enabled. It may get a little confusing if you run all three at the same time.
Hopefully you have more luck now. Just experiment with it for a while I'm sure you can see how each example should work.
PS. The first example doesn't need the mystate variable because it uses the "Enable exclusive" actions, which simply enable/disable the macros.
Re: toggle a command (on/off)
hi jinxdone,
tks for your answer - i can see i have some learning to do
I will experiment over the weekend - and get back to tell you when it works (or with additional questions.
)
br
Brille
tks for your answer - i can see i have some learning to do
I will experiment over the weekend - and get back to tell you when it works (or with additional questions.
br
Brille
Re: toggle a command (on/off)
Bumping this old thread:
I was wondering if it possible to disable and enable (toggle) macro/command via python script?
Thx!
I was wondering if it possible to disable and enable (toggle) macro/command via python script?
Thx!
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: toggle a command (on/off)
It is at least very difficult, and no one has the need to devote precious time to resolve.TRIROG1 wrote:I was wondering if it possible to disable and enable (toggle) macro/command via python script?
It is easy to get around, and certainly more ways.
You can for example create a auxiliary macros that will perform the required work (enable or disable) other macro.
Auxiliary macros you can run through the events that are triggered from your script.
If you really need a toggle command (that means only one auxiliary macro that performs both functions),
then you can not do without state variable.
This we can improve.
In the next version of EventGhost I can add a new action "Get item enable state."
It is easy, I've tested it.
Pako