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)) 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: self.layout().addRow(label, RadioWidget(config_changed, child)) 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 __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: self.layout().addRow(label, RadioWidget(config_changed, child)) 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 change_iso_setting(self): camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) camera_config = gp.check_result(gp.gp_camera_get_config(camera)) for child in gp.check_result(gp.gp_widget_get_children(camera_config)): print(gp.check_result(gp.gp_widget_get_label(child))) gp.check_result(gp.gp_camera_exit(camera))
def get(self, config): parent_options = dict() child_count = gp.check_result(gp.gp_widget_count_children(config)) if child_count < 1: return parent_options for child in gp.check_result(gp.gp_widget_get_children(config)): 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)) try: handler_class = handlers[child_type] except KeyError: print('Cannot make widget type %d for %s' % (child_type, label)) child_options = dict() else: handler = handler_class() child_options = handler.get(child) finally: child_options['prototype'] = child_type child_options['label'] = label child_options['name'] = name parent_options[name] = child_options return parent_options
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 test_camera(): global camera, context, config, camera_config_name, camera_config print("Testing Camera") logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) gp.check_result(gp.use_python_logging()) context = gp.gp_context_new() camera_list = [] for name, addr in context.camera_autodetect(): camera_list.append((name, addr)) if not camera_list: print('No camera detected') return 1 camera_list.sort(key=lambda x: x[0]) name, addr = camera_list[0] camera = gp.Camera() #camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera, context)) config = gp.check_result(gp.gp_camera_get_config(camera, context)) text = gp.check_result(gp.gp_camera_get_summary(camera, context)) print('Summary') print('=======') print(text.text) print('Abilities') print('=========') abilities = gp.check_result(gp.gp_camera_get_abilities(camera)) print('model:', abilities.model) print('status:', abilities.status) print('port:', abilities.port) print('speed:', abilities.speed) print('operations:', abilities.operations) print('file_operations:', abilities.file_operations) print('folder_operations:', abilities.folder_operations) print('usb_vendor:', abilities.usb_vendor) print('usb_product:', abilities.usb_product) print('usb_class:', abilities.usb_class) print('usb_subclass:', abilities.usb_subclass) print('usb_protocol:', abilities.usb_protocol) print('library:', abilities.library) print('id:', abilities.id) print('device_type:', abilities.device_type) child_count = gp.check_result(gp.gp_widget_count_children(config)) if child_count < 1: return tabs = None for n in range(child_count): child = gp.check_result(gp.gp_widget_get_child(config, n)) camera_config.append(getConfig(child)) label = gp.check_result(gp.gp_widget_get_label(child)) camera_config_name.append(label) print('!!!!!!! CONFIG ', child, label) name = gp.check_result(gp.gp_widget_get_name(child)) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def initialise(self): # get camera config tree self.camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(self.camera)) self.camera_config = gp.check_result( gp.gp_camera_get_config(self.camera)) # create corresponding tree of tab widgets self.setWindowTitle( gp.check_result(gp.gp_widget_get_label(self.camera_config))) self.centralWidget().layout().addWidget( SectionWidget(self.config_changed, self.camera_config), 0, 0, 1, 3)
def initialise(self): # get camera config tree self.camera = gp.check_result(gp.gp_camera_new()) self.context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(self.camera, self.context)) self.camera_config = gp.check_result( gp.gp_camera_get_config(self.camera, self.context)) # create corresponding tree of tab widgets self.setWindowTitle( gp.check_result(gp.gp_widget_get_label(self.camera_config))) self.centralWidget().layout().addWidget(SectionWidget( self.config_changed, self.camera_config), 0, 0, 1, 3)
def initialise(self): # get camera config tree self.camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(self.camera)) self.camera_config = gp.check_result( gp.gp_camera_get_config(self.camera)) # create corresponding tree of tab widgets self.setWindowTitle( gp.check_result(gp.gp_widget_get_label(self.camera_config))) top_widget = SectionWidget(self.config_changed, self.camera_config) scroll_area = QtWidgets.QScrollArea() scroll_area.setWidget(top_widget) scroll_area.setWidgetResizable(True) self.centralWidget().layout().addWidget(scroll_area, 0, 0, 1, 3)
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