maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   how can I be informed when the date changes in python (https://talk.maemo.org/showthread.php?t=51466)

farhadi 2010-04-30 08:23

how can I be informed when the date changes in python
 
Hi,

I'm writing a calendar widget for maemo5 using python something like datetoday-home-widget and I'm almost done. the only thing remained is that I don't know how to be informed when the date changes so I can redraw the widget.

Does any body know how to implement it in python or any reference or sample code?

twaelti 2010-04-30 09:59

Re: how can I be informed when the date changes in python
 
Perhaps setting an alarm at 00:00 for your app using python-alarm / libalarm could help?
http://wiki.maemo.org/Documentation/...larm_Framework

(I have no clue if 100% of that is implemented inside python-alarm.)

farhadi 2010-04-30 16:27

Re: how can I be informed when the date changes in python
 
Thanks for the reply
I found another way using signal module:
Code:

signal.signal(signal.SIGALRM, lambda signum, frame: self.update_calendar())
signal.alarm(int(86400 - (time.time() - time.mktime(time.strptime(time.strftime('%Y%m%d'), '%Y%m%d')))))

Anyway I'm new to python so any advice is greatly appreciated.

thp 2010-04-30 16:41

Re: how can I be informed when the date changes in python
 
You can also use gobject.timeout_add and calculate the time until midnight like above. This will call the callback in GTK+ mainloop, which might be cleaner than using Unix signals (which can happen at any point during execution). (assuming you use GTK+ - there's surely a similiar mechanism in the Qt world)

farhadi 2010-04-30 17:21

Re: how can I be informed when the date changes in python
 
Thanks thp

I've just implemented it using gobject.timeout_add.

And one more question. How can I be informed when user manually changes date?

farhadi 2010-05-01 20:38

Re: how can I be informed when the date changes in python
 
I found the solution:
Code:

import dbus
from dbus.mainloop.glib import DBusGMainLoop

DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(self.update_calendar,
dbus_interface="com.nokia.alarmd",
signal_name='time_change_ind',
path='/com/nokia/alarmd')



All times are GMT. The time now is 18:01.

vBulletin® Version 3.8.8