Improved error handling
This commit is contained in:
@@ -52,7 +52,7 @@ class Camera_gPhoto:
|
|||||||
raise subprocess.CalledProcessError(returncode=0, cmd=cmd, output=output)
|
raise subprocess.CalledProcessError(returncode=0, cmd=cmd, output=output)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
if "Canon EOS Capture failed: 2019" in e.output:
|
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:
|
elif "No camera found" in e.output:
|
||||||
raise CameraException("No (supported) camera detected!", False)
|
raise CameraException("No (supported) camera detected!", False)
|
||||||
elif "command not found" in e.output:
|
elif "command not found" in e.output:
|
||||||
|
|||||||
27
gui.py
27
gui.py
@@ -96,10 +96,10 @@ class GUI_PyGame:
|
|||||||
if font.size(requested_line)[0] > size[0]:
|
if font.size(requested_line)[0] > size[0]:
|
||||||
# Split at white spaces
|
# Split at white spaces
|
||||||
words = requested_line.split(' ')
|
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:
|
for word in words:
|
||||||
if font.size(word)[0] >= size[0]:
|
while font.size(word)[0] >= size[0]:
|
||||||
raise GuiException("The word " + word + " is too long to fit.")
|
word = word[:-1]
|
||||||
# Start a new line
|
# Start a new line
|
||||||
accumulated_line = ""
|
accumulated_line = ""
|
||||||
# Put words on the line as long as they fit
|
# Put words on the line as long as they fit
|
||||||
@@ -108,13 +108,22 @@ class GUI_PyGame:
|
|||||||
# Build the line while the words fit.
|
# Build the line while the words fit.
|
||||||
if font.size(test_line)[0] < size[0]:
|
if font.size(test_line)[0] < size[0]:
|
||||||
accumulated_line = test_line
|
accumulated_line = test_line
|
||||||
else:
|
else:
|
||||||
accumulated_height += font.size(test_line)[1]
|
# Start a new line
|
||||||
final_lines.append(accumulated_line)
|
line_height = font.size(accumulated_line)[1]
|
||||||
accumulated_line = word + " "
|
if accumulated_height + line_height > size[1]:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
accumulated_height += line_height
|
||||||
|
final_lines.append(accumulated_line)
|
||||||
|
accumulated_line = word + " "
|
||||||
# Finish requested_line
|
# Finish requested_line
|
||||||
accumulated_height += font.size(accumulated_line)[1]
|
line_height = font.size(accumulated_line)[1]
|
||||||
final_lines.append(accumulated_line)
|
if accumulated_height + line_height > size[1]:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
accumulated_height += line_height
|
||||||
|
final_lines.append(accumulated_line)
|
||||||
# Line fits as it is
|
# Line fits as it is
|
||||||
else:
|
else:
|
||||||
accumulated_height += font.size(requested_line)[1]
|
accumulated_height += font.size(requested_line)[1]
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ class Photobooth:
|
|||||||
self.display.clear()
|
self.display.clear()
|
||||||
self.display.show_message(e.message)
|
self.display.show_message(e.message)
|
||||||
self.display.apply()
|
self.display.apply()
|
||||||
sleep(2)
|
sleep(3)
|
||||||
else:
|
else:
|
||||||
raise CameraException("Giving up! Please start again!", False)
|
raise CameraException("Giving up! Please start again!", False)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -4,5 +4,7 @@ PHOTOBOOTH_DIR=/home/pi/photobooth
|
|||||||
|
|
||||||
cd "${PHOTOBOOTH_DIR}"
|
cd "${PHOTOBOOTH_DIR}"
|
||||||
|
|
||||||
sudo ./photobooth.py 2>&1 > photobooth.log
|
sudo ./photobooth.py > photobooth.log 2> photobooth.err
|
||||||
|
|
||||||
|
cd -
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user