-
Notifications
You must be signed in to change notification settings - Fork 35
/
features.py
89 lines (67 loc) · 2.38 KB
/
features.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from __future__ import absolute_import
import weakref
from defcon.objects.base import BaseObject
class Features(BaseObject):
"""
This object contais the test represening features in the font.
**This object posts the following notifications:**
- Features.Changed
- Features.BeginUndo
- Features.EndUndo
- Features.BeginRedo
- Features.EndRedo
- Features.TextChanged
"""
changeNotificationName = "Features.Changed"
beginUndoNotificationName = "Features.BeginUndo"
endUndoNotificationName = "Features.EndUndo"
beginRedoNotificationName = "Features.BeginRedo"
endRedoNotificationName = "Features.EndRedo"
representationFactories = {}
def __init__(self, font=None):
self._font = None
if font is not None:
self._font = weakref.ref(font)
super(Features, self).__init__()
self.beginSelfNotificationObservation()
self._dirty = False
self._text = None
# --------------
# Parent Objects
# --------------
def getParent(self):
return self.font
def _get_font(self):
if self._font is not None:
return self._font()
return None
font = property(_get_font, doc="The :class:`Font` that this object belongs to.")
# ----
# Text
# ----
def _set_text(self, value):
oldValue = self._text
if oldValue == value:
return
self._text = value
self.postNotification("Features.TextChanged", data=dict(oldValue=oldValue, newValue=value))
self.dirty = True
def _get_text(self):
return self._text
text = property(_get_text, _set_text, doc="The raw feature text. Setting this post *Features.TextChanged* and *Features.Changed* notifications.")
# ------------------------
# Notification Observation
# ------------------------
def endSelfNotificationObservation(self):
super(Features, self).endSelfNotificationObservation()
self._font = None
# -----------------------------
# Serialization/Deserialization
# -----------------------------
def getDataForSerialization(self, **kwargs):
from functools import partial
getters = [('text', partial(getattr, self))]
return self._serialize(getters, **kwargs)
def setDataFromSerialization(self, data):
if 'text' in data:
self.text = data['text']