Changeset 314


Ignore:
Timestamp:
01/14/09 23:15:00 (4 years ago)
Author:
tal
Message:
I never got around to fully wrapping the lib and the note. That is taken care of now. The classes also moved to properties to prevent tampering.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • packages/defcon/branches/ufo2/Lib/defcon/objects/glyph.py

    r310 r314  
    44from defcon.tools.notifications import NotificationCenter 
    55 
    6  
    76_representationFactories = {} 
    87 
     
    1716 
    1817    """ 
    19     XXX lib, note, controlPointBounds 
     18    XXX controlPointBounds 
    2019 
    2120    This object represents a glyph and it contains contour, component, anchor 
     
    5150    _notificationName = "Glyph.Changed" 
    5251 
    53     def __init__(self, contourClass=None, componentClass=None, anchorClass=None): 
     52    def __init__(self, contourClass=None, componentClass=None, anchorClass=None, libClass=None): 
    5453        super(Glyph, self).__init__() 
     54 
    5555        self._parent = None 
    5656        self._dirty = False 
     
    5858        self._unicodes = [] 
    5959        self._width = 0 
    60         self.note = None 
    61         self.lib = {} 
     60        self._note = None 
    6261        self._dispatcher = None 
    6362 
     
    6564        self._components = [] 
    6665        self._anchors = [] 
     66 
     67        self._lib = None 
    6768 
    6869        self._boundsCache = None 
     
    7980            from anchor import Anchor 
    8081            anchorClass = Anchor 
    81  
    82         self.contourClass = contourClass 
    83         self.componentClass = componentClass 
    84         self.anchorClass = anchorClass 
     82        if libClass is None: 
     83            from lib import Lib 
     84            libClass = Lib 
     85 
     86        self._contourClass = contourClass 
     87        self._componentClass = componentClass 
     88        self._anchorClass = anchorClass 
     89 
     90        self._lib = libClass() 
     91        self._lib.setParent(self) 
    8592 
    8693    def _set_dispatcher(self, dispatcher): 
     
    93100            for anchor in self._anchors: 
    94101                self._setParentDataInAnchor(anchor) 
     102            self._lib.dispatcher = dispatcher 
     103            self._lib.addObserver(observer=self, methodName="_libContentChanged", notification="Lib.Changed") 
    95104            self.addObserver(observer=self, methodName="destroyAllRepresentations", notification="Glyph.Changed") 
    96105 
     
    103112    # Attributes 
    104113    # ---------- 
     114 
     115    def _get_contourClass(self): 
     116        return self._contourClass 
     117 
     118    contourClass = property(_get_contourClass, doc="The class used for contours.") 
     119 
     120    def _get_componentClass(self): 
     121        return self._componentClass 
     122 
     123    componentClass = property(_get_componentClass, doc="The class used for components.") 
     124 
     125    def _get_anchorClass(self): 
     126        return self._anchorClass 
     127 
     128    anchorClass = property(_get_anchorClass, doc="The class used for anchors.") 
    105129 
    106130    def _set_name(self, value): 
     
    209233 
    210234    anchors = property(_get_anchors, doc="An ordered list of :class:`Anchor` objects stored in the glyph.") 
     235 
     236    def _get_note(self): 
     237        return self._note 
     238 
     239    def _set_note(self, value): 
     240        assert isinstance(value, basestring) 
     241        self._note = value 
     242        self.dirty = True 
     243 
     244    note = property(_get_note, _set_note, doc="An arbitrary note for the glyph. Setting this will post a *Glyph.Changed* notification.") 
     245 
     246    def _get_lib(self): 
     247        return self._lib 
     248 
     249    def _set_lib(self, value): 
     250        self._lib.clear() 
     251        self._lib.update(value) 
     252        self.dirty = True 
     253 
     254    lib = property(_get_lib, _set_lib, doc="The glyph's :class:`Lib` object. Setting this will clear any existing lib data and post a *Glyph.Changed* notification if data was replaced.") 
    211255 
    212256    # ----------- 
     
    678722        self.dirty = True 
    679723 
     724    def _libContentChanged(self, notification): 
     725        self.dirty = True 
     726 
    680727 
    681728# ----- 
Note: See TracChangeset for help on using the changeset viewer.