How to use __update_shape method in yandex-tank

Best Python code snippet using yandex-tank

KLNumpySurface.py

Source:KLNumpySurface.py Github

copy

Full Screen

...92 typename = type(new).__name__93 e = "Cannot create a NumpySurface from an object of type '{0}'."94 raise TypeError(e.format(typename))95 self.__content = new_arr.astype(np.uint8)96 self.__update_shape()97 def __update_shape(self):98 try:99 self.__width = self.__content.shape[1]100 self.__height = self.__content.shape[0]101 except AttributeError:102 pass103 def render(self):104 """Renders and returns the contents of the NumpySurface as an RGBA texture.105 Returns:106 :obj:`numpy.ndarray`: A 3-dimensional RGBA array of the surface content.107 """108 surftype = self.content.dtype109 return self.content if surftype == np.uint8 else self.content.astype(np.uint8)110 def copy(self):111 """Returns a copy of the current surface as a new NumpySurface object.112 Returns:113 :obj:`~NumpySurface`: A copy of the current surface.114 """115 return NumpySurface(self.content.astype(np.uint8))116 def blit(self, source, registration=7, location=(0,0), clip=True, blend=True):117 """Draws a shape, image, or other texture at a given location on the surface.118 Valid source content types include :obj:`NumpySurface` objects, :obj:`Drawbject` shapes,119 and :obj:`numpy.ndarray` or :obj:`Pillow.Image` objects in RGBA format.120 Args:121 source: The content to draw to the surface.122 registration (int, optional): An integer from 1 to 9 indicating which point on the123 source to align to the location coordinates. Defaults to 7 (top-left corner).124 location([int, int], optional): The (x, y) pixel coordinates indicating where the 125 content should be placed on the surface. Defaults to (0, 0).126 clip (bool, optional): Whether to clip content that exceeds the bounds of the surface127 to fit instead of raising an exception. Defaults to True.128 exceed the margins of the surface, or return an error instead. Defaults to True.129 blend (bool, optional): Whether to blend the image with the existing background or130 simply replace the contents of the target region (faster). Defaults to True131 (blend source with surface).132 Raises:133 ValueError: if the source does not fit on the surface with the given registration134 and location.135 """136 # TODO: Add reference to location/registration explanation in the docstring once it's written137 if isinstance(source, np.ndarray):138 source = add_alpha(source)139 elif isinstance(source, NumpySurface):140 source = source.render()141 else:142 try:143 source = NumpySurface(source)144 source = source.render()145 except TypeError:146 e = "'{0} is not a supported NumpySurface content format."147 raise TypeError(e.format(type(source).__name__))148 # Calculate top-left corner for source, using location, registration, & size149 source_h, source_w = (source.shape[0], source.shape[1])150 r_x, r_y = _build_registrations(source_h, source_w)[registration]151 location = (int(location[0] + r_x), int(location[1] + r_y))152 153 # Get source dimensions (sx/sy) and source bounding box on surface (cx/cy)154 sx1, sy1, sx2, sy2 = (0, 0, source_w, source_h)155 cx1, cy1, cx2, cy2 = location + (location[0] + source_w, location[1] + source_h)156 # Make sure location/registration actually place source on surface157 if cx1 > self.width or cy1 > self.height or cx2 < 0 or cy2 < 0:158 e = ("Provided blit location ({0}, {1}) and registration ({2}) place source "159 "completely outside surface bounds.")160 raise ValueError(e.format(cx1, cy1, registration))161 # If source is partly outside surface, adjust dimensions & bounding box to clip162 if clip == True:163 if cx1 < 0: sx1, cx1 = (abs(cx1), 0)164 if cy1 < 0: sy1, cy1 = (abs(cy1), 0)165 if cx2 > self.width: sx2, cx2 = (sx2 + (self.width - cx2), self.width)166 if cy2 > self.height: sy2, cy2 = (sy2 + (self.height - cy2), self.height)167 else:168 if source_h > self.height or source_w > self.width:169 e = "Source ({0}x{1}) is larger than the destination surface ({2}x{3})"170 raise ValueError(e.format(source_w, source_h, self.width, self.height))171 elif cx1 < 0 or cy1 < 0 or cx2 > self.width or cy2 > self.height:172 e = ("Provided blit location ({0}, {1}) and registration ({2}) place source "173 "partially outside surface bounds.")174 raise ValueError(e.format(cx1, cy1, registration))175 # Add source to surface, optionally blending alpha channels176 if blend == True:177 img = Image.fromarray(self.content)178 src = Image.fromarray(source[sy1:sy2, sx1:sx2, :])179 img.alpha_composite(src, (cx1, cy1))180 self.__content = np.array(img)181 else:182 self.__content[cy1:cy2, cx1:cx2, :] = source[sy1:sy2, sx1:sx2, :]183 return self184 def scale(self, width=None, height=None):185 """Scales the surface and its contents to a given size. If only one dimension is provided,186 the contents will be scaled to that size preserving the surface's aspect ratio. If both187 height and width are provided, the surface contents will be stretched to fit.188 Args:189 width (int, optional): The width in pixels to scale the surface to.190 height (int, optional): The height in pixels to scale the surface to.191 Raises:192 ValueError: if neither height or width are provided.193 194 """195 aspect = self.width / float(self.height)196 if width != None:197 size = (width, height) if height != None else (width, int(round(width / aspect)))198 elif height != None:199 size = (int(round(height * aspect)), height)200 else:201 raise ValueError("At least one of 'height' or 'width' must be provided.")202 img = Image.fromarray(self.content)203 self.__content = np.array(img.resize(size, Image.ANTIALIAS))204 self.__update_shape()205 return self206 def mask(self, mask, registration=7, location=(0,0), complete=False, invert=True):207 """Applies a transparency mask to the surface at a given location.208 209 If 'invert' is True (the default), the opacity of the mask is subtracted from the opacity210 of the surface, making the surface fully transparent wherever the mask is fully opaque211 (and vice versa). If 'invert' is False, this replaces the surface's transparency layer with212 the mask's alpha for the region covered by the mask.213 If an RGBA mask is provided, this function will use its alpha channel for masking. If a214 greyscale ('L') mask is provided, it will be used directly. If a mask in any other format215 is provided, the values from its first channel (e.g. 'R' for RGB, 'C' for CMYK) will be216 used.217 Args:218 mask (:obj:`NumpySurface`, :obj:`numpy.ndarray`): The image or array to use as a219 transparency mask.220 registration (int, optional): An integer from 1 to 9 indicating which point on the221 mask to align to the location coordinates. Defaults to 7 (top-left corner).222 location ([int, int], optional): The (x, y) pixel coordinates indicating where the 223 mask should be placed on the surface. Defaults to (0, 0).224 complete (bool, optional): If True, the entire surface outside of the mask region225 will be made transparent. Defaults to False. 226 invert (bool, optional): Whether the alpha values in the mask region should be227 the inverse of the mask's alpha instead of the same. Defaults to True.228 """229 # TODO: Add reference to location/registration explanation in the docstring once it's written230 from .KLDraw import Drawbject231 if type(mask) is NumpySurface:232 mask = Image.fromarray(mask.content)233 elif type(mask) is np.ndarray:234 mask = Image.fromarray(mask.astype(np.uint8))235 elif isinstance(mask, Drawbject):236 mask = mask.draw()237 elif not isinstance(mask, Image.Image):238 typename = type(mask).__name__239 raise TypeError("'{0}' is not a valid mask type.".format(typename))240 # For handling legacy code where location was second argument241 if hasattr(registration, '__iter__') and not isinstance(registration, str):242 location = registration243 registration = 7244 # Calculate top-left corner for mask, using location, registration, & size245 registration = _build_registrations(mask.height, mask.width)[registration]246 location = (int(location[0] + registration[0]), int(location[1] + registration[1]))247 # Initialize surface and mask248 surface_content = Image.fromarray(self.content)249 surface_alpha = surface_content.getchannel('A')250 if mask.mode != 'L':251 try:252 mask = mask.getchannel('A')253 except:254 mask = mask.getchannel(0)255 if invert == True:256 mask = ImageChops.invert(mask)257 # Create a new surface-sized alpha layer and place the mask on it258 mask_alpha = Image.new('L', surface_content.size, 0 if complete else 255)259 mask_alpha.paste(mask, location)260 # Merge the surface/mask alpha layers and replace surface alpha with result261 new_alpha = ImageChops.darker(surface_alpha, mask_alpha)262 surface_content.putalpha(new_alpha)263 self.__content = np.array(surface_content)264 return self265 def trim(self):266 """Trims the surface to fit the content, discarding any transparent padding.267 Raises:268 RuntimeError: If the entire surface is transparent.269 """270 img = Image.fromarray(self.content)271 contentbounds = img.getbbox()272 if contentbounds == None:273 raise RuntimeError('Cannot trim transparent padding from a fully transparent surface.')274 x1, y1, x2, y2 = contentbounds275 self.__content = self.content[y1:y2, x1:x2, :]276 self.__update_shape()277 return self278 def flip_left(self):279 """Flips the surface 90 degrees to the left.280 """281 self.__content = np.rot90(self.content)282 self.__update_shape()283 return self284 def flip_right(self):285 """Flips the surface 90 degrees to the right.286 """287 self.__content = np.rot90(self.content, k=3)288 self.__update_shape()289 return self290 def flip_x(self):291 """Flips the surface contents along the x-axis.292 """293 self.__content = np.fliplr(self.content)294 return self295 def flip_y(self):296 """Flips the surface contents along the y-axis.297 """298 self.__content = np.flipud(self.content)299 return self300 def get_pixel_value(self, coords):301 """Retrieves the RGBA colour value of a given pixel of the surface.302 Args:...

