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

Source Code for Module pytilities.geometry.verboserectangle

  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 pytilities.delegation import Delegator 
 23  from .verbosevector import VerboseVector 
 24   
 25  @event.dispatcher("size_changed") 
26 -class VerboseRectangle(AttributeCollectionBase):
27 28 """ 29 A `Rectangle` wrapper that sends out events 30 31 It supports all attributes of `Rectangle`. For `Rectangle` specific 32 documentation, see `Rectangle`. 33 34 Events: 35 36 size_changed 37 Parameters: 38 39 `old_size` :: Vector 40 the old size 41 """ 42
43 - def __init__(self, r):
44 """ 45 Construct a `VerboseRectangle`. 46 47 Parameters: 48 r :: Rectangle 49 the rectangle to wrap 50 """ 51 AttributeCollectionBase.__init__(self) 52 53 self.__r = r 54 55 self.__top_left = VerboseVector(self.__r.top_left) 56 self.__top_right = VerboseVector(self.__r.top_right) 57 self.__bottom_left = VerboseVector(self.__r.bottom_left) 58 self.__bottom_right = VerboseVector(self.__r.bottom_right) 59 60 # delegate to wrapped object 61 delegator = Delegator() 62 delegator.target = r 63 delegator.profile.add_mappings("r", *"""__copy__ copy contains overlaps move_to 64 move_by __str__ __repr__""".split()) 65 delegator.profile.add_mappings("rw", *"""__center_x __center_y center""".split()) 66 67 self._append_attribute_collection(delegator)
68 69 @property
70 - def bounds(self):
71 return self.__r.bounds
72 73 @bounds.setter
74 - def bounds(self, args):
75 old_size = self.size 76 self.__r.bounds = args 77 if old_size != self.size: 78 self.__dispatch("size_changed", old_size)
79 80 @property
81 - def width(self):
82 return self.__r.width
83 84 @width.setter
85 - def width(self, value):
86 old_size = self.size 87 self.__r.width = value 88 if old_size != self.size: 89 self.__dispatch("size_changed", old_size)
90 91 @property
92 - def height(self):
93 return self.__r.height
94 95 @height.setter
96 - def height(self, value):
97 old_size = self.size 98 self.__r.height = value 99 if old_size != self.size: 100 self.__dispatch("size_changed", old_size)
101 102 @property
103 - def size(self):
104 return self.__r.size
105 106 @size.setter
107 - def size(self, value):
108 if self.size != value: 109 old_size = self.size 110 self.__r.size = value 111 self.__dispatch("size_changed", old_size)
112 113 @property
114 - def left(self):
115 return self.__r.left
116 117 @left.setter
118 - def left(self, value):
119 if self.left != value: 120 old_size = self.size 121 self.__r.left = value 122 self.__dispatch("size_changed", old_size)
123 124 @property
125 - def top(self):
126 return self.__r.top
127 128 @top.setter
129 - def top(self, value):
130 if self.top != value: 131 old_size = self.size 132 self.__r.top = value 133 self.__dispatch("size_changed", old_size)
134 135 @property
136 - def right(self):
137 return self.__r.right
138 139 @right.setter
140 - def right(self, value):
141 if self.right != value: 142 old_size = self.size 143 self.__r.right = value 144 self.__dispatch("size_changed", old_size)
145 146 @property
147 - def bottom(self):
148 return self.__r.bottom
149 150 @bottom.setter
151 - def bottom(self, value):
152 if self.bottom != value: 153 old_size = self.size 154 self.__r.bottom = value 155 self.__dispatch("size_changed", old_size)
156 157 @property
158 - def top_left(self):
159 return self.__top_left
160 161 @top_left.setter
162 - def top_left(self, value):
163 self.__top_left.assign(value)
164 165 @property
166 - def top_right(self):
167 return self.__top_right
168 169 @top_right.setter
170 - def top_right(self, value):
171 self.__top_right.assign(value)
172 173 @property
174 - def bottom_left(self):
175 return self.__bottom_left
176 177 @bottom_left.setter
178 - def bottom_left(self, value):
179 self.__bottom_left.assign(value)
180 181 @property
182 - def bottom_right(self):
183 return self.__bottom_right
184 185 @bottom_right.setter
186 - def bottom_right(self, value):
187 self.__bottom_right.assign(value)
188
189 - def inflate(self, *args):
190 old_size = self.size 191 self.__r.inflate(*args) 192 if old_size != self.size: 193 self.__dispatch("size_changed", old_size)
194