enable.trait_defs.kiva_font_trait module

Trait definition for a wxPython-based Kiva font.

class enable.trait_defs.kiva_font_trait.KivaFont(default_value=None, *, parser=<function simple_parser>, **metadata)[source]

Bases: traits.trait_type.TraitType

A Trait which casts strings to a Kiva Font value.

clone(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Copy, optionally modifying default value and metadata.

Clones the contents of this object into a new instance of the same class, and then modifies the cloned copy using the specified default_value and metadata. Returns the cloned object as the result.

Note that subclasses can change the signature of this method if needed, but should always call the ‘super’ method if possible.

Parameters
  • default_value (any) – The new default value for the trait.

  • **metadata (dict) – A dictionary of metadata names and corresponding values as arbitrary keyword arguments.

Returns

clone – Clone of self.

Return type

TraitType

default_value_type = 7

The default value should be a tuple (factory, args, kwargs)

get_editor(trait)[source]

Returns a trait editor that allows the user to modify the trait trait. This method only needs to be specified if traits defined using this trait handler require a non-default trait editor in trait user interfaces. The default implementation of this method returns a trait editor that allows the user to type an arbitrary string as the value.

For more information on trait user interfaces, refer to the Traits UI User Guide.

Parameters

trait (Trait) – The trait to be edited.

info()[source]

Must return a string describing the type of value accepted by the trait handler.

The string should be a phrase describing the type defined by the TraitHandler subclass, rather than a complete sentence. For example, use the phrase, “a square sprocket” instead of the sentence, “The value must be a square sprocket.” The value returned by info() is combined with other information whenever an error occurs and therefore makes more sense to the user if the result is a phrase. The info() method is similar in purpose and use to the info attribute of a validator function.

Note that the result can include information specific to the particular trait handler instance. If the info() method is not overridden, the default method returns the value of the ‘info_text’ attribute.

parser = None

The parser to use when converting text to keyword args. This should accept a string and return a dictionary of Font class trait values (ie. “family”, “size”, “weight”, etc.). If it can’t parse the string, it should raise FontParseError.

validate(object, name, value)[source]
enable.trait_defs.kiva_font_trait.font_attrs = ['face_name', 'size', 'family', 'weight', 'style', 'underline', 'encoding']

Expected attributes on the Font class.

enable.trait_defs.kiva_font_trait.pyface_family_to_kiva_family = {'cursive': 5, 'decorative': 4, 'default': 0, 'fantasy': 4, 'modern': 3, 'monospace': 3, 'roman': 2, 'sans-serif': 1, 'script': 5, 'serif': 2, 'swiss': 1, 'teletype': 6, 'typewriter': 6}

Mapping from Pyface Font generic family names to corresponding constants.

enable.trait_defs.kiva_font_trait.pyface_font_to_font(font)[source]

Convert a Pyface font to an equivalent Kiva Font.

This ignores stretch and some options like small caps and strikethrough as the Kiva font object can’t represent these at the moment.

Parameters

font (Pyface Font instance) – The font to convert.

Returns

font – The resulting Kiva Font object.

Return type

Kiva Font instance