| | 351 | class TriggerProperty(UnitProperty): |
|---|
| | 352 | """UnitProperty subclass for managing immediate triggers on set. |
|---|
| | 353 | |
|---|
| | 354 | The __set__ method will call the on_set method, which should then |
|---|
| | 355 | deal with the new value. |
|---|
| | 356 | """ |
|---|
| | 357 | |
|---|
| | 358 | def __set__(self, unit, value): |
|---|
| | 359 | if self.coerce: |
|---|
| | 360 | value = self.coerce(unit, value) |
|---|
| | 361 | oldvalue = unit._properties[self.key] |
|---|
| | 362 | if oldvalue != value: |
|---|
| | 363 | unit._properties[self.key] = value |
|---|
| | 364 | if unit.sandbox: |
|---|
| | 365 | self.on_set(unit, oldvalue) |
|---|
| | 366 | |
|---|
| | 367 | def on_set(self, unit, oldvalue): |
|---|
| | 368 | pass |
|---|
| | 369 | |
|---|
| | 370 | |
|---|