Contour

See also

Notifications:
The Contour object uses notifications to notify observers of changes.

Tasks

Hit Testing

Changed State

Parent

Contour

class defcon.Contour(pointClass=None)

This object represents a contour and it contains a list of points.

This object posts the following notifications:

Name Note
Contour.Changed Posted when the dirty attribute is set.

The Contour object has list like behavior. This behavior allows you to interact with point data directly. For example, to get a particular point:

point = contour[0]

To iterate over all points:

for point in contour:

To get the number of points:

pointCount = len(contour)

To interact with components or anchors in a similar way, use the components and anchors attributes.

bounds

The bounds of the contour’s outline expressed as a tuple of form (xMin, yMin, xMax, yMax).

controlPointBounds

The control bounds of all points in the contour. This only measures the point positions, it does not measure curves. So, curves without points at the extrema will not be properly measured.

clockwise

A boolean representing if the contour has a clockwise direction. Setting this posts a Contour.Changed notification.

open

A boolean indicating if the contour is open or not.

onCurvePoints

A list of all on curve points in the contour.

segments

A list of all points in the contour organized into segments.

clear()

Clear the contents of the contour.

This posts a Contour.Changed notification.

reverse()

Reverse the direction of the contour.

This posts a Contour.Changed notification.

move((x, y))

Move all points in the contour by (x, y).

This posts a Contour.Changed notification.

pointInside((x, y), evenOdd=False)

Returns a boolean indicating if (x, y) is in the “black” area of the contour.

index(point)

Get the index for point.

setStartPoint(index)

Set the point at index as the first point in the contour. This point must be an on-curve point.

This posts a Contour.Changed notification.

positionForProspectivePointInsertionAtSegmentAndT(segmentIndex, t)

Get the precise coordinates and a boolean indicating if the point will be smooth for the given segmentIndex and t.

splitAndInsertPointAtSegmentAndT(segmentIndex, t)

Insert a point into the contour for the given segmentIndex and t.

This posts a Contour.Changed notification.

removeSegment(segmentIndex, preserveCurve=False)

Remove the segment at segmentIndex. If preserveCurve is True, the contour will try to preserve the overall curve shape.

beginPath()

Standard point pen beginPath method. This should not be used externally.

endPath()

Standard point pen endPath method. This should not be used externally.

addPoint((x, y), segmentType=None, smooth=False, name=None)

Standard point pen addPoint method. This should not be used externally.

draw(pen)

Draw the contour with pen.

drawPoints(pointPen)

Draw the contour with pointPen.

addObserver(observer, methodName, notification)

Add an observer to this object’s notification dispatcher.

  • observer An object that can be referenced with weakref.
  • methodName A string epresenting the method to be called when the notification is posted.
  • notification The notification that the observer should be notified of.

The method that will be called as a result of the action must accept a single notification argument. This will be a defcon.tools.notifications.Notification object.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.addObserver(observer=observer, methodName=methodName,
    notification=notification, observable=anObject)
dirty

The dirty state of the object. True if the object has been changed. False if not. Setting this to True will cause the base changed notification to be posted. The object will automatically maintain this attribute and update it as you change the object.

disableNotifications(notification=None, observer=None)

Disable this object’s notifications until told to resume them.

  • notification The specific notification to disable. This is optional. If no notification is given, all notifications will be disabled.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.disableNotifications(
    observable=anObject, notification=notification, observer=observer)
dispatcher

The defcon.tools.notifications.NotificationCenter assigned to this object.

enableNotifications(notification=None, observer=None)

Enable this object’s notifications.

  • notification The specific notification to enable. This is optional.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.enableNotifications(
    observable=anObject, notification=notification, observer=observer)
getParent()

Get the parent. Returns None if no parent is set. Note that because the reference to the parent is stored as a weakref, the parent can disappear if it is no longer referenced by any object other than this one.

hasObserver(observer, notification)

Returns a boolean indicating is the observer is registered for notification.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.hasObserver(observer=observer,
    notification=notification, observable=anObject)
holdNotifications(notification=None)

Hold this object’s notifications until told to release them.

  • notification The specific notification to hold. This is optional. If no notification is given, all notifications will be held.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.holdNotifications(
    observable=anObject, notification=notification)
releaseHeldNotifications(notification=None)

Release this object’s held notifications.

  • notification The specific notification to hold. This is optional.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.releaseHeldNotifications(
    observable=anObject, notification=notification)
removeObserver(observer, notification)

Remove an observer from this object’s notification dispatcher.

  • observer A registered object.
  • notification The notification that the observer was registered to be notified of.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.removeObserver(observer=observer,
    notification=notification, observable=anObject)
setParent(obj)

Set the parent of the object. This will reference the parent using weakref.

undoManager

The undo manager assigned to this object.