Some of you might have seen the screenshot of my (work-in-progress)
Python-based "maemoClock" application on the itt forum
However, I've now "wasted" too many evenings trying to fix a strange issue and
would be very glad for any help/ideas:
I'm trying to use the osso.DeviceState(context).display_blanking_pause() in
Python to keep the screen from dimming and blanking.
However, while the following codesnippet works on Benoit's (pygtkeditor) IT, it
just won't work on my N800, freshly flashed, Python 2.5 installed :-(
Here is the relevant code "prototype":
##################################
#!/usr/bin/python
import pygame
from pygame.locals import *
import os
import datetime
import math
import osso
import gobject
#from sun import *
EVT_STEP = pygame.USEREVENT
EVT_STEPSCREEN = pygame.USEREVENT+1
backBottom = pygame.Surface((800, 80))
# Class that handles all display stuff
class display:
def __init__(self):
pygame.init()
pygame.display.set_caption('maemoClock')
self.scale = False
self.screen = pygame.display.set_mode((800,480),FULLSCREEN,16)
self.back = pygame.Surface((800, 480))
def UpdateTime(self): #Simply write time and date onto the screen
#Reset bottom to black
self.screen.blit(backBottom, (0,400))
#Update time
font = pygame.font.Font(None, 96)
theTime = datetime.datetime.now().strftime("%X")
theDate = datetime.datetime.now().strftime("%a %d %b")
textTime = font.render(theTime, 1, (128, 128, 255, 192))
textDate = font.render(theDate, 1, (128, 128, 255, 192))
self.screen.blit(textTime,
(0,self.screen.get_height()-textTime.get_height()))
self.screen.blit(textDate,
(self.screen.get_width()-textDate.get_width(),self.screen.get_height()-textTime.get_height()))
#Update display
pygame.display.flip()
#Display---------------------------------------------
def keepDisplayOn(device_state):
print "keepDisplayOn() at " + datetime.datetime.now().strftime("%X")
if device_state is not None:
device_state.display_blanking_pause()
print "display_blanking_pause() at " +
datetime.datetime.now().strftime("%X")
return True #or gobject will stop calling the timeout_add
def main():
osso_ctxt = osso.Context("com.tomch.maemoclock", "0.1", False)
applic = osso.Application(osso_ctxt)
device_state = osso.DeviceState(osso_ctxt)
d = display()
d.UpdateTime()
pygame.time.set_timer(EVT_STEP, 1000) #Update the seconds display
every second
pygame.time.set_timer(EVT_STEPSCREEN, 8000) #Re-activate the screen every
8 seconds
pygame.mouse.set_visible(False) #disable the cursor
# Wait for user input
while True:
event = pygame.event.wait()
if (event.type == KEYUP) and (event.key == 287): # Fullscreen button / F6
: Toggle fullscreen
pygame.display.toggle_fullscreen()
elif (event.type == EVT_STEP): #Timer-Event
d.UpdateTime()
elif (event.type == EVT_STEPSCREEN) : #Timer-Event
keepDisplayOn(device_state)
elif (event.type == MOUSEBUTTONDOWN): #Touchscreen-Event
break
print "Event " + str(event.type)
if __name__ == '__main__':
main()
##################################
While the events get called, nothing ever happens with the display on my N800 -
it simply keeps dimming and blanking...
OTOH, If I call the display_blanking_pause() in the main() loop, the call will
work (for once). So the API does work.
If I play around with the examples from the wiki doc
(osso_test_device_blank_pause.py, osso_test_device_on.py), they both work, too.
However, once I start shifting the timer from a gobject.timeout_add to an
pygame.time.set_timer, the calls to display_blanking_pause (in the function
called by the timer) won't do anything anymore.
My guess is that I'm somehow losing the osso.context.
Helpy anbody? Does that code snippet work on your device, keeping your screen
from dimming and blanking?
Anybody who can explain what is happening?
Thanks!
-Tom (desperate, bordering towards madness :-)
_______________________________________________
maemo-developers mailing list
[email protected]
https://lists.maemo.org/mailman/listinfo/maemo-developers