brown.interface.path_interface

Qt paths have a few quirks which are good to know about if you're working with them at a lower level.

At creation time, paths have elementCount() == 0, but after a line is created, elementCount() == 2. The first element is a moveTo to the origin; second is the lineTo you asked for. brown paths maintain this behavior.

TODO: This is out of date and may not be true.

If a lineTo(0, 0), a moveTo(0, 0) is performed instead:

>>> from brown.core import brown; brown.setup()
>>> line_to_origin = PathInterface((5, 6))
>>> line_to_origin.line_to((0, 0))
>>> assert(line_to_origin._qt_path == line_to_origin.qt_object.path())
>>> assert(line_to_origin._qt_path.elementCount() == 1)
>>> assert(line_to_origin._qt_path.elementAt(0).isMoveTo() == True)
>>> line_to_elsewhere = PathInterface((5, 6))
>>> line_to_elsewhere.line_to((1, 0))
>>> assert(line_to_elsewhere._qt_path == line_to_elsewhere.qt_object.path())
>>> assert(line_to_elsewhere._qt_path.elementCount() == 2)
>>> assert(line_to_elsewhere._qt_path.elementAt(0).isMoveTo() == True)
>>> assert(line_to_elsewhere._qt_path.elementAt(1).isLineTo() == True)
QPainterPath::ElementType is ambiguous in differentiating between curve control points and curve end points. They are stored sequentially in the path element list; the first element in the sequence is a CurveToElement (enum 2), all following elements in the curve are CurveToDataElement (enum 3). Despite this, all elements until the last in the sequence are control points; the final element is the curve end point.

For instance, if a cubic line is drawn with two control points - cubic_to((0, 5), (10, 5), (10, 0)) - they are stored in the Qt element list as [CurveToElement, CurveToDataElement, CurveToDataElement], which the brown API translates to: [control_point, control_point, curve_to]

classes

Interface for a generic graphic path object.

__init__ (brown_object, pos, pen, brush, clip_start_x=None, clip_width=None) permalink view source

overriden from Interface

arguments:

brown_object (Path): The path this interface belongs to

pos (Point[GraphicUnit] or tuple): The position of the path root relative to the document.

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

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

clip_start_x (Unit or None): The local starting position for the path clipping region. Use None to render from the start.

clip_width (Unit or None): The width of the path clipping region. Use None to render to the end

properties

current_draw_pos: Point[GraphicUnit] The current relative drawing position. permalink view source

This is the location from which operations like line_to() will draw, relative to the position of the Path (self.x and self.y).

This property is read-only. To move the current position, use the move_to() method, implicitly closing the current sub-path and beginning a new one.

read-only.

element_count: int The number of elements in the path. permalink view source

read-only.

inherited properties

pos: Point[Unit] The absolute position of the object. permalink view source

This setter automatically propagates changes to the underlying Qt object.

x: Unit The absolute x position of the object permalink view source

This setter automatically propagates changes to the underlying Qt object.

y: Unit The absolute y position of the object permalink view source

This setter automatically propagates changes to the underlying Qt object.

pen: PenInterface The pen to draw outlines with. permalink view source

This setter automatically propagates changes to the underlying Qt object.

brush: BrushInterface The brush to fill shapes with. permalink view source

This setter automatically propagates changes to the underlying Qt object.

methods

line_to (pos) permalink view source

Draw a path from the current position to a new point.

arguments:

pos (Point or tuple): The target position

returns:

None

Connect a path from the current position to a new position specified by pos, and move self.current_draw_pos to the new point.

cubic_to (self, control_1, control_2, end) permalink view source

Draw a cubic spline from the current position to a new point.

arguments:

control_1 (Point): The local position of the 1st control point

control_2 (Point): The local position of the 2nd control point

end (Point): The local position of the end point

returns:

None

Moves self.current_draw_pos to the new end point.

move_to (pos) permalink view source

Close the current sub-path and start a new one.

arguments:

pos (Point or tuple): The target position

returns:

None

close_subpath () permalink view source

Close the current sub-path and start a new one at (0, 0).

returns:

None

This is equivalent to move_to(0, 0)

element_at (index) permalink view source

Find the element at a given index and return it.

arguments:

index (int): The element index. Use -1 for the last index.

set_element_position_at (index, pos) permalink view source

Set the element at an index to a given position.

arguments:

index (int): The element index to modify

pos (Point[Unit]): The new position for the element.

returns:

None

render () permalink view source

Render the line to the scene.

returns:

None

update_qt_path () permalink view source

Synchronize the contents of self.qt_path to self.qt_object

returns:

None