def main(): # use Python logging logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) callback_obj = gp.check_result(gp.use_python_logging()) # get user value if len(sys.argv) != 2: print('One command line parameter required') return 1 try: value = int(sys.argv[1]) except: print('Integer parameter required') return 1 # open camera connection camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera)) # find the capture target config item capture_target = gp.check_result( gp.gp_widget_get_child_by_name(config, 'capturetarget')) # check value in range count = gp.check_result(gp.gp_widget_count_choices(capture_target)) if value < 0 or value >= count: print('Parameter out of range') return 1 # set value value = gp.check_result(gp.gp_widget_get_choice(capture_target, value)) gp.check_result(gp.gp_widget_set_value(capture_target, value)) # set config gp.check_result(gp.gp_camera_set_config(camera, config)) # clean up gp.check_result(gp.gp_camera_exit(camera)) return 0
def one_photo(camera, context, value, filename): # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera, context)) # find the capture target config item shutterspeed = gp.check_result( gp.gp_widget_get_child_by_name(config, 'shutterspeed')) # check value in range count = gp.check_result(gp.gp_widget_count_choices(shutterspeed)) if value < 0 or value >= count: print('Parameter out of range') return 1 # set value speedvalue = gp.check_result(gp.gp_widget_get_choice(shutterspeed, value)) gp.check_result( gp.gp_widget_set_value(shutterspeed, speedvalue) ) # set config gp.check_result(gp.gp_camera_set_config(camera, config, context)) print('Capturing image (shutterspeed=%d)' % value) file_path = gp.check_result( gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, context)) target = filename + ".jpg" camera_file = gp.check_result( gp.gp_camera_file_get(camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL, context)) gp.check_result(gp.gp_file_save(camera_file, target))
def main(): # use Python logging logging.basicConfig( format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) callback_obj = gp.check_result(gp.use_python_logging()) # get user value if len(sys.argv) != 2: print('One command line parameter required') return 1 try: value = int(sys.argv[1]) except: print('Integer parameter required') return 1 # open camera connection camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera)) # find the capture target config item capture_target = gp.check_result( gp.gp_widget_get_child_by_name(config, 'capturetarget')) # check value in range count = gp.check_result(gp.gp_widget_count_choices(capture_target)) if value < 0 or value >= count: print('Parameter out of range') return 1 # set value value = gp.check_result(gp.gp_widget_get_choice(capture_target, value)) gp.check_result(gp.gp_widget_set_value(capture_target, value)) # set config gp.check_result(gp.gp_camera_set_config(camera, config)) # clean up gp.check_result(gp.gp_camera_exit(camera)) return 0
def get_exposure_bias(self): error, bias = gp.gp_widget_get_child_by_name(self.config,'exposurecompensation') if error !=0: print(error) print('get_exposure_bias: cannot read widget!') return else: self.bias = bias error, value = gp.gp_widget_get_value(bias) if error !=0: print(error) print('get_exposure_bias: cannot read value!') return count = gp.check_result(gp.gp_widget_count_choices(self.bias)) for choice in range(count): error, test = gp.gp_widget_get_choice(self.bias, choice) if test == value: break if error !=0: print(error) print('get_exposure_bias: cannot find choice!') return return choice, value
def get_exposure_time(self): error, exptime = gp.gp_widget_get_child_by_name(self.config,'shutterspeed2') if error !=0: print(error) print('get_exposure_time: cannot read widget!') return else: self.exptime = exptime error, value = gp.gp_widget_get_value(exptime) if error !=0: print(error) print('get_exposure_time: cannot read value!') return count = gp.check_result(gp.gp_widget_count_choices(self.exptime)) for choice in range(count): error, test = gp.gp_widget_get_choice(self.exptime, choice) if test == value: break if error !=0: print(error) print('get_exposure_time: cannot find choice!') return return choice, value
def get_iso(self): error, isovalue = gp.gp_widget_get_child_by_name(self.config,'iso') if error !=0: print(error) print('get_iso: cannot read widget!') return else: self.iso = isovalue error, value = gp.gp_widget_get_value(isovalue) if error !=0: print(error) print('get_iso: cannot read value!') return count = gp.check_result(gp.gp_widget_count_choices(self.iso)) for choice in range(count): error, test = gp.gp_widget_get_choice(self.iso, choice) if test == value: break if error !=0: print(error) print('get_iso: cannot find choice!') return return choice, value
def one_photo(camera, context, value, filename): # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera, context)) # find the capture target config item shutterspeed = gp.check_result( gp.gp_widget_get_child_by_name(config, 'shutterspeed')) # check value in range count = gp.check_result(gp.gp_widget_count_choices(shutterspeed)) if value < 0 or value >= count: print('Parameter out of range') return 1 # set value speedvalue = gp.check_result(gp.gp_widget_get_choice(shutterspeed, value)) gp.check_result(gp.gp_widget_set_value(shutterspeed, speedvalue)) # set config gp.check_result(gp.gp_camera_set_config(camera, config, context)) print('Capturing image (shutterspeed=%d)' % value) file_path = gp.check_result(gp.gp_camera_capture( camera, gp.GP_CAPTURE_IMAGE, context)) target = filename+".jpg" camera_file = gp.check_result(gp.gp_camera_file_get( camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL, context)) gp.check_result(gp.gp_file_save(camera_file, target))
def __walk_config(self, widget, cfg, pname=''): child_count = gp.check_result(gp.gp_widget_count_children(widget)) for n in range(child_count): child = gp.check_result(gp.gp_widget_get_child(widget, n)) label = gp.check_result(gp.gp_widget_get_label(child)) name = gp.check_result(gp.gp_widget_get_name(child)) child_type = gp.check_result(gp.gp_widget_get_type(child)) _name = pname + '/' +name _cfg = {'_type':child_type,'_widget':child,'_label':label} if child_type != gp.GP_WIDGET_SECTION: value = gp.check_result(gp.gp_widget_get_value(child)) print label, name, value _cfg['_value'] = value if child_type == gp.GP_WIDGET_RADIO: _cfg['_choice'] = [] choice_count = gp.check_result(gp.gp_widget_count_choices(child)) for n in range(choice_count): choice = gp.check_result(gp.gp_widget_get_choice(child, n)) if choice: _cfg['_choice'].append(choice) if child_type == gp.GP_WIDGET_RANGE: lo, hi, inc = gp.check_result(gp.gp_widget_get_range(child)) _cfg['_lo'] = lo _cfg['_hi'] = hi _cfg['_inc'] = inc cfg[_name]=_cfg self.__walk_config(child,cfg,pname=_name)
def main(): # use Python logging logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) gp.check_result(gp.use_python_logging()) # open camera connection camera = gp.check_result(gp.gp_camera_new()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera, context)) # find the capture target config item capture_target = gp.check_result( gp.gp_widget_get_child_by_name(config, 'capturetarget')) # print current setting value = gp.check_result(gp.gp_widget_get_value(capture_target)) print('Current setting:', value) # print possible settings for n in range(gp.check_result( gp.gp_widget_count_choices(capture_target))): choice = gp.check_result(gp.gp_widget_get_choice(capture_target, n)) print('Choice:', n, choice) # clean up gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def _set_config_value_checked(self, name, value): value = str(value) ret = False for t in range(0, 20): try: config = gp.check_result( gp.gp_camera_get_config(self.camera, self.context)) OK, widget = gp.gp_widget_get_child_by_name(config, name) if OK >= gp.GP_OK: num = None choice_count = gp.check_result( gp.gp_widget_count_choices(widget)) logging.info("count %d", choice_count) for i in range(choice_count): vi = gp.check_result(gp.gp_widget_get_choice( widget, i)) if vi.lower() == value.lower(): num = i value = vi break try: if abs(float(vi) - float(value)) < 0.000001: value = vi num = i break except ValueError: pass try: if '/' in vi: fr = vi.split('/') fr = float(fr[0]) / float(fr[1]) if abs(fr - float(value)) < abs(fr * 0.001): value = vi num = i break except: pass if num is not None: logging.info("set %s => %s (choice %d)" % (name, value, num)) # set value gp.check_result(gp.gp_widget_set_value(widget, value)) ret = True else: logging.info("cant't set %s => %s" % (name, value)) # set config gp.check_result( gp.gp_camera_set_config(self.camera, config, self.context)) break except gp.GPhoto2Error as ex: logging.exception('failed') time.sleep(0.1) ret = False continue return ret
def set_capture_target(self, value): config = gp.check_result(gp.gp_camera_get_config(self.camera)) capture_target = gp.check_result( gp.gp_widget_get_child_by_name(config, 'capturetarget')) count = gp.check_result(gp.gp_widget_count_choices(capture_target)) if value < 0 or value >= count: print('Parameter out of range') value = 1 value = gp.check_result(gp.gp_widget_get_choice(capture_target, value)) gp.check_result(gp.gp_widget_set_value(capture_target, value)) gp.check_result(gp.gp_camera_set_config(self.camera, config)) gp.check_result(gp.gp_camera_exit(self.camera))
def get(self, config): assert count_children(config) == 0 # not sure layout = dict() options = list() value = get_value(config) layout['options'] = options layout['value'] = value choice_count = gp.check_result(gp.gp_widget_count_choices(config)) for n in range(choice_count): choice = gp.check_result(gp.gp_widget_get_choice(config, n)) if choice: options.append(choice) return layout
def getAllChoiceFromParameter(camera, parameter): config = getConfigurationOf(camera) capture_target = getPropertyIn(config, parameter) for n in range(gp.check_result( gp.gp_widget_count_choices(capture_target))): choice = gp.check_result(gp.gp_widget_get_choice(capture_target, n)) if not (cameraConfiguration.has_key(parameter)): cameraConfiguration[parameter] = {} if not (cameraTechnicalConfiguration.has_key(parameter)): cameraTechnicalConfiguration[parameter] = {} cameraConfiguration[parameter][choice] = n cameraTechnicalConfiguration[parameter][n] = choice return
def __init__(self, config_changed, config, parent=None): QtGui.QComboBox.__init__(self, parent) self.config_changed = config_changed self.config = config if gp.check_result(gp.gp_widget_get_readonly(config)): self.setDisabled(True) assert gp.check_result(gp.gp_widget_count_children(config)) == 0 value = gp.check_result(gp.gp_widget_get_value(config)) choice_count = gp.check_result(gp.gp_widget_count_choices(config)) for n in range(choice_count): choice = gp.check_result(gp.gp_widget_get_choice(config, n)) if choice: self.addItem(choice) if choice == value: self.setCurrentIndex(n) self.currentIndexChanged.connect(self.new_value)
def set_capture_target(camera, value:int): config = gp.check_result(gp.gp_camera_get_config(camera)) # find the capture target config item capture_target = gp.check_result(gp.gp_widget_get_child_by_name(config, 'capturetarget')) # check value in range count = gp.check_result(gp.gp_widget_count_choices(capture_target)) if value < 0 or value >= count: print('Parameter out of range') return 1 # set value value = gp.check_result(gp.gp_widget_get_choice(capture_target, value)) gp.check_result(gp.gp_widget_set_value(capture_target, value)) # set config gp.check_result(gp.gp_camera_set_config(camera, config)) # clean up # gp.check_result(gp.gp_camera_exit(camera)) return 0
def __init__(self, config_changed, camera_config, parent=None): QtGui.QWidget.__init__(self, parent) self.setLayout(QtGui.QFormLayout()) if gp.check_result(gp.gp_widget_get_readonly(camera_config)): self.setDisabled(True) child_count = gp.check_result( gp.gp_widget_count_children(camera_config)) if child_count < 1: return tabs = None for n in range(child_count): child = gp.check_result(gp.gp_widget_get_child(camera_config, n)) label = gp.check_result(gp.gp_widget_get_label(child)) name = gp.check_result(gp.gp_widget_get_name(child)) label = '{} ({})'.format(label, name) child_type = gp.check_result(gp.gp_widget_get_type(child)) if child_type == gp.GP_WIDGET_SECTION: if not tabs: tabs = QtGui.QTabWidget() self.layout().insertRow(0, tabs) tabs.addTab(SectionWidget(config_changed, child), label) elif child_type == gp.GP_WIDGET_TEXT: self.layout().addRow(label, TextWidget(config_changed, child)) elif child_type == gp.GP_WIDGET_RANGE: self.layout().addRow(label, RangeWidget(config_changed, child)) elif child_type == gp.GP_WIDGET_TOGGLE: self.layout().addRow(label, ToggleWidget(config_changed, child)) elif child_type == gp.GP_WIDGET_RADIO: choice_count = gp.check_result( gp.gp_widget_count_choices(child)) if choice_count > 3: widget = MenuWidget(config_changed, child) else: widget = RadioWidget(config_changed, child) self.layout().addRow(label, widget) elif child_type == gp.GP_WIDGET_MENU: self.layout().addRow(label, MenuWidget(config_changed, child)) elif child_type == gp.GP_WIDGET_DATE: self.layout().addRow(label, DateWidget(config_changed, child)) else: print('Cannot make widget type %d for %s' % (child_type, label))
def set_config_value_checked(self, name, value): value = str(value) ret = False for t in range(0, 20): try: config = gp.check_result(gp.gp_camera_get_config(self.camera, self.context)) OK, widget = gp.gp_widget_get_child_by_name(config, name) if OK >= gp.GP_OK: num = None choice_count = gp.check_result(gp.gp_widget_count_choices(widget)) print "count", choice_count for i in range(choice_count): vi = gp.check_result(gp.gp_widget_get_choice(widget, i)) if vi.lower() == value.lower(): num = i value = vi break try: if abs(float(vi) - float(value)) < 0.000001: value = vi num = i break except ValueError: pass if num is not None: print "set %s => %s (choice %d)" % (name, value, num) # set value gp.check_result(gp.gp_widget_set_value(widget, value)) ret = True else: print "cant't set %s => %s" % (name, value) # set config gp.check_result(gp.gp_camera_set_config(self.camera, config, self.context)) break except gp.GPhoto2Error as ex: print ex.code time.sleep(0.1) ret = False continue return ret
def __init__(self, config_changed, config, parent=None): QtGui.QWidget.__init__(self, parent) self.config_changed = config_changed self.config = config if gp.check_result(gp.gp_widget_get_readonly(config)): self.setDisabled(True) assert gp.check_result(gp.gp_widget_count_children(config)) == 0 self.setLayout(QtGui.QHBoxLayout()) value = gp.check_result(gp.gp_widget_get_value(config)) choice_count = gp.check_result(gp.gp_widget_count_choices(config)) self.buttons = [] for n in range(choice_count): choice = gp.check_result(gp.gp_widget_get_choice(config, n)) if choice: button = QtGui.QRadioButton(choice) self.layout().addWidget(button) if choice == value: button.setChecked(True) self.buttons.append((button, choice)) button.clicked.connect(self.new_value)
def __init__(self, config_changed, camera_config, parent=None): QtGui.QWidget.__init__(self, parent) self.setLayout(QtGui.QFormLayout()) if gp.check_result(gp.gp_widget_get_readonly(camera_config)): self.setDisabled(True) child_count = gp.check_result(gp.gp_widget_count_children(camera_config)) if child_count < 1: return tabs = None for n in range(child_count): child = gp.check_result(gp.gp_widget_get_child(camera_config, n)) label = gp.check_result(gp.gp_widget_get_label(child)) name = gp.check_result(gp.gp_widget_get_name(child)) label = '{} ({})'.format(label, name) child_type = gp.check_result(gp.gp_widget_get_type(child)) if child_type == gp.GP_WIDGET_SECTION: if not tabs: tabs = QtGui.QTabWidget() self.layout().insertRow(0, tabs) tabs.addTab(SectionWidget(config_changed, child), label) elif child_type == gp.GP_WIDGET_TEXT: self.layout().addRow(label, TextWidget(config_changed, child)) elif child_type == gp.GP_WIDGET_RANGE: self.layout().addRow(label, RangeWidget(config_changed, child)) elif child_type == gp.GP_WIDGET_TOGGLE: self.layout().addRow(label, ToggleWidget(config_changed, child)) elif child_type == gp.GP_WIDGET_RADIO: choice_count = gp.check_result(gp.gp_widget_count_choices( child)) if choice_count > 3: widget = MenuWidget(config_changed, child) else: widget = RadioWidget(config_changed, child) self.layout().addRow(label, widget) elif child_type == gp.GP_WIDGET_MENU: self.layout().addRow(label, MenuWidget(config_changed, child)) elif child_type == gp.GP_WIDGET_DATE: self.layout().addRow(label, DateWidget(config_changed, child)) else: print('Cannot make widget type %d for %s' % (child_type, label))
def main(): # use Python logging logging.basicConfig( format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) callback_obj = gp.check_result(gp.use_python_logging()) # open camera connection camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera)) # find the capture target config item capture_target = gp.check_result( gp.gp_widget_get_child_by_name(config, 'capturetarget')) # print current setting value = gp.check_result(gp.gp_widget_get_value(capture_target)) print('Current setting:', value) # print possible settings for n in range(gp.check_result(gp.gp_widget_count_choices(capture_target))): choice = gp.check_result(gp.gp_widget_get_choice(capture_target, n)) print('Choice:', n, choice) # clean up gp.check_result(gp.gp_camera_exit(camera)) return 0
def set_iso(self,choice): count = gp.check_result(gp.gp_widget_count_choices(self.iso)) if choice < 0 or choice > count-1: print('choice max is:',count) print('set_iso: choice out of range!') return error, value = gp.gp_widget_get_choice(self.iso, choice) error = gp.gp_widget_set_value(self.iso,value) if error !=0: print('set_iso: cannot set value!') error = gp.gp_camera_set_config(self.camera, self.config, self.context) if error !=0: print('set_iso: cannot push config!') return value
def set_config(config, parameters, parameter, field_name, error_message): try: node = gp.check_result( gp.gp_widget_get_child_by_name(config, parameter)) except: msg = 'Specified parameter not found in camera: ' msg += '{0}'.format(parameter) raise ValueError(msg) choices = ['implicit auto', 'auto'] for idx in range(gp.gp_widget_count_choices(node)): choice = gp.check_result(gp.gp_widget_get_choice(node, idx)) choices.append(choice) if parameters[field_name] in choices: try: node.set_value(parameters[field_name]) parameters['connection'].set_config(config) except: msg = 'A problem occurred when setting camera configuration: ' msg += '{0}'.format(parameter) raise RuntimeError(msg) else: raise ValueError(error_message)
def getConfig(child): global config_all new_object = {} label = gp.check_result(gp.gp_widget_get_label(child)) name = gp.check_result(gp.gp_widget_get_name(child)) label = '{} ({})'.format(label, name) new_object['name'] = name new_object['label'] = label config_all[name] = child child_type = gp.check_result(gp.gp_widget_get_type(child)) if child_type == gp.GP_WIDGET_SECTION: new_object['type'] = "SECTION" new_object['children'] = [] child_count = gp.check_result(gp.gp_widget_count_children(child)) for n in range(child_count): grand_child = gp.check_result(gp.gp_widget_get_child(child, n)) new_object['children'].append(getConfig(grand_child)) elif child_type == gp.GP_WIDGET_TEXT: new_object['type'] = "TEXT" if gp.check_result(gp.gp_widget_get_readonly(child)): new_object['disabled'] = True value = gp.check_result(gp.gp_widget_get_value(child)) new_object['value'] = value elif child_type == gp.GP_WIDGET_RANGE: new_object['type'] = "RANGE" if gp.check_result(gp.gp_widget_get_readonly(child)): new_object['disabled'] = True value = gp.check_result(gp.gp_widget_get_value(child)) new_object['value'] = value lo, hi, inc = gp.check_result(gp.gp_widget_get_range(child)) new_object['low'] = lo new_object['high'] = hi new_object['increment'] = inc elif child_type == gp.GP_WIDGET_TOGGLE: new_object['type'] = "TOGGLE" if gp.check_result(gp.gp_widget_get_readonly(child)): new_object['disabled'] = True value = gp.check_result(gp.gp_widget_get_value(child)) new_object['value'] = value elif child_type == gp.GP_WIDGET_RADIO: new_object['type'] = "RADIO" if gp.check_result(gp.gp_widget_get_readonly(child)): new_object['disabled'] = True value = gp.check_result(gp.gp_widget_get_value(child)) new_object['value'] = value choice_count = gp.check_result(gp.gp_widget_count_choices(child)) new_object['choices'] = [] for j in range(choice_count): choice = gp.check_result(gp.gp_widget_get_choice(child, j)) if choice: new_object['choices'].append(choice) elif child_type == gp.GP_WIDGET_MENU: new_object['type'] = "MENU" if gp.check_result(gp.gp_widget_get_readonly(child)): new_object['disabled'] = True elif child_type == gp.GP_WIDGET_DATE: new_object['type'] = "DATE" if gp.check_result(gp.gp_widget_get_readonly(child)): new_object['disabled'] = True value = gp.check_result(gp.gp_widget_get_value(child)) new_object['value'] = value else: print('Cannot make widget type %d for %s' % (child_type, label)) return new_object
def initCamera(camera, context): # Globals to take the modifs into account in other parts # Needed to modify global copy of camera and context variables #global camera, context # Detects the camera X times tryouts = 10 for x in range(1, tryouts + 1): error = gp.gp_camera_init(camera, context) if error >= gp.GP_OK: # Camera detected, get the model logging.info("Camera detected") break elif error == gp.GP_ERROR_MODEL_NOT_FOUND: # no camera, try again in 2 seconds logging.error("Camera not found (" + str(x) + "/" + str(tryouts) + "), trying again in 5s...") time.sleep(5) else: # some other error we can't handle here raise gp.GPhoto2Error(error) logging.error("Gphoto2 error : " + error) break # Check if all tryouts have run if x == tryouts: logging.critical("Camera not found. Aborting initilization.") return False # Get configuration tree cameraConfig = gp.check_result(gp.gp_camera_get_config(camera)) ######### # Get Camera model cameraNameWidget = gp.check_result( gp.gp_widget_get_child_by_name(cameraConfig, 'model')) cameraName = "" cameraName = gp.check_result( gp.gp_widget_get_value(cameraNameWidget)) #, cameraName)) logging.info("Camera model : %s" % cameraName) ######### # Find the capture target config item captureTarget = gp.check_result( gp.gp_widget_get_child_by_name(cameraConfig, 'capturetarget')) value = 1 # 0 is for internal memory, 1 is for SD card # Check value in range count = gp.check_result(gp.gp_widget_count_choices(captureTarget)) if value < 0 or value >= count: logging.error('Parameter out of range') return False # set value value = gp.check_result(gp.gp_widget_get_choice(captureTarget, value)) gp.check_result(gp.gp_widget_set_value(captureTarget, value)) # # set config # gp.check_result(gp.gp_camera_set_config(camera, cameraConfig)) ######### # Set the autofocusdrive # Find the capture target config item autoFocusDrive = gp.check_result( gp.gp_widget_get_child_by_name(cameraConfig, 'autofocusdrive')) autofocus = 1 # 1 is to trigger the AF drive # set value gp.check_result(gp.gp_widget_set_value(autoFocusDrive, autofocus))
camera = gp.Camera() camera.init() config = camera.get_config() for item in items: msg = separator msg += '\n' try: node = gp.check_result(gp.gp_widget_get_child_by_name(config, item)) msg += 'Label: {0}'.format(node.get_label()) msg += '\n' msg += 'Item: {0}'.format(item) msg += '\n' msg += separator msg += '\n' for idx in range(gp.gp_widget_count_choices(node)): choice = gp.check_result(gp.gp_widget_get_choice(node, idx)) msg += '{0}'.format(choice) msg += '\n' except: msg += 'Label: n/a' msg += '\n' msg += 'Item: {0} ***** NOT FOUND ON THIS CAMERA *****'.format(item) msg += '\n' msg += separator msg += '\n' msg += '\n' sys.stdout.write(msg) sys.stdout.flush()
def main(): # use Python logging #logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) #gp.check_result(gp.use_python_logging()) # open camera connection camera = gp.check_result(gp.gp_camera_new()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) # valIso = 1 # 1=100, 25=25600 valImageformat = 32 # 32=RAW, 33=mRAW, 34=sRAW valWhitebalance = 1 # 1=Natural valShutterspeed = 20 # 15=1s valAperture = 0 # 0=min valCapturetarget = 1 # 1=Carte memoire # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera, context)) # find the capture target config item iso = gp.check_result(gp.gp_widget_get_child_by_name(config, 'iso')) imageformat = gp.check_result( gp.gp_widget_get_child_by_name(config, 'imageformat')) whitebalance = gp.check_result( gp.gp_widget_get_child_by_name(config, 'whitebalance')) shutterspeed = gp.check_result( gp.gp_widget_get_child_by_name(config, 'shutterspeed')) aperture = gp.check_result( gp.gp_widget_get_child_by_name(config, 'aperture')) capturetarget = gp.check_result( gp.gp_widget_get_child_by_name(config, 'capturetarget')) # Print Info print(">>>> Vitesse {} Ouverture {} ISO {} ".format( shutterspeed, aperture, iso)) print(">>>> Balance {} Format {} Destination {} ".format( whitebalance, imageformat, capturetarget)) # check value in range count = gp.check_result(gp.gp_widget_count_choices(iso)) if valIso < 0 or valIso >= count: print('Parameter out of range') return 1 # set value valIso = gp.check_result(gp.gp_widget_get_choice(iso, valIso)) gp.check_result(gp.gp_widget_set_value(iso, valIso)) valImageformat = gp.check_result( gp.gp_widget_get_choice(imageformat, valImageformat)) gp.check_result(gp.gp_widget_set_value(imageformat, valImageformat)) valWhitebalance = gp.check_result( gp.gp_widget_get_choice(whitebalance, valWhitebalance)) gp.check_result(gp.gp_widget_set_value(whitebalance, valWhitebalance)) valShutterspeed = gp.check_result( gp.gp_widget_get_choice(shutterspeed, valShutterspeed)) gp.check_result(gp.gp_widget_set_value(shutterspeed, valShutterspeed)) valAperture = gp.check_result( gp.gp_widget_get_choice(aperture, valAperture)) gp.check_result(gp.gp_widget_set_value(aperture, valAperture)) valCapturetarget = gp.check_result( gp.gp_widget_get_choice(capturetarget, valCapturetarget)) gp.check_result(gp.gp_widget_set_value(capturetarget, valCapturetarget)) # set config gp.check_result(gp.gp_camera_set_config(camera, config, context)) # Shoot capture = gp.check_result(gp.gp_camera_capture(camera, 0, context)) # Print Info print(capture.name) print(valAperture, valShutterspeed, valIso, valImageformat, valWhitebalance, valCapturetarget) # clean up gp.check_result(gp.gp_camera_exit(camera, context)) return 0