Skip to content

Commit

Permalink
retry on capture error
Browse files Browse the repository at this point in the history
  • Loading branch information
patkan committed Aug 14, 2023
1 parent 5dcb247 commit 94c5ca1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
17 changes: 15 additions & 2 deletions photobooth/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def startup(self):
)
)

test_picture = self._cap.getPicture()
test_picture = self._getPicture()
if self._rotation is not None:
test_picture = test_picture.transpose(self._rotation)

Expand Down Expand Up @@ -162,9 +162,22 @@ def capturePreview(self):
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(f"Error on capture #{tries} ErrorCode: {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 @@ -74,6 +74,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 = 1

[Picture]
# Number of pictures in horizontal direction
Expand Down
11 changes: 11 additions & 0 deletions photobooth/gui/Qt5Gui/Frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,19 @@ def createPhotoboothSettings(self):
)
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 @@ -1187,6 +1193,11 @@ def storeConfigAndRestart(self):
"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",
Expand Down

0 comments on commit 94c5ca1

Please sign in to comment.