brown.core.key_signature

classes

A logical and graphical key signature.

The signature will be rendered initially at the given pos_x, and at the beginning of subsequent lines until a new KeySignature is encountered.

All traditional key signatures (those included in KeySignatureTypes) are supported by this class. Nontraditional key signatures could be implemented in a fairly straightforward way in a subclass of this.

__init__ (pos_x, staff, key_signature_type) permalink view source

overriden from GraphicObject

arguments:

pos_x (Unit): The x position relative to the parent staff.

staff (Staff): The parent staff

key_signature_type (KeySignatureType or str): A description of the key signature. Any KeySignatureType may be used, or a str of one's name.

properties

key_signature_type: KeySignatureType A logical description of the key signature. permalink view source

read-only.

length: KeySignatures extend until another is found in the staff. permalink view source

overriden from GraphicObject

read-only.

inherited properties

staff: Staff The staff associated with this object permalink view source

read-only.

inherited from StaffObject

pos_in_staff: Point The position of this object relative to the staff. permalink view source

This position is in non-flowed space.

# TODO: Definitely cache me when property caching is implemented

read-only.

inherited from StaffObject

interfaces: set(GraphicObjectInterface) The interfaces for this object permalink view source

Interface objects are created upon calling GraphicObject.render()

Typically each GraphicObject will have one interface for each flowable line it appears in. Objects which fit completely in one visual line will typically have exactly one interface.

If this is an empty set, the object has not been rendered yet with the render() method.

read-only.

inherited from GraphicObject

pos: Point The position of the object relative to its parent. permalink view source

inherited from GraphicObject

x: Unit The x position of the object relative to its parent. permalink view source

inherited from GraphicObject

y: Unit The x position of the object relative to its parent. permalink view source

inherited from GraphicObject

pen: Pen The pen to draw outlines with permalink view source

inherited from GraphicObject

brush: Brush The brush to draw outlines with permalink view source

As a convenience, this may be set with a hex color string for a solid color brush of that color. For brushes using alpha channels and non-solid-color fill patterns, a fully initialized brush must be passed to this.

inherited from GraphicObject

parent: GraphicObject The parent object. permalink view source

If this is set to None, it defaults to the first page of the document.

inherited from GraphicObject

children: set(GraphicObject) All objects who have self as their parent. permalink view source

inherited from GraphicObject

descendants: iter[GraphicObject] All of the objects in the children subtree. permalink view source

This recursively searches all of the object's children (and their children, etc.) and provides an iterator over them.

The current implementation performs a simple recursive DFS over the tree, and has the potential to be rather slow.

read-only.

inherited from GraphicObject

ancestors: iter[GraphicObject] All ancestors of this object. permalink view source

Follows the chain of parents until a document page is reached. The iterable will not include the document Page.

The order begins with self.parent and traverses upward in the tree.

read-only.

inherited from GraphicObject

flowable: Flowable or None The flowable this object belongs in. permalink view source

read-only.

inherited from GraphicObject

page_index: The index of the page this object appears on. permalink view source

>>> from brown.core import brown; brown.setup()
>>> some_object = GraphicObject((Mm(20), Mm(50)),
...                             parent=brown.document.pages[5])
>>> some_object.page_index
5
>>> some_object in brown.document.pages[5].descendants
True

read-only.

inherited from GraphicObject

inherited class methods

map_between_items (source, destination) permalink view source

Find a GraphicObject's position relative to another GraphicObject

arguments:

source (GraphicObject): The object to map from

destination (GraphicObject): The object to map to

returns:

Point: The canvas position of destination relative to source

inherited from GraphicObject

inherited static methods

find_staff (graphic_object) permalink view source

Find the first staff which is graphic_object or an ancestor of it.

arguments:

graphic_object (GraphicObject):

returns:

Staff or None

inherited from StaffObject

inherited methods

descendants_of_class_or_subclass (graphic_object_class) permalink view source

Yield all child descendants with a given class or its subclasses.

Args: graphic_object_class (type): The type to search for. This should be a subclass of GraphicObject.

Yields: GraphicObject

inherited from GraphicObject

descendants_of_exact_class (graphic_object_class) permalink view source

Yield all child descendants with a given class.

Args: graphic_object_class (type): The type to search for. This should be a subclass of GraphicObject.

Yields: GraphicObject

inherited from GraphicObject

first_ancestor_of_class_or_subclass (graphic_object_class) permalink view source

Get the closest ancestor with a class or its subclasses.

arguments:

graphic_object_class (type): The type to search for. This should be a subclass of GraphicObject.

returns:

GraphicObject or None

If none can be found, returns None.

inherited from GraphicObject

first_ancestor_of_exact_class (graphic_object_class) permalink view source

Get the closest ancestor with a class.

arguments:

graphic_object_class (type or str): The type to search for. This should be a subclass of GraphicObject. A str of a class name may also be used.

returns:

GraphicObject or None

If none can be found, returns None.

inherited from GraphicObject
permalink view source

_KeySignatureAccidental (MusicText, StaffObject)

A visual accidental.

This should only be used within KeySignatures.

Render one appearance of one key signature accidental.

Because this performs a lot of nontrivial computation for each occurrence of each accidental, this is very inefficient.

