From 01dad9d6f2860324c254fdcfb406e1f68656b0c3 Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Wed, 5 Sep 2012 18:36:55 +0200 Subject: [PATCH] Warns user when no image found, or source folder not found. Avoids ugly error --- ivolution/FacemovieThread.py | 10 +++++++++- ivolution/Facemovie_lib.py | 15 +++++++++++---- ivolution/gui/IvolutionWindow.py | 4 ++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ivolution/FacemovieThread.py b/ivolution/FacemovieThread.py index 67d6b4c..6f4a2ea 100644 --- a/ivolution/FacemovieThread.py +++ b/ivolution/FacemovieThread.py @@ -92,7 +92,15 @@ class FacemovieThread(threading.Thread, Observable, Observer): self.my_logger.debug("Listing pictures") self.notify(["Interface", ["PROGRESS", "Listing pictures", 0.0]]) - self.facemovie.list_guys() + num_guys = self.facemovie.list_guys() + + # FIXME: Later to be done in Lib + if num_guys < 0: + self.notify(["Interface", ["STATUS", "Source folder not found", 0.0]]) + self.stop_process = True + elif num_guys == 0: + self.notify(["Interface", ["STATUS", "No image found in source folder", 0.0]]) + self.stop_process = True if not self.stop_process: self.my_logger.debug("Detecting Faces") diff --git a/ivolution/Facemovie_lib.py b/ivolution/Facemovie_lib.py index 944d022..0bddcf5 100644 --- a/ivolution/Facemovie_lib.py +++ b/ivolution/Facemovie_lib.py @@ -91,7 +91,10 @@ class FaceMovie(object, Observable, Observer): except: # find precise exception #self.console_logger.critical("Source folder not found ! Exiting. . .") self.my_logger.critical("Source folder not found ! Exiting. . .") - sys.exit(0) + + self.run = False + #sys.exit(0) + return -1 # loading images, create Guys and store it into guys ptr = 0 @@ -126,9 +129,13 @@ class FaceMovie(object, Observable, Observer): #self.console_logger.info("Skipping %s. Not an image file" % (guy_source)) self.my_logger.info("Skipping %s. Not an image file" % (guy_source)) - self.sort_guys() - ##self.console_logger.info("%d guys found in source folder." % (self.number_guys())) - self.my_logger.info("%d guys found in source folder." % (self.number_guys())) + # Checking if we have at least one image + if self.number_guys > 0: + self.sort_guys() + ##self.console_logger.info("%d guys found in source folder." % (self.number_guys())) + self.my_logger.info("%d guys found in source folder." % (self.number_guys())) + + return self.number_guys() def sort_guys(self): """ diff --git a/ivolution/gui/IvolutionWindow.py b/ivolution/gui/IvolutionWindow.py index 3c04818..bb5d067 100644 --- a/ivolution/gui/IvolutionWindow.py +++ b/ivolution/gui/IvolutionWindow.py @@ -275,7 +275,7 @@ either expressed or implied, of the FreeBSD Project.""" self.my_logger.setLevel(logging.DEBUG) # create file handler which logs even debug messages - #fh = logging.StreamHandler() + #fh = logging.StreamHandler() # uncomment here for console output fh = logging.FileHandler(log_file) fh.setLevel(logging.DEBUG) @@ -283,7 +283,7 @@ either expressed or implied, of the FreeBSD Project.""" #self.console_logger = logging.getLogger('ConsoleLog') #self.console_logger.setLevel(logging.DEBUG) # not needed - ch = logging.StreamHandler() + #ch = logging.StreamHandler() #ch.setLevel(logging.DEBUG) # not needed # add the handlers to the logger