Package pype :: Module ptable
[frames] | no frames]

Module ptable

source code

Parameter tables with type validation

Parameter table (aka worksheet) implementation. This module provides a standard way to create task-specific parameter tables to be filled out by the user and passed into running tasks.

Validator function (is_int, is_pdf etc) are provided for a number of common cases. If you want to write your own, the validation function must be a function two args, eg:

def is_int(s, evaluate=None): ...

s is a string to validate -- when evaluate is None, then the function simply decides whether or not s is in a valid form and returns True or False. If evaluate is True, then the validator function should return the actual valid of the string -- ie, for is_int, return a validated integer (not a string, but an actual integer).

Author -- James A. Mazer (mazerj@gmail.com)

Classes
  ParamTable
Functions
 
psection(name)
Header for ParamTable (starts new section); same as ptitle
source code
 
ptitle(name)
Header for ParamTable (starts new section); same as psection
source code
 
pslot(name, default=None, val=None, info='', lockonrun=None)
Generic parameter ParamTable slot
source code
 
pslot_ro(name, default=None, val=None, info='')
Generic READONLY ParamTable slot
source code
 
pchoice(name, default=None, choices=None, info='', lockonrun=None)
Dropdown list of choices
source code
 
pbool(name, default=1, info='', lockonrun=None)
Yes/No box that (generates bool 0/1 value)
source code
 
pyesno(name, default=1, info='', lockonrun=None)
Yes/No box that (generates bool 0/1 value); save as pbool
source code
 
pparam(name, default, info='', lockonrun=None)
param slot -- see pype_aux.param_expand
source code
 
piparam(name, default, info='', lockonrun=None)
integer param slot -- see pype_aux.param_expand
source code
 
pcolor(name, default, info='', lockonrun=None)
Color spec (R,G,B,A)
source code
 
pint(name, default, info='', lockonrun=None)
Integer
source code
 
pfloat(name, default, info='', lockonrun=None)
Floating point number
source code
 
plist(name, default, info='', lockonrun=None)
List of numbers (really should be pseq, for sequence)
source code
 
pany(name, default, info='', lockonrun=None)
Anything -- basically no validation at all
source code
 
is_dir(s, evaluate=None)
Must be a directory.
source code
 
is_file(s, evaluate=None)
Must be name of an EXISTING file.
source code
 
is_newfile(s, evaluate=None)
Must be name of NON-EXISTING file.
source code
 
is_any(s, evaluate=None)
No type checking --> always returns true.
source code
 
is_boolean(s, evaluate=None)
Must be some sort of boolean flag.
source code
 
is_bool(s, evaluate=None)
Must be some sort of boolean flag.
source code
 
is_int(s, evaluate=None)
Must be simple integer (positive, negative or zero).
source code
 
is_posint(s, evaluate=None)
Must be positive (> 0) integer.
source code
 
is_negint(s, evaluate=None)
Must be negative (< 0) integer.
source code
 
is_gteq_zero(s, evaluate=None)
Must be greater than or equal to zero.
source code
 
is_lteq_zero(s, evaluate=None)
Must be less than or equal to zero.
source code
 
is_rgb(s, evaluate=None)
Must be a properly formed RGB color triple.
source code
 
is_color(s, evaluate=None)
Must be a properly formed RGB color triple.
source code
 
is_rgba(s, evaluate=None)
Must be proper RGBA tuple (RGB+alpha).
source code
 
is_gray(s, evaluate=None)
entry must be a valid 8-bit grayscale value (0-255)
source code
 
is_rgba2(s, evaluate=None, meanlum=(128,128,128))
RGBA triple where values are 0-1
source code
 
is_float(s, evaluate=None)
Must be a valid floating point number
source code
 
is_percent(s, evaluate=None)
Must be valid percentage (ie, float in range 0-1) (technically this is is_fraction!)
source code
 
is_angle_degree(s, evaluate=None)
Must be valid angle in degrees (ie, float in range 0-360)
source code
 
is_param(s, evaluate=None)
Is 'special parameter' string.
source code
 
is_iparam(s, evaluate=None)
Like is_param, but integer values.
source code
 
is_cdf(s, evaluate=None)
Must describe a cummulative distribution <-- NO REALLY, PDF...
source code
 
is_pdf(s, evaluate=None)
Probability density function.
source code
 
is_list(s, evaluate=None)
Must be a list/vector or range.
source code
Variables
  VALID = Pmw.OK
  INVALID = Pmw.PARTIAL
Function Details

is_boolean(s, evaluate=None)

source code 

Must be some sort of boolean flag.

Try to do a bit of parsing:
  • 1,yes,on,true -> 1
  • 0,no,off,false -> 0

Use pyesno() or something like that for drop down.

is_bool(s, evaluate=None)

source code 

Must be some sort of boolean flag.

Try to do a bit of parsing:
  • 1,yes,on,true -> 1

  • 0,no,off,false -> 0

Use pyesno() or something like that for drop down.

is_rgb(s, evaluate=None)

source code 

Must be a properly formed RGB color triple.

Form should be (R,G,B) were R G and B are all in the range 0-255. Parens are required.

Note: is_color is an alias for this fn

is_color(s, evaluate=None)

source code 

Must be a properly formed RGB color triple.

Form should be (R,G,B) were R G and B are all in the range 0-255. Parens are required.

Note: is_color is an alias for this fn

is_rgba(s, evaluate=None)

source code 

Must be proper RGBA tuple (RGB+alpha).

Like is_color()/is_rgb(), but allows for alpha channel specification.

is_param(s, evaluate=None)

source code 

Is 'special parameter' string.

See the param_expand function (pype_aux.py) for full documentation on the valid forms of special parameter strings.

is_cdf(s, evaluate=None)

source code 

Must describe a cummulative distribution <-- NO REALLY, PDF...

This ensures that the specified value is an integer or a vector describing a valid cummulative PDF. If an integer, then return a n-length cdf of uniform prob (eg, [1/n, 1/n .. 1/n]) Otherwise, normalize the vector to have unity area.

IMPROVED: 23-mar-2002 JM --> changed so you don't have to make stuff add to 1.0, evaluating divides by the sum to force it to add up to 1.0...

is_pdf(s, evaluate=None)

source code 

Probability density function.

  • If a list, then the list is normalized to sum=1.0 when retrieved.
  • If an integeer, then a uniform distribution of specified length is used (ie, [1/n, 1/n .. 1/n]) is generated on retrieval
  • If of the form 'hazard(N)', where N is an integer

is_list(s, evaluate=None)

source code 

Must be a list/vector or range.

Lists are specified in []'s. Ranges can be either:

=start:stop:step (inclusive: both start and stop in list)

start:stop:step (stop is not included in the list)