From c906ff5ecbccc2f8b803b1b363e4d1727cdf4a88 Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Tue, 3 Jul 2018 23:45:59 +0200 Subject: [PATCH] Added functionality to switch automatically to JPEG Fine and restore the original setting on teardown. This closes #10 --- photobooth/Photobooth.py | 1 + photobooth/camera/CameraGphoto2.py | 33 +++++++++++++++++++------- photobooth/camera/CameraGphoto2Cffi.py | 23 +++++++++++++++--- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/photobooth/Photobooth.py b/photobooth/Photobooth.py index 3545f97..5f53478 100644 --- a/photobooth/Photobooth.py +++ b/photobooth/Photobooth.py @@ -92,6 +92,7 @@ class Photobooth: logging.info('Teardown of camera') self.triggerOff() self.setCameraIdle() + self._cap.cleanup() def recvEvent(self, expected): diff --git a/photobooth/camera/CameraGphoto2.py b/photobooth/camera/CameraGphoto2.py index c13bb91..1d95039 100644 --- a/photobooth/camera/CameraGphoto2.py +++ b/photobooth/camera/CameraGphoto2.py @@ -43,12 +43,16 @@ class CameraGphoto2(Camera): def cleanup(self): - self._cap.set_config(self._oldconfig) + 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) self._cap.exit(self._ctxt) def _setupLogging(self): - gp.error_severity[gp.GP_ERROR] = logging.WARNING + gp.error_severity[gp.GP_ERROR] = logging.ERROR gp.check_result(gp.use_python_logging()) def _setupCamera(self): @@ -61,16 +65,29 @@ class CameraGphoto2(Camera): str(self._cap.get_summary(self._ctxt))) # get configuration tree - # self._config = self._cap.get_config() - # self._oldconfig = self._config config = self._cap.get_config() # make sure camera format is not set to raw - imageformat = config.get_child_by_name('imageformat').get_value() - if 'raw' in imageformat.lower(): - raise RuntimeError('Camera file format is 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') - self._printConfig(config) + # 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) + self._printConfig(self._cap.get_config()) @staticmethod def _configTreeToText(tree, indent=0): diff --git a/photobooth/camera/CameraGphoto2Cffi.py b/photobooth/camera/CameraGphoto2Cffi.py index 2978fb8..a00d713 100644 --- a/photobooth/camera/CameraGphoto2Cffi.py +++ b/photobooth/camera/CameraGphoto2Cffi.py @@ -40,16 +40,33 @@ class CameraGphoto2Cffi(Camera): self._setupCamera() + def cleanup(self): + + self._cap.config['imgsettings']['imageformat'].set(self._imageformat) + self._cap.config['imgsettings']['imageformatsd'].set(self._imageformatsd) + # self._cap.config['settings']['autopoweroff'].set(self._autopoweroff) + def _setupCamera(self): self._cap = gp.Camera() logging.info('Supported operations: %s', self._cap.supported_operations) - imageformat = self._cap.config['imgsettings']['imageformat'].value - if 'raw' in imageformat.lower(): - raise RuntimeError('Camera file format is set to RAW') + # make sure camera format is not set to raw + self._imageformat = self._cap.config['imgsettings']['imageformat'].value + if 'raw' in self._imageformat.lower(): + self._cap.config['imgsettings']['imageformat'].set('Large Fine JPEG') + self._imageformatsd = self._cap.config['imgsettings']['imageformatsd'].value + if 'raw' in self._imageformatsd.lower(): + self._cap.config['imgsettings']['imageformatsd'].set('Large Fine JPEG') + # 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") + + # print current config self._printConfig(self._cap.config) @staticmethod