Advertisement
SVXX

BaseFrame Property Setter

Jun 2nd, 2014
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. @preferred_representation.setter
  2. def preferred_representation(self, value):
  3. # In reality do validation of `value` and allow string input
  4. rep_dict = {'spherical': SphericalRepresentation,
  5. 'cartesian': CartesianRepresentation,
  6. 'unitspherical': UnitSphericalRepresentation,
  7. 'cylindrical': CylindricalRepresentation}
  8.  
  9. # If value is a string, parse it
  10. if type(value) is str and value.lower() in rep_dict:
  11. value = rep_dict[value.lower()]
  12. # Converted to representation object, now check allowed representations
  13. if value in self._representations:
  14. self._preferred_representation = value
  15. else:
  16. raise ValueError('{0} is not a valid representation for {1}'.format(value, self.__class__))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement