Пример #1
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))
         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))
Пример #2
0
    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
Пример #3
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:
             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))
Пример #4
0
def setConfig(config_item, config_value):
    child_type = gp.check_result(gp.gp_widget_get_type(
        config_all[config_item]))
    if child_type == gp.GP_WIDGET_RADIO:
        value = gp.check_result(
            gp.gp_widget_get_choice(config_all[config_item],
                                    int(config_value)))
        gp.check_result(gp.gp_widget_set_value(config_all[config_item], value))
        gp.check_result(gp.gp_camera_set_config(camera, config, context))
    elif child_type == gp.GP_WIDGET_TEXT:
        gp.check_result(
            gp.gp_widget_set_value(config_all[config_item], config_value))
        gp.check_result(gp.gp_camera_set_config(camera, config, context))
    elif child_type == gp.GP_WIDGET_RANGE:
        gp.check_result(
            gp.gp_widget_set_value(config_all[config_item], int(config_value)))
        gp.check_result(gp.gp_camera_set_config(camera, config, context))
    elif child_type == gp.GP_WIDGET_TOGGLE:
        value = gp.check_result(gp.gp_widget_get_value(
            config_all[config_item]))
        if value:
            gp.check_result(gp.gp_widget_set_value(config_all[config_item], 0))
        else:
            gp.check_result(gp.gp_widget_set_value(config_all[config_item], 1))
        gp.check_result(gp.gp_camera_set_config(camera, config, context))
    return "done"
Пример #5
0
    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
Пример #6
0
    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
Пример #7
0
 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)
Пример #8
0
 def my_set(name, value):
     OK, widget = gp.gp_widget_get_child_by_name(config, name)
     if OK >= gp.GP_OK:
         widget_type = gp.check_result(gp.gp_widget_get_type(widget))
         gp.check_result(gp.gp_widget_set_value(widget, value))
         gp.check_result(gp.gp_camera_set_config(camera, config))
     else:
         print("Error setting value %s for %s using widget %s" % (value, name, widget))
 def set_datetime(config):
     OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetime')
     if OK >= gp.GP_OK:
         widget_type = gp.check_result(gp.gp_widget_get_type(date_config))
         if widget_type == gp.GP_WIDGET_DATE:
             now = int(time.time())
             gp.check_result(gp.gp_widget_set_value(date_config, now))
         else:
             now = time.strftime('%Y-%m-%d %H:%M:%S')
             gp.check_result(gp.gp_widget_set_value(date_config, now))
         return True
     return False
Пример #10
0
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 date/time setting config item and get it
    # name varies with camera driver
    #   Canon EOS350d - 'datetime'
    #   PTP - 'd034'
    for name, fmt in (('datetime', '%Y-%m-%d %H:%M:%S'),
                      ('d034',     None)):
        now = datetime.now()
        OK, datetime_config = gp.gp_widget_get_child_by_name(config, name)
        if OK >= gp.GP_OK:
            widget_type = gp.check_result(gp.gp_widget_get_type(datetime_config))
            if widget_type == gp.GP_WIDGET_DATE:
                raw_value = gp.check_result(
                    gp.gp_widget_get_value(datetime_config))
                camera_time = datetime.fromtimestamp(raw_value)
            else:
                raw_value = gp.check_result(
                    gp.gp_widget_get_value(datetime_config))
                if fmt:
                    camera_time = datetime.strptime(raw_value, fmt)
                else:
                    camera_time = datetime.utcfromtimestamp(float(raw_value))
            print('Camera clock:  ', camera_time.isoformat(' '))
            print('Computer clock:', now.isoformat(' '))
            err = now - camera_time
            if err.days < 0:
                err = -err
                lead_lag = 'ahead'
                print('Camera clock is ahead by',)
            else:
                lead_lag = 'behind'
            print('Camera clock is %s by %d days and %d seconds' % (
                lead_lag, err.days, err.seconds))
            break
    else:
        print('Unknown date/time config item')
    # clean up
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
def set_datetime(config):
    OK, sync_config = gp.gp_widget_get_child_by_name(config, "syncdatetime")
    if OK >= gp.GP_OK:
        gp.check_result(gp.gp_widget_set_value(sync_config, 1))
        return True
    OK, date_config = gp.gp_widget_get_child_by_name(config, "datetime")
    if OK >= gp.GP_OK:
        widget_type = gp.check_result(gp.gp_widget_get_type(date_config))
        if widget_type == gp.GP_WIDGET_DATE:
            now = int(time.time())
            gp.check_result(gp.gp_widget_set_value(date_config, now))
        else:
            now = time.strftime("%Y-%m-%d %H:%M:%S")
            gp.check_result(gp.gp_widget_set_value(date_config, now))
        return True
    return False
Пример #12
0
def set_datetime(config, model):
    if model == 'Canon EOS 100D':
        OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetimeutc')
        if OK >= gp.GP_OK:
            now = int(time.time())
            gp.check_result(gp.gp_widget_set_value(date_config, now))
            return True
    OK, sync_config = gp.gp_widget_get_child_by_name(config, 'syncdatetime')
    if OK >= gp.GP_OK:
        gp.check_result(gp.gp_widget_set_value(sync_config, 1))
        return True
    OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetime')
    if OK >= gp.GP_OK:
        widget_type = gp.check_result(gp.gp_widget_get_type(date_config))
        if widget_type == gp.GP_WIDGET_DATE:
            now = int(time.time())
            gp.check_result(gp.gp_widget_set_value(date_config, now))
        else:
            now = time.strftime('%Y-%m-%d %H:%M:%S')
            gp.check_result(gp.gp_widget_set_value(date_config, now))
        return True
    return False
def set_datetime(config, model):
    if model == 'Canon EOS 100D':
        OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetimeutc')
        if OK >= gp.GP_OK:
            now = int(time.time())
            gp.check_result(gp.gp_widget_set_value(date_config, now))
            return True
    OK, sync_config = gp.gp_widget_get_child_by_name(config, 'syncdatetime')
    if OK >= gp.GP_OK:
        gp.check_result(gp.gp_widget_set_value(sync_config, 1))
        return True
    OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetime')
    if OK >= gp.GP_OK:
        widget_type = gp.check_result(gp.gp_widget_get_type(date_config))
        if widget_type == gp.GP_WIDGET_DATE:
            now = int(time.time())
            gp.check_result(gp.gp_widget_set_value(date_config, now))
        else:
            now = time.strftime('%Y-%m-%d %H:%M:%S')
            gp.check_result(gp.gp_widget_set_value(date_config, now))
        return True
    return False
Пример #14
0
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