Ok so I did some research, and im coming up with blanks. I am not very educated on python, but i kind of understand it.
Basically I made an on screen menu for a sleep timer with the options 60 90 120 and cancel, so it will stop media players and send ir signal to turn of tv. I would like an osd to show current remaining time when I bring up the menu for a few seconds, so I can track how much longer is on the sleep timer.
So to have ShowOSD show this I have gotten this far
I know I need to insert python info in brackets such as {eg.plugins.timer.............}
The timer is named sleep, and I go into the python sonsole and look through all the name space, and I don't think there is a value that shows remaining time, just a value that shows when the end event will happen. but even that is foreign to me. This is what I could find.
eg.plugins.Timer.plugin.timerObjects[Sleep].nextEventAt
Type: <type 'float'>
Value: 1391405993.35
Now the sleep in the brackets in timerObjects[sleep] messes things up, when the following is entered into the console
eg.plugins.Timer.plugin.timerObjects[Sleep].nextEventAt
it shows
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'Sleep' is not defined
So first I need to figure out how to get this value and convert it in some sort of time format, then I am going to have to recieve the current system time, have it do some subtraction in a seperate python script and write that value to its own namespace. then have the show osd plugin in show the value for that name space.
Am I on the right track here?
If someone is interested in a interesting project and figure this out for me it would be great, seeing the finished product would help me learn a bit more about what I can do with the show OSD plugin.
Thanks
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.
Show OSD help
Re: Show OSD help
I can't say that I understand why they're not included in the Namespace description, but you need to surround Sleep in single quotes: 'Sleep'
print eg.eg.plugins.Timer.plugin.timerObjects['Sleep'].nextEventAt
1391439321.92
That should get you past your first hurdle.
print eg.eg.plugins.Timer.plugin.timerObjects['Sleep'].nextEventAt
1391439321.92
That should get you past your first hurdle.
-
ralphmichael17
- Posts: 4
- Joined: Fri Jan 17, 2014 3:33 pm
Re: Show OSD help
Thanks for the help
So based on that and some other research this i how far I have gotten
When OS menu trigger event happens, these two seperate scripts run right before the os menu opens
1st Code
2nd Code
I had to make them seperate because if the sleep timer did not exist, then it would just throw an error, at least this way no matter what it will go to the if else statement.
If the if statement was true, for some reason it does not leave a value in the eg.result, so I just copied the first code as an action in the sleeptimer.true trigger
I wish I knew of a cleaner way to due this with only one script... and when testing things I hate seeing the red errors on event ghost everytime I open the menu with no current timer, but this is the only way I could get this to work after 3 hours of fiddling around with a code I dont fully understand.
I suppose you could call this case closed, but if anyone wants to undertake how to perform this in a cleaner manner, let me know, I would be interested to understand this more.
So based on that and some other research this i how far I have gotten
When OS menu trigger event happens, these two seperate scripts run right before the os menu opens
1st Code
Code: Select all
import time
eg.result = time.time()
eg.result = eg.plugins.Timer.plugin.timerObjects['Sleep'].nextEventAt - time.time()
eg.result = int(eg.result / 60)
Code: Select all
result = eg.result
if result < 120:
eg.TriggerEvent(u"Sleeptimer.True")
else:
eg.TriggerEvent(u"Sleeptimer.False")
If the if statement was true, for some reason it does not leave a value in the eg.result, so I just copied the first code as an action in the sleeptimer.true trigger
I wish I knew of a cleaner way to due this with only one script... and when testing things I hate seeing the red errors on event ghost everytime I open the menu with no current timer, but this is the only way I could get this to work after 3 hours of fiddling around with a code I dont fully understand.
I suppose you could call this case closed, but if anyone wants to undertake how to perform this in a cleaner manner, let me know, I would be interested to understand this more.
Re: Show OSD help
Do you need to determine if the timer exists at all, or if it is active? If you just want to know if it's active, there's a boolean variable for that, eg.eg.plugins.Timer.plugin.timerObjects['Sleep'].active, which will return True or False.ralphmichael17 wrote: I had to make them seperate because if the sleep timer did not exist, then it would just throw an error, at least this way no matter what it will go to the if else statement.
If you need to know if the timer event exists, you'll have to use something like this: http://stackoverflow.com/questions/1592 ... -in-python
But I would think you would know if the timer exists, just not necessarily whether it is active or inactive.
BTW, you probably don't want to modify eg.result as a variable. It could be overwritten at any time by EG. If you need to set a variable that is available to other python scripts, you can use eg.globals.myvariablename, where myvariablename is whatever non-reserved name you want to use.
-
ralphmichael17
- Posts: 4
- Joined: Fri Jan 17, 2014 3:33 pm
Re: Show OSD help
Thanks, thats exactly what I was looking for, I just replace nameerror with keyerror, now I was able to bring it down to one simple python script
Then I have two seperaate OSD's that go with each trigger event.
One that simply says no Timer, and the other that says {eg.globals.sleeptimeleft} Minutes
I guess the only quesion I have left is what if I wanted to not have it run trigger events, and instead have it with the same event as the script but the action right after. I would have to have the script either write "No Timer" to the variable, or write "XX Minutes" to the variable.
I know I can us eg.globals.sleeptimeleft = "No Timer", but in the shell when checking the variable after it returns it with the quotes, how would I return it without the quotes. And how would I right the calculated minutes left plus a string of charactors to the same variable? I know that what I have now is working just fine, but the less events and actions the better I like it.
Code: Select all
try:
eg.plugins.Timer.plugin.timerObjects['Sleep'].nextEventAt
except KeyError:
eg.TriggerEvent (u"Sleeptimer.False")
else:
import time
eg.globals.sleeptimeleft = eg.plugins.Timer.plugin.timerObjects['Sleep'].nextEventAt - time.time()
eg.globals.sleeptimeleft = int(eg.globals.sleeptimeleft / 60)
eg.TriggerEvent (u"Sleeptimer.True")
One that simply says no Timer, and the other that says {eg.globals.sleeptimeleft} Minutes
I guess the only quesion I have left is what if I wanted to not have it run trigger events, and instead have it with the same event as the script but the action right after. I would have to have the script either write "No Timer" to the variable, or write "XX Minutes" to the variable.
I know I can us eg.globals.sleeptimeleft = "No Timer", but in the shell when checking the variable after it returns it with the quotes, how would I return it without the quotes. And how would I right the calculated minutes left plus a string of charactors to the same variable? I know that what I have now is working just fine, but the less events and actions the better I like it.
Re: Show OSD help
I'm sorry, but I really don't understand what you're asking. Perhaps you could rephrase your questions.