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 __getattr__(self, key): dev = self.__dict__['dev'] optdict = self.__dict__['opt'] if key == 'optlist': return self.opt.keys() if key == 'area': return (self.tl_x, self.tl_y), (self.br_x, self.br_y) if not optdict.has_key(key): raise AttributeError, 'No such attribute: ' + key opt = optdict[key] if opt.type == TYPE_BUTTON: raise AttributeError, "Buttons don't have values: " + key if opt.type == TYPE_GROUP: raise AttributeError, "Groups don't have values: " + key if not _sane.OPTION_IS_ACTIVE(opt.cap): raise AttributeError, 'Inactive option: ' + key value = dev.get_option(opt.index) return value
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 __getattr__(self, key): d = self.__dict__ if key == 'optlist': return list(self.opt.keys()) if key == 'area': return (self.tl_x, self.tl_y), (self.br_x, self.br_y) if key == 'sane_signature': return self.__get_sane_signature() if key == 'scanner_model': return self.__get_sane_signature()[1:3] if key in d: return d[key] if key not in d['opt']: raise AttributeError("No such attribute: " + key) 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) return d['dev'].get_option(opt.index)
def is_active(self): return _sane.OPTION_IS_ACTIVE(self.cap)
def is_active(self): """ :returns: Whether the option is active. """ return _sane.OPTION_IS_ACTIVE(self.cap)