1 '''
2 Defines classes for representing device capabilities and styles.
3
4 @author: Brett Clippingdale
5 @author: Peter Parente
6 @author: Scott Haeger
7 @organization: IBM Corporation
8 @copyright: Copyright (c) 2005, 2007 IBM Corporation
9
10 @license: I{The BSD License}
11 All rights reserved. This program and the accompanying materials are made
12 available under the terms of the BSD license which accompanies
13 this distribution, and is available at
14 U{http://www.opensource.org/licenses/bsd-license.php}
15 '''
16
17 from AccessEngine import AEState
18 from Tools.i18n import _
19 from AccessEngine.AEConstants import *
20
21 -class Style(AEState.AEState):
22 '''
23 Extends L{AEState <AEState.AEState>} with new kinds of settings for devices.
24
25 Mute (bool): Is all output inhibited? Non-persistent by default.
26
27 @ivar parent_style: Another style object to which this one should dispatch
28 attribute lookups if attributes are not defined in this object
29 @type parent_style: L{Style}
30 '''
32 '''
33 Initializes the style object to which to dispatch requests for attributes
34 that are not defined in this object.
35
36 @param parent_style: Parent style object
37 @type parent_style: L{Style}
38 '''
39 super(Style, self).__init__()
40
41 self.parent_style = parent_style
42
43 if self.isDefault():
44
45 self._initDefault()
46
47 self.newBool('Mute', False, _('Mute'),
48 _('When set, all output is inhibited. This setting is not '
49 'saved to disk.'), False)
50 else:
51
52 self._initFlyweight()
53
54 - def init(self, device):
55 '''
56 Extends the default method signature with a parameter containing a
57 reference the device to which this style belongs.
58
59 @param device: Output device reference
60 @type device: L{AEOutput <AEOutput.AEOutput>}
61 '''
62 pass
63
65 '''
66 Does nothing by default. Override to initialze settings that should be
67 created on default objects.
68 '''
69 pass
70
72 '''
73 Copies references to all default settings into this object. This means the
74 setting are shared between this object and the default.
75 '''
76 self.settings.update(self.parent_style.settings)
77
79 '''
80 Gets if the current style is the default meaning it does not have a parent.
81
82 @return: Is this style the default?
83 @rtype: boolean
84 '''
85 return self.parent_style is None
86
88 '''
89 Gets a reference to the default style if it exists or None if it does not.
90
91 @return: L{parent_style}
92 @rtype: L{Style}
93 '''
94 return self.parent_style
95
97 '''
98 Makes a copy of this object and its parent.
99
100 @return: New style object
101 @rtype: L{Style}
102 '''
103 c = super(Style, self).copy()
104 ps = self.parent_style
105 if ps is not None:
106 psc = ps.copy()
107 c.parent_style = psc
108 return c
109
111 '''
112 Gets if values in settings have changed since the last call to
113 L{makeClean}.
114
115 @return: Dirty or not?
116 @rtype: boolean
117 '''
118 d = super(Style, self).isDirty()
119 if self.parent_style is None:
120 return d
121 else:
122 return d or self.parent_style.isDirty()
123
125 '''
126 Resets the dirty set to empty.
127 '''
128 super(Style, self).makeClean()
129 if self.parent_style is not None:
130 self.parent_style.makeClean()
131
133 '''
134 Iterates over all of the names in L{AEState.dirty
135 <AccessEngine.AEState.Base.AEState.dirty>} starting with the parent and then
136 working through this object.
137
138 @return: Name of a dirty setting
139 @rtype: string
140 '''
141 for name in self.parent_style.iterDirty():
142 yield name
143 for name in self.dirty:
144 yield name
145
146 - def newRelNumeric(self, name, default, label, min, max, precision,
147 description='', persist=True):
148 '''
149 Adds a new L{AEState.Setting.RelNumericSetting} to this group.
150
151 @param name: New name of the setting
152 @type name: string
153 @param default: Default value of the setting
154 @type default: float
155 @param label: Label for the new L{AEState.Setting}
156 @type label: string
157 @param min: Minimum value in the range
158 @type min: number
159 @param max: Maximum value in the range
160 @type max: number
161 @param precision: Number of decimal places
162 @type precision: integer
163 @param description: Extended description of the L{AEState.Setting}
164 @type description: string
165 @param persist: Persist the setting value to disk?
166 @type persist: boolean
167 @return: New setting object
168 @rtype: L{AEState.NumericSetting}
169 '''
170 s = AEState.RelNumericSetting(self, name, default, label, description,
171 persist, min, max, precision)
172 self.settings[name] = s
173 return s
174
175 - def newRelRange(self, name, default, label, min, max, precision,
176 description='', persist=True):
177 '''
178 Adds a new L{AEState.Setting.RelRangeSetting} to this group.
179
180 @param name: New name of the setting
181 @type name: string
182 @param default: Default value of the setting
183 @type default: float
184 @param label: Label for the new L{AEState.Setting}
185 @type label: string
186 @param min: Minimum value in the range
187 @type min: number
188 @param max: Maximum value in the range
189 @type max: number
190 @param precision: Number of decimal places
191 @type precision: integer
192 @param description: Extended description of the L{AEState.Setting}
193 @type description: string
194 @param persist: Persist the setting value to disk?
195 @type persist: boolean
196 @return: New setting object
197 @rtype: L{AEState.RangeSetting}
198 '''
199 s = AEState.RelRangeSetting(self, name, default, label, description,
200 persist, min, max, precision)
201 self.settings[name] = s
202 return s
203
204 - def newRelPercent(self, name, default, label, min, max, precision,
205 description='', persist=True):
206 '''
207 Adds a new L{AEState.Setting.RelPercentRangeSetting} to this group.
208
209 @param name: New name of the setting
210 @type name: string
211 @param default: Default value of the setting
212 @type default: float
213 @param label: Label for the new L{AEState.Setting}
214 @type label: string
215 @param min: Minimum value in the range to be shown as 0%
216 @type min: number
217 @param max: Maximum value in the range to be shown as 100%
218 @type max: number
219 @param precision: Number of decimal places
220 @type precision: integer
221 @param description: Extended description of the L{AEState.Setting}
222 @type description: string
223 @param persist: Persist the setting value to disk?
224 @type persist: boolean
225 @return: New setting object
226 @rtype: L{AEState.Setting.PercentRangeSetting}
227 '''
228 s = AEState.RelPercentRangeSetting(self, name, default, label, description,
229 persist, min, max, precision)
230 self.settings[name] = s
231 return s
232