Skip to content

Commit

Permalink
Merge pull request #352 from robotools/sticky_image_object
Browse files Browse the repository at this point in the history
Make the glyph.image object sticky just like lib objects
  • Loading branch information
typesupply committed Apr 21, 2021
2 parents 4eae46d + dd917d8 commit 6cfd94f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
11 changes: 6 additions & 5 deletions Lib/defcon/objects/glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class Glyph(BaseObject):
- Glyph.NoteChanged
- Glyph.LibChanged
- Glyph.ImageChanged
- Glyph.ImageWillBeDeleted
- Glyph.ImageWillBeCleared
- Glyph.ImageCleared
- Glyph.ContourWillBeAdded
- Glyph.ContourWillBeDeleted
- Glyph.ContoursChanged
Expand Down Expand Up @@ -1120,12 +1121,12 @@ def _get_image(self):
return self._image

def _set_image(self, image):
# removing image
# clearing the image
if image is None:
if self._image is not None:
self.postNotification(notification="Glyph.ImageWillBeDeleted")
self.endSelfImageNotificationObservation()
self._image = None
self.postNotification(notification="Glyph.ImageWillBeCleared")
self._image.clear()
self.postNotification(notification="Glyph.ImageCleared")
self.postNotification(notification="Glyph.ImageChanged")
self.dirty = True
# adding image
Expand Down
20 changes: 13 additions & 7 deletions Lib/defcon/objects/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from defcon.objects.base import BaseDictObject
from defcon.objects.color import Color

_defaultTransformation = {

_defaultImage = {
"fileName": None,
"color" : None,
"xScale" : 1,
"xyScale" : 0,
"yxScale" : 0,
Expand All @@ -12,7 +15,6 @@
"yOffset" : 0
}


class Image(BaseDictObject):

"""
Expand Down Expand Up @@ -42,13 +44,11 @@ def __init__(self, glyph=None, imageDict=None):
self.glyph = glyph
super(Image, self).__init__()
self.beginSelfNotificationObservation()
self["fileName"] = None
self["color"] = None
if imageDict is not None:
self.update(imageDict)
for key, value in _defaultTransformation.items():
for key, value in _defaultImage.items():
if self.get(key) is None:
self[key] = value
if imageDict is not None:
self.update(imageDict)
self._dirty = False

def __len__(self):
Expand All @@ -61,6 +61,12 @@ def __len__(self):
return 0
return super(Image, self).__len__()

def clear(self):
# clear all the image data and fill it with default values
super(BaseDictObject, self).clear()
for key, value in _defaultImage.items():
if self.get(key) is None:
self[key] = value
# --------------
# Parent Objects
# --------------
Expand Down

0 comments on commit 6cfd94f

Please sign in to comment.