Add config screen
parent
9091d7ca75
commit
6bf5d9c0b7
|
@ -1,5 +1,5 @@
|
|||
import io, os, sys, time, pygame
|
||||
import photoboite.screens, photoboite.buttons
|
||||
import photoboite.screens, photoboite.buttons, photoboite.buttons.config
|
||||
|
||||
try:
|
||||
import picamera
|
||||
|
@ -84,6 +84,7 @@ class Photoboite:
|
|||
|
||||
self.clock = pygame.time.Clock()
|
||||
|
||||
self.config = photoboite.screens.Config(self)
|
||||
self.sleep = photoboite.screens.Sleep(30, self)
|
||||
self.capture = photoboite.screens.Capture(self, self.sleep)
|
||||
|
||||
|
@ -115,7 +116,9 @@ class Photoboite:
|
|||
|
||||
def run(self):
|
||||
while True:
|
||||
if self.sleep.enabled:
|
||||
if self.config.enabled:
|
||||
self.config.run()
|
||||
elif self.sleep.enabled:
|
||||
self.sleep.run()
|
||||
else:
|
||||
self.capture.run()
|
||||
|
|
|
@ -22,6 +22,27 @@ class Button:
|
|||
def run(self):
|
||||
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):
|
||||
def __init__(self, rect, photoboite):
|
||||
self.count = 0
|
||||
|
|
|
@ -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()
|
|
@ -14,7 +14,8 @@ class Capture:
|
|||
self.capture_button = photoboite.buttons.CaptureButton(button_size, topleft, self)
|
||||
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.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)
|
||||
self.camera = photoboite.Camera(camera_rect)
|
||||
|
@ -52,6 +53,45 @@ class Capture:
|
|||
self.sleep.sleep()
|
||||
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:
|
||||
def __init__(self, seconds, main):
|
||||
|
|
Loading…
Reference in New Issue