def __setattr__(self, key, value): d = self.__dict__ if key in ('dev', 'optlist', 'area', 'sane_signature', 'scanner_model'): raise AttributeError("Read-only attribute: " + key) if key not in self.opt: d[key] = value return opt = d['opt'][key] if opt.type == _sane.TYPE_BUTTON: raise AttributeError("Buttons don't have values: " + key) if opt.type == _sane.TYPE_GROUP: raise AttributeError("Groups don't have values: " + key) if not _sane.OPTION_IS_ACTIVE(opt.cap): raise AttributeError("Inactive option: " + key) if not _sane.OPTION_IS_SETTABLE(opt.cap): raise AttributeError("Option can't be set by software: " + key) if isinstance(value, int) and opt.type == _sane.TYPE_FIXED: # avoid annoying errors of backend if int is given instead float: value = float(value) result = d['dev'].set_option(opt.index, value) # do binary AND to find if we have to reload options: if result & _sane.INFO_RELOAD_OPTIONS: self.__load_option_dict()
def __setattr__(self, key, value): dev=self.__dict__['dev'] optdict=self.__dict__['opt'] if key not in optdict: self.__dict__[key]=value ; return opt=optdict[key] if opt.type==TYPE_GROUP: raise AttributeError("Groups can't be set: "+key) if not _sane.OPTION_IS_ACTIVE(opt.cap): raise AttributeError('Inactive option: '+key) if not _sane.OPTION_IS_SETTABLE(opt.cap): raise AttributeError("Option can't be set by software: "+key) if isinstance(value, int) and opt.type == TYPE_FIXED: # avoid annoying errors of backend if int is given instead float: value = float(value) self.last_opt = dev.set_option(opt.index, value) # do binary AND to find if we have to reload options: if self.last_opt & INFO_RELOAD_OPTIONS: self.__load_option_dict()
def is_settable(self): return _sane.OPTION_IS_SETTABLE(self.cap)
def is_settable(self): """ :returns: Whether the option is settable. """ return _sane.OPTION_IS_SETTABLE(self.cap)