Common

Global Variables

Version numbers are used as default values in Header and to select a matching json schema file if no version is set.

pyfdl.FDL_SCHEMA_MAJOR = 1 module-attribute

pyfdl.FDL_SCHEMA_MINOR = 0 module-attribute

pyfdl.FDL_SCHEMA_VERSION = {'major': FDL_SCHEMA_MAJOR, 'minor': FDL_SCHEMA_MINOR} module-attribute


Different workflows have different requirements for precision, so we are flexible in how to apply rounding of values

pyfdl.DEFAULT_ROUNDING_STRATEGY = NO_ROUNDING module-attribute

This is the default behavior for rounding the values of dimensions. The rules are the same as for CanvasTemplate.round.

pyfdl.NO_ROUNDING = {} module-attribute

This will disable rounding of values in dimensions. Exception being Canvas.dimensions when created by a canvas templates

pyfdl.set_rounding_strategy(rules)

pyfdl.rounding_strategy()

Base Classes

Below is a collection of the common classes that are used by other classes.

pyfdl.Base()

Base class not to be instanced directly.

Attributes:
  • attributes

    list of attributes described in FDL spec

  • kwarg_map

    map attribute names that clash with reserved builtin python functions to safe alternatives like: (id -> id_) and (uuid -> uuid_)

  • object_map

    map attributes to custom classes

  • required

    list of required attributes. Supports linked attributes like: "effective_dimensions.effective_anchor_point" where "effective_anchor_point" is required if "effective_dimensions" is set

  • defaults

    map default values to attributes. In addition to primitive values supports: callable, subclasses of Base

apply_defaults()

Applies default values defined in the defaults attribute to attributes that are None

check_required()

Check that required attributes contain values. Checks linked attributes like: "effective_dimensions.effective_anchor_point" where "effective_anchor_point" is required if "effective_dimensions" is set

Returns:
  • list

    a list of missing attributes

from_dict(raw) classmethod

Create instances of classes from a provided dict.

Parameters:
  • raw (dict) –

    dictionary to convert to supported classes

Returns:
  • cls( Any ) –

    and instance of the current class

to_dict()

Produce a dictionary representation of the current object along with all sub objects.

Raises:
  • FDLError

    if required keys are missing

Returns:
  • dict

    representation of object

pyfdl.TypedCollection(cls)

Collection only accepting items of a given class. In addition, a strict control of unique id's is enforced.

Parameters:
  • cls (Any) –

    type of class to be accepted

add(item)

Add an item to the collection. All items added to a collection get associated to the collection by passing itself as parent

Parameters:
  • item (Any) –

    of type passed at instancing of the collection.

Raises:
  • FDLError

    for missing id or if a duplicate id is detected

get(item_id)

Get an item in the collection

Parameters:
  • item_id (str) –

    id of item you'd like to get

Returns:
  • item( Union[Any, None] ) –

    in collection or None if not found

remove(item_id)

Remove an item in the collection if found

Parameters:
  • item_id (str) –

    id of item to be removed

pyfdl.Dimensions(width=None, height=None, dtype=float)

Bases: Base

Dimensions may be either ints or floats. You may pass the desired data type at instantiation. However, the objects using the dimensions will set the required type for you when they are passed to them

Parameters:
  • width (Optional[Union[int, float]], default: None ) –
  • height (Optional[Union[int, float]], default: None ) –
  • dtype (Optional[Union[int, float]], default: float ) –

    set data type of dimension values, mostly used behind the scenes.

copy()

Create a copy of these dimensions

Returns:

scale_by(factor)

Scale the dimensions by the provider factor

Parameters:
  • factor (float) –

pyfdl.Point(x=None, y=None)

Bases: Base

Point properly formatted

Parameters:
  • x (Optional[float], default: None ) –
  • y (Optional[float], default: None ) –

pyfdl.RoundStrategy(even=None, mode=None)

Bases: Base

Describes how to handle rounding canvas dimensions when applying a CanvasTemplate.

Parameters:
  • even (Optional[str], default: None ) –

    "whole" = to nearest integer, "even" = to nearest even-numbered integer

  • mode (Optional[str], default: None ) –

    "up" = always round up, "down" = always round down "round" = standard rounding, >= +0.5 rounds up,< +0.5 rounds down

Raises:
  • FDLError

    if you provide a value other than the ones listed above

round_dimensions(dimensions)

Round the provided dimensions based on the rules defined in this object

Parameters:
Returns:
  • dimensions( Dimensions ) –

    rounded based on rules