Full Screen

Full Screen

rounded_rectangle.py

Source:rounded_rectangle.py Github

copy

Full Screen

...17 self.border_up: int = rect.y18 self.border_down: int = rect.y + rect.h19 self.border_left: int = rect.x20 self.border_right: int = rect.x + rect.w21 self.__update_shape()2223 def render(self, screen: pg.Surface):24 screen.blit(self.__shape, self.pos)2526 def __update_shape(self):27 if self.__alpha == 0: return2829 rectangle = pg.Surface(self.rect.size, pg.SRCALPHA)30 circle = pg.Surface([min(self.rect.size) * 3] * 2, pg.SRCALPHA)31 pg.draw.ellipse(circle, (0, 0, 0), circle.get_rect(), 0)32 circle = pg.transform.smoothscale(circle, [int(min(self.rect.size) * self.__roundness)] * 2)33 self.rect.topleft = (0, 0)3435 radius: pg.Rect36 radius = rectangle.blit(circle, (0, 0))3738 radius.bottomright = self.rect.bottomright39 rectangle.blit(circle, radius)4041 radius.topright = self.rect.topright42 rectangle.blit(circle, radius)4344 radius.bottomleft = self.rect.bottomleft45 rectangle.blit(circle, radius)4647 rectangle.fill((0, 0, 0), self.rect.inflate(-radius.w, 0))48 rectangle.fill((0, 0, 0), self.rect.inflate(0, -radius.h))49 rectangle.fill(self.__color, special_flags=pg.BLEND_RGBA_MAX)50 rectangle.fill((255, 255, 255, self.__alpha), special_flags=pg.BLEND_RGBA_MIN)51 self.__shape = rectangle5253 def set_color(self, color: pg.Color):54 if self.__color != color:55 self.__color = color56 self.__color.a = 057 self.__update_shape()5859 def set_alpha(self, alpha: int):60 if self.__alpha != alpha:61 self.__alpha = alpha62 self.__update_shape()6364 def set_rect(self, rect: pg.Rect):65 if self.rect != rect:66 self.rect = rect67 self.pos = self.rect.topleft68 self.__update_shape()6970 def set_width(self, width: int):71 if self.rect.w != width:72 self.rect.w = width73 self.__update_shape()7475 def get_width(self): ...

