Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit ec45c6888da9ac3abbea25454bf7e70487de888a

Adapt to python-sane 2.8.x API changes

python-sane 2.8.x doesn't expose the constants for types and units
anymore. Instead we'd need to look up the value against a
dictionary (sane.TYPE_STR resp. sane.UNIT_STR) and perform a string
comparison.

For compatibility with python-sane < 2.8, we continue doing integer
comparison. When running with python-sane 2.8+, we import an inverted
version of the dictionary into the global namespace. For python-sane <
2.8, we then just import the constants into the global namespace.
scan.py
(22 / 11)
  
4949import postproc
5050
5151
52if hasattr(sane, 'TYPE_STR'):
53 # python-sane 2.8+
54 for value, name in sane.TYPE_STR.items():
55 globals()[name] = value
56else:
57 from sane import TYPE_BOOL, TYPE_BUTTON, TYPE_FIXED, TYPE_GROUP, TYPE_INT
58 # python-sane < 2.8
59
60
5261class SettingsToolbar(gtk.ToolPalette):
5362
5463 @trace()
143143 groups = [(None, group)]
144144 options = self._scanner.get_options()
145145 for idx, name, title, dsc_, _type, unit_, siz_, cap_, cons_ in options:
146 if _type == sane.TYPE_GROUP:
146 if _type == TYPE_GROUP:
147147 group = []
148148 groups.append((title, group))
149149 continue
150150
151 if not name and idx != 0:
152 logging.warning('ignoring unnamed option (index %d)', idx)
151 if not name:
152 if idx != 0:
153 logging.warning('ignoring unnamed option (index %d)', idx)
153154 continue
154155
155156 group.append(name)
164164 for py_name in self._scanner.optlist])
165165
166166 first_group = True
167 print(repr(groups))
167168 for group_name, group in groups:
168169 if not group:
169170 continue
182182 py_name = name_map[option_name]
183183 option = self._scanner[py_name]
184184
185 if (option.type == sane.TYPE_BOOL):
185 if (option.type == TYPE_BOOL):
186186 widget = self._add_bool(option)
187 elif (option.type == sane.TYPE_INT):
187 elif (option.type == TYPE_INT):
188188 widget = self._add_integer(option)
189 elif (option.type == sane.TYPE_FIXED):
189 elif (option.type == TYPE_FIXED):
190190 widget = self._add_fixed_point(option)
191 elif (option.type == sane.TYPE_STRING):
191 elif (option.type == TYPE_STRING):
192192 widget = self._add_string(option)
193 elif (option.type == sane.TYPE_BUTTON):
193 elif (option.type == TYPE_BUTTON):
194194 widget = self._add_action(option)
195195 else:
196196 logging.warning('Skipping setting %r of unknown type %r',
290290 spin.props.snap_to_ticks = True
291291 spin.set_digits(self._calc_digits(step))
292292
293 if option.type == sane.TYPE_INT:
293 if option.type == TYPE_INT:
294294 spin.connect('value-changed', lambda widget, option=option:
295295 self._spin_int_changed_cb(widget, option))
296296 else:
682682 for py_name in self._current_scanner.optlist:
683683 logging.debug('getting value for setting %r', py_name)
684684 option = self._current_scanner[py_name]
685 if option.type in [sane.TYPE_BOOL, sane.TYPE_INT,
686 sane.TYPE_FIXED, sane.TYPE_STRING] and option.is_active():
685 if (option.type in [TYPE_BOOL, TYPE_INT, TYPE_FIXED, TYPE_STRING]
686 and option.is_active()):
687687
688688 settings[py_name] = getattr(self._current_scanner, py_name)
689689