From 2617ce35ac3bffc4feee3db96c844c7f801460bc Mon Sep 17 00:00:00 2001 From: Guillaume Dott Date: Tue, 7 Nov 2017 11:50:18 +0100 Subject: [PATCH] Add info and power buttons --- photoboite.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++- raspberrypi.png | Bin 0 -> 4237 bytes 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 raspberrypi.png 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 0000000000000000000000000000000000000000..17961005db89d0f0a84b5b92ac0a3fff4c7092f5 GIT binary patch literal 4237 zcmV;85OVK{P)p?Zv%E29C#f#1@wIp;g!Jszze`ZzywT55zN$o#V)4*0~!zjHUQOS z_VExf3WPJ{q~&Jz1q6YA1D*or6%r=oJYNCa4lKc%5df;|ZJf2Fg5Hh@%fI2JV^@&s zi8gwVMez?M2#sn4hBd;Y8m37fumiXQ7%0%+!@#$JY3^#7NKj|-bu}E?>gVda8`!mJ zlsPLZIo%e+6SuIUSD!u{u6nF+Oautz)AxRM`6`P3ak+|i-X6&lS>GlZI z&UYi^stv>=1^~zRgouZAHm>bOk_EK5c^u1C`ZKD(41C+BiquZBam^1K8SaiVeW9Cp z#K5MCdGh-^qll6~U6Y*;U+ZV@W*??$5(^suD}hb9iU`0dk5`$r`l+ed9Qi`aLFe8O zVV}SRd9NwFVx3pZw>L`s{;TR0sjM*6;hZ8{Bta9 z$Q3m*4Kvg))JfGu8{R2)qCuUWqtWTW9-s$!Tdk1PTOMqtrqPCC|6&uRCrsXarVA}@ z0(=7O2FR3F0oa>ns!Utp&Tg!k44jP7eK>+?me=9M-}I(t{Aa-Tf$9tYx(-*BTvq$w zh{nkSVM0DF>%D2hCAWH0zEqcbpJ|a{;8Opf)*>q+Q|7wT1)?b6s+2KJ*s)=R!ILrS zCfkwZ0*fXkSP=;Ob-E8nnt<7gUG!Z0qedj9cpHGO!x46D7(oE0&3EUy_)u4zjW6^P zj~FJf3TyF`Yu~6S3Am~x^hEyDd+HRH-CW0{nJRyJs*7!J45k)cLA1A>MfG6sHe{S#g_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