From 74fea1d310147943548291f0af50ebf08c639927 Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Tue, 21 Aug 2012 22:02:24 +0200 Subject: [PATCH] Adds Errors handling in GUI --- ivolution/FacemovieThread.py | 14 ++++++++++---- ivolution/Facemovie_lib.py | 4 ++-- ivolution/gui_wx/IvolutionWindow.py | 6 ++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ivolution/FacemovieThread.py b/ivolution/FacemovieThread.py index 169e86e..83bdfd4 100644 --- a/ivolution/FacemovieThread.py +++ b/ivolution/FacemovieThread.py @@ -48,8 +48,7 @@ class FacemovieThread(threading.Thread, Observable, Observer): Trigerred by IvolutionWindow. Uses the Observer pattern to inform the user about the progress of the GUI. """ - if len(message) == 1: - # system commands + if len(message) == 1: # system commands if message[0] == "STOP": self.console_logger.debug("Facemovie is going to stop") self.my_logger.debug("Facemovie is going to stop") @@ -61,13 +60,20 @@ class FacemovieThread(threading.Thread, Observable, Observer): self.my_logger.debug("Unrecognized system command") #self.console_logger.debug(message) self.my_logger.debug(message) - elif len(message) == 2: - # notifications + elif len(message) == 2: # notifications + #self.console_logger.debug(message) self.my_logger.debug(message) # notify gui about small updates self.notify(["STATUS", message[0], message[1]]) + # checking for fatal error + if message[0] == "Error": + self.console_logger.debug("Fatal Error detected") + self.my_logger.debug("Fatal Error detected") + self.stop_process = True + self.notify(["STOP"]) + else: self.console_logger.debug("Unrecognized command") self.my_logger.debug("Unrecognized command") diff --git a/ivolution/Facemovie_lib.py b/ivolution/Facemovie_lib.py index db5d75b..9f089f1 100644 --- a/ivolution/Facemovie_lib.py +++ b/ivolution/Facemovie_lib.py @@ -192,7 +192,6 @@ class FaceMovie(object, Observable, Observer): message = message_root + " %d / %d" % (num, den) self.notify([message, self.percent(num, den)]) except (ArithmeticError, ZeroDivisionError): - #pass self.notify(["Error", 0]) def clean_guys(self): @@ -221,7 +220,8 @@ class FaceMovie(object, Observable, Observer): if self.number_guys() == 0: self.console_logger.error("No face has been found in the whole repository! Exiting. . . ") self.my_logger.error("No face has been found in the whole repository! Exiting. . . ") - sys.exit(0) # FIXME : Find better way to do that + self.notify(["Error", 0]) + sys.exit(0) # normalize faces to make them clean self.set_guys_ratio() # sets all faces to the same size, by calculating a ratio to a reference diff --git a/ivolution/gui_wx/IvolutionWindow.py b/ivolution/gui_wx/IvolutionWindow.py index 9a0d71a..488a5ae 100644 --- a/ivolution/gui_wx/IvolutionWindow.py +++ b/ivolution/gui_wx/IvolutionWindow.py @@ -490,6 +490,12 @@ class IvolutionWindow(wx.Frame, Observer, Observable): self.process_running = False elif message[0] == "STATUS": # status label + if message[1] == "Error": + wx.MutexGuiEnter() # to avoid thread problems + self.sb.SetStatusText("Error detected", 0) + self.progressgauge.SetValue(0) + wx.MutexGuiLeave() + wx.MutexGuiEnter() # to avoid thread problems self.sb.SetStatusText(message[1], 1) wx.MutexGuiLeave()