Package pytilities :: Package geometry :: Module verbosevector
[hide private]
[frames] | no frames]

Source Code for Module pytilities.geometry.verbosevector

  1  # Copyright (C) 2010 Tim Diels <limyreth@users.sourceforge.net> 
  2  #  
  3  # This file is part of pytilities. 
  4  #  
  5  # pytilities is free software: you can redistribute it and/or modify 
  6  # it under the terms of the GNU General Public License as published by 
  7  # the Free Software Foundation, either version 3 of the License, or 
  8  # (at your option) any later version. 
  9  #  
 10  # pytilities is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  # GNU General Public License for more details. 
 14  #  
 15  # You should have received a copy of the GNU General Public License 
 16  # along with pytilities.  If not, see <http://www.gnu.org/licenses/>. 
 17  # 
 18   
 19  __docformat__ = 'reStructuredText' 
 20   
 21  from pytilities import event, AttributeCollectionBase 
 22  from .vector import Vector 
 23   
 24  @event.dispatcher("changed") 
25 -class VerboseVector(AttributeCollectionBase):
26 27 """ 28 `Vector` wrapper that sends out events. 29 30 It supports all attributes of `Vector`. For `Vector` specific 31 documentation, see `Vector`. 32 33 Events: 34 35 changed 36 x and/or y value changed 37 38 Parameters: 39 40 `old_tuple` :: (x, y) 41 the old x and y values 42 """ 43
44 - def __init__(self, v):
45 """ 46 Construct a VerboseVector. 47 48 Parameters: 49 50 v :: Vector 51 the vector to wrap 52 """ 53 AttributeCollectionBase.__init__(self) 54 55 self.__v = v 56 57 # delegate to wrapped object 58 delegator = Vector.Delegator("immutable", v) 59 self._append_attribute_collection(delegator)
60 61 @property
62 - def x(self):
63 return self.__v.x
64 65 @x.setter
66 - def x(self, value):
67 old_tuple = self.__v.xy 68 self.__v.x = value 69 self.__dispatch("changed", old_tuple)
70 71 @property
72 - def y(self):
73 return self.__v.y
74 75 @y.setter
76 - def y(self, value):
77 old_tuple = self.__v.xy 78 self.__v.y = value 79 self.__dispatch("changed", old_tuple)
80
81 - def move_to(self, *args):
82 old_tuple = self.__v.xy 83 self.__v.move_to(*args) 84 self.__dispatch("changed", old_tuple)
85
86 - def move_by(self, *args):
87 old_tuple = self.__v.xy 88 self.__v.move_by(*args) 89 self.__dispatch("changed", old_tuple)
90
91 - def assign(self, v):
92 old_tuple = self.__v.xy 93 self.__v.assign(v) 94 self.__dispatch("changed", old_tuple)
95 96 @property
97 - def length(self):
98 return abs(self)
99 100 @length.setter
101 - def length(self, value):
102 old_tuple = self.__v.xy 103 self.__v.length = value 104 self.__dispatch("changed", old_tuple)
105
106 - def normalize(self):
107 old_tuple = self.__v.xy 108 self.__v.normalize() 109 self.__dispatch("changed", old_tuple) 110 return self
111
112 - def __iadd__(self, other):
113 old_tuple = self.__v.xy 114 self.__v += other 115 self.__dispatch("changed", old_tuple) 116 return self
117
118 - def __imul__(self, other):
119 old_tuple = self.__v.xy 120 self.__v *= other 121 self.__dispatch("changed", old_tuple) 122 return self
123