rkviewer.canvas package

Submodules

rkviewer.canvas.canvas module

The main canvas panel.

This handles user input actions, updates the model, and performs redraws after the model is updated.

class rkviewer.canvas.canvas.Alignment(value)[source]

Bases: enum.Enum

BOTTOM = 4
CENTER = 2
GRID = 6
HORIZONTAL = 7

Arrange into a row

LEFT = 0
MIDDLE = 5
RIGHT = 1
TOP = 3
VERTICAL = 8

Arrange into a column

rkviewer.canvas.canvas.BOUNDS_EPS = 0

The padding around the canvas to ensure nodes are not moved out of bounds due to floating pont issues.

rkviewer.canvas.canvas.BOUNDS_EPS_VEC = (0, 0)

2D bounds vector formed from BOUNDS_EPS

rkviewer.canvas.data module

Classes for storing and managing data for graph elements.

rkviewer.canvas.data.CURVE_SLACK = 5

Distance allowed on either side of a curve for testing click hit.

class rkviewer.canvas.data.ChoiceItem(value, text)[source]

Bases: tuple

text: str

Alias for field number 1

value: Any

Alias for field number 0

class rkviewer.canvas.data.CirclePrim(fill_color: rkviewer.config.Color = Color(r=255, g=0, b=0, a=255), border_color: rkviewer.config.Color = Color(r=0, g=255, b=0, a=255), border_width: float = 2)[source]

Bases: rkviewer.canvas.data.Primitive

Parameters
  • fill_color (Color) –

  • border_color (Color) –

  • border_width (float) –

border_color: rkviewer.config.Color = Color(r=0, g=255, b=0, a=255)
border_width: float = 2
fill_color: rkviewer.config.Color = Color(r=255, g=0, b=0, a=255)
name: ClassVar[str] = 'circle'
class rkviewer.canvas.data.Compartment(id: str, net_index: int, nodes: List[int], volume: float, position: rkviewer.canvas.geometry.Vec2, size: rkviewer.canvas.geometry.Vec2, fill: wx.Colour, border: wx.Colour, border_width: float, index: int = - 1)[source]

Bases: rkviewer.canvas.data.RectData

Parameters
  • id (str) –

  • net_index (int) –

  • nodes (List[int]) –

  • volume (float) –

  • position (Vec2) –

  • size (Vec2) –

  • fill (Colour) –

  • border (Colour) –

  • border_width (float) –

  • index (int) –

border: wx.Colour
border_width: float
fill: wx.Colour
id: str
index: int = -1
net_index: int
nodes: List[int]
position: rkviewer.canvas.geometry.Vec2
property rect

The same as s_rect, but the rectangle is unscaled.

size: rkviewer.canvas.geometry.Vec2

Size for drawing on the GUI

volume: float

Size (i.e. length/area/volume/…) of the container

class rkviewer.canvas.data.CompositeShape(items: List[Tuple[rkviewer.canvas.data.Primitive, rkviewer.canvas.data.Transform]], text_item: Tuple[rkviewer.canvas.data.TextPrim, rkviewer.canvas.data.Transform], name: str)[source]

Bases: object

Parameters
items: List[Tuple[rkviewer.canvas.data.Primitive, rkviewer.canvas.data.Transform]]
name: str
text_item: Tuple[rkviewer.canvas.data.TextPrim, rkviewer.canvas.data.Transform]
class rkviewer.canvas.data.CompositeShapeFactory(item_factories, text_factory, name)[source]

Bases: object

A factory for a composite shape, see PrimitiveFactory for more information.

Parameters
produce()[source]
class rkviewer.canvas.data.HandleData(tip, base=None)[source]

Bases: object

Struct for keeping handle data in-sync between the BezierHandle element and the Reaction.

tip

The position of the tip of the handle. May be modified by BezierHandle when user drags the handle element.

base

The position of the base of the handle. May be modified by ReactionBezier, etc. as a response to movement of nodes, handles, etc. HACK this is only updated in the do_paint method of ReactionElement, and since the BezierHandles are drawn after the ReactionElements, the position of the base happens to be updated each time, but if it were drawn before, it would be one step behind.

Parameters
  • tip (Vec2) –

  • base (Optional[Vec2]) –

base: Optional[rkviewer.canvas.geometry.Vec2]
tip: rkviewer.canvas.geometry.Vec2
class rkviewer.canvas.data.HexagonPrim(points: Tuple[rkviewer.canvas.geometry.Vec2, ] = 0.5, 0.0, 0.25000000000000006, 0.4330127018922193, - 0.2499999999999999, 0.43301270189221935, - 0.5, 6.123233995736766e-17, - 0.2500000000000002, - 0.43301270189221924, 0.24999999999999967, - 0.4330127018922195, 0.5, - 1.2246467991473532e-16, fill_color: rkviewer.config.Color = Color(r=255, g=0, b=0, a=255), border_color: rkviewer.config.Color = Color(r=0, g=255, b=0, a=255), border_width: float = 2, radius: float = 0.5)[source]

Bases: rkviewer.canvas.data.PolygonPrim

Parameters
  • points (Tuple[Vec2, …]) –

  • fill_color (Color) –

  • border_color (Color) –

  • border_width (float) –

  • radius (float) –

name: ClassVar[str] = 'hexagon'
points: Tuple[rkviewer.canvas.geometry.Vec2, ] = ((0.5, 0.0), (0.25000000000000006, 0.4330127018922193), (-0.2499999999999999, 0.43301270189221935), (-0.5, 6.123233995736766e-17), (-0.2500000000000002, -0.43301270189221924), (0.24999999999999967, -0.4330127018922195), (0.5, -1.2246467991473532e-16))
rkviewer.canvas.data.INITIALIZED = False

Flag for asserting that the above data is initialized

class rkviewer.canvas.data.LinePrim(points: Tuple[rkviewer.canvas.geometry.Vec2, ] = 0.5, 0.0, - 0.5, 6.123233995736766e-17, fill_color: rkviewer.config.Color = Color(r=255, g=0, b=0, a=255), border_color: rkviewer.config.Color = Color(r=0, g=255, b=0, a=255), border_width: float = 2, radius: float = 0.5)[source]

Bases: rkviewer.canvas.data.PolygonPrim

Parameters
  • points (Tuple[Vec2, …]) –

  • fill_color (Color) –

  • border_color (Color) –

  • border_width (float) –

  • radius (float) –

name: ClassVar[str] = 'line'
points: Tuple[rkviewer.canvas.geometry.Vec2, ] = ((0.5, 0.0), (-0.5, 6.123233995736766e-17))
class rkviewer.canvas.data.ModifierTipStyle(value)[source]

Bases: enum.Enum

An enumeration.

