Groups

See also

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

Tasks

Parent

Groups

class defcon.Groups

This object contains all of the groups in a font.

This object posts the following notifications:

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

This object behaves like a dict. The keys are group names and the values are lists of glyph names:

{
    "myGroup" : ["a", "b"],
    "myOtherGroup" : ["a.alt", "g.alt"],
}

The API for interacting with the data is the same as a standard dict. For example, to get a list of all group names:

groupNames = groups.keys()

To get all groups including the glyph lists:

for groupName, glyphList in groups.items():

To get the glyph list for a particular group name:

glyphList = groups["myGroup"]

To set the glyph list for a particular group name:

groups["myGroup"] = ["x", "y", "z"]

And so on.

Note: You should not modify the group list and expect the object to know about it. For example, this could cause your changes to be lost:

glyphList = groups["myGroups"]
glyphList.append("n")

To make sure the change is noticed, reset the list into the object:

glyphList = groups["myGroups"]
glyphList.append("n")
groups["myGroups"] = glyphList

This may change in the future.

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.