Add sleep mode
parent
1a7fed1e1e
commit
4f7a833151
|
@ -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,10 +265,15 @@ class Photoboite:
|
||||||
def run(self):
|
def run(self):
|
||||||
pressed = False
|
pressed = False
|
||||||
while True:
|
while True:
|
||||||
self.event()
|
if self.sleep.enabled:
|
||||||
self.draw()
|
self.sleep.event()
|
||||||
|
self.sleep.draw_on(self.screen)
|
||||||
pygame.display.flip()
|
self.clock.tick(60)
|
||||||
|
else:
|
||||||
|
self.event()
|
||||||
|
self.draw()
|
||||||
|
self.sleep.sleep()
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
def quit(self):
|
def quit(self):
|
||||||
self.camera.close()
|
self.camera.close()
|
||||||
|
|
Loading…
Reference in New Issue