CIRCLE = 'circle'
TEE = 'tee'
class rkviewer.canvas.data.Node(id, net_index, *, pos, size, comp_idx=- 1, floatingNode=True, lockNode=False, shape_index=0, composite_shape=None, index=- 1, original_index=- 1, concentration=0.0, node_name='', node_SBO='')[source]

Bases: rkviewer.canvas.data.RectData

Class that represents a Node for rendering purposes.

index

The index of the node. If this node has not yet been added to the NOM, this takes on the value of -1.

id

The ID of the node.

fill_color

The fill color of the node.

border_color

The border color of the node.

border_width

The border width of the node.

position

Position of the size.

size

Position of the size.

net_index

The network index of the node.

Parameters
  • id (str) –

  • net_index (int) –

  • pos (Vec2) –

  • size (Vec2) –

  • comp_idx (int) –

  • floatingNode (bool) –

  • lockNode (bool) –

  • shape_index (int) –

  • composite_shape (Optional[CompositeShape]) –

  • index (int) –

  • original_index (int) –

  • concentration (float) –

  • node_name (str) –

  • node_SBO (str) –

property border_color
property border_width
comp_idx: int
composite_shape: Optional[rkviewer.canvas.data.CompositeShape]
concentration: float
property fill_color
floatingNode: bool
id: str
index: int
lockNode: bool
net_index: int
node_SBO: str
node_name: str
original_index: int
position: rkviewer.canvas.geometry.Vec2
props_equal(other)[source]
Parameters

other (Node) –

property rect

The same as s_rect, but the rectangle is unscaled.

property s_position

The scaled position of the node obtained by multiplying the scale.

property s_rect

Return scaled position/size as Rect.

Note that the fields of the returned rect is copied, so one cannot modify this node through the rect.

property s_size

The scaled size of the node obtained by multiplying the scale.

shape_index: int
size: rkviewer.canvas.geometry.Vec2
class rkviewer.canvas.data.PolygonPrim(points: Tuple[rkviewer.canvas.geometry.Vec2, ], fill_color: rkviewer.config.Color = Color(r=255, g=0, b=0, a=255), border_color: rkviewer.config.Color = Color(r=0, g=255, b=0, a=255), border_width: float = 2, radius: float = 0.5)[source]

Bases: rkviewer.canvas.data.Primitive

Parameters
  • points (Tuple[Vec2, …]) –

  • fill_color (Color) –

  • border_color (Color) –

  • border_width (float) –

  • radius (float) –

border_color: rkviewer.config.Color = Color(r=0, g=255, b=0, a=255)
border_width: float = 2
fill_color: rkviewer.config.Color = Color(r=255, g=0, b=0, a=255)
name: ClassVar[str] = 'polygon'
points: Tuple[rkviewer.canvas.geometry.Vec2, ]
radius: float = 0.5
class rkviewer.canvas.data.Primitive[source]

Bases: object

name: ClassVar[str] = 'generic primitive'
class rkviewer.canvas.data.PrimitiveFactory(prim_class, **kwargs)[source]

Bases: object

Factory that produces primitives.

Why do we need this?
  1. Dynamic population of fields. When I need a primitive, I call produce(), which creates a primitive based on the latest data, e.g. theme.

  2. That’s it.

How do we achieve dynamically created fields? In the constructor of this class, we allow passing functions as values for fields. On product(), we call these functions to populate the fields. Of course, the user can still pass all-static fields, which would work as intended.

produce()[source]
class rkviewer.canvas.data.Reaction(id, net_index, *, sources, targets, handle_positions, fill_color, line_thickness, rate_law, center_pos=None, bezierCurves=True, modifiers=None, modifier_tip_style=<ModifierTipStyle.CIRCLE: 'circle'>, index=-1)[source]

Bases: object

Parameters
  • id (str) –

  • net_index (int) –

  • sources (List[int]) –

  • targets (List[int]) –

  • handle_positions (List[Vec2]) –

  • fill_color (Colour) –

  • line_thickness (float) –

  • rate_law (str) –

  • center_pos (Optional[Vec2]) –

  • bezierCurves (bool) –

  • modifiers (Optional[Set[int]]) –

  • modifier_tip_style (ModifierTipStyle) –

  • index (int) –

bezierCurves: bool
center_pos: Optional[rkviewer.canvas.geometry.Vec2]
dest_c_handle: rkviewer.canvas.data.HandleData
fill_color: wx.Colour
handles: List[rkviewer.canvas.data.HandleData]
id: str
index: int
modifier_tip_style: rkviewer.canvas.data.ModifierTipStyle
modifiers: Set[int]
net_index: int
rate_law: str
property sources
Return type

List[int]

src_c_handle: rkviewer.canvas.data.HandleData
property targets
Return type

List[int]

property thickness
Return type

float

class rkviewer.canvas.data.ReactionBezier(reaction, reactants, products)[source]

Bases: object

Class that keeps track of all Bezier curve data for a reaction.

TODO move this documentation to utils
CENTER_RATIO

The ratio of source centroid handle length to the distance between the zeroth node and the centroid (center handle is aligned with the zeroth node)

DUPLICATE_RATIO

Valid for a Bezier whose node is both a product and a reactant. The ratio of length of the product Bezier handle to the distance between the node and the centroid.

DUPLICATE_ROT

Rotation (radians) applied to the product Bezier handle, for nodes that are both reactant and product. The handle is rotated so as to not align perfectly with the source Bezier handle (otherwise the reactant and product curves would completely overlap).

src_beziers

List of SpeciesBezier instances for reactants.

dest_beziers

List of SpeciesBezier instances for products.

TODO move this to Reaction
src_c_handle

Centroid bezier handle that controls the reactant curves.

dest_c_handle

Centroid bezier handle that controls the product curves.

handles

List of all the BezierHandle instances, stored for convenience.

Parameters
center_moved(offset)[source]
Parameters

offset (Vec2) –

dest_beziers: List[rkviewer.canvas.data.SpeciesBezier]
dest_handle_moved()[source]

Special callback for when the dest centroid handle is moved.

do_paint(gc, fill, selected)[source]
Parameters
  • gc (GraphicsContext) –

  • fill (Colour) –

  • selected (bool) –

get_bounding_rect()[source]
is_mouse_on(pos)[source]

Return whether mouse is on the Bezier curve (not including the handles).

pos is the logical position of the mouse (and not multiplied by any scale).

Parameters

pos (Vec2) –

Return type

bool

make_handle_moved_func(sb)[source]

Manufacture a callback function (on_moved) for the given SpeciesBezier.

Parameters

sb (SpeciesBezier) –

nodes_moved(rects)[source]
Parameters

rects (List[Rect]) –

property real_center
Return type

Vec2

src_beziers: List[rkviewer.canvas.data.SpeciesBezier]
src_handle_moved()[source]

Special callback for when the source centroid handle is moved.

class rkviewer.canvas.data.RectData[source]

Bases: object

