Hello everybody,
i want to get an event every midgnight. I know wx.Timer, but that uses an intervall where i can’t set the starting time.
I came up with the following idea:
class AlarmClock:
def __init__(self):
print "init timer"
self.t = wx.Timer()
self.t.Bind(wx.EVT_TIMER, self.on_timer)
self.on_timer(None)
def on_timer(self, event):
print "on timer"
if event:
print "it's time"
wx.Bell()
nxt = (
(wx.DateTime_Now().SetHMS(00, 00, 00))
+ wx.DateSpan_Day()
- wx.DateTime_Now()
)
print "next call in", str(nxt)
self.t.Start(nxt.GetMilliseconds(), wx.TIMER_ONE_SHOT)
``
This seems to be working, but i just want to know if someone has a better approach.
alarmclock.py (720 Bytes)
The first idea is to make a more frequent timer, let me say, once per minute. Every minute check the system time inside the on_timer function. When it is close enough to the midnight, then do what you need. By the way, what tolerance do you need, when you are going to detect the midnight?
The second idea. You can just schedule you program using cron or another system scheduler.
If your current solution seems to work okay without any performance
issues or other bugs, then maybe you don't need anything else. However,
you could take a look at APScheduler:
https://apscheduler.readthedocs.io/
···
'Torsten' via wxPython-users wrote:
i want to get an event every midgnight. I know wx.Timer, but that uses
an intervall where i can't set the starting time.
--
James Scholes
http://twitter.com/JamesScholes
If you happen to be on a Linux platform I’d use cron. But all the OS’s have some type of job scheduler. I know this not using wxPython but it works very well (as long as the computer clock works).
···
On Sun, Feb 5, 2017 at 10:59 AM, James Scholes james@jls-radio.com wrote:
‘Torsten’ via wxPython-users wrote:
i want to get an event every midgnight. I know wx.Timer, but that uses
an intervall where i can’t set the starting time.
If your current solution seems to work okay without any performance
issues or other bugs, then maybe you don’t need anything else. However,
you could take a look at APScheduler:
https://apscheduler.readthedocs.io/
–
James Scholes
http://twitter.com/JamesScholes
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thank you all three for your input.
The
first idea is to make a more frequent timer, let me say, once per minute. Every minute check the system time inside the on_timer function.
When it is close enough to the midnight, then do what you need. By the way, what tolerance do you need, when you are going to detect the midnight?
The second idea. You can just schedule you program using cron or another system scheduler.
Why should i make it more frequent? What will be the benefit? I think a tolerance of one minute should be enough.
you could take a look at APScheduler:
https://apscheduler.readthedocs.io/
Interesting but maybe a bit overkill for my simple app.
···
Am Sonntag, 5. Februar 2017 19:50:06 UTC+1 schrieb Michael Salin:
Am Sonntag, 5. Februar 2017 19:59:14 UTC+1 schrieb James Scholes:‘Torsten’ via wxPython-users wrote:
Am Sonntag, 5. Februar 2017 20:57:40 UTC+1 schrieb johnf:
If you happen to be on a Linux platform I’d use cron. But all the OS’s have some type of job scheduler. I know this not using wxPython but it works very well (as long as the computer clock works).
I knew i should have been more precise
I have a wxPython app that runs 24/7. I want it every night to do some housekeeping and make a backup of its (internal) data. That’s why i want a wxpython event inside my app.