Changeset 1036
- Timestamp:
- 12/02/11 21:59:11 (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
packages/defcon/branches/ufo3/Lib/defcon/objects/layer.py
r1031 r1036 22 22 Layer.GlyphsChanged 23 23 Layer.GlyphChanged 24 Layer.GlyphWillBeAdded 24 25 Layer.GlyphAdded 26 Layer.GlyphWillBeDeleted 25 27 Layer.GlyphDeleted 26 Layer.GlyphWillBeDeleted27 28 Layer.GlyphNameChanged 28 29 Layer.NameChanged … … 175 176 raise KeyError, "%s not in layer" % name 176 177 glyph = self.instantiateGlyphObject() 177 self.beginSelfGlyphNotificationObservation(glyph)178 178 glyph.disableNotifications() 179 glyph.name = name 180 self._insertGlyph(glyph) 179 181 pointPen = glyph.getPointPen() 180 182 self._glyphSet.readGlyph(glyphName=name, glyphObject=glyph, pointPen=pointPen) 181 183 glyph.dirty = False 182 184 glyph.enableNotifications() 183 self._glyphs[name] = glyph184 185 self._stampGlyphDataState(glyph) 185 186 return glyph … … 191 192 with the new glyph. 192 193 193 This posts *Layer.GlyphAdded* and *Layer.Changed* notifications. 194 """ 194 This posts *Layer.GlyphWillBeAdded*, *Layer.GlyphAdded* 195 and *Layer.Changed* notifications. 196 """ 197 self.postNotification("Layer.GlyphWillBeAdded", data=(dict(name=name))) 195 198 if name in self: 196 199 self._unicodeData.removeGlyphData(name, self[name].unicodes) 197 200 glyph = self.instantiateGlyphObject() 198 self.beginSelfGlyphNotificationObservation(glyph)199 201 glyph.disableNotifications() 200 202 glyph.name = name 203 self._insertGlyph(glyph) 201 204 glyph.enableNotifications() 202 self._glyphs[name] = glyph203 if name in self._scheduledForDeletion:204 del self._scheduledForDeletion[name]205 self._keys.add(name)206 205 self.postNotification("Layer.GlyphAdded", data=(dict(name=name))) 207 206 self.dirty = True … … 215 214 be replaced with the new glyph. 216 215 217 This posts *Layer.GlyphAdded* and *Layer.Changed* notifications. 216 This posts *Layer.GlyphWillBeAdded*, *Layer.GlyphAdded* 217 and *Layer.Changed* notifications. 218 218 """ 219 219 # DO NOT ACTUALLY INSERT THE GLYPH! … … 225 225 if name is None: 226 226 name = source.name 227 self.postNotification("Layer.GlyphWillBeAdded", data=(dict(name=name))) 227 228 self.holdNotifications() 228 229 self.newGlyph(name) 229 230 dest = self[name] 230 dest.disableNotifications()231 231 dest.copyDataFromGlyph(glyph) 232 dest.enableNotifications()233 if dest.unicodes:234 self._unicodeData.addGlyphData(name, dest.unicodes)235 232 self.releaseHeldNotifications() 236 233 return dest 234 235 def _insertGlyph(self, glyph, beginObservations=True): 236 name = glyph.name 237 self._glyphs[name] = glyph 238 if name in self._scheduledForDeletion: 239 del self._scheduledForDeletion[name] 240 self._keys.add(name) 241 if beginObservations: 242 self.beginSelfGlyphNotificationObservation(glyph) 243 if glyph.unicodes: 244 self._unicodeData.addGlyphData(name, glyph.unicodes) 237 245 238 246 # ------------- … … 256 264 raise KeyError, "%s not in layer" % name 257 265 self.postNotification("Layer.GlyphWillBeDeleted", data=dict(name=name)) 266 self._deleteGlyph(name) 267 self.postNotification("Layer.GlyphDeleted", data=dict(name=name)) 268 self.dirty = True 269 270 def _deleteGlyph(self, name, endObservations=True): 258 271 self._unicodeData.removeGlyphData(name, self[name].unicodes) 259 272 dataOnDiskTimeStamp = None … … 261 274 if name in self._glyphs: 262 275 glyph = self._glyphs.pop(name) 263 self.endSelfGlyphNotificationObservation(glyph) 276 if endObservations: 277 self.endSelfGlyphNotificationObservation(glyph) 264 278 dataOnDiskTimeStamp = glyph._dataOnDiskTimeStamp 265 279 dataOnDisk = glyph._dataOnDisk … … 268 282 if self._glyphSet is not None and name in self._glyphSet: 269 283 self._scheduledForDeletion[name] = dict(dataOnDiskTimeStamp=dataOnDiskTimeStamp, dataOnDisk=dataOnDisk) 270 self.postNotification("Layer.GlyphDeleted", data=dict(name=name))271 self.dirty = True272 284 273 285 def __len__(self): … … 707 719 newName = data["newValue"] 708 720 glyph = self._glyphs[oldName] 709 self.disableNotifications() 710 del self[oldName] # use __del__ because *lots* of things have to be adjusted 711 self.enableNotifications() 712 self._glyphs[newName] = glyph 713 self._keys.add(newName) 721 self._deleteGlyph(oldName, endObservations=False) 714 722 self._unicodeData.removeGlyphData(oldName, glyph.unicodes) 715 self._ unicodeData.addGlyphData(newName, glyph.unicodes)723 self._insertGlyph(glyph, beginObservations=False) 716 724 self.postNotification("Layer.GlyphNameChanged", data=dict(oldValue=oldName, newValue=newName)) 717 725
Note: See TracChangeset
for help on using the changeset viewer.
