config printout for gphoto bindings improved
This commit is contained in:
@@ -69,6 +69,7 @@ class Photobooth:
|
|||||||
self._gpio.setButton(trigger_pin, self.gpioTrigger)
|
self._gpio.setButton(trigger_pin, self.gpioTrigger)
|
||||||
self._gpio.setButton(exit_pin, self.gpioExit)
|
self._gpio.setButton(exit_pin, self.gpioExit)
|
||||||
else:
|
else:
|
||||||
|
logging.info('GPIO disabled')
|
||||||
self._lampOn = lambda : None
|
self._lampOn = lambda : None
|
||||||
self._lampOff = lambda : None
|
self._lampOff = lambda : None
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import gphoto2 as gp
|
|||||||
from . import Camera
|
from . import Camera
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CameraGphoto2(Camera):
|
class CameraGphoto2(Camera):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -17,8 +18,7 @@ class CameraGphoto2(Camera):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.hasPreview = True
|
self.hasPreview = True
|
||||||
self.hasIdle = False
|
self.hasIdle = True
|
||||||
self._isActive = False
|
|
||||||
|
|
||||||
logging.info('Using python-gphoto2 bindings')
|
logging.info('Using python-gphoto2 bindings')
|
||||||
|
|
||||||
@@ -28,11 +28,13 @@ class CameraGphoto2(Camera):
|
|||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
|
|
||||||
|
self._cap.set_config(self._oldconfig)
|
||||||
self._cap.exit(self._ctxt)
|
self._cap.exit(self._ctxt)
|
||||||
|
|
||||||
|
|
||||||
def _setupLogging(self):
|
def _setupLogging(self):
|
||||||
|
|
||||||
|
gp.error_severity[gp.GP_ERROR] = logging.WARNING
|
||||||
gp.check_result(gp.use_python_logging())
|
gp.check_result(gp.use_python_logging())
|
||||||
|
|
||||||
|
|
||||||
@@ -42,61 +44,78 @@ class CameraGphoto2(Camera):
|
|||||||
self._cap = gp.Camera()
|
self._cap = gp.Camera()
|
||||||
self._cap.init(self._ctxt)
|
self._cap.init(self._ctxt)
|
||||||
|
|
||||||
self._printSummary()
|
logging.info('Camera summary: %s', str(self._cap.get_summary(self._ctxt)))
|
||||||
|
|
||||||
|
|
||||||
# get configuration tree
|
# get configuration tree
|
||||||
config = gp.check_result(gp.gp_camera_get_config(self._cap))
|
self._config = self._cap.get_config()
|
||||||
|
self._oldconfig = self._config
|
||||||
|
|
||||||
# find the image format config item
|
# make sure camera format is not set to raw
|
||||||
OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat')
|
if 'raw' in self._config.get_child_by_name('imageformat').get_value().lower():
|
||||||
if OK >= gp.GP_OK:
|
raise RuntimeError('Camera file format is set to RAW')
|
||||||
# get current setting
|
|
||||||
value = gp.check_result(gp.gp_widget_get_value(image_format))
|
|
||||||
# make sure it's not raw
|
|
||||||
if 'raw' in value.lower():
|
|
||||||
raise RuntimeError('Camera file format is set to RAW')
|
|
||||||
|
|
||||||
print(config)
|
self._printConfig(self._config)
|
||||||
|
|
||||||
|
|
||||||
def _printSummary(self):
|
@staticmethod
|
||||||
|
def _configTreeToText(tree, indent=0):
|
||||||
|
|
||||||
# self.setActive()
|
config_txt = ''
|
||||||
|
|
||||||
text = self._cap.get_summary(self._ctxt)
|
for child in tree.get_children():
|
||||||
logging.info('Camera summary: %s', str(text))
|
config_txt += indent * ' '
|
||||||
|
config_txt += child.get_label() + ' [' + child.get_name() + ']: '
|
||||||
|
|
||||||
# self.setIdle()
|
if child.count_children() > 0:
|
||||||
|
config_txt += '\n'
|
||||||
|
config_txt += CameraGphoto2._configTreeToText(child, indent + 4)
|
||||||
|
else:
|
||||||
|
config_txt += str(child.get_value())
|
||||||
|
try:
|
||||||
|
choice_txt = ' ('
|
||||||
|
|
||||||
|
for c in child.get_choices():
|
||||||
|
choice_txt += c + ', '
|
||||||
|
|
||||||
|
choice_txt += ')'
|
||||||
|
config_txt += choice_txt
|
||||||
|
except gp.GPhoto2Error:
|
||||||
|
pass
|
||||||
|
config_txt += '\n'
|
||||||
|
|
||||||
|
return config_txt
|
||||||
|
|
||||||
|
|
||||||
# def setActive(self):
|
@staticmethod
|
||||||
|
def _printConfig(config):
|
||||||
# self._cap.init(self._ctxt)
|
config_txt = 'Camera configuration:\n'
|
||||||
# if not self._isActive:
|
config_txt += CameraGphoto2._configTreeToText(config)
|
||||||
# self._cap.init(self._ctxt)
|
logging.info(config_txt)
|
||||||
# self._isActive = True
|
|
||||||
|
|
||||||
|
|
||||||
# def setIdle(self):
|
def setActive(self):
|
||||||
|
|
||||||
# self._cap.exit(self._ctxt)
|
self._config.get_child_by_name('viewfinder').set_value(True)
|
||||||
# if self._isActive:
|
self._cap.set_config(self._config)
|
||||||
# self._cap.exit(self._ctxt)
|
|
||||||
# self._isActive = False
|
|
||||||
|
def setIdle(self):
|
||||||
|
|
||||||
|
self._config.get_child_by_name('viewfinder').set_value(False)
|
||||||
|
self._cap.set_config(self._config)
|
||||||
|
|
||||||
|
|
||||||
def getPreview(self):
|
def getPreview(self):
|
||||||
|
|
||||||
# self.setActive()
|
# self._config.get_child_by_name('autofocusdrive').set_value(1)
|
||||||
camera_file = self._cap.capture_preview() #gp.check_result(gp.gp_camera_capture_preview(self._cap))
|
# self._cap.set_config(self._config)
|
||||||
file_data = camera_file.get_data_and_size() # gp.check_result(gp.gp_file_get_data_and_size(camera_file))
|
camera_file = self._cap.capture_preview()
|
||||||
|
file_data = camera_file.get_data_and_size()
|
||||||
return Image.open(io.BytesIO(file_data))
|
return Image.open(io.BytesIO(file_data))
|
||||||
|
|
||||||
|
|
||||||
def getPicture(self):
|
def getPicture(self):
|
||||||
|
|
||||||
# self.setActive()
|
|
||||||
file_path = self._cap.capture(gp.GP_CAPTURE_IMAGE)
|
file_path = self._cap.capture(gp.GP_CAPTURE_IMAGE)
|
||||||
camera_file = self._cap.file_get(file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL)
|
camera_file = self._cap.file_get(file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL)
|
||||||
file_data = camera_file.get_data_and_size()
|
file_data = camera_file.get_data_and_size()
|
||||||
|
|||||||
@@ -32,6 +32,33 @@ class CameraGphoto2Cffi(Camera):
|
|||||||
if 'raw' in self._cap.config['imgsettings']['imageformat'].value.lower():
|
if 'raw' in self._cap.config['imgsettings']['imageformat'].value.lower():
|
||||||
raise RuntimeError('Camera file format is set to RAW')
|
raise RuntimeError('Camera file format is set to RAW')
|
||||||
|
|
||||||
|
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'
|
||||||
|
config_txt += CameraGphoto2Cffi._configTreeToText(config)
|
||||||
|
logging.info(config_txt)
|
||||||
|
|
||||||
|
|
||||||
def setActive(self):
|
def setActive(self):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user