| 1 |
from defcon.objects.base import BaseDictObject |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
class Groups(BaseDictObject): |
|---|
| 5 |
|
|---|
| 6 |
""" |
|---|
| 7 |
This object contains all of the groups in a font. |
|---|
| 8 |
|
|---|
| 9 |
**This object posts the following notifications:** |
|---|
| 10 |
|
|---|
| 11 |
============== ==== |
|---|
| 12 |
Name Note |
|---|
| 13 |
============== ==== |
|---|
| 14 |
Groups.Changed Posted when the *dirty* attribute is set. |
|---|
| 15 |
============== ==== |
|---|
| 16 |
|
|---|
| 17 |
This object behaves like a dict. The keys are group names and the |
|---|
| 18 |
values are lists of glyph names:: |
|---|
| 19 |
|
|---|
| 20 |
{ |
|---|
| 21 |
"myGroup" : ["a", "b"], |
|---|
| 22 |
"myOtherGroup" : ["a.alt", "g.alt"], |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
The API for interacting with the data is the same as a standard dict. |
|---|
| 26 |
For example, to get a list of all group names:: |
|---|
| 27 |
|
|---|
| 28 |
groupNames = groups.keys() |
|---|
| 29 |
|
|---|
| 30 |
To get all groups including the glyph lists:: |
|---|
| 31 |
|
|---|
| 32 |
for groupName, glyphList in groups.items(): |
|---|
| 33 |
|
|---|
| 34 |
To get the glyph list for a particular group name:: |
|---|
| 35 |
|
|---|
| 36 |
glyphList = groups["myGroup"] |
|---|
| 37 |
|
|---|
| 38 |
To set the glyph list for a particular group name:: |
|---|
| 39 |
|
|---|
| 40 |
groups["myGroup"] = ["x", "y", "z"] |
|---|
| 41 |
|
|---|
| 42 |
And so on. |
|---|
| 43 |
|
|---|
| 44 |
**Note:** You should not modify the group list and expect the object to |
|---|
| 45 |
know about it. For example, this could cause your changes to be lost:: |
|---|
| 46 |
|
|---|
| 47 |
glyphList = groups["myGroups"] |
|---|
| 48 |
glyphList.append("n") |
|---|
| 49 |
|
|---|
| 50 |
To make sure the change is noticed, reset the list into the object:: |
|---|
| 51 |
|
|---|
| 52 |
glyphList = groups["myGroups"] |
|---|
| 53 |
glyphList.append("n") |
|---|
| 54 |
groups["myGroups"] = glyphList |
|---|
| 55 |
|
|---|
| 56 |
This may change in the future. |
|---|
| 57 |
""" |
|---|
| 58 |
|
|---|
| 59 |
changeNotificationName = "Groups.Changed" |
|---|
| 60 |
beginUndoNotificationName = "Groups.BeginUndo" |
|---|
| 61 |
endUndoNotificationName = "Groups.EndUndo" |
|---|
| 62 |
beginRedoNotificationName = "Groups.BeginRedo" |
|---|
| 63 |
endRedoNotificationName = "Groups.EndRedo" |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
if __name__ == "__main__": |
|---|
| 67 |
import doctest |
|---|
| 68 |
doctest.testmod() |
|---|