position: rkviewer.canvas.geometry.Vec2
size: rkviewer.canvas.geometry.Vec2
class rkviewer.canvas.data.RectanglePrim(fill_color: rkviewer.config.Color = Color(r=255, g=0, b=0, a=255), border_color: rkviewer.config.Color = Color(r=0, g=255, b=0, a=255), border_width: float = 2, corner_radius: float = 4)[source]

Bases: rkviewer.canvas.data.Primitive

Parameters
  • fill_color (Color) –

  • border_color (Color) –

  • border_width (float) –

  • corner_radius (float) –

border_color: rkviewer.config.Color = Color(r=0, g=255, b=0, a=255)
border_width: float = 2
corner_radius: float = 4
fill_color: rkviewer.config.Color = Color(r=255, g=0, b=0, a=255)
name: ClassVar[str] = 'rectangle'
class rkviewer.canvas.data.SpeciesBezier(node_idx, node_rect, handle, real_center, centroid_handle, is_source, thickness, bezierCurves)[source]

Bases: object

Class that keeps track of the Bezier curve associated with a reaction species.

Note

When drawing the reaction curve, the builtin AddCurveToPoint is used. However, for the purpose of detecting a click on the curve, we still need to compute a rough approximation of the Bezier curve (e.g. 5 straight line segments). Hence why we need to compute the Bezier curve.

node

The associated node.

node_intersection

The intersection point between the handle and the padded node, i.e. the point after which the handle is not drawn, to create a gap.

handle

Beizer handle for the side on the species.

cnetroid_handle

Bezier handle for the centroid, shared among all reactants/products of this reaction.

is_source

Whether this species is considered a source or a dest node.

arrow_adjusted_coords

Coordinate array for the arrow vertices.

bezierCurves

True if we are drawing Bezier curves. Otherwise we are drawing simple straight lines.

Parameters
  • node_idx (int) –

  • node_rect (Rect) –

  • handle (HandleData) –

  • real_center (Vec2) –

  • centroid_handle (HandleData) –

  • is_source (bool) –

  • thickness (float) –

  • bezierCurves (bool) –

arrow_tip_changed()[source]
bezierCurves: bool
bezier_points: List[rkviewer.canvas.geometry.Vec2]
centroid_handle: rkviewer.canvas.data.HandleData
do_paint(gc, fill, selected)[source]
Parameters
  • gc (GraphicsContext) –

  • fill (Colour) –

  • selected (bool) –

get_bounding_rect()[source]
Return type

Rect

handle: rkviewer.canvas.data.HandleData
is_on_curve(pos)[source]

Check if position is on curve; pos is scaled logical position.

Parameters

pos (Vec2) –

Return type

bool

is_source: bool
node_idx: int
node_intersection: Optional[rkviewer.canvas.geometry.Vec2]
paint_arrow_tip(gc, fill)[source]
Parameters
  • gc (GraphicsContext) –

  • fill (Colour) –

real_center: rkviewer.canvas.geometry.Vec2
thickness: float
update_curve(real_center)[source]

Called after either the node, the centroid, or at least one of their handles changed.

Parameters

real_center (Vec2) –

class rkviewer.canvas.data.TextAlignment(value)[source]

Bases: enum.Enum

An enumeration.

CENTER = 2
LEFT = 1
RIGHT = 3
class rkviewer.canvas.data.TextPosition(value)[source]

Bases: enum.Enum

An enumeration.

ABOVE = 2
BELOW = 3
IN_NODE = 1
NEXT_TO = 4
class rkviewer.canvas.data.TextPrim(bg_color: rkviewer.config.Color = Color(r=255, g=255, b=0, a=0), font_color: rkviewer.config.Color = Color(r=0, g=0, b=0, a=255), font_size: int = 11, font_family: int = wx.FONTFAMILY_SWISS, font_style: int = wx.FONTSTYLE_NORMAL, font_weight: int = wx.FONTWEIGHT_MEDIUM, alignment: rkviewer.canvas.data.TextAlignment = <TextAlignment.CENTER: 2>, position: rkviewer.canvas.data.TextPosition = <TextPosition.IN_NODE: 1>)[source]

Bases: rkviewer.canvas.data.Primitive

Parameters
  • bg_color (Color) –

  • font_color (Color) –

  • font_size (int) –

  • font_family (int) –

  • font_style (int) –

  • font_weight (int) –

  • alignment (TextAlignment) –

  • position (TextPosition) –

alignment: rkviewer.canvas.data.TextAlignment = 2
bg_color: rkviewer.config.Color = Color(r=255, g=255, b=0, a=0)
font_color: rkviewer.config.Color = Color(r=0, g=0, b=0, a=255)
font_size: int = 11
name: ClassVar[str] = 'text'
position: rkviewer.canvas.data.TextPosition = 1
class rkviewer.canvas.data.Transform(translation: rkviewer.canvas.geometry.Vec2 = 0, 0, rotation: float = 0, scale: rkviewer.canvas.geometry.Vec2 = 1, 1)[source]

Bases: object

Parameters
  • translation (Vec2) –

  • rotation (float) –

  • scale (Vec2) –

rotation: float = 0
scale: rkviewer.canvas.geometry.Vec2 = (1, 1)
translation: rkviewer.canvas.geometry.Vec2 = (0, 0)
class rkviewer.canvas.data.TrianglePrim(points: Tuple[rkviewer.canvas.geometry.Vec2, ] = 0.5, 0.0, - 0.2499999999999999, 0.43301270189221935, - 0.2500000000000002, - 0.43301270189221924, 0.5, - 1.2246467991473532e-16, fill_color: rkviewer.config.Color = Color(r=255, g=0, b=0, a=255), border_color: rkviewer.config.Color = Color(r=0, g=255, b=0, a=255), border_width: float = 2, radius: float = 0.5)[source]

Bases: rkviewer.canvas.data.PolygonPrim

Parameters
  • points (Tuple[Vec2, …]) –

  • fill_color (Color) –

  • border_color (Color) –

  • border_width (float) –

  • radius (float) –

name: ClassVar[str] = 'triangle'
points: Tuple[rkviewer.canvas.geometry.Vec2, ] = ((0.5, 0.0), (-0.2499999999999999, 0.43301270189221935), (-0.2500000000000002, -0.43301270189221924), (0.5, -1.2246467991473532e-16))
rkviewer.canvas.data.comb(n, k)[source]
rkviewer.canvas.data.compute_centroid(rects)[source]

Compute the centroid position of a list of reactant and product nodes.

Parameters

rects (Sequence[Rect]) –

Return type

Vec2

rkviewer.canvas.data.gen_polygon_pts(n, r=0.5, phase=0)[source]

This function is used to define the vertices in 2D space of n-polygons. Each equilateral polygon is drawn inside a circle with specified radius.

n: the number of sides of the polygon r: radius of the circle in which the polygon is drawn phase: the phase of the first point, in radians. If phase is 0, the first point is drawn at

