RWESharp.utils

Functions

circle2rect(pos, radius)

Turns position and radius into rectangle

closest_line(pos, lastpos)

Returns the line closest to one in 8 directions

color_lerp(c1, c2, t)

Interpolates between 2 colors

distance(a, b)

Calculates distance between a and b

draw_ellipse(rect, hollow, callback)

Calls callback for each point ellipse intersects with

draw_line(pointa, pointb, callback)

Calls callback function for each point line intersected with

draw_rect(rect, hollow, callback)

Calls callback for each point inside rectangle

fit_rect(lastpos, pos, shift, alt)

Creates rectangle from 2 points and more

inject_method(func, newfunc, self)

insensitive_path(path)

Tries to find file in path without checking case

lerp(a, b, t)

linear interpolation or something

log(message[, error])

Logs a message in both terminal and log file

modify_path_url(path)

converts specified path to file url

paint_svg(filename, color)

Paints svg image with caching

paint_svg_qicon(filename, color)

Paints svg image with caching

paint_svg_qpixmap(filename, color)

Paints svg image with caching

point2polar(pos)

Converts from Cartesian to polar coordinates

polar2point(pos)

Converts from polar to Cartesian coordinates

remap(x, in_min, in_max, out_min, out_max)

Converts value from one range to another

rotate_point(point, angle)

Rotates point with some angle

Classes

Delegate(func)

RWESharp.utils.log(message, error=False) None[source]

Logs a message in both terminal and log file

Parameters:
  • message – message to log

  • error – Whether it’s error or not

Returns:

None

Return type:

None

RWESharp.utils.distance(a: QPointF, b: QPointF) float[source]

Calculates distance between a and b

Parameters:
Returns:

Distance

Return type:

float

RWESharp.utils.draw_line(pointa: QPoint, pointb: QPoint, callback: Callable) None[source]

Calls callback function for each point line intersected with

Parameters:
  • pointa (QPoint) – Line point a

  • pointb (QPoint) – Line point b

  • callback (Callable) – Callback function(lambda QPoint:)

Returns:

None

Return type:

None

RWESharp.utils.insensitive_path(path) str | None[source]

Tries to find file in path without checking case

Parameters:

path – path to file

Returns:

Path to fixed file if found

Return type:

str

RWESharp.utils.fit_rect(lastpos: QPoint, pos: QPoint, shift: bool, alt: bool) QRect[source]

Creates rectangle from 2 points and more

Literally stolen from photoshop

Parameters:
  • lastpos (QPoint) – First rect point

  • pos (QPoint) – Second rect point

  • shift (bool) – Makes square

  • alt (bool) – Makes lastpos center of rectangle

Returns:

Result rectangle

Return type:

QRect

RWESharp.utils.draw_rect(rect: QRect, hollow: bool, callback: Callable) None[source]

Calls callback for each point inside rectangle

Parameters:
  • rect (QRect) – rectangle

  • hollow (bool) – call callback only on edges

  • callback (Callable) – callback function(lambda QPoint:)

Returns:

None

Return type:

None

RWESharp.utils.draw_ellipse(rect: QRect, hollow: bool, callback: Callable) None[source]

Calls callback for each point ellipse intersects with

NOTE: Callback may be called multiple times on same point

Parameters:
  • rect (QRect)

  • hollow (bool) – call callback only on edges or whole ellipse

  • callback (Callable) – callback function(lambda QPoint:)

Returns:

None

Return type:

None

RWESharp.utils.paint_svg(filename: str, color: QColor) str[source]

Paints svg image with caching

works with resources too

if file is already stored in cache, passes it instead

Parameters:
  • filename (str) – path to file or resource

  • color (QColor) – svg’s color

Returns:

Path to coloured icon in cache

Return type:

str

RWESharp.utils.paint_svg_qicon(filename: str, color: QColor) QIcon[source]

Paints svg image with caching

works with resources too

if file is already stored in cache, passes it instead

Parameters:
  • filename (str) – path to file or resource

  • color (QColor) – svg’s color

Returns:

Colored icon

Return type:

QIcon

RWESharp.utils.paint_svg_qpixmap(filename: str, color: QColor) QPixmap[source]

Paints svg image with caching

works with resources too

if file is already stored in cache, passes it instead

Parameters:
  • filename (str) – path to file or resource

  • color (QColor) – svg’s color

Returns:

Colored pixmap

Return type:

QPixmap

RWESharp.utils.remap(x: float, in_min: float, in_max: float, out_min: float, out_max: float) float[source]

Converts value from one range to another

Parameters:
  • x (float) – value in in range

  • in_min (float) – in in start

  • in_max (float) – in end

  • out_min (float) – out start

  • out_max (float) – out end

Returns:

value in out range

Return type:

float

RWESharp.utils.lerp(a: float, b: float, t: float) float[source]

linear interpolation or something

Parameters:
Returns:

value interpolated between a and b

Return type:

float

RWESharp.utils.color_lerp(c1: QColor, c2: QColor, t: float) QColor[source]

Interpolates between 2 colors

Parameters:
  • c1 (QColor) – First color

  • c2 (QColor) – Second color

  • t (float) – Amount to interpolate between 0 and 1

Returns:

Interpolated color

Return type:

float

RWESharp.utils.closest_line(pos, lastpos) QLineF[source]

Returns the line closest to one in 8 directions

Parameters:
  • pos – start of line

  • lastpos – end of line

Returns:

closest line to given argument

Return type:

QLineF

RWESharp.utils.rotate_point(point: QPointF, angle) QPointF[source]

Rotates point with some angle

Parameters:
  • point (QPointF) – point to rotate

  • angle – angle to rotate in degrees

Returns:

rotated point

Return type:

QPointF

RWESharp.utils.circle2rect(pos: QPointF, radius: float) QRectF[source]

Turns position and radius into rectangle

Parameters:
  • pos (QPointF) – Position of circle

  • radius (float) – Radius of circle

Returns:

Rectangle

Return type:

QRectF

RWESharp.utils.point2polar(pos: QPointF) QPointF[source]

Converts from Cartesian to polar coordinates

Parameters:

pos (QPointF) – Position in cartesian coordinates

Returns:

Point in polar coordinates where x is angle and y is distance

Return type:

QPointF

RWESharp.utils.polar2point(pos: QPointF) QPointF[source]

Converts from polar to Cartesian coordinates

Parameters:

pos (QPointF) – Position in polar coordinates where x is angle and y is distance

Returns:

Point in Cartesian coordinates

Return type:

QPointF

RWESharp.utils.modify_path_url(path: str) str[source]

converts specified path to file url

Parameters:

path (str) – path to convert

Returns:

converted path

Return type:

str

class RWESharp.utils.Delegate(func)[source]
Deprecated:

Delegate allows for adding hooks to methods

!!!Does not work for methods!!!

To make method hookable, add @Delegate attribute

To hook prefix to delegate, use *= or @method.prefix attribute

To hook postfix to delegate, use += or @method.postfix attribute

Prefixes get called before delegate and can change arguments before passing it to delegate

  • simply return (args, kwargs, returnval)

  • if returnval is not None, stops delegate from being called

Postfixes can change return value of delegate by returning not None and can get value of delegate or previous postfix

To unhook your method from delegate, use -=

prefix(func)[source]
postfix(func)[source]
RWESharp.utils.inject_method(func, newfunc, self)[source]
Deprecated:

Parameters:
  • func

  • newfunc

  • self

Returns: