Additional comments
This commit is contained in:
@@ -53,6 +53,7 @@ class Images:
|
|||||||
# Find existing files
|
# Find existing files
|
||||||
count_pattern = "[0-9]" * self.count_width
|
count_pattern = "[0-9]" * self.count_width
|
||||||
pictures = glob.glob(self.basename + count_pattern + self.suffix)
|
pictures = glob.glob(self.basename + count_pattern + self.suffix)
|
||||||
|
# Get number of latest file
|
||||||
if len(pictures) == 0:
|
if len(pictures) == 0:
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
else:
|
else:
|
||||||
@@ -115,48 +116,59 @@ class GUI_PyGame:
|
|||||||
self.screen.blit(image, offset)
|
self.screen.blit(image, offset)
|
||||||
|
|
||||||
def show_message(self, msg):
|
def show_message(self, msg):
|
||||||
|
# Choose font
|
||||||
font = pygame.font.Font(None, 36)
|
font = pygame.font.Font(None, 36)
|
||||||
|
# Render text
|
||||||
text = font.render(msg, 1, (10, 10, 10))
|
text = font.render(msg, 1, (10, 10, 10))
|
||||||
|
# Position and display text
|
||||||
textpos = text.get_rect()
|
textpos = text.get_rect()
|
||||||
textpos.centerx = self.screen.get_rect().centerx
|
textpos.centerx = self.screen.get_rect().centerx
|
||||||
self.screen.blit(text, textpos)
|
self.screen.blit(text, textpos)
|
||||||
|
|
||||||
def mainloop(self, filename):
|
def mainloop(self, filename):
|
||||||
while True:
|
while True:
|
||||||
|
# Check for events
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT: return
|
if event.type == pygame.QUIT: return
|
||||||
elif event.type == pygame.KEYDOWN: handle_keypress(event.key)
|
elif event.type == pygame.KEYDOWN: handle_keypress(event.key)
|
||||||
|
# Clear display
|
||||||
self.clear()
|
self.clear()
|
||||||
|
# Show idle-picture and message
|
||||||
self.show_picture(filename)
|
self.show_picture(filename)
|
||||||
self.show_message("Hit me!")
|
self.show_message("Hit me!")
|
||||||
|
# Render everything
|
||||||
self.apply()
|
self.apply()
|
||||||
|
|
||||||
def teardown(self):
|
def teardown(self):
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
|
||||||
class CameraException(Exception):
|
class CameraException(Exception):
|
||||||
|
"""Custom exception class to handle gPhoto errors"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Camera:
|
class Camera:
|
||||||
"""Camera class providing functionality to take pictures"""
|
"""Camera class providing functionality to take pictures"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
# Print the abilities of the connected camera
|
||||||
try:
|
try:
|
||||||
print(self.call_gphoto("-a", "/dev/null"))
|
print(self.call_gphoto("-a", "/dev/null"))
|
||||||
except CameraException as e:
|
except CameraException as e:
|
||||||
handle_exception(e.message)
|
handle_exception(e.message)
|
||||||
|
|
||||||
def call_gphoto(self, action, filename):
|
def call_gphoto(self, action, filename):
|
||||||
|
# Try to run the command
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output("gphoto2 --force-overwrite --quiet "
|
output = subprocess.check_output("gphoto2 --force-overwrite --quiet "
|
||||||
+ action + " --filename " + filename,
|
+ action + " --filename " + filename,
|
||||||
shell=True, stderr=subprocess.STDOUT)
|
shell=True, stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise CameraException("Can't call gphoto2!")
|
raise CameraException("Can't call gphoto2!")
|
||||||
# Check for non-fatal errors
|
# Handle non-fatal errors
|
||||||
if "Canon EOS Capture failed: 2019" in output:
|
if "Canon EOS Capture failed: 2019" in output:
|
||||||
raise CameraException("Cannot focus! Move a little bit and try again!")
|
raise CameraException("Cannot focus! Move a little bit and try again!")
|
||||||
elif "ERROR" in output:
|
elif "ERROR" in output:
|
||||||
raise CameraException("Unknown error:\n" + output)
|
raise CameraException("Unknown error:\n" + output)
|
||||||
|
# Return the command line output
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def preview(self, filename="/tmp/preview.jpg"):
|
def preview(self, filename="/tmp/preview.jpg"):
|
||||||
@@ -173,34 +185,38 @@ class Camera:
|
|||||||
### Functions ###
|
### Functions ###
|
||||||
#################
|
#################
|
||||||
|
|
||||||
|
def take_picture():
|
||||||
|
display.clear()
|
||||||
|
# Show pose message
|
||||||
|
display.show_picture(image_pose)
|
||||||
|
display.show_message("POSE! Taking four pictures...");
|
||||||
|
display.apply()
|
||||||
|
time.sleep(pose_time)
|
||||||
|
# Extract display and image sizes
|
||||||
|
size = display.get_size()
|
||||||
|
image_size = (int(size[0]/2), int(size[1]/2))
|
||||||
|
# Take pictures
|
||||||
|
filenames = [i for i in range(4)]
|
||||||
|
for x in range(4):
|
||||||
|
filenames[x] = camera.take_picture(images.get_next())
|
||||||
|
# Show pictures for 10 seconds
|
||||||
|
display.clear()
|
||||||
|
display.show_picture(filenames[0], image_size, (0,0))
|
||||||
|
display.show_picture(filenames[1], image_size, (image_size[0],0))
|
||||||
|
display.show_picture(filenames[2], image_size, (0,image_size[1]))
|
||||||
|
display.show_picture(filenames[3], image_size, (image_size[0],image_size[1]))
|
||||||
|
display.apply()
|
||||||
|
time.sleep(display_time)
|
||||||
|
|
||||||
def handle_keypress(key):
|
def handle_keypress(key):
|
||||||
|
"""Implements the actions for the different keypress events"""
|
||||||
# Exit the application
|
# Exit the application
|
||||||
if key == ord('q'):
|
if key == ord('q'):
|
||||||
teardown()
|
teardown()
|
||||||
# Take pictures
|
# Take pictures
|
||||||
elif key == ord('c'):
|
elif key == ord('c'):
|
||||||
display.clear()
|
take_picture()
|
||||||
# Show pose message
|
|
||||||
display.show_picture(image_pose)
|
|
||||||
display.show_message("POSE! Taking four pictures...");
|
|
||||||
display.apply()
|
|
||||||
time.sleep(pose_time)
|
|
||||||
# Extract display and image sizes
|
|
||||||
size = display.get_size()
|
|
||||||
image_size = (int(size[0]/2), int(size[1]/2))
|
|
||||||
# Take pictures
|
|
||||||
filenames = [i for i in range(4)]
|
|
||||||
for x in range(4):
|
|
||||||
filenames[x] = camera.take_picture(images.get_next())
|
|
||||||
# Show pictures for 10 seconds
|
|
||||||
display.clear()
|
|
||||||
display.show_picture(filenames[0], image_size, (0,0))
|
|
||||||
display.show_picture(filenames[1], image_size, (image_size[0],0))
|
|
||||||
display.show_picture(filenames[2], image_size, (0,image_size[1]))
|
|
||||||
display.show_picture(filenames[3], image_size, (image_size[0],image_size[1]))
|
|
||||||
display.apply()
|
|
||||||
time.sleep(display_time)
|
|
||||||
|
|
||||||
def handle_exception(msg):
|
def handle_exception(msg):
|
||||||
display.clear()
|
display.clear()
|
||||||
display.show_message("Error: " + msg)
|
display.show_message("Error: " + msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user