From 89551c8a0cf00d6527f37eed5285405c029fe1ec Mon Sep 17 00:00:00 2001 From: srevinsaju Date: Fri, 20 Dec 2019 21:04:08 +0300 Subject: [PATCH] Make the message 'camera not found' and 'Click the Load Image Button' in failure of getting file path more meaningful --- puntillism.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/puntillism.py b/puntillism.py index b0655b6..73c3b8b 100755 --- a/puntillism.py +++ b/puntillism.py @@ -100,9 +100,8 @@ def run(self): # define some colors for not cam found font = pygame.font.Font('freesansbold.ttf', 32) - text = font.render(_('Camera not found'), True, (255, 255, 255), (0, 0, 0)) - text_frame = text.get_rect() - text_frame.center = (x_s // 2, y_s // 2) + message = _('Camera not found') + if not self.has_camera: print("LOG: No /dev/video0 found") @@ -116,7 +115,7 @@ def run(self): if self.load_image_loop: self.image_load_handler(screen, frames, - x_s, y_s, clock, text, text_frame) + x_s, y_s, clock, message, font) # Destroy image load events try: @@ -162,7 +161,7 @@ def read_events(self, events, screen): if event.key == pygame.K_ESCAPE: self.running = False self.load_image_loop = False - + elif event.key == pygame.K_s: self.parent.save_image(screen) @@ -192,14 +191,22 @@ def read_events(self, events, screen): print("warning : ", e) self.running = True - def image_load_handler(self, screen, frames, x_s, y_s, clock, text, text_frame): + def image_load_handler(self, screen, frames, x_s, y_s, clock, message, font): screen.fill((0, 0, 0)) pygame.display.update() + if not self.has_camera: + text = font.render(message, True, (255, 255, 255), (0, 0, 0)) + text_frame = text.get_rect() + text_frame.center = (x_s // 2, y_s // 2) + else: + text = font.render(_("Click the Load Image Button"), True, (255, 255, 255), (0, 0, 0)) + text_frame = text.get_rect() + text_frame.center = (x_s // 2, y_s // 2) + while self.load_image_loop: if self.file_path is not None: - cad = pygame.image.load(self.file_path).convert() cad = pygame.transform.scale(cad, (640, 480)) rect = []