Logo Search packages:      
Sourcecode: eikazo version File versions  Download package

def Eikazo::Widgets::SaneDevice::createOptionWidget (   self,
  optname,
  config,
  optwidget = 'default',
  kw 
)

return an appropriate widget for a device option. optnum
    is the number of the option as returned by GetOptions()

Definition at line 409 of file Widgets.py.

00409                                                                             :
        """ return an appropriate widget for a device option. optnum
            is the number of the option as returned by GetOptions()
        """
        opt = self._device.opt[optname]
        if opt.type == SANE_TYPE_BOOL:
            if opt.is_settable():
                res = CheckButton(optname, self, config, **kw)
            else:
                # we can have the funny case that an option has the capability
                # SANE_CAP_HARD_SELECT, but not SANE_CAP_SOFT_DETECT,
                # i.e., that is_settable() returns false.This
                # means that the option is set by hardware, and can't be
                # read by software. In other words, it is completely
                # useless for a program ;) This is true for test backend,
                # option bool_hard_select. We'll simply ignore such an option.
                if opt.cap & sane._sane.CAP_SOFT_DETECT == 0:
                    return None
                res = BoolDisplay(optname, self, **kw)
            self._registerWidget(optname, res)
            return res
        elif opt.type in (SANE_TYPE_FIXED, SANE_TYPE_INT):
            # slider for range constraints; choicebox for list constraints,
            # textfield no non-constraint values
            # FIXME: check for arrays!!!
            
            # check, if we have a single value or an array. The value
            # of opt.size is platform dependent (quote from from the Sane
            # API doc: " The size must be a positive integer multiple of 
            # the size of a SANE_Word. The option value is a vector of length
            # size/sizeof(SANE_Word)", so we'll use the Python type
            
            constr = opt.constraint

            # FIXME: the sane module returns the option size as specified
            # by the backend, i.e., for SANE_Word, SANE_Int in multiples
            # of sizeof(SANE_Word). This is not of much value in Python:
            # here, we don't know the value of sizeof(SANE_Word).
            # we need a function in the C extension that tells us the
            # size.
            if 0:
                if opt.size > 1:
                    if type(constr) == type(()):
                        print "xxx cCURVES DISABLED"
                        return None
                        res = SaneCurve(optname, self, config, **kw)
                    elif type(constr) == type([]):
                        # FIXME: might be reasonable to build a table of
                        # choiceboxes for shorter lists
                        print "can't build a widget for a float/integer list with selection constraint"
                        return None
                    else:
                        # hrmm. What to do here?
                        print "can't build a widget for a float/integer list without constraint"
                        return None
            
            elif type(constr) == type(()):
                minValue = constr[0]
                maxValue = constr[1]
                if optwidget in ('default', 'hscale'):
                    res = HScale(optname, self, config, **kw)
                elif optwidget == 'labeled hscale':
                    res = HScalePanel(optname, self, config, **kw)
                elif optwidget == 'vscale':
                    res = VScale(optname, self, config, **kw)
                elif optwidget == 'labeled vscale':
                    res = VScalePanel(optname, self, config, **kw)
                elif optwidget == 'number field':
                    res = NumberField(optname, self, config, **kw)
                elif optwidget == 'labeled number field':
                    res = LabeledNumberField(optname, self, config, **kw)
                else:
                    raise EikazoWidgetError(
                      'invalid widget type for integer or fixed widget: %s %s' \
                      % (opt.name, optwidget))
            elif type(constr) == type([]):
                if optwidget in ('default', 'choice'):
                    res = Choice(optname, self, config, **kw)
                elif optwidget == 'labeled choice':
                    res = LabeledChoice(optname, self, config, **kw)
                else:
                    raise EikazoWidgetError(
                      'invalid widget type for integer or fixed widget: %s %s' \
                      % (opt.name, optwidget))
            else:
                res = NumberField(optname, self, config, **kw)
            self._registerWidget(optname, res)
            return res
        elif opt.type == SANE_TYPE_STRING:
            # right now, we'll support only selection lists, i.e., 
            # the constraint type must be a list
            constr = opt.constraint
            if type(constr) == type([]):
                if optwidget in ('default', 'choice'):
                    res = Choice(optname, self, config, **kw)
                elif optwidget == 'labeled choice':
                    res = LabeledChoice(optname, self, config, **kw)
                else:
                    raise EikazoWidgetError(
                      'invalid widget type for integer or fixed widget: %s %s' \
                      % (opt.name, optwidget))
                self._registerWidget(optname, res)
                return res
            res = StringOption(optname, self, config, **kw)
            self._registerWidget(optname, res)
            return res
        elif opt.type == SANE_TYPE_BUTTON:
            res = Button(optname, self, **kw)
            self._registerWidget(optname, res)
            return res
        elif opt.type == SANE_TYPE_GROUP:
            # this is a "layout hint"; should be handled externally
            return None
        # self._showOptInfo(opt, optname)
        raise EikazoWidgetError("unknown option type %i" % opt.type)
    
    def reloadOptions(self):


Generated by  Doxygen 1.6.0   Back to index