Improved error handling

This commit is contained in:
Balthasar Reuter
2015-07-01 00:19:52 +02:00
parent 928ba63bd1
commit fa877a60bc
4 changed files with 23 additions and 12 deletions

View File

@@ -52,7 +52,7 @@ class Camera_gPhoto:
raise subprocess.CalledProcessError(returncode=0, cmd=cmd, output=output)
except subprocess.CalledProcessError as e:
if "Canon EOS Capture failed: 2019" in e.output:
raise CameraException("Can't focus! Move a little bit!", True)
raise CameraException("Can't focus!\nMove a little bit!", True)
elif "No camera found" in e.output:
raise CameraException("No (supported) camera detected!", False)
elif "command not found" in e.output:

27
gui.py
View File

@@ -96,10 +96,10 @@ class GUI_PyGame:
if font.size(requested_line)[0] > size[0]:
# Split at white spaces
words = requested_line.split(' ')
# if any of our words are too long to fit, return.
# if any of our words are too long to fit, trim them
for word in words:
if font.size(word)[0] >= size[0]:
raise GuiException("The word " + word + " is too long to fit.")
while font.size(word)[0] >= size[0]:
word = word[:-1]
# Start a new line
accumulated_line = ""
# Put words on the line as long as they fit
@@ -108,13 +108,22 @@ class GUI_PyGame:
# Build the line while the words fit.
if font.size(test_line)[0] < size[0]:
accumulated_line = test_line
else:
accumulated_height += font.size(test_line)[1]
final_lines.append(accumulated_line)
accumulated_line = word + " "
else:
# Start a new line
line_height = font.size(accumulated_line)[1]
if accumulated_height + line_height > size[1]:
break
else:
accumulated_height += line_height
final_lines.append(accumulated_line)
accumulated_line = word + " "
# Finish requested_line
accumulated_height += font.size(accumulated_line)[1]
final_lines.append(accumulated_line)
line_height = font.size(accumulated_line)[1]
if accumulated_height + line_height > size[1]:
break
else:
accumulated_height += line_height
final_lines.append(accumulated_line)
# Line fits as it is
else:
accumulated_height += font.size(requested_line)[1]

View File

@@ -320,7 +320,7 @@ class Photobooth:
self.display.clear()
self.display.show_message(e.message)
self.display.apply()
sleep(2)
sleep(3)
else:
raise CameraException("Giving up! Please start again!", False)
else:

View File

@@ -4,5 +4,7 @@ PHOTOBOOTH_DIR=/home/pi/photobooth
cd "${PHOTOBOOTH_DIR}"
sudo ./photobooth.py 2>&1 > photobooth.log
sudo ./photobooth.py > photobooth.log 2> photobooth.err
cd -