Add sleep mode

master
Guillaume Dott 2017-10-03 16:36:23 +02:00
parent 1a7fed1e1e
commit 4f7a833151
1 changed files with 41 additions and 5 deletions

View File

@ -126,7 +126,7 @@ class CaptureButton(Button):
capture = Capture(self.count) capture = Capture(self.count)
self.count += 1 self.count += 1
for i in range(4): for i in range(3):
wait = True wait = True
start = time.time() start = time.time()
while wait: while wait:
@ -143,6 +143,7 @@ class CaptureButton(Button):
pygame.event.set_allowed((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP)) pygame.event.set_allowed((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
self.capture_mode = False self.capture_mode = False
self.enabled = True self.enabled = True
self.photoboite.sleep.move()
class Capture: class Capture:
@ -166,6 +167,32 @@ class Photo:
return self return self
class SleepMode:
def __init__(self, seconds):
self.enabled = True
self.drawn = False
self.seconds = seconds
def move(self):
self.last_action = time.time()
def event(self):
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP or event.type == pygame.KEYUP:
self.move()
self.enabled = False
def draw_on(self, screen):
if not self.drawn:
screen.fill((255,255,255))
pygame.display.flip()
self.drawn = True
def sleep(self):
if time.time() - self.last_action > self.seconds:
self.enabled = True
self.drawn = False
class Photoboite: class Photoboite:
def __init__(self): def __init__(self):
self.screen = self.screen() self.screen = self.screen()
@ -185,6 +212,8 @@ class Photoboite:
self.clock = pygame.time.Clock() self.clock = pygame.time.Clock()
self.sleep = SleepMode(30)
def screen(self): def screen(self):
if os.getenv('DISPLAY'): if os.getenv('DISPLAY'):
@ -220,6 +249,8 @@ class Photoboite:
def event(self): def event(self):
for event in pygame.event.get(): for event in pygame.event.get():
self.sleep.move()
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.unicode == 'q': if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.unicode == 'q':
self.quit() self.quit()
elif event.type == pygame.MOUSEBUTTONDOWN: elif event.type == pygame.MOUSEBUTTONDOWN:
@ -234,9 +265,14 @@ class Photoboite:
def run(self): def run(self):
pressed = False pressed = False
while True: while True:
if self.sleep.enabled:
self.sleep.event()
self.sleep.draw_on(self.screen)
self.clock.tick(60)
else:
self.event() self.event()
self.draw() self.draw()
self.sleep.sleep()
pygame.display.flip() pygame.display.flip()
def quit(self): def quit(self):