Lib¶
Overview¶
Copy the current object into a new object of the same type. |
|
Get or set the lib's parent glyph object. |
|
Get or set the lib's parent font object. |
|
Return the number of keys in the lib. |
|
Return the lib's keys. |
|
Return the lib's items. |
|
Return the lib's values. |
|
Check if the given key exists in the lib. |
|
Set the value for a given key in the lib. |
|
Get the value associated with the given key. |
|
Get the value for the given key in the lib. |
|
Remove the given key from the lib. |
|
Remove the specified key and return its associated value. |
|
Return an iterator over the keys in the lib. |
|
Update the current lib with key-value pairs from another. |
|
Remove all keys from the lib. |
|
Return the environment's native object wrapped by the current object. |
|
Tell the environment that something has changed in the object. |
Reference¶
- class fontParts.base.BaseLib(*args: Any, **kwargs: Any)[source]¶
Represent the basis for a lib object.
This object behaves like a Python
dictobject. Most of the dictionary functionality comes fromBaseDict. Consult that object’s documentation for the required environment implementation details.- Variables:
KeyNormalizer – A function to normalize the key of the dictionary. Defaults to
normalizers.normalizeLibKey.ValueNormalizer – A function to normalize the value of the dictionary. Defaults to
normalizers.normalizeLibValue.
This object is normally created as part of a
BaseFont. An orphanBaseLibobject instance can be created like this:>>> lib = RLib()
Copy¶
- BaseLib.copy() BaseObjectType¶
Copy the current object into a new object of the same type.
The returned object will not have a parent object.
- Returns:
A new
BaseObjectsubclass instance with the same attributes.
Parents¶
- BaseLib.glyph: dynamicProperty¶
Get or set the lib’s parent glyph object.
The value must be a
BaseGlyphinstance orNone.- Returns:
- Raises:
If the font for the lib has already been set.
If attempting to set the glyph when it has already been set and is not the same as the provided glyph.
Example:
>>> glyph = lib.glyph
- BaseLib.font: dynamicProperty¶
Get or set the lib’s parent font object.
The value must be a
BaseFontinstance orNone.- Returns:
- Raises:
If attempting to set the font when it has already been set and is not the same as the provided font.
If the glyph for the lib has already been set.
Example:
>>> font = lib.font
Dictionary¶
- BaseLib.__len__() int[source]¶
Return the number of keys in the lib.
- Returns:
An
intrepresenting the number of keys in the lib.
Example:
>>> len(font.lib) 5
- BaseLib.keys() BaseKeys[str][source]¶
Return the lib’s keys.
- Returns:
A type-view of
stritems representing the lib’s keys.
Example:
>>> font.lib.keys() ["public.glyphOrder", "org.robofab.scripts.SomeData", "public.postscriptNames"]
- BaseLib.items() BaseItems[str, LibValueType][source]¶
Return the lib’s items.
- Each item is represented as a
tupleof key-value pairs, where: key is a
str.value is a type-lib-value.
- Returns:
A type-view of the lib’s
(key, value)pairs.
Example:
>>> font.lib.items() [("public.glyphOrder", ["A", "B", "C"]), ("public.postscriptNames", {'be': 'uni0431', 'ze': 'uni0437'})]
- Each item is represented as a
- BaseLib.values() BaseValues[LibValueType][source]¶
Return the lib’s values.
- Returns:
A type-view of type-lib-value.
Example:
>>> font.lib.items() [["A", "B", "C"], {'be': 'uni0431', 'ze': 'uni0437'}]
- BaseLib.__contains__(key: str) bool[source]¶
Check if the given key exists in the lib.
- Parameters:
key – The key to check for existence as a
str.- Returns:
Example:
>>> "public.glyphOrder" in font.lib True
- BaseLib.__setitem__(key: str, value: LibValue) None[source]¶
Set the value for a given key in the lib.
- Parameters:
key – The key to set as a
str.value – The type-lib-value to set for the given key.
Example:
>>> font.lib["public.glyphOrder"] = ["A", "B", "C"]
- BaseLib.__getitem__(key: str) LibValue[source]¶
Get the value associated with the given key.
- Parameters:
key – The key to retrieve the value for as a
str.- Returns:
The type-lib-value associated with the specified key.
- Raises:
KeyError – If the specified key does not exist.
Example:
>>> font.lib["public.glyphOrder"] ["A", "B", "C"]
Note
Any changes to the returned lib contents will not be reflected in it’s
BaseLibinstance. To make changes to this content, do the following:>>> lib = font.lib["public.glyphOrder"] >>> lib.remove("A") >>> font.lib["public.glyphOrder"] = lib
- BaseLib.get(key: str, default: TypeAliasForwardRef('~fontParts.base.annotations.LibValue') | None = None) TypeAliasForwardRef('~fontParts.base.annotations.LibValue') | None[source]¶
Get the value for the given key in the lib.
If the given key is not found, The specified default will be returned.
- Parameters:
- Returns:
The type-lib-value for the given key, or the default value if the key is not found.
Example:
>>> font.lib.get("public.glyphOrder") ["A", "B", "C"] >>> font.lib.get("missingKey", default="Default Value") "Default Value"
..note:
Any changes to the returned lib contents will not be reflected in it's :class:`BaseLib` instance. To make changes to this content, do the following:: >>> lib = font.lib.get("public.glyphOrder") >>> lib.remove("A") >>> font.lib["public.glyphOrder"] = lib
- BaseLib.__delitem__(key: str) None[source]¶
Remove the given key from the lib.
- Parameters:
key – The key to remove as a
str.
Example:
>>> del font.lib["public.glyphOrder"]
- BaseLib.pop(key: str, default: TypeAliasForwardRef('~fontParts.base.annotations.LibValue') | None = None) TypeAliasForwardRef('~fontParts.base.annotations.LibValue') | None[source]¶
Remove the specified key and return its associated value.
If the key does not exist, the default value is returned.
- Parameters:
- Returns:
The type-lib-value associated with the given key, or the default value if the key is not found.
Example:
>>> font.lib.pop("public.glyphOrder") ["A", "B", "C"]
- BaseLib.__iter__() Iterator[str][source]¶
Return an iterator over the keys in the lib.
The iteration order is not fixed.
- Returns:
An
Iteratorover thestrkeys.
Example:
>>> for key in font.lib: >>> print key "public.glyphOrder" "org.robofab.scripts.SomeData" "public.postscriptNames"
- BaseLib.update(otherLib: MutableMapping[str, TypeAliasForwardRef('~fontParts.base.annotations.LibValue')]) None[source]¶
Update the current lib with key-value pairs from another.
- For each key in otherLib:
If the key exists in the current lib, its value is replaced with the value from otherLib.
If the key does not exist in the current lib, it is added.
Keys that exist in the current lib but are not in otherLib remain unchanged.
- Parameters:
otherLib – A
MutableMappingofstrkeys mapped to type-lib-value to update the current lib with.
Example:
>>> font.lib.update(newLib)
Environment¶
- BaseLib.naked() Any¶
Return the environment’s native object wrapped by the current object.
- Raises:
NotImplementedError – If the method has not been overridden by a subclass.
Example:
>>> loweLevelObj = obj.naked()