Class GPath

This class represents a sequence of line segements. The path is defined by the points attribute which is an (even) sequence of alternating x and y values. When drawn in a GView object, the line starts from one x-y pair in points and goes to the next x-y pair. If points has length 2n, then the result is n-1 line segments.

The class uses the attribute linecolor to determine the color of the line and the attribute linewidth to determine the width. The attribute fillcolor is unused (even though it is inherited from GObject).

The attributes width and height are present in this object, but they are now read-only. These values are computed from the list of points.

On the other hand, the attributes x and y are used. By default, these values are 0. However, if they are nonzero, then Python will add them to all of the points in the path, shifting the path accordingly.

Constructor

GPath(**keywords)

Creates a new sequence of line segments.

To use the constructor for this class, you should provide it with a list of keyword arguments that initialize various attributes. For example, to create a path from (0,0) to (2,3) with width 2, use the constructor call

GPath(points=[0,0,2,3],linewidth=2)

This class supports the same keywords as GObject, though some of them are unused, as the width and height attributes are now immutable. The primary keywords for this class are points, linecolor, and linewidth.

Parameter:keywords (keys are attribute names) – dictionary of keyword arguments

Attributes

This class has all of the attributes of GObject. In addition, it has the following new or altered attributes.

points

The sequence of points that make up this line.

Invariant: Must be a sequence (list or tuple) of int or float. The length of this sequence must be even with length at least 4.

x

The horizontal coordinate of the object center.

invariant: Value must be an int or float

y

The vertical coordinate of the object center.

invariant: Value must be an int or float

width

The horizontal width of this path.

The value is the width of the smallest bounding box that contains all of the points in the line AND the origin (0,0).

Invariant: Must be an int or float > 0.

height

The vertical height of this path.

The value is the height of the smallest bounding box that contains all of the points in the line AND the origin (0,0).

Invariant: Must be an int or float > 0.

fillcolor

This attribute is ignored.

Methods

This class has all of the methods of GObject. In addition, it has the following new or altered methods.

contains(point)

Checks whether this shape contains the point

This method always returns False as a GPath has no interior.

Parameter:point (Point2` or a pair of numbers) – the point to check
Returns:True if the shape contains this point
Return type:bool
near(point)

Checks whether this path is near the given point

To determine if (x,y) is near the path, we compute the minimum distances from (x,y) to the path. If this distance is less than e-6, we return True.

Parameter:point (Point2` or a pair of numbers) – the point to check
Returns:True if this path is near the give point; False otherwise.
Return type:bool

Return to top level