mirror of https://git.sr.ht/~michalr/menu
Events after screensaver should be ignored for a short time
This commit is contained in:
parent
c20557cc32
commit
75659d8142
18
menu.py
18
menu.py
|
@ -162,6 +162,7 @@ class MenuBoard(IBoard):
|
||||||
class App:
|
class App:
|
||||||
FPS = 30
|
FPS = 30
|
||||||
SHOW_REQUEST_MESSAGE_FOR_AT_LEAST_S = 5
|
SHOW_REQUEST_MESSAGE_FOR_AT_LEAST_S = 5
|
||||||
|
IGNORE_EVENTS_FOR_TICKS_AFTER_SCREENSAVER = 5
|
||||||
|
|
||||||
def __init__(self, actions: List[Action], theme: Dict, fullscreen: bool, screensaver_delay: int):
|
def __init__(self, actions: List[Action], theme: Dict, fullscreen: bool, screensaver_delay: int):
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
@ -178,7 +179,6 @@ class App:
|
||||||
self.task_q = Queue()
|
self.task_q = Queue()
|
||||||
self.screensaver = ClockScreensaver()
|
self.screensaver = ClockScreensaver()
|
||||||
self.TICKS_UNTIL_SCREENSAVER = screensaver_delay * self.FPS
|
self.TICKS_UNTIL_SCREENSAVER = screensaver_delay * self.FPS
|
||||||
self.screensaver_ticks = self.TICKS_UNTIL_SCREENSAVER
|
|
||||||
|
|
||||||
def get_screen_rect(self) -> pygame.Rect:
|
def get_screen_rect(self) -> pygame.Rect:
|
||||||
return pygame.Rect(0, 0, self.screen.get_width(), self.screen.get_height())
|
return pygame.Rect(0, 0, self.screen.get_width(), self.screen.get_height())
|
||||||
|
@ -241,24 +241,32 @@ class App:
|
||||||
def loop(self):
|
def loop(self):
|
||||||
self.running = True
|
self.running = True
|
||||||
needs_redrawing = True
|
needs_redrawing = True
|
||||||
|
# Block event handling for some time after screensaver is disabled to prevent
|
||||||
|
# user from clicking somewhere they don't intend to.
|
||||||
|
ticks_after_screensaver = 0
|
||||||
|
# how many ticks left until the screensaver should be engaged
|
||||||
|
screensaver_ticks = self.TICKS_UNTIL_SCREENSAVER
|
||||||
while self.running:
|
while self.running:
|
||||||
try:
|
try:
|
||||||
self.task_q.get_nowait()()
|
self.task_q.get_nowait()()
|
||||||
except Empty:
|
except Empty:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
ticks_after_screensaver = max(ticks_after_screensaver-1, 0)
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
self.running = False
|
self.running = False
|
||||||
if self.screensaver_ticks != 0:
|
if screensaver_ticks != 0 and ticks_after_screensaver == 0:
|
||||||
self.board.handle_event(event)
|
self.board.handle_event(event)
|
||||||
self.screensaver_ticks = self.TICKS_UNTIL_SCREENSAVER
|
screensaver_ticks = self.TICKS_UNTIL_SCREENSAVER
|
||||||
needs_redrawing = True
|
needs_redrawing = True
|
||||||
|
|
||||||
if self.screensaver_ticks == 0:
|
if screensaver_ticks == 0:
|
||||||
self.screensaver.draw(self.screen, False)
|
self.screensaver.draw(self.screen, False)
|
||||||
|
ticks_after_screensaver = self.IGNORE_EVENTS_FOR_TICKS_AFTER_SCREENSAVER
|
||||||
else:
|
else:
|
||||||
self.board.draw(self.screen, needs_redrawing)
|
self.board.draw(self.screen, needs_redrawing)
|
||||||
self.screensaver_ticks -= 1
|
screensaver_ticks -= 1
|
||||||
needs_redrawing = False
|
needs_redrawing = False
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
Loading…
Reference in New Issue