If this proves to be a performance bottleneck in the future, there's lots of room for optimization here.

__init__ (pos, length=None, pen=None, brush=None, parent=None) permalink view source

arguments:

pos (Point[Unit] or tuple): The position of the object relative to its parent

length (Unit): The width of the object which can be subject to breaking across lines when in aFlowable. If the object is not inside a Flowable, this has no effect

pen (Pen): The pen to draw outlines with.

brush (Brush): The brush to draw outlines with.

parent (GraphicObject): The parent object or None

inherited properties

staff: Staff The staff associated with this object permalink view source

read-only.

inherited from StaffObject

pos_in_staff: Point The position of this object relative to the staff. permalink view source

This position is in non-flowed space.

# TODO: Definitely cache me when property caching is implemented

read-only.

inherited from StaffObject

length: Unit The breakable length of the object. permalink view source

This is used to determine how and where rendering cuts should be made.

read-only.

inherited from GraphicObject

bounding_rect: The bounding rect override for this text. permalink view source

read-only.

inherited from Text

text: str The text to be drawn permalink view source

read-only.

inherited from Text

font: Font The text font permalink view source

inherited from Text

baseline_y: Unit The y coordinate of the first text line's baseline. permalink view source

read-only.

inherited from Text

scale_factor: float A hard scale factor to be applied to the rendered text permalink view source

inherited from Text

interfaces: set(GraphicObjectInterface) The interfaces for this object permalink view source

Interface objects are created upon calling GraphicObject.render()

Typically each GraphicObject will have one interface for each flowable line it appears in. Objects which fit completely in one visual line will typically have exactly one interface.

If this is an empty set, the object has not been rendered yet with the render() method.

read-only.

inherited from GraphicObject

pos: Point The position of the object relative to its parent. permalink view source

inherited from GraphicObject

x: Unit The x position of the object relative to its parent. permalink view source

inherited from GraphicObject

y: Unit The x position of the object relative to its parent. permalink view source

inherited from GraphicObject

pen: Pen The pen to draw outlines with permalink view source

inherited from GraphicObject

brush: Brush The brush to draw outlines with permalink view source

As a convenience, this may be set with a hex color string for a solid color brush of that color. For brushes using alpha channels and non-solid-color fill patterns, a fully initialized brush must be passed to this.

inherited from GraphicObject

parent: GraphicObject The parent object. permalink view source

If this is set to None, it defaults to the first page of the document.

inherited from GraphicObject

children: set(GraphicObject) All objects who have self as their parent. permalink view source

inherited from GraphicObject

descendants: iter[GraphicObject] All of the objects in the children subtree. permalink view source

This recursively searches all of the object's children (and their children, etc.) and provides an iterator over them.

The current implementation performs a simple recursive DFS over the tree, and has the potential to be rather slow.

read-only.

inherited from GraphicObject

ancestors: iter[GraphicObject] All ancestors of this object. permalink view source

Follows the chain of parents until a document page is reached. The iterable will not include the document Page.

The order begins with self.parent and traverses upward in the tree.

read-only.

inherited from GraphicObject

flowable: Flowable or None The flowable this object belongs in. permalink view source

read-only.

inherited from GraphicObject

page_index: The index of the page this object appears on. permalink view source

>>> from brown.core import brown; brown.setup()
>>> some_object = GraphicObject((Mm(20), Mm(50)),
...                             parent=brown.document.pages[5])
>>> some_object.page_index
5
>>> some_object in brown.document.pages[5].descendants
True

read-only.

inherited from GraphicObject

inherited class methods

map_between_items (source, destination) permalink view source

Find a GraphicObject's position relative to another GraphicObject

arguments:

source (GraphicObject): The object to map from

destination (GraphicObject): The object to map to

returns:

Point: The canvas position of destination relative to source

inherited from GraphicObject

inherited static methods

find_staff (graphic_object) permalink view source

Find the first staff which is graphic_object or an ancestor of it.

arguments:

graphic_object (GraphicObject):

returns:

Staff or None

inherited from StaffObject

inherited methods

descendants_of_class_or_subclass (graphic_object_class) permalink view source

Yield all child descendants with a given class or its subclasses.

Args: graphic_object_class (type): The type to search for. This should be a subclass of GraphicObject.

Yields: GraphicObject

inherited from GraphicObject

descendants_of_exact_class (graphic_object_class) permalink view source

Yield all child descendants with a given class.

Args: graphic_object_class (type): The type to search for. This should be a subclass of GraphicObject.

Yields: GraphicObject

inherited from GraphicObject

first_ancestor_of_class_or_subclass (graphic_object_class) permalink view source

Get the closest ancestor with a class or its subclasses.

arguments:

graphic_object_class (type): The type to search for. This should be a subclass of GraphicObject.

returns:

GraphicObject or None

If none can be found, returns None.

inherited from GraphicObject

first_ancestor_of_exact_class (graphic_object_class) permalink view source

Get the closest ancestor with a class.

arguments:

graphic_object_class (type or str): The type to search for. This should be a subclass of GraphicObject. A str of a class name may also be used.

returns:

GraphicObject or None

If none can be found, returns None.

inherited from GraphicObject