def __init__(self): print "init AstroCamCanon" gp.check_result(gp.use_python_logging()) self.context = gp.gp_context_new() self.camera = gp.check_result(gp.gp_camera_new()) print "config" camera_config = gp.check_result(gp.gp_camera_get_config(self.camera, self.context)) child_count = gp.check_result(gp.gp_widget_count_children(camera_config)) print child_count for n in range(child_count): try: print "============" child = gp.check_result(gp.gp_widget_get_child(camera_config, n)) name = gp.check_result(gp.gp_widget_get_name(child)) print name chtype = gp.check_result(gp.gp_widget_get_type(child)) print chtype ro = gp.check_result(gp.gp_widget_get_readonly(child)) print ro cdildcen = gp.check_result(gp.gp_widget_count_children(child)) print cdildcen except Exception, e: print e
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 __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 set(self, config, value): child_count = gp.check_result(gp.gp_widget_count_children(config)) if child_count < 1: return for child in gp.check_result(gp.gp_widget_get_children(config)): name = gp.check_result(gp.gp_widget_get_name(child)) child_type = gp.check_result(gp.gp_widget_get_type(child)) # do we have a config to change? try: child_value = value[name] except KeyError: pass else: # yes, let's change it try: handler_class = handlers[child_type] except KeyError: pass else: handler = handler_class() try: handler.set(child, child_value) except NotImplementedError: pass
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 __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 __init__(self, config_changed, config, parent=None): QtGui.QCheckBox.__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)) self.setChecked(value != 0) self.clicked.connect(self.new_value)
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 __init__(self, config_changed, config, parent=None): QtGui.QLineEdit.__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)) if value: self.setText(value) self.editingFinished.connect(self.new_value)
def __init__(self, config_changed, config, parent=None): QtGui.QDateTimeEdit.__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)) if value: self.setDateTime(datetime.fromtimestamp(value)) self.dateTimeChanged.connect(self.new_value) self.setDisplayFormat('yyyy-MM-dd hh:mm:ss')
def __init__(self, config_changed, config, parent=None): QtGui.QSlider.__init__(self, Qt.Horizontal, 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 lo, hi, self.inc = gp.check_result(gp.gp_widget_get_range(config)) value = gp.check_result(gp.gp_widget_get_value(config)) self.setRange(int(lo * self.inc), int(hi * self.inc)) self.setValue(int(value * self.inc)) self.sliderReleased.connect(self.new_value)
def __init__(self, config_changed, config, parent=None): QtWidgets.QLineEdit.__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)) if value: if sys.version_info[0] < 3: value = value.decode('utf-8') self.setText(value) self.editingFinished.connect(self.new_value)
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 __init__(self, config_changed, config, parent=None): QtWidgets.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(QtWidgets.QHBoxLayout()) value = gp.check_result(gp.gp_widget_get_value(config)) self.buttons = [] for choice in gp.check_result(gp.gp_widget_get_choices(config)): if choice: button = QtWidgets.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, 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)) self.buttons = [] for choice in gp.check_result(gp.gp_widget_get_choices(config)): 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 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 count_children(config): return gp.check_result(gp.gp_widget_count_children(config))
def get(self, config): assert gp.check_result(gp.gp_widget_count_children(config)) == 0 value = gp.check_result(gp.gp_widget_get_value(config)) return {'value': bool(value)}