Lib¶
Overview¶
BaseLib.copy |
Copy this object into a new object of the same type. |
BaseLib.glyph |
The lib’s parent glyph. |
BaseLib.font |
The lib’s parent font. |
BaseLib.__len__ |
Returns the number of keys in Lib as an int .. |
BaseLib.keys |
Returns a list of all the key names in Lib. |
BaseLib.items |
Returns a list of tuple of each key name and key items. |
BaseLib.values |
Returns a list of each named key’s members. |
BaseLib.__contains__ |
Tests to see if a lib name is in the Lib. |
BaseLib.__setitem__ |
Sets the key to the list of items. |
BaseLib.__getitem__ |
Returns the contents of the named lib. |
BaseLib.get |
Returns the contents of the named key. |
BaseLib.__delitem__ |
Removes key from the Lib. |
BaseLib.pop |
Removes the key from the Lib and returns the list of key members. |
BaseLib.__iter__ |
Iterates through the Lib, giving the key for each iteration. |
BaseLib.update |
Updates the Lib based on otherLib. |
BaseLib.clear |
Removes all keys from Lib, resetting the Lib to an empty dictionary. |
BaseLib.naked |
Return the environment’s native object that has been wrapped by this object. |
BaseLib.changed |
Tell the environment that something has changed in the object. |
Reference¶
-
class
fontParts.base.
BaseLib
(*args, **kwargs)[source]¶ A Lib object. This object normally created as part of a
BaseFont
. An orphan Lib object can be created like this:>>> lib = RLib()
This object behaves like a Python dictionary. Most of the dictionary functionality comes from
BaseDict
, look at that object for the required environment implementation details.Lib uses
normalizers.normalizeLibKey
to normalize the key of thedict
, andnormalizers.normalizeLibValue
to normalize the value of thedict
.
Copy¶
-
BaseLib.
copy
()¶ Copy this object into a new object of the same type. The returned object will not have a parent object.
Dictionary¶
-
BaseLib.
keys
()[source]¶ Returns a
list
of all the key names in Lib. This list will be unordered.:>>> font.lib.keys() ["public.glyphOrder", "org.robofab.scripts.SomeData", "public.postscriptNames"]
-
BaseLib.
items
()[source]¶ Returns a list of
tuple
of each key name and key items. Keys are String and key members are alist
of String. The initial list will be unordered.>>> font.lib.items() [("public.glyphOrder", ["A", "B", "C"]), ("public.postscriptNames", {'be': 'uni0431', 'ze': 'uni0437'})]
-
BaseLib.
values
()[source]¶ Returns a
list
of each named key’s members. This will be a list of lists, the key members will be alist
of String. The initial list will be unordered.>>> font.lib.items() [["A", "B", "C"], {'be': 'uni0431', 'ze': 'uni0437'}]
-
BaseLib.
__contains__
(key)[source]¶ Tests to see if a lib name is in the Lib. key will be a String. This returns a
bool
indicating if the key is in the Lib.>>> "public.glyphOrder" in font.lib True
-
BaseLib.
__setitem__
(key, items)[source]¶ Sets the key to the list of items. key is the lib name as a String and items is a
list
of items as String.>>> font.lib["public.glyphOrder"] = ["A", "B", "C"]
-
BaseLib.
__getitem__
(key)[source]¶ Returns the contents of the named lib. key is a String. The returned value will be a
list
of the lib contents.:>>> font.lib["public.glyphOrder"] ["A", "B", "C"]
It is important to understand that any changes to the returned lib contents will not be reflected in the Lib object. If one wants to make a change to the lib contents, one should do the following:
>>> lib = font.lib["public.glyphOrder"] >>> lib.remove("A") >>> font.lib["public.glyphOrder"] = lib
-
BaseLib.
get
(key, default=None)[source]¶ Returns the contents of the named key. key is a String, and the returned values will either be
list
of key contents orNone
if no key was found.>>> font.lib["public.glyphOrder"] ["A", "B", "C"]
It is important to understand that any changes to the returned key contents will not be reflected in the Lib object. If one wants to make a change to the key contents, one should do the following:
>>> lib = font.lib["public.glyphOrder"] >>> lib.remove("A") >>> font.lib["public.glyphOrder"] = lib
-
BaseLib.
__delitem__
(key)[source]¶ Removes key from the Lib. key is a String.:
>>> del font.lib["public.glyphOrder"]
-
BaseLib.
pop
(key, default=None)[source]¶ Removes the key from the Lib and returns the
list
of key members. If no key is found, default is returned. key is a String. This must return either default or alist
of items as String.>>> font.lib.pop("public.glyphOrder") ["A", "B", "C"]
-
BaseLib.
__iter__
()[source]¶ Iterates through the Lib, giving the key for each iteration. The order that the Lib will iterate though is not fixed nor is it ordered.:
>>> for key in font.lib: >>> print key "public.glyphOrder" "org.robofab.scripts.SomeData" "public.postscriptNames"
-
BaseLib.
update
(otherLib)[source]¶ Updates the Lib based on otherLib. otherLib* is a
dict
of keys. If a key from otherLib is in Lib the key members will be replaced by the key members from otherLib. If a key from otherLib is not in the Lib, it is added to the Lib. If Lib contain a key name that is not in otherLib*, it is not changed.>>> font.lib.update(newLib)
Environment¶
-
BaseLib.
naked
()¶ Return the environment’s native object that has been wrapped by this object.
>>> loweLevelObj = obj.naked()
-
BaseLib.
changed
(*args, **kwargs)¶ Tell the environment that something has changed in the object. The behavior of this method will vary from environment to environment.
>>> obj.changed()