Back to index

system-config-printer  1.3.9+20120706
Classes | Functions
options Namespace Reference

Classes

class  IPPResolution
class  OptionInterface
class  OptionAlwaysShown
class  OptionAlwaysShownSpecial
class  Option
class  OptionSelectOne
class  OptionSelectOneResolution
class  OptionSelectOneNumber
class  OptionSelectMany
class  OptionNumeric
class  OptionText

Functions

def OptionWidget

Function Documentation

def options.OptionWidget (   name,
  v,
  s,
  on_change 
)

Definition at line 65 of file options.py.

00065 
00066 def OptionWidget(name, v, s, on_change):
00067     if isinstance(v, list):
00068         # XXX
00069         if isinstance(s, list):
00070             for vv in v + s:
00071                 if not isinstance(vv, str): raise ValueError
00072             return OptionSelectMany(name, v, s, on_change)
00073         print v, s
00074         raise NotImplemented
00075     else:
00076         if (isinstance(s, int) or
00077             isinstance(s, float) or
00078             (isinstance(s, tuple) and
00079              len(s) == 2 and
00080              ((isinstance(s[0], int) and isinstance(s[1], int)) or
00081               (isinstance(s[0], float) and isinstance(s[1], float))))):
00082             try:
00083                 if (isinstance(s, int) or
00084                     isinstance(s, tuple) and isinstance(s[0], int)):
00085                     v = int(v)
00086                 else:
00087                     v = float(v)
00088             except ValueError:
00089                 return OptionText(name, v, "", on_change)
00090             return OptionNumeric(name, v, s, on_change)
00091         elif isinstance(s, list):
00092             for sv in s:
00093                 if isinstance(sv, tuple) and len (sv) == 3:
00094                     return OptionSelectOneResolution(name, v, s, on_change)
00095                 elif not isinstance(sv, int):
00096                     return OptionSelectOne(name, v, s, on_change)
00097             try:
00098                 v = int(v)
00099             except ValueError:
00100                 return OptionSelectOne(name, v, s, on_change)
00101             return OptionSelectOneNumber(name, v, s, on_change)
00102         elif isinstance(s, str):
00103             return OptionText(name, v, s, on_change)
00104         else:
00105             raise ValueError
00106 
00107 # ---------------------------------------------------------------------------

Here is the caller graph for this function: