From 1615f658c1433c7e7ea8bd1355043a3cac34acd9 Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Fri, 19 Oct 2018 23:37:36 +0200 Subject: [PATCH] Enclosed changes to camera settings in try-catch block. Fixes #55 --- photobooth/camera/CameraGphoto2.py | 61 +++++++++++++++----------- photobooth/camera/CameraGphoto2Cffi.py | 43 +++++++++++------- 2 files changed, 62 insertions(+), 42 deletions(-) diff --git a/photobooth/camera/CameraGphoto2.py b/photobooth/camera/CameraGphoto2.py index 71b131f..60b2add 100644 --- a/photobooth/camera/CameraGphoto2.py +++ b/photobooth/camera/CameraGphoto2.py @@ -43,11 +43,18 @@ class CameraGphoto2(CameraInterface): def cleanup(self): - config = self._cap.get_config() - config.get_child_by_name('imageformat').set_value(self._imageformat) - config.get_child_by_name('imageformatsd').set_value(self._imageformat) - # config.get_child_by_name('autopoweroff').set_value(self._autopoweroff) - self._cap.set_config(config) + try: + config = self._cap.get_config() + config.get_child_by_name('imageformat').set_value( + self._imageformat) + config.get_child_by_name('imageformatsd').set_value( + self._imageformat) + # config.get_child_by_name('autopoweroff').set_value( + # self._autopoweroff) + self._cap.set_config(config) + except BaseException as e: + logging.warn('Error while changing camera settings: {}.'.format(e)) + self._cap.exit(self._ctxt) def _setupLogging(self): @@ -64,29 +71,33 @@ class CameraGphoto2(CameraInterface): logging.info('Camera summary: %s', str(self._cap.get_summary(self._ctxt))) - # get configuration tree - config = self._cap.get_config() + try: + # get configuration tree + config = self._cap.get_config() - # make sure camera format is not set to raw - imageformat = config.get_child_by_name('imageformat') - self._imageformat = imageformat.get_value() - if 'raw' in self._imageformat.lower(): - imageformat.set_value('Large Fine JPEG') - imageformatsd = config.get_child_by_name('imageformatsd') - self._imageformatsd = imageformatsd.get_value() - if 'raw' in self._imageformatsd.lower(): - imageformatsd.set_value('Large Fine JPEG') + # make sure camera format is not set to raw + imageformat = config.get_child_by_name('imageformat') + self._imageformat = imageformat.get_value() + if 'raw' in self._imageformat.lower(): + imageformat.set_value('Large Fine JPEG') + imageformatsd = config.get_child_by_name('imageformatsd') + self._imageformatsd = imageformatsd.get_value() + if 'raw' in self._imageformatsd.lower(): + imageformatsd.set_value('Large Fine JPEG') - # make sure autopoweroff is disabled - # this doesn't seem to work - # autopoweroff = config.get_child_by_name('autopoweroff') - # self._autopoweroff = autopoweroff.get_value() - # logging.info('autopoweroff: {}'.format(self._autopoweroff)) - # if int(self._autopoweroff) > 0: - # autopoweroff.set_value('0') + # make sure autopoweroff is disabled + # this doesn't seem to work + # autopoweroff = config.get_child_by_name('autopoweroff') + # self._autopoweroff = autopoweroff.get_value() + # logging.info('autopoweroff: {}'.format(self._autopoweroff)) + # if int(self._autopoweroff) > 0: + # autopoweroff.set_value('0') + + # apply configuration and print current config + self._cap.set_config(config) + except BaseException as e: + logging.warn('Error while changing camera settings: {}.'.format(e)) - # apply configuration and print current config - self._cap.set_config(config) self._printConfig(self._cap.get_config()) @staticmethod diff --git a/photobooth/camera/CameraGphoto2Cffi.py b/photobooth/camera/CameraGphoto2Cffi.py index e33c3e7..4b9cf03 100644 --- a/photobooth/camera/CameraGphoto2Cffi.py +++ b/photobooth/camera/CameraGphoto2Cffi.py @@ -42,9 +42,14 @@ class CameraGphoto2Cffi(CameraInterface): def cleanup(self): - self._cap.config['imgsettings']['imageformat'].set(self._imgfmt) - self._cap.config['imgsettings']['imageformatsd'].set(self._imgfmtsd) - # self._cap.config['settings']['autopoweroff'].set(self._autopoweroff) + try: + self._cap.config['imgsettings']['imageformat'].set(self._imgfmt) + self._cap.config['imgsettings']['imageformatsd'].set( + self._imgfmtsd) + # self._cap.config['settings']['autopoweroff'].set( + # self._autopoweroff) + except BaseException as e: + logging.warn('Error while changing camera settings: {}.'.format(e)) def _setupCamera(self): @@ -52,21 +57,25 @@ class CameraGphoto2Cffi(CameraInterface): logging.info('Supported operations: %s', self._cap.supported_operations) - # make sure camera format is not set to raw - imgfmt = 'Large Fine JPEG' - self._imgfmt = self._cap.config['imgsettings']['imageformat'].value - if 'raw' in self._imgfmt.lower(): - self._cap.config['imgsettings']['imageformat'].set(imgfmt) - self._imgfmtsd = self._cap.config['imgsettings']['imageformatsd'].value - if 'raw' in self._imgfmtsd.lower(): - self._cap.config['imgsettings']['imageformatsd'].set(imgfmt) + try: + # make sure camera format is not set to raw + imgfmt = 'Large Fine JPEG' + self._imgfmt = self._cap.config['imgsettings']['imageformat'].value + if 'raw' in self._imgfmt.lower(): + self._cap.config['imgsettings']['imageformat'].set(imgfmt) + self._imgfmtsd = ( + self._cap.config['imgsettings']['imageformatsd'].value) + if 'raw' in self._imgfmtsd.lower(): + self._cap.config['imgsettings']['imageformatsd'].set(imgfmt) - # make sure autopoweroff is disabled - # this doesn't seem to work - # self._autopoweroff = int( - # self._cap.config['settings']['autopoweroff'].value) - # if self._autopoweroff > 0: - # self._cap.config['settings']['autopoweroff'].set("0") + # make sure autopoweroff is disabled + # this doesn't seem to work + # self._autopoweroff = int( + # self._cap.config['settings']['autopoweroff'].value) + # if self._autopoweroff > 0: + # self._cap.config['settings']['autopoweroff'].set("0") + except BaseException as e: + logging.warn('Error while changing camera settings: {}.'.format(e)) # print current config self._printConfig(self._cap.config)