Add config screen

master
Guillaume Dott 2018-09-11 09:59:36 +02:00
parent 9091d7ca75
commit 6bf5d9c0b7
4 changed files with 76 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import io, os, sys, time, pygame import io, os, sys, time, pygame
import photoboite.screens, photoboite.buttons import photoboite.screens, photoboite.buttons, photoboite.buttons.config
try: try:
import picamera import picamera
@ -84,6 +84,7 @@ class Photoboite:
self.clock = pygame.time.Clock() self.clock = pygame.time.Clock()
self.config = photoboite.screens.Config(self)
self.sleep = photoboite.screens.Sleep(30, self) self.sleep = photoboite.screens.Sleep(30, self)
self.capture = photoboite.screens.Capture(self, self.sleep) self.capture = photoboite.screens.Capture(self, self.sleep)
@ -115,7 +116,9 @@ class Photoboite:
def run(self): def run(self):
while True: while True:
if self.sleep.enabled: if self.config.enabled:
self.config.run()
elif self.sleep.enabled:
self.sleep.run() self.sleep.run()
else: else:
self.capture.run() self.capture.run()

View File

@ -22,6 +22,27 @@ class Button:
def run(self): def run(self):
pass pass
class ConfigButton(Button):
def __init__(self, rect, config):
self.config = config
self.count = 0
self.timestamp = 0
super(ConfigButton, self).__init__(rect)
def run(self):
if time.time() - self.timestamp > 0.5:
self.count = 1
self.timestamp = time.time()
else:
self.count += 1
self.timestamp = time.time()
if self.count >= 5:
self.config.activate()
class InfoButton(Button): class InfoButton(Button):
def __init__(self, rect, photoboite): def __init__(self, rect, photoboite):
self.count = 0 self.count = 0

View File

@ -0,0 +1,9 @@
import photoboite.buttons
class Close(photoboite.buttons.Button):
def __init__(self, rect, config):
self.config = config
super(Close, self).__init__(rect)
def run(self):
self.config.deactivate()

View File

@ -14,7 +14,8 @@ class Capture:
self.capture_button = photoboite.buttons.CaptureButton(button_size, topleft, self) self.capture_button = photoboite.buttons.CaptureButton(button_size, topleft, self)
self.buttons.append(self.capture_button) self.buttons.append(self.capture_button)
self.buttons.append(photoboite.buttons.PowerButton(pygame.Rect(self.main.screen.get_width() - 50, 0, 50, 50))) self.buttons.append(photoboite.buttons.PowerButton(pygame.Rect(self.main.screen.get_width() - 50, 0, 50, 50)))
self.buttons.append(photoboite.buttons.InfoButton(pygame.Rect(0, 0, 50, 50), self)) self.buttons.append(photoboite.buttons.InfoButton(pygame.Rect(0, 0, 50, 50), self.main))
self.buttons.append(photoboite.buttons.ConfigButton(pygame.Rect(0, self.main.screen.get_height() - 50, 50, 50), self.main.config))
camera_rect = pygame.Rect(0, 0, 800, 480) camera_rect = pygame.Rect(0, 0, 800, 480)
self.camera = photoboite.Camera(camera_rect) self.camera = photoboite.Camera(camera_rect)
@ -52,6 +53,45 @@ class Capture:
self.sleep.sleep() self.sleep.sleep()
pygame.display.flip() pygame.display.flip()
class Config:
def __init__(self, main):
self.main = main
self.enabled = False
self.drawn = False
self.buttons = []
self.buttons.append(photoboite.buttons.config.Close(pygame.Rect(self.main.screen.get_width() - 50, 0, 50, 50), self))
def activate(self):
self.enabled = True
self.drawn = False
def deactivate(self):
self.enabled = False
def draw(self):
if not self.drawn:
self.main.screen.fill((255,255,255))
pygame.display.flip()
self.drawn = True
def event(self):
for event in pygame.event.get():
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.unicode == 'q':
self.main.quit()
elif event.type == pygame.MOUSEBUTTONDOWN:
for button in self.buttons:
if button.is_pressed(event.pos):
button.press()
elif event.type == pygame.MOUSEBUTTONUP:
for button in self.buttons:
if button.is_pressed(event.pos):
button.unpress()
def run(self):
self.event()
self.draw()
class Sleep: class Sleep:
def __init__(self, seconds, main): def __init__(self, seconds, main):