From 7df2fd66c39ace2004c89f3e381c189355d1e8ad Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Sat, 12 Jan 2019 21:31:34 +0100 Subject: [PATCH] Enclosed config changes in setActive/setIdle in try-catch-blocks to avoid crashes with Nikon cameras (fixes #55) --- photobooth/camera/CameraGphoto2.py | 18 ++++++++++++------ photobooth/camera/CameraGphoto2Cffi.py | 14 ++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/photobooth/camera/CameraGphoto2.py b/photobooth/camera/CameraGphoto2.py index 60b2add..0661db0 100644 --- a/photobooth/camera/CameraGphoto2.py +++ b/photobooth/camera/CameraGphoto2.py @@ -136,15 +136,21 @@ class CameraGphoto2(CameraInterface): def setActive(self): - config = self._cap.get_config() - config.get_child_by_name('output').set_value('PC') - self._cap.set_config(config) + try: + config = self._cap.get_config() + config.get_child_by_name('output').set_value('PC') + self._cap.set_config(config) + except BaseException as e: + logging.warn('Error while setting camera output to active: {}.'.format(e)) def setIdle(self): - config = self._cap.get_config() - config.get_child_by_name('output').set_value('Off') - self._cap.set_config(config) + try: + config = self._cap.get_config() + config.get_child_by_name('output').set_value('Off') + self._cap.set_config(config) + except BaseException as e: + logging.warn('Error while setting camera output to idle: {}.'.format(e)) def getPreview(self): diff --git a/photobooth/camera/CameraGphoto2Cffi.py b/photobooth/camera/CameraGphoto2Cffi.py index 4b9cf03..c4a7b47 100644 --- a/photobooth/camera/CameraGphoto2Cffi.py +++ b/photobooth/camera/CameraGphoto2Cffi.py @@ -106,13 +106,19 @@ class CameraGphoto2Cffi(CameraInterface): def setActive(self): - self._cap._get_config()['actions']['viewfinder'].set(True) - self._cap._get_config()['settings']['output'].set('PC') + try: + self._cap._get_config()['actions']['viewfinder'].set(True) + self._cap._get_config()['settings']['output'].set('PC') + except BaseException as e: + logging.warn('Error while setting camera output to active: {}.'.format(e)) def setIdle(self): - self._cap._get_config()['actions']['viewfinder'].set(False) - self._cap._get_config()['settings']['output'].set('Off') + try: + self._cap._get_config()['actions']['viewfinder'].set(False) + self._cap._get_config()['settings']['output'].set('Off') + except BaseException as e: + logging.warn('Error while setting camera output to idle: {}.'.format(e)) def getPreview(self):