(r, 0) relative to the origin.

Return type

Tuple[Vec2, …]

rkviewer.canvas.data.init_bezier()[source]

Initialize (precompute) the Bezier data.

rkviewer.canvas.data.paint_handle(gc, base, handle, hovering)[source]

Paint the handle as given by its base and tip positions, highlighting it if hovering.

Parameters
  • gc (GraphicsContext) –

  • base (Vec2) –

  • handle (Vec2) –

  • hovering (bool) –

rkviewer.canvas.elements module

class rkviewer.canvas.elements.BezierHandle(data, layer, on_moved, on_dropped, reaction, node_idx)[source]

Bases: rkviewer.canvas.elements.CanvasElement

Class that keeps track of a Bezier control handle tip.

HANDLE_RADIUS

radius of the control handle.

data

The associated HandleData>

on_moved

The function called when the handle is moved.

on_dropped

The function called when the handle is dropped (i.e. mouse up).

reaction

The associated Reaction.

twin

The twin BezierHandle; used only for the center handles.

node_idx

The index of the node associated with this handle. -1 if this is a source centroid handle, and -2 if this is a target centroid handle.

Parameters
  • data (HandleData) –

  • layer (Union[int, Tuple[int, …]]) –

  • on_moved (Callable[[Vec2], None]) –

  • on_dropped (Callable[[Vec2], None]) –

  • reaction (Reaction) –

  • node_idx (int) –

HANDLE_RADIUS = 5
data: rkviewer.canvas.data.HandleData
node_idx: int
on_dropped: Callable[[rkviewer.canvas.geometry.Vec2], None]
on_left_down(logical_pos)[source]

Handler for when the mouse left button is pressed down inside the shape.

Parameters

logical_pos (Vec2) –

Return type

bool

on_left_up(logical_pos)[source]

Handler for when the mouse left button is springs up inside the shape.

Parameters

logical_pos (Vec2) –

on_mouse_drag(logical_pos, rel_pos)[source]

Handler for when the mouse drags inside the shape, with the left mouse button down.

Parameters
  • logical_pos (Vec2) –

  • rel_pos (Vec2) –

Return type

bool

on_mouse_enter(logical_pos)[source]

Handler for when the mouse has entered the shape.

Parameters

logical_pos (Vec2) –

Return type

bool

on_mouse_leave(logical_pos)[source]

Handler for when the mouse has exited the shape

Parameters

logical_pos (Vec2) –

Return type

bool

on_moved: Callable[[rkviewer.canvas.geometry.Vec2], None]
on_paint(gc)[source]

Paint the handle as given by its base and tip positions, highlighting it if hovering.

Parameters

gc (GraphicsContext) –

on_paint_cue(gc)[source]

This is called to paint special visual cues tha tthe element may need to display

Parameters

gc (GraphicsContext) –

pos_inside(logical_pos)[source]

Returns whether logical_pos is inside the diplayed shape of this element.

Parameters

logical_pos (Vec2) –

reaction: rkviewer.canvas.data.Reaction
twin = typing.Any
class rkviewer.canvas.elements.CanvasElement(layers)[source]

Bases: object

Base class for an element positioned on the canvas.

layers

The layer(s) number of this element.

enabled

Whether the element is enabled.

destroyed

Whether the object was destroyed (if this is True then you shouldn’t use this)

Parameters

layers (Union[int, Tuple[int, …]]) –

bounding_rect()[source]

Return the bounding rectangle of the element.

Return type

Rect

destroy()[source]

Destroy this element; override this for specific implementations.

destroyed: bool
enabled: bool
layers: Union[int, Tuple[int, ]]
on_left_down(logical_pos)[source]

Handler for when the mouse left button is pressed down inside the shape.

Parameters

logical_pos (Vec2) –

Return type

bool

on_left_up(logical_pos)[source]

Handler for when the mouse left button is springs up inside the shape.

Parameters

logical_pos (Vec2) –

Return type

bool

on_mouse_drag(logical_pos, rel_pos)[source]

Handler for when the mouse drags inside the shape, with the left mouse button down.

Parameters
  • logical_pos (Vec2) –

  • rel_pos (Vec2) –

Return type

bool

on_mouse_enter(logical_pos)[source]

Handler for when the mouse has entered the shape.

Parameters

logical_pos (Vec2) –

Return type

bool

on_mouse_leave(logical_pos)[source]

Handler for when the mouse has exited the shape

Parameters

logical_pos (Vec2) –

Return type

bool

on_mouse_move(logical_pos)[source]

Handler for when the mouse moves inside the shape, with the left mouse button up.

Parameters

logical_pos (Vec2) –

Return type

bool

abstract on_paint(gc)[source]

Paint the shape onto the given GraphicsContext.

This draws onto the scrolled canvas, i.e. the position of the drawn item will respond to scrolling, so you don’t need to account for that.

Parameters

gc (GraphicsContext) –

on_paint_cue(gc)[source]

This is called to paint special visual cues tha tthe element may need to display

Parameters

gc (GraphicsContext) –

pos_inside(logical_pos)[source]

Returns whether logical_pos is inside the diplayed shape of this element.

Parameters

logical_pos (Vec2) –

Return type

bool

set_layers(layers)[source]
Parameters

layers (Union[int, Tuple[int, …]]) –

class rkviewer.canvas.elements.CompartmentElt(compartment, major_layer, minor_layer)[source]

Bases: rkviewer.canvas.elements.CanvasElement

Parameters
  • compartment (Compartment) –

  • major_layer (int) –

  • minor_layer (int) –

bounding_rect()[source]

Return the bounding rectangle of the element.

Return type

Rect

destroyed: bool
enabled: bool
highlight_paint(gc)[source]
Parameters

gc (GraphicsContext) –

layers: Union[int, Tuple[int, ]]
on_left_down(logical_pos)[source]

Handler for when the mouse left button is pressed down inside the shape.

Parameters

logical_pos (Vec2) –

Return type

bool

on_paint(gc)[source]

Paint the shape onto the given GraphicsContext.

This draws onto the scrolled canvas, i.e. the position of the drawn item will respond to scrolling, so you don’t need to account for that.

Parameters

gc (GraphicsContext) –

pos_inside(logical_pos)[source]

Returns whether logical_pos is inside the diplayed shape of this element.

Parameters

logical_pos (Vec2) –

Return type

bool

class rkviewer.canvas.elements.NodeElement(node, canvas, layers)[source]

Bases: rkviewer.canvas.elements.CanvasElement

CanvasElement for nodes.

Parameters
  • node (Node) –

  • layers (Union[int, Tuple[int, …]]) –

bounding_rect()[source]

Return the bounding rectangle of the element.

Return type

Rect

canvas: Any
node: rkviewer.canvas.data.Node
on_left_down(_)[source]

Handler for when the mouse left button is pressed down inside the shape.

