diff --git a/photoboite/__init__.py b/photoboite/__init__.py index 1782a1a..f653a28 100644 --- a/photoboite/__init__.py +++ b/photoboite/__init__.py @@ -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() diff --git a/photoboite/buttons/__init__.py b/photoboite/buttons/__init__.py index 0de3d5c..ccd7711 100644 --- a/photoboite/buttons/__init__.py +++ b/photoboite/buttons/__init__.py @@ -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 diff --git a/photoboite/buttons/config/__init__.py b/photoboite/buttons/config/__init__.py new file mode 100644 index 0000000..da1f28f --- /dev/null +++ b/photoboite/buttons/config/__init__.py @@ -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() diff --git a/photoboite/screens/__init__.py b/photoboite/screens/__init__.py index 0adb77a..6c738e7 100644 --- a/photoboite/screens/__init__.py +++ b/photoboite/screens/__init__.py @@ -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):