Add sleep mode
parent
1a7fed1e1e
commit
4f7a833151
|
@ -126,7 +126,7 @@ class CaptureButton(Button):
|
|||
capture = Capture(self.count)
|
||||
self.count += 1
|
||||
|
||||
for i in range(4):
|
||||
for i in range(3):
|
||||
wait = True
|
||||
start = time.time()
|
||||
while wait:
|
||||
|
@ -143,6 +143,7 @@ class CaptureButton(Button):
|
|||
pygame.event.set_allowed((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
|
||||
self.capture_mode = False
|
||||
self.enabled = True
|
||||
self.photoboite.sleep.move()
|
||||
|
||||
|
||||
class Capture:
|
||||
|
@ -166,6 +167,32 @@ class Photo:
|
|||
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:
|
||||
def __init__(self):
|
||||
self.screen = self.screen()
|
||||
|
@ -185,6 +212,8 @@ class Photoboite:
|
|||
|
||||
self.clock = pygame.time.Clock()
|
||||
|
||||
self.sleep = SleepMode(30)
|
||||
|
||||
|
||||
def screen(self):
|
||||
if os.getenv('DISPLAY'):
|
||||
|
@ -220,6 +249,8 @@ class Photoboite:
|
|||
|
||||
def event(self):
|
||||
for event in pygame.event.get():
|
||||
self.sleep.move()
|
||||
|
||||
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.unicode == 'q':
|
||||
self.quit()
|
||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||
|
@ -234,9 +265,14 @@ class Photoboite:
|
|||
def run(self):
|
||||
pressed = False
|
||||
while True:
|
||||
if self.sleep.enabled:
|
||||
self.sleep.event()
|
||||
self.sleep.draw_on(self.screen)
|
||||
self.clock.tick(60)
|
||||
else:
|
||||
self.event()
|
||||
self.draw()
|
||||
|
||||
self.sleep.sleep()
|
||||
pygame.display.flip()
|
||||
|
||||
def quit(self):
|
||||
|
|
Loading…
Reference in New Issue