Parameters

_ (Vec2) –

on_paint(gc)[source]

Paint the shape onto the given GraphicsContext.

This draws onto the scrolled canvas, i.e. the position of the drawn item will respond to scrolling, so you don’t need to account for that.

Parameters

gc (GraphicsContext) –

pos_inside(logical_pos)[source]

Returns whether logical_pos is inside the diplayed shape of this element.

Parameters

logical_pos (Vec2) –

Return type

bool

class rkviewer.canvas.elements.ReactionCenter(parent, layers)[source]

Bases: rkviewer.canvas.elements.CanvasElement

Parameters
bounding_rect()[source]

Return the bounding rectangle of the element.

Return type

Rect

on_left_down(logical_pos)[source]

Handler for when the mouse left button is pressed down inside the shape.

Parameters

logical_pos (Vec2) –

Return type

bool

on_left_up(logical_pos)[source]

Handler for when the mouse left button is springs up inside the shape.

Parameters

logical_pos (Vec2) –

Return type

bool

on_mouse_drag(logical_pos, rel_pos)[source]

Handler for when the mouse drags inside the shape, with the left mouse button down.

Parameters
  • logical_pos (Vec2) –

  • rel_pos (Vec2) –

Return type

bool

on_mouse_enter(logical_pos)[source]

Handler for when the mouse has entered the shape.

Parameters

logical_pos (Vec2) –

Return type

bool

on_mouse_leave(logical_pos)[source]

Handler for when the mouse has exited the shape

Parameters

logical_pos (Vec2) –

Return type

bool

on_paint(gc)[source]

Paint the shape onto the given GraphicsContext.

This draws onto the scrolled canvas, i.e. the position of the drawn item will respond to scrolling, so you don’t need to account for that.

Parameters

gc (GraphicsContext) –

on_paint_cue(gc)[source]

This is called to paint special visual cues tha tthe element may need to display

Parameters

gc (GraphicsContext) –

parent: rkviewer.canvas.elements.ReactionElement
pos_inside(logical_pos)[source]

Returns whether logical_pos is inside the diplayed shape of this element.

Parameters

logical_pos (Vec2) –

Return type

bool

class rkviewer.canvas.elements.ReactionElement(reaction, bezier, canvas, layers, handle_layer)[source]

Bases: rkviewer.canvas.elements.CanvasElement

CanvasElement for reactions.

Note that if new nodes are constructed, all ReactionBezier instances that use these nodes should be re-constructed with the new nodes. On the other hand, if the nodes are merely modified, the corresponding update methods should be called.

Parameters
  • reaction (Reaction) –

  • bezier (ReactionBezier) –

  • layers (Union[int, Tuple[int, …]]) –

  • handle_layer (Union[int, Tuple[int, …]]) –

bezier: rkviewer.canvas.data.ReactionBezier
bhandles: List[rkviewer.canvas.elements.BezierHandle]
bounding_rect()[source]

Return the bounding rectangle of the element.

Return type

Rect

canvas: Any
center_el: rkviewer.canvas.elements.ReactionCenter
commit_node_pos()[source]

Handler for after the controller is told to move a node.

controller: rkviewer.mvc.IController
destroy()[source]

Destroy this element; override this for specific implementations.

index_to_bz: Dict[Tuple[int, bool], rkviewer.canvas.data.SpeciesBezier]
make_drop_handle_func(ctrl, neti, reai, nodei, is_source)[source]
Parameters
  • ctrl (IController) –

  • neti (int) –

  • reai (int) –

  • nodei (int) –

  • is_source (bool) –

moved_handler_id: int
nodes_moved(evt)[source]

Handler for after a node has moved.

Parameters

evt (CanvasEvent) –

on_left_down(logical_pos)[source]

Handler for when the mouse left button is pressed down inside the shape.

Parameters

logical_pos (Vec2) –

Return type

bool

on_mouse_enter(logical_pos)[source]

Handler for when the mouse has entered the shape.

Parameters

logical_pos (Vec2) –

on_paint(gc)[source]

Paint the shape onto the given GraphicsContext.

This draws onto the scrolled canvas, i.e. the position of the drawn item will respond to scrolling, so you don’t need to account for that.

Parameters

gc (GraphicsContext) –

pos_inside(logical_pos)[source]

Returns whether logical_pos is inside the diplayed shape of this element.

Parameters

logical_pos (Vec2) –

Return type

bool

reaction: rkviewer.canvas.data.Reaction
property selected
Return type

bool

class rkviewer.canvas.elements.SelectBox(canvas, nodes, compartments, bounds, controller, net_index, layer)[source]

Bases: rkviewer.canvas.elements.CanvasElement

Class that represents a select box, i.e. the bounding box draw around the selected nodes.

Supports moving and resizing operations.

CURSOR_TYPES

List of cursor types starting with that for the top-left handle and going clockwise.

nodes

List of selected nodes, as contained in this select box.

related_elts

List of NodeElements related to each node instance; matches the node list 1-1.

bounding_rect

The exact bounding rectangle (without padding).

mode

Current input mode of the SelectBox.

Note

The behavior of the SelectBox depends on the nodes and compartments selected, but not the reactions. The cases of behaviors are documented here:

  1. Only compartments are selected. Nodes within these compartments are dragged along with them, but they are not resized.

  1. Only nodes are selected, and they are all in the same compartment. In this case, the nodes may be moved normally. They also may be moved outside of their compartment to be assigned to another compartment (this is the only case where this is possible). However note that the nodes may not be resized to be larger than the containing compartment.

  1. Otherwise, there are two cases depending on if the selected nodes are in the union of the selected compartments.

    1. If the selected nodes are entirely contained in the list of selected compartments, then everything is moved and resized together, as usual.

    2. Otherwise (i.e. some node is not in any selected compartment), then dragging and resizing are disabled.

Note that in case 2), if all selected nodes are in the base compartment (i.e. no compartment), then the base compartment is assumed to be selected, and resizing and moving work as usual.

Parameters
CURSOR_TYPES = [wx.CURSOR_SIZENWSE, wx.CURSOR_SIZENS, wx.CURSOR_SIZENESW, wx.CURSOR_SIZEWE, wx.CURSOR_SIZENWSE, wx.CURSOR_SIZENS, wx.CURSOR_SIZENESW, wx.CURSOR_SIZEWE]
HANDLE_MULT = [(0, 0), (0.5, 0), (1, 0), (1, 0.5), (1, 1), (0.5, 1), (0, 1), (0, 0.5)]
class Mode(value)[source]

Bases: enum.Enum

An enumeration.

IDLE = 0
MOVING = 1
RESIZING = 2
class SMode(value)[source]

Bases: enum.Enum

For what this does, see “Notes” section of the class documentation.

COMP_ONLY = 0

Only compartments are selected.

CONTAINED = 2

Nodes are entirely contained in the selected compartments, or they are all in the base compartment.

