| Reply | « Previous Thread | Next Thread » |
|
Hi,
I've a problem when I would to create a control code like timer Example: When it's 12:00AM the code print a messagge info: "It is 12:00AM!" I think it's possible with a "while" cicle. But whit "while" is not more expansive for the RAM?? Thank for answer! |
|
Hi orebla
Replying to your subject of the thread how to create a timer Code:
timer = e32.Ao_timer() timer.after( time, function_name ) If you want to print the time then you can use time function from ctime module.And yes you can make a while loop running to print the time at several intervals. However i didnt get your this question Quote:
Best Regards croozeus |
|
Sorry for my bad english!
![]() The function AO_timer() checks whether the time, for example, is 12:00 AM. But the function controls the time only once, when the script is loaded, right? My question is: But using the while loop to check the time not create a loop infinitive? I hope that I explained ![]() Sorry for my bad bad english :-( :-( |
|
Quote:
Hope I got you correct this time you can use an infinit while loop to print the time at certains intervals like below where time specifies time in seconds.The function_name specifies function which is to be repeated after time seconds and should be define in the begininng. Code:
timer = e32.Ao_timer()
# loop forever
while True:
timer.after( time, function_name )
Best Regards croozeus
Last edited by croozeus : 2007-11-07 at 13:15.
Reason: mistype
|
|
This is incorrect:
Code:
timer = e32.Ao_timer()
# loop forever
while True:
timer.after( time, function_name )
The correct way (you can search this forum for more examples) is to restart the timer inside the called function. Code:
import e32 timer = e32.Ao_timer() delay = 4.0 def do_something(): # your code to be repeated every interval goes here timer.after(delay, do_something) # still have to start the timer once timer.after(delay, do_something) One way to do that is using atexit. Code:
import atexit atexit.register(timer.cancel)
Last edited by nlsp : 2007-11-08 at 01:29.
|
|
Hello nlsp
True,we do get a runtime error in my code however its not wrong.The runtime error occurs because the timer is still pending and we need to cancel it.As My code before I now define the body of the function_name as in the below code. Code:
import e32
def function_name():
print "Hello"
timer.after( 4, function_name )
timer = e32.Ao_timer()
# loop forever
while True:
timer.after( 4, function_name )
Code:
import e32 timer = e32.Ao_timer() delay = 4.0 def do_something(): # your code to be repeated every interval goes here timer.after(delay, do_something) # still have to start the timer once timer.after(delay, do_something) Code:
t=4
While True:
e32.ao_sleep(t)
function_name()
croozeus |
|
Thanks for answer!!
I understand how use the function Ao_timer. But how can print a message at twelve o'clock?? Sorry for my bad bad english :-( :-( |
|
I'm not sure there exists a ready to use interface to do something like timer.at(<sometime>, func). However you can get the current time, calculate how many seconds in the future you want to be called back, and use timer.after() to do your thing at the calculated time.
|
|
Ok I get current time with time.localtime()
but is very difficult for me calculate the difference between two date. What can I do? Sorry for my bad bad english :-( :-( |
|
Code:
import e32 import time def waittime(): t = list(time.localtime()) n = time.mktime(t) t[3] = t[4] = t[5] = 0 t[2] += 1 return time.mktime(t) - n timer=e32.Ao_timer() w = waittime() while w > 60: h = w / 3600 m = w % 3600 / 60 s = w % 60 print "waiting %02d:%02d:%02d ..." % (h, m, s) timer.after(s or 60) w = waittime() timer.after(w) print "It's time!!" |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| When can you set the screensaver's Refresh Timer Value? | azhrei | Symbian Tools & SDKs | 6 | 2008-08-23 11:12 |
| Crash with multiple ao_timer | noreli | Python | 2 | 2007-11-01 07:18 |
| inactivity timer, backlight, system dialogue windows. | davidmaxwaterman | Series 40 & S60 Platform Feedback | 0 | 2007-05-24 04:11 |
| Can anybody help me create a "periodic" timer? | supertoync | General Symbian C++ | 1 | 2005-10-27 09:41 |
| How to create countdown timer display in the nokia 7610? | Hector_D | Mobile Java General | 0 | 2005-01-19 03:02 |