diff --git a/photoboite.py b/photoboite.py index 0e55741..9668ba9 100755 --- a/photoboite.py +++ b/photoboite.py @@ -77,6 +77,64 @@ class Button: def run(self): pass +class InfoButton(Button): + def __init__(self, rect, photoboite): + self.count = 0 + self.timestamp = 0 + self.photoboite = photoboite + + super(InfoButton, self).__init__(rect) + + self.enabled = False + + self.font = pygame.font.Font(None, 25) + self.logo = pygame.image.load(os.path.dirname(os.path.realpath(__file__)) + '/raspberrypi.png').convert_alpha() + + def draw_on(self, screen): + if self.enabled: + screen.blit(self.logo, self.logo.get_rect()) + + top = self.logo.get_rect().height + 10 + + text = "COUNT: " + str(self.photoboite.capture_button.count) + size = self.font.size(text) + ren = self.font.render(text, True, (255, 255, 255)) + screen.blit(ren, (0, top)) + + text = "FPS: " + str(self.photoboite.clock.get_fps()) + size = self.font.size(text) + ren = self.font.render(text, True, (255, 255, 255)) + screen.blit(ren, (0, top + 20)) + + def run(self): + if time.time() - self.timestamp > 0.5: + self.count = 1 + else: + self.count += 1 + + self.timestamp = time.time() + + if self.count >= 2: + self.enabled = not self.enabled + +class PowerButton(Button): + def __init__(self, rect): + self.count = 0 + self.timestamp = 0 + + super(PowerButton, 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: + print('POWEROFF') + class CaptureButton(Button): countdown = 3 @@ -228,7 +286,10 @@ class Photoboite: button_size = int(self.screen.get_height() / 4) topleft = (self.screen.get_width() - button_size) / 2, self.screen.get_height() - button_size - 10 - self.buttons.append(CaptureButton(button_size, topleft, self)) + self.capture_button = CaptureButton(button_size, topleft, self) + self.buttons.append(self.capture_button) + self.buttons.append(PowerButton(pygame.Rect(self.screen.get_width() - 50, 0, 50, 50))) + self.buttons.append(InfoButton(pygame.Rect(0, 0, 50, 50), self)) camera_rect = pygame.Rect(0, 0, 800, 480) self.camera = Camera(camera_rect) diff --git a/raspberrypi.png b/raspberrypi.png new file mode 100644 index 0000000..1796100 Binary files /dev/null and b/raspberrypi.png differ