Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 15:04, 29 March 2008.

A simple screensaver

From Forum Nokia Wiki

This is an example of a simple PyS60 screensaver.

import appuifw, e32
from time import *
from graphics import *
 
app_lock=e32.Ao_lock()
def quit():
   global running
   running=0
   app_lock.signal()
appuifw.app.exit_key_handler=quit
 
#We create the background, a blank image
bg=Image.new((240,320))        #These dimensions are purely orientational. For best results, adapt them to your device
 
#Now we create a white rectangle that will hold the date and time, for example
dt=Image.new((240,160))
 
#The screensaver takes up the entire screen
appuifw.app.screen="full"
 
y=0
coord_inc=0
running=1
while(running==1):
   if(e32.inactivity()>=5):  #The screensaver kicks in after 5 seconds of user inactivity
      #The background and the area displaying date and time are cleared
      bg.clear()
      dt.clear()
 
      #The date and time are stored as unicode strings
      year=str(localtime()[0])
      month=str(localtime()[1])
      day=str(localtime()[2])
      date=u"%s/%s/%s" % (day,month,year)
      if(localtime()[4]<10):min="0"+str(localtime()[4])
      else:min=str(localtime()[4])
      if(localtime()[5]<10):sec="0"+str(localtime()[5])
      else:sec=str(localtime()[5])
      time=u"%d:%s:%s" % (localtime()[3],min,sec)
	
      #We write the information on the rectangle:
      dt.text((80,25), date, font="annotation")
      dt.text((70,50), time, font="title")
	
      #We place the rectangle on the background
      bg.blit(dt, target=(0,y))
      #We increase the y coordinate to tell the program where to show the rectangle next
      if(coord_inc==0):
         y+=160
         coord_inc=1   #Tells that y has been increased
      else:
         y=0
         coord_inc=0
		
      #We set the background:
      def handle_redraw(rect):canvas.blit(bg)
      canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
      appuifw.app.body=canvas
 
      #Tell it to wait 5 seconds before moving the information
      e32.ao_sleep(5)


Screenshot:


Image:Saver.JPG

 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZpythonQ
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX