# Path: photobooth/camera/CameraInterface.py
# class CameraInterface:
# 
#     def __init__(self):
# 
#         self.hasPreview = False
#         self.hasIdle = False
#         self._initConfig()
# 
#     def __enter__(self):
# 
#         return self
# 
#     def __exit__(self, exc_type, exc_value, traceback):
# 
#         self.cleanup()
# 
#     def cleanup(self):
# 
#         pass
# 
#     @property
#     def hasPreview(self):
# 
#         return self._has_preview
# 
#     @hasPreview.setter
#     def hasPreview(self, value):
# 
#         if not isinstance(value, bool):
#             raise ValueError('Expected bool')
# 
#         self._has_preview = value
# 
#     @property
#     def hasIdle(self):
# 
#         return self._has_idle
# 
#     @hasIdle.setter
#     def hasIdle(self, value):
# 
#         if not isinstance(value, bool):
#             raise ValueError('Expected bool')
# 
#         self._has_idle = value
# 
#     @property
#     def config(self):
#         return self._cfg
# 
#     def setActive(self):
# 
#         if not self.hasIdle:
#             pass
#         else:
#             raise NotImplementedError()
# 
#     def setIdle(self):
# 
#         if not self.hasIdle:
#             raise RuntimeError('Camera does not have idle functionality')
# 
#         raise NotImplementedError()
# 
#     def getPreview(self):
# 
#         if not self.hasPreview:
#             raise RuntimeError('Camera does not have preview functionality')
# 
#         raise NotImplementedError()
# 
#     def getPicture(self):
# 
#         raise NotImplementedError()
# 
#     def _initConfig(self):
# 
#         self._cfg = configparser.ConfigParser(interpolation=None)
#         filename = os.path.join(os.path.dirname(__file__), 'models',
#                                 'defaults.cfg')
#         self._cfg.read(filename)
# 
#     def loadConfig(self, model):
# 
#         name = ''.join(c for c in model.lower() if c.isalnum()) + '.cfg'
#         filename = os.path.join(os.path.dirname(__file__), 'models', name)
#         logging.info('Loading camera config "{}"'.format(name))
#         self._cfg.read(filename)


import io
import logging
import gphoto2cffi as gp
from PIL import Image
from .CameraInterface import CameraInterface
            # 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)

    @staticmethod
    def _configTreeToText(config, indent=0):

        config_txt = ''

        for k, v in config.items():
            config_txt += indent * ' '
            config_txt += k + ': '

            if hasattr(v, '__len__') and len(v) > 1:
                config_txt += '\n'
                config_txt += CameraGphoto2Cffi._configTreeToText(v,
                                                                  indent + 4)
            else:
                config_txt += str(v) + '\n'

        return config_txt

    @staticmethod
    def _printConfig(config):

# Path: photobooth/camera/CameraInterface.py
# class CameraInterface:
# 
#     def __init__(self):
# 
#         self.hasPreview = False
#         self.hasIdle = False
#         self._initConfig()
# 
#     def __enter__(self):
# 
#         return self
# 
#     def __exit__(self, exc_type, exc_value, traceback):
# 
#         self.cleanup()
# 
#     def cleanup(self):
# 
#         pass
# 
#     @property
#     def hasPreview(self):
# 
#         return self._has_preview
# 
#     @hasPreview.setter
#     def hasPreview(self, value):
# 
#         if not isinstance(value, bool):
#             raise ValueError('Expected bool')
# 
#         self._has_preview = value
# 
#     @property
#     def hasIdle(self):
# 
#         return self._has_idle
# 
#     @hasIdle.setter
#     def hasIdle(self, value):
# 
#         if not isinstance(value, bool):
#             raise ValueError('Expected bool')
# 
#         self._has_idle = value
# 
#     @property
#     def config(self):
#         return self._cfg
# 
#     def setActive(self):
# 
#         if not self.hasIdle:
#             pass
#         else:
#             raise NotImplementedError()
# 
#     def setIdle(self):
# 
#         if not self.hasIdle:
#             raise RuntimeError('Camera does not have idle functionality')
# 
#         raise NotImplementedError()
# 
#     def getPreview(self):
# 
#         if not self.hasPreview:
#             raise RuntimeError('Camera does not have preview functionality')
# 
#         raise NotImplementedError()
# 
#     def getPicture(self):
# 
#         raise NotImplementedError()
# 
#     def _initConfig(self):
# 
#         self._cfg = configparser.ConfigParser(interpolation=None)
#         filename = os.path.join(os.path.dirname(__file__), 'models',
#                                 'defaults.cfg')
#         self._cfg.read(filename)
# 
#     def loadConfig(self, model):
# 
#         name = ''.join(c for c in model.lower() if c.isalnum()) + '.cfg'
#         filename = os.path.join(os.path.dirname(__file__), 'models', name)
#         logging.info('Loading camera config "{}"'.format(name))
#         self._cfg.read(filename)


# Path: photobooth/camera/CameraGphoto2Cffi.py
import io
import logging
import gphoto2cffi as gp
from PIL import Image
from .CameraInterface import CameraInterface

            # 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)

    @staticmethod
    def _configTreeToText(config, indent=0):

        config_txt = ''

        for k, v in config.items():
            config_txt += indent * ' '
            config_txt += k + ': '

            if hasattr(v, '__len__') and len(v) > 1:
                config_txt += '\n'
                config_txt += CameraGphoto2Cffi._configTreeToText(v,
                                                                  indent + 4)
            else:
                config_txt += str(v) + '\n'

        return config_txt

    @staticmethod
    def _printConfig(config):

        config_txt = 'Camera configuration:\n'