NODES_IN_ONE = 1

Only nodes are selected, and they are in a single compartment.

NOT_CONTAINED = 3

Nodes are not entirely contained in the selected compartments.

comp_indices: List[int]
comp_min_ratio: Optional[rkviewer.canvas.geometry.Vec2]
compartments: List[rkviewer.canvas.data.Compartment]
compute_min_ratio()[source]

Compute minimum size ratio resizing nodes and compartments.

Return type

Tuple[Optional[Vec2], Optional[Vec2]]

Returns

A tuple containing (node mininum resize ratio, comp minimum resize ratio). Each ratio may be None, in the case that no elements of that type is selected.

map_rel_pos(positions)[source]
Parameters

positions (Iterable[Vec2]) –

Return type

List[Vec2]

property mode
move_offset(offset)[source]
Parameters

offset (Vec2) –

node_indices: List[int]
node_min_ratio: Optional[rkviewer.canvas.geometry.Vec2]
nodes: List[rkviewer.canvas.data.Node]
on_left_down(logical_pos)[source]

Handler for when the mouse left button is pressed down inside the shape.

Parameters

logical_pos (Vec2) –

on_left_up(logical_pos)[source]

Handler for when the mouse left button is springs up inside the shape.

Parameters

logical_pos (Vec2) –

on_mouse_drag(logical_pos, rel_pos)[source]

Handler for when the mouse drags inside the shape, with the left mouse button down.

Parameters
  • logical_pos (Vec2) –

  • rel_pos (Vec2) –

Return type

bool

on_mouse_enter(logical_pos)[source]

Handler for when the mouse has entered the shape.

Parameters

logical_pos (Vec2) –

on_mouse_leave(logical_pos)[source]

Handler for when the mouse has exited the shape

Parameters

logical_pos (Vec2) –

on_mouse_move(logical_pos)[source]

Handler for when the mouse moves inside the shape, with the left mouse button up.

Parameters

logical_pos (Vec2) –

on_paint(gc)[source]

Paint the shape onto the given GraphicsContext.

This draws onto the scrolled canvas, i.e. the position of the drawn item will respond to scrolling, so you don’t need to account for that.

Parameters

gc (GraphicsContext) –

outline_rect()[source]

Helper that returns the scaled, padded bounding rectangle.

Return type

Rect

peripheral_nodes: List[rkviewer.canvas.data.Node]
pos_inside(logical_pos)[source]

Returns whether logical_pos is inside the diplayed shape of this element.

Parameters

logical_pos (Vec2) –

related_elts: List[rkviewer.canvas.elements.CanvasElement]
special_mode: rkviewer.canvas.elements.SelectBox.SMode
update(nodes, compartments)[source]
Parameters
rkviewer.canvas.elements.draw_circle_to_gc(gc, box, circle, is_alias)[source]
Parameters
  • gc (GraphicsContext) –

  • box (Rect) –

  • circle (CirclePrim) –

  • is_alias (bool) –

rkviewer.canvas.elements.draw_composite_shape(gc, bounding_rect, node)[source]
Parameters
  • gc (GraphicsContext) –

  • bounding_rect (Rect) –

  • node (Node) –

rkviewer.canvas.elements.draw_polygon_to_gc(gc, box, poly, is_alias)[source]
Parameters
  • gc (GraphicsContext) –

  • box (Rect) –

  • poly (PolygonPrim) –

  • is_alias (bool) –

rkviewer.canvas.elements.draw_rect_to_gc(gc, box, rect, is_alias)[source]
Parameters
  • gc (GraphicsContext) –

  • box (Rect) –

  • rect (RectanglePrim) –

  • is_alias (bool) –

rkviewer.canvas.elements.draw_text_to_gc(gc, bounding_rect, full_text_string, text_item)[source]
Parameters
rkviewer.canvas.elements.layer_above(layer, count=1)[source]

Return the next layer above this layer, without increasing the length of the layer list.

count is optionally the layer number increment.

Parameters
  • layer (Union[int, Tuple[int, …]]) –

  • count (int) –

Return type

Union[int, Tuple[int, …]]

rkviewer.canvas.elements.primitive_brush(color, is_alias)[source]
Parameters
  • color (Color) –

  • is_alias (bool) –

rkviewer.canvas.elements.primitive_peninfo(color, width, is_alias)[source]
Parameters
  • color (Color) –

  • width (float) –

  • is_alias (bool) –

rkviewer.canvas.geometry module

class rkviewer.canvas.geometry.Direction(value)[source]

Bases: enum.Enum

An enumeration.

BOTTOM = 3
LEFT = 0
RIGHT = 2
TOP = 1
class rkviewer.canvas.geometry.Orientation(value)[source]

Bases: enum.Enum

An enumeration.

CLOCKWISE = 0
COLINEAR = 2
COUNTERCLOCKWISE = 1
class rkviewer.canvas.geometry.Rect(pos, size)[source]

Bases: object

Class that represents a rectangle by keeping a position and a size.

Parameters
aligned()[source]

Return rectangle aligned to the pixel coordinate system.

Note

See https://github.com/evilnose/PyRKViewer/issues/12 for why this is necessary.

Return type

Rect

as_tuple()[source]

Return the position and the size in a tuple.

Return type

Tuple[Vec2, Vec2]

property center_point
Return type

Vec2

contains(other)[source]

Returns whether self contains the other rectangle entirely.

Parameters

other (Rect) –

Return type

bool

nth_vertex(n)[source]

Return the nth vertex of the rectangle.

The top-left vertex is the 0th vertex, and subsequence vertices are indexed in clockwise fashion.

Parameters

n (int) –

sides()[source]
to_wx_rect()[source]
union(other)[source]

Return a Rect that contains both self and other

Parameters

other (Rect) –

Return type

Rect

class rkviewer.canvas.geometry.Vec2(x=None, y=None)[source]

Bases: object

Class that represents a 2D vector. Supports common vector operations like add and sub.

Note

Vec2 objects are immutable, meaning one cannot modify elements of the vector.

as_int()[source]

Convert each element to integers using int()

Return type

Vec2

as_tuple()[source]
Return type

Tuple[Union[float, int], Union[float, int]]

dot(other)[source]
Parameters

other (Vec2) –

Return type

Union[float, int]

elem_abs()[source]

Return the Vec2 obtained by taking the element-wise absolute value of this Vec2.

Return type

Vec2

elem_div(other)[source]

Return the resulting Vec2 by performing element-wise division.

Examples

>>> c = a.elem_div(b)  # is equivalent to...
>>> c = Vec2(a.x / b.x, a.y / b.y)
Parameters

other (Vec2) –

Return type

Vec2

elem_mul(other)[source]

Return the resulting Vec2 by performing element-wise multiplication.

Examples

>>> c = a.elem_mul(b)  # is equivalent to...
>>> c = Vec2(a.x * b.x, a.y * b.y)
Parameters