Full Screen

Full Screen

text_object.py

Source:text_object.py Github

copy

Full Screen

...25 self.__str_size: pg.Rect = pg.Rect(0, 0, 0, 0)26 self.__is_centered = is_centered27 self.shape: Optional[pg.Surface] = None2829 self.__update_shape()3031 def __update_shape(self):32 offset: pg.Rect33 self.shape, self.__str_size = self.__font.render(text=self.__str,34 fgcolor=self.__color,35 style=self.__style,36 rotation=0,37 size=self.__size)3839 self.__offset.x = self.pos.x - self.__str_size.w // 2 * self.__is_centered40 self.__offset.y = self.pos.y - self.__str_size.h // 24142 def render(self, screen: pg.Surface):43 screen.blit(self.shape, self.__offset)4445 def set_str(self, str_: str):46 if str_ != self.__str:47 self.__str = str_48 self.__update_shape()4950 def set_size(self, size: int):51 if size != self.__size:52 self.__size = size53 self.__update_shape()5455 def set_style(self, style):56 if style != self.__style:57 self.__style = style58 self.__update_shape()5960 def set_color(self, color: pg.Color):61 if color != self.__color:62 self.__color = color63 self.__update_shape()6465 def get_offset(self):66 return self.__offset6768 def get_str_width(self):69 return self.__str_size.w7071 def __repr__(self): ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful