~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to Sane/sane.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (27.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130131204920-b5zshy6vgfvdionl
Tags: 1.1.7+1.7.8-1ubuntu1
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    """
47
47
 
48
48
    def __init__(self, args, scanDev):
49
 
        import string
50
49
        self.scanDev = scanDev # needed to get current value of this option
51
50
        self.index, self.name = args[0], args[1]
52
51
        self.title, self.desc = args[2], args[3]
56
55
        def f(x):
57
56
            if x=='-': return '_'
58
57
            else: return x
59
 
        if type(self.name)!=type(''): self.py_name=str(self.name)
60
 
        else: self.py_name=string.join(map(f, self.name), '')
 
58
        if not isinstance(self.name, str): self.py_name=str(self.name)
 
59
        else: self.py_name=''.join(map(f, self.name))
61
60
 
62
61
    def is_active(self):
63
62
        return _sane.OPTION_IS_ACTIVE(self.cap)
86
85
settable:  %s\n""" % (self.py_name, curValue,
87
86
                      self.index, self.title, self.desc,
88
87
                      TYPE_STR[self.type], UNIT_STR[self.unit],
89
 
                      `self.constraint`, active, settable)
 
88
                      repr(self.constraint), active, settable)
90
89
        return s
91
90
 
92
91
 
106
105
    def next(self):
107
106
        try:
108
107
            self.device.start()
109
 
        except error, v:
 
108
        except error as v:
110
109
            if v == 'Document feeder out of documents':
111
110
                raise StopIteration
112
111
            else:
166
165
    def __setattr__(self, key, value):
167
166
        dev=self.__dict__['dev']
168
167
        optdict=self.__dict__['opt']
169
 
        if not optdict.has_key(key):
 
168
        if key not in optdict:
170
169
            self.__dict__[key]=value ; return
171
170
        opt=optdict[key]
172
171
        if opt.type==TYPE_GROUP:
173
 
            raise AttributeError, "Groups can't be set: "+key
 
172
            raise AttributeError("Groups can't be set: "+key)
174
173
        if not _sane.OPTION_IS_ACTIVE(opt.cap):
175
 
            raise AttributeError, 'Inactive option: '+key
 
174
            raise AttributeError('Inactive option: '+key)
176
175
        if not _sane.OPTION_IS_SETTABLE(opt.cap):
177
 
            raise AttributeError, "Option can't be set by software: "+key
178
 
        if type(value) == int and opt.type == TYPE_FIXED:
 
176
            raise AttributeError("Option can't be set by software: "+key)
 
177
        if isinstance(value, int) and opt.type == TYPE_FIXED:
179
178
            # avoid annoying errors of backend if int is given instead float:
180
179
            value = float(value)
181
180
        self.last_opt = dev.set_option(opt.index, value)
187
186
        dev=self.__dict__['dev']
188
187
        optdict=self.__dict__['opt']
189
188
        if key=='optlist':
190
 
            return self.opt.keys()
 
189
            return list(self.opt.keys())
191
190
        if key=='area':
192
191
            return (self.tl_x, self.tl_y),(self.br_x, self.br_y)
193
 
        if not optdict.has_key(key):
194
 
            raise AttributeError, 'No such attribute: '+key
 
192
        if key not in optdict:
 
193
            raise AttributeError('No such attribute: '+key)
195
194
        opt=optdict[key]
196
195
        if opt.type==TYPE_BUTTON:
197
 
            raise AttributeError, "Buttons don't have values: "+key
 
196
            raise AttributeError("Buttons don't have values: "+key)
198
197
        if opt.type==TYPE_GROUP:
199
 
            raise AttributeError, "Groups don't have values: "+key
 
198
            raise AttributeError("Groups don't have values: "+key)
200
199
        if not _sane.OPTION_IS_ACTIVE(opt.cap):
201
 
            raise AttributeError, 'Inactive option: '+key
 
200
            raise AttributeError('Inactive option: '+key)
202
201
        value = dev.get_option(opt.index)
203
202
        return value
204
203