Add info and power buttons

master
Guillaume Dott 2017-11-07 11:50:18 +01:00
parent 4406b45f7a
commit 2617ce35ac
2 changed files with 62 additions and 1 deletions

View File

@ -77,6 +77,64 @@ class Button:
def run(self): def run(self):
pass 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): class CaptureButton(Button):
countdown = 3 countdown = 3
@ -228,7 +286,10 @@ class Photoboite:
button_size = int(self.screen.get_height() / 4) button_size = int(self.screen.get_height() / 4)
topleft = (self.screen.get_width() - button_size) / 2, self.screen.get_height() - button_size - 10 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) camera_rect = pygame.Rect(0, 0, 800, 480)
self.camera = Camera(camera_rect) self.camera = Camera(camera_rect)

BIN
raspberrypi.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB