Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry image capture on error, allow configuration #237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion photobooth/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,23 @@ def capturePreview(self):
self._comm.send(Workers.GUI,
StateMachine.CameraEvent('preview', byte_data))

def _getPicture(self):
tries = 0
max_retries = self._cfg.getInt('Photobooth', 'capture_error_retry')
while True:
try:
return self._cap.getPicture()
except BaseException as e:
if tries < max_retries:
logging.warn(('CameraGphoto2: Error on capture #{} ErrorCode: {}').format(tries, str(e)))
tries += 1
else:
raise e

def capturePicture(self, state):

self.setIdle()
picture = self._cap.getPicture()
picture = self._getPicture()
if self._rotation is not None:
picture = picture.transpose(self._rotation)
byte_data = BytesIO()
Expand Down
2 changes: 2 additions & 0 deletions photobooth/defaults.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ display_time = 5
postprocess_time = 60
# Overwrite displayed error message (Leave empty for none)
overwrite_error_message =
# Number of retries on capture error
capture_error_retry = 0

[Picture]
# Number of pictures in horizontal direction
Expand Down
9 changes: 9 additions & 0 deletions photobooth/gui/Qt5Gui/Frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,20 @@ def createPhotoboothSettings(self):
self._cfg.get('Photobooth', 'overwrite_error_message'))
self.add('Photobooth', 'overwrite_error_message', err_msg)

capture_retry = QtWidgets.QSpinBox()
capture_retry.setRange(0,10)
capture_retry.setValue(self._cfg.getInt('Photobooth',
'capture_error_retry'))
self.add('Photobooth', 'capture_error_retry', capture_retry)

layout = QtWidgets.QFormLayout()
layout.addRow(_('Show preview during countdown:'), preview)
layout.addRow(_('Greeter time before countdown [s]:'), greet_time)
layout.addRow(_('Countdown time [s]:'), count_time)
layout.addRow(_('Picture display time [s]:'), displ_time)
layout.addRow(_('Postprocess timeout [s]:'), postproc_time)
layout.addRow(_('Overwrite displayed error message:'), err_msg)
layout.addRow(_('Retries on capture error:'), capture_retry)

widget = QtWidgets.QWidget()
widget.setLayout(layout)
Expand Down Expand Up @@ -991,6 +998,8 @@ def storeConfigAndRestart(self):
str(self.get('Photobooth', 'postprocess_time').text()))
self._cfg.set('Photobooth', 'overwrite_error_message',
self.get('Photobooth', 'overwrite_error_message').text())
self._cfg.set('Photobooth', 'capture_error_retry',
self.get('Photobooth', 'capture_error_retry').text())

self._cfg.set('Camera', 'module',
camera.modules[self.get('Camera',
Expand Down