# enaml.styling

Classes

`Setter` | A declarative class for defining a style field setter.
`Stylable` | A mixin class for defining stylable declarative objects.
`Style` | A declarative class for defining a style sheet style.
`StyleCache` | An object which manages the styling caches.
`StyleSheet` | A declarative class for defining a widget style sheet.

class enaml.styling.Setter(parent=None, **kwargs)

  Bases: `Declarative`

  A declarative class for defining a style field setter.

  A `Setter` is declared as a child of a `Style`. It defines the value to be applied to a style field.

  field

    The style field to which this setter applies.

  value

    The value to apply to the style field.

  destroy()

    A reimplemented destructor.

    This will notify the `StyleCache` when the setter is destroyed.

class enaml.styling.Stylable(parent=None, **kwargs)

  Bases: `Declarative`

  A mixin class for defining stylable declarative objects.

  This class can be used as a mixin with any `Declarative` class which wishes to support style sheets.

  style_class

    The style class to which this item belongs. Multiple classes can be separated with whitespace. An empty string indicates the widget does not belong to any style class.

  destroy()

    A reimplemented destructor.

    This will notify the `StyleCache` when the stylable item is destroyed.

  style_sheet()

    Get the `StyleSheet` defined on the item.

    Returns:

      result – The last `StyleSheet` child defined on the item, or None if the item has no such child.

    Return type:

      `StyleSheet` or None

  restyle()

    Restyle the object.

    This method will be called when the style dependencies for the object have changed. It should be reimplemented in a subclass to take appropriate action for the restyle.

  parent_changed(old, new)

    A reimplemented parent changed event handler.

    This will notify the `StyleCache` if the parent of the item has changed.

  child_added(child)

    A reimplemented child added event handler.

    This will notify the `StyleCache` if the `StyleSheet` children of the item have changed.

  child_removed(child)

    A reimplemented child removed event handler.

    This will notify the `StyleCache` if the `StyleSheet` children of the item have changed.

class enaml.styling.Style(parent=None, **kwargs)

  Bases: `Declarative`

  A declarative class for defining a style sheet style.

  A `Style` is declared as a child of a `StyleSheet`. It uses child `Setter` objects to define the style fields to apply to widgets which are a match for the style.

  A `Style` may have an arbitrary number of `Setter` children.

  element

    The type name of the element which will match the style. An empty string will match all elements. Multiple elements can be separated by a comma and will match using logical OR semantics.

  style_class

    The name of the widget style class which will match the style. An empty string will match all style classes. Multiple classes can be separated by a comma and will match using logical OR semantics.

  object_name

    The object name of the widget which will match the style. An empty string will match all object names. Multiple object names can be separated by a comma and will match using logical OR semantics.

  pseudo_class

    The pseudo-class which must be active for the style to apply. An empty string will apply the syle for all pseudo-classes. Multiple classes can be separated by a colon will match using logical AND semantics. Commas can be used to separate multiple classes which will match using logical OR semantics.

  pseudo_element

    The pseudo-element to which the style applies. An empty string indicates the style applies to the primary element. Multiple pseudo elements can be separated comma and match using logical OR semantics.

  setters()

    Get the `Setter` objects declared for the style.

    Returns:

      result – The `Setter` objects declared for the style.

    Return type:

      list

  match(item)

    Get whether or not the style matches an item.

    Parameters:

      item (`Stylable`) – The item to test for a style match.

    Returns:

      result – The match value for the item. A value less than zero indicates no match. A value greater than or equal to zero indicates a match and the specificity of the match.

    Return type:

      int

  destroy()

    A reimplemented destructor.

    This will notify the `StyleCache` when the style is destroyed.

  child_added(child)

    A reimplemented child added event handler.

    This will notify the `StyleCache` if the `Setter` children of the style have changed.

  child_removed(child)

    A reimplemented child removed event handler.

    This will notify the `StyleCache` if the `Setter` children of the style have changed.

class enaml.styling.StyleCache(*args, **kwargs)

  Bases: `object`

  An object which manages the styling caches.

  All interaction with this class is through public class methods. This class should be used by code which implements the styling for a stylable item. The public API methods can be used to query for the Style object which matchs a `Stylable` item.

  classmethod style_sheets(item)

    Get the `StyleSheet` objects which apply to an item.

    Parameters:

      item (`Stylable`) – The stylable item of interest.

    Returns:

      result – The `StyleSheet` objects which apply to the item, in order of ascending precedence.

    Return type:

      tuple

  classmethod styles(item)

    Get the `Style` objects which apply to an item.

    Parameters:

      item (`Stylable`) – The stylable item of interest.

    Returns:

      result – The `Style` objects which apply to the item, in order of ascending precedence.

    Return type:

      tuple

  classmethod toolkit_setter(setter, translate)

    Get the toolkit representation of a setter.

    This method will return the cached toolkit setter, if available, or invoke the translator to create the cached setter. The cached toolkit setter will be cleared when the setter is invalidated.

    Parameters:

      - setter (`Setter`) – The style setter of interest.

      - translate (callable) – A callable which accepts a single `Setter` argument and returns a toolkit representation of the setter. The returned value is cached until the setter is invalidated.

    Returns:

      result – The toolkit representation of the setter.

    Return type:

      object

  static __new__(cls, *args, **kwargs)
  __weakref__

    list of weak references to the object

class enaml.styling.StyleSheet(parent=None, **kwargs)

  Bases: `Declarative`

  A declarative class for defining a widget style sheet.

  A `StyleSheet` is declared as a child of a `Stylable` widget. It uses child `Style` objects to apply styling to its parent widget and all of the widget’s decendents. A `StyleSheet` can also be provided to the global `Application`, in which case the styling will be applied to all stylable widgets. The effective style sheet for a widget is the union of all its ancestor style sheets plus the application style sheet.

  A `StyleSheet` may have an arbitrary number of `Style` children. The child style objects are applied to a widget in the order of their match specificity within the style sheet.

  destroy()

    A reimplemented destructor.

    This will notify the `StyleCache` when the style sheet is destroyed.

  styles()

    Get the `Style` objects declared for the style sheet.

    Returns:

      result – The `Style` objects declared for the style sheet.

    Return type:

      list

  child_added(child)

    A reimplemented child added event handler.

    This will notify the `StyleCache` if the `Style` children of the style sheet have changed.

  child_removed(child)

    A reimplemented child removed event handler.

    This will notify the `StyleCache` if the `Style` children of the style sheet have changed.