other (Vec2) –

Return type

Vec2

map(op)[source]

Map the given operation across the two elements of the vector.

Parameters

op (Callable[[Union[float, int]], Any]) –

Return type

Vec2

property norm
Return type

Union[float, int]

property norm_sq
Return type

Union[float, int]

normalized(norm=1)[source]
Parameters

norm (Union[float, int]) –

Return type

Vec2

reduce2(op, other)[source]
Parameters
  • op (Callable[[Union[float, int], Union[float, int]], Any]) –

  • other (Vec2) –

Return type

Vec2

classmethod repeat(val=1)[source]

Return the Vec2 obtained by repeating the given scalar value across the two elements.

Examples

>>> print(Vec2.repeat(5.4))
(5.4, 5.4)
Parameters

val (Union[float, int]) –

Return type

Vec2

swapped(i, val)[source]

Return a Vec2 equal to this one but with the ith element swapped for val.

Parameters
  • i (int) –

  • val (Union[float, int]) –

to_wx_point()[source]

Convert this to wx.Point; return the result.

Return type

Point

property x
property y
rkviewer.canvas.geometry.calc_node_dimensions(x, y, ratio)[source]

Resize node so that area is unchanged and y/x=ratio. Returns vector in form (x,y).

Parameters
  • x (int) –

  • y (int) –

  • ratio (float) –

rkviewer.canvas.geometry.circle_bounds(center, radius)[source]

Return the bounding rectangle (actually a square) of circle.

Parameters
  • center (Vec2) –

  • radius (float) –

Return type

Rect

rkviewer.canvas.geometry.clamp_point(pos, bounds, padding=0)[source]

Clamp the given point (pos) so that it is entirely within the bounds rectangle.

This is the same as calling clamp_rect_pos() with a clamped rectangle of size 1x1.

Return type

Vec2

Returns

The clamp position.

Parameters
  • pos (Vec2) –

  • bounds (Rect) –

  • padding (int) –

rkviewer.canvas.geometry.clamp_point_outside(pos, bounds)[source]

Clamp the point so that it is outside the given bounds rectangle.

The point is clamped so that its new position differs minimally from the old position.

Parameters
Return type

Vec2

rkviewer.canvas.geometry.clamp_rect_pos(rect, bounds, padding=0)[source]

Clamp the position of rect, so that it is entirely within the bounds rectangle.

The position is clamped such that the new position of the rectangle moves the least amount of distance possible.

Note

The clamped rectangle must be able to fit inside the bounds rectangle, inclusive. The given rect is not modified, but a position is returned.

Return type

Vec2

Returns

The clamped position.

Parameters
rkviewer.canvas.geometry.clamp_rect_size(rect, botright, padding=0)[source]

Clamp the size of the given rectangle if its bottom-right corner exceeds botright.

Parameters
  • rect (Rect) –

  • botright (Vec2) –

  • padding (int) –

Return type

Vec2

rkviewer.canvas.geometry.determinant(v1, v2)[source]

Computes the 2D determinant of the two vectors.

Parameters
rkviewer.canvas.geometry.get_bounding_rect(rects, padding=0)[source]

Compute the bounding rectangle of a given list of rects.

This computes the smallest possible rectangle needed to cover each of the rects (inclusive), as well as its position. Additionally a padding may be specified to provide some space.

Parameters
  • rets – The list of rectangles.

  • padding (float) – The padding of the bounding rectangle. If positive, there will be x pixels of padding for each side of the rectangle.

  • rects (Sequence[Rect]) –

Return type

Rect

Returns

The bounding rectangle.

rkviewer.canvas.geometry.linear_coefficients(p, q)[source]

Given two points that define a line ax + c, return (a, c)

Parameters
Return type

Tuple[float, float]

rkviewer.canvas.geometry.orientation(p1, p2, p3)[source]

Compute the orientation of the three points listed in order.

Parameters
Return type

Orientation

rkviewer.canvas.geometry.padded_rect(rect, padding)[source]

Return a rectangle padded by length padding, with the same center as the original.

Parameters
  • rect (Rect) –

  • padding (float) –

Return type

Rect

rkviewer.canvas.geometry.pt_in_circle(center, radius, point)[source]

Returns whether point is inside the circle with the given center and radius.

Parameters
  • center (Vec2) –

  • radius (float) –

  • point (Vec2) –

Return type

bool

rkviewer.canvas.geometry.pt_in_rect(pos, rect)[source]

Returns whether the given position is within the rectangle, inclusive.

Parameters
Return type

bool

rkviewer.canvas.geometry.pt_on_line(a, b, point, threshold=0)[source]

Returns whether point is on line ab, with the given threshold distance on either side.

Parameters
  • a (Vec2) –

  • b (Vec2) –

  • point (Vec2) –

  • threshold (float) –

Return type

bool

rkviewer.canvas.geometry.pt_on_rect_sides(pos, rect, thickness=5)[source]
Parameters
rkviewer.canvas.geometry.rects_overlap(r1, r2)[source]

Returns whether the two given rectangles overlap, counting if they are touching.

Parameters
Return type

bool

rkviewer.canvas.geometry.rotate_unit(vec, rad)[source]

Rotate a vector by rad radians and return the rotated unit vector.

Parameters
  • vec (Vec2) –

  • rad (float) –

Return type

Vec2

rkviewer.canvas.geometry.segment_intersects_line(seg, line)[source]

Returns the intersection between seg and line or None if there is no intersection.

line is defined by any two points on it.

Parameters
Return type

Optional[Vec2]

rkviewer.canvas.geometry.segment_rect_intersection(segment, rect)[source]
Parameters
Return type

Optional[Vec2]

rkviewer.canvas.geometry.segments_intersect(seg1, seg2)[source]

Returns the intersection point if line1 and line2 intersect, and None otherwise.

Parameters
Return type

Optional[Vec2]

rkviewer.canvas.overlays module

Widgets that are floating on top of the canvas (overlaid) which do not change position on scroll.

class rkviewer.canvas.overlays.CanvasOverlay[source]

Bases: abc.ABC

Abstract class for a fixed-position overlay within the canvas.

hovering

Used to set whether the mouse is current hovering over the overlay.

Note

Overlays use device positions since it makes the most sense for these static items.

abstract DoPaint(gc)[source]

Re-paint the overlay.

Parameters

gc (GraphicsContext) –

abstract OnLeftDown(device_pos)[source]

Trigger a mouse left button down event on the overlay.

Parameters

device_pos (Vec2) –

abstract OnLeftUp(device_pos)[source]

Trigger a mouse left button up event on the overlay.

Parameters

device_pos (Vec2) –

abstract OnMotion(device_pos, is_down)[source]

Trigger a mouse motion event on the overlay.

Parameters
  • device_pos (Vec2) –

  • is_down (bool) –

hovering: bool
property position

Return the position (i.e. of the top-left corner) of the overlay.

Return type

Vec2

property size

Return the size (i.e. of a rectangle) of the overlay.

Return type

Vec2

class rkviewer.canvas.overlays.Minimap(*, pos, device_pos, width, realsize, window_pos=0, 0, window_size, pos_callback)[source]

Bases: rkviewer.canvas.overlays.CanvasOverlay

The minimap class that derives from CanvasOverlay.

Callback

Type of the callback function called when the position of the minimap changes.

window_pos

Position of the canvas window, as updated by canvas.

window_size

Size of the canvas window, as updated by canvas.

device_pos

The device position (i.e. seen on screen) of the top left corner. Used for determining user click/drag offset. It is important to use the device_pos, since it does not change, whereas window_pos (logical position) changes based on scrolling. This coupled with delays in update causes very noticeable jitters when dragging.

elements

The list of elements updated by canvas.

Parameters
  • pos (Vec2) –

  • device_pos (Vec2) –

  • width (int) –

  • realsize (Vec2) –

  • window_pos (Vec2) –

  • window_size (Vec2) –

  • pos_callback (Callable[[Vec2], None]) –

Callback = typing.Callable[[rkviewer.canvas.geometry.Vec2], NoneType]
DoPaint(gc)[source]

Re-paint the overlay.

Parameters

gc (GraphicsContext) –

OnLeftDown(device_pos)[source]

Trigger a mouse left button down event on the overlay.

Parameters

device_pos (Vec2) –

OnLeftUp(_)[source]

Trigger a mouse left button up event on the overlay.

Parameters

_ (Vec2) –

OnMotion(device_pos, is_down)[source]

Trigger a mouse motion event on the overlay.

Parameters
  • device_pos (Vec2) –

  • is_down (bool) –

device_pos: rkviewer.canvas.geometry.Vec2
property dragging

Whether the user is current dragging on the minimap window.

elements: sortedcontainers.sortedlist.SortedKeyList
property realsize

The actual, full size of the canvas, including those not visible on screen.

window_pos: rkviewer.canvas.geometry.Vec2
window_size: rkviewer.canvas.geometry.Vec2

rkviewer.canvas.state module

class rkviewer.canvas.state.ArrowTip(points)[source]

Bases: object

Parameters

points (List[Vec2]) –

clone()[source]
points: List[rkviewer.canvas.geometry.Vec2]
class rkviewer.canvas.state.CanvasState(scale: float = 1, bounds: rkviewer.canvas.geometry.Rect = Rect((0, 0), (0, 0)), input_mode_changed: Callable[[rkviewer.canvas.state.InputMode], None] = <function CanvasState.<lambda>>, _input_mode: rkviewer.canvas.state.InputMode = <InputMode.SELECT: 'Select'>, arrow_tip: rkviewer.canvas.state.ArrowTip = <rkviewer.canvas.state.ArrowTip object>)[source]

Bases: object

The current global state of the canvas.

scale

The zoom scale of the canvas.

multi_select

Whether the user is pressing the keys that signify multiple selection of items.

Parameters
arrow_tip: rkviewer.canvas.state.ArrowTip = <rkviewer.canvas.state.ArrowTip object>
bounds: rkviewer.canvas.geometry.Rect = Rect((0, 0), (0, 0))
property input_mode
input_mode_changed()
property multi_select
scale: float = 1
class rkviewer.canvas.state.InputMode(value)[source]

Bases: enum.Enum

Enum for the current input mode of the canvas.

ADD_COMPARTMENTS = 'Add Compartments'
ADD_NODES = 'Add Nodes'
SELECT = 'Select'
ZOOM = 'Zoom'

rkviewer.canvas.utils module

Utility functions for the canvas.

This includes drawing helpers and 2D geometry functions.

class rkviewer.canvas.utils.Observer(update_callback)[source]

Bases: abc.ABC, typing.Generic

Observer abstract base class; encapsulates object of type T.

Parameters

update_callback (Callable[[~T], None]) –

class rkviewer.canvas.utils.SetSubject(*args, **kwds)[source]

Bases: rkviewer.canvas.utils.Subject

Subject class that encapsulates a set.

add(el)[source]

Add an element from the set, notifying observers if the set changed.

Parameters

el (~T) –

contains(val)[source]
Parameters

val (~T) –

Return type

bool

intersect(other)[source]
Parameters

other (Set[~T]) –

item_copy()[source]

Return a copy of the encapsulated set.

Return type

Set

remove(el)[source]

Remove an element from the set, notifying observers if the set changed.

Parameters

el (~T) –

set_item(item)[source]

Update the value of the item, notifying observers if the new value differs from the old.

Parameters

item (Set) –

union(other)[source]
Parameters

other (Set[~T]) –

class rkviewer.canvas.utils.Subject(*args, **kwds)[source]

Bases: typing.Generic

Subject abstract base class; encapsulates object of type T.

attach(observer)[source]

Attach an observer.

Parameters

observer (Observer) –

detach(observer)[source]

Detach an observer.

Parameters

observer (Observer) –

notify()[source]

Trigger an update in each Subject.

Return type

None

rkviewer.canvas.utils.default_handle_positions(centroid, reactants, products)[source]
Parameters
  • centroid (Vec2) –

  • reactants (List[Node]) –

  • products (List[Node]) –

rkviewer.canvas.utils.draw_rect(gc, rect, *, fill=None, border=None, border_width=1, fill_style=wx.BRUSHSTYLE_SOLID, border_style=wx.PENSTYLE_SOLID, corner_radius=0)[source]

Draw a rectangle with the given graphics context.

Either fill or border must be specified to avoid drawing an entirely transparent rectangle.

Parameters
  • gc (GraphicsContext) – The graphics context.

  • rect (Rect) – The rectangle to draw.

  • fill (Optional[Colour]) – If specified, the fill color of the rectangle.

  • border (Optional[Colour]) – If specified, the border color of the rectangle.

  • border_width (float) – The width of the borders. Defaults to 1. This cannot be 0 when border is specified.

  • corner_radius (float) – The corner radius of the rounded rectangle. Defaults to 0.

rkviewer.canvas.utils.get_nodes_by_ident(nodes, ids)[source]

Simple helper that maps the given list of IDs to their corresponding nodes.

Parameters
  • nodes (List[Node]) –

  • ids (Collection[str]) –

rkviewer.canvas.utils.get_nodes_by_idx(nodes, indices)[source]

Simple helper that maps the given list of indices to their corresponding nodes.

Parameters
  • nodes (List[Node]) –

  • indices (Collection[int]) –

rkviewer.canvas.utils.get_rxns_by_idx(rxns, indices)[source]

Simple helper that maps the given list of indices to their corresponding rxns.

Parameters
  • rxns (List[Reaction]) –

  • indices (Collection[int]) –

Module contents