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
-
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
-
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
item_factories (
List
[Tuple
[PrimitiveFactory
,Transform
]]) –text_factory (
Tuple
[PrimitiveFactory
,Transform
]) –name (
str
) –
-
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.
-
base
: Optional[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
-
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
-
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¶
-
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¶
-
-
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
-
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?
Dynamic population of fields. When I need a primitive, I call produce(), which creates a primitive based on the latest data, e.g. theme.
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.
-
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.
-
dest_beziers
: List[rkviewer.canvas.data.SpeciesBezier]¶
-
do_paint
(gc, fill, selected)[source]¶ - Parameters
gc (
GraphicsContext
) –fill (
Colour
) –selected (
bool
) –
-
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
) –
-
src_beziers
: List[rkviewer.canvas.data.SpeciesBezier]¶
-
-
class
rkviewer.canvas.data.
RectData
[source]¶ Bases:
object
-
position
: 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
-
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
) –
-
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
) –
-
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]¶
-
real_center
: rkviewer.canvas.geometry.Vec2¶
-
thickness
: float¶
-
-
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
-
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
-
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.
compute_centroid
(rects)[source]¶ Compute the centroid position of a list of reactant and product nodes.
-
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.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¶
-
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.
-
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
, …]]) –
-
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.
-
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
) –
-
-
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
) –
-
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
-
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
, …]]) –
-
canvas
: Any¶
-
on_left_down
(_)[source]¶ Handler for when the mouse left button is pressed down inside the shape.
- Parameters
_ (
Vec2
) –
-
class
rkviewer.canvas.elements.
ReactionCenter
(parent, layers)[source]¶ Bases:
rkviewer.canvas.elements.CanvasElement
- Parameters
parent (
ReactionElement
) –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.
-
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
) –
-
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
, …]]) –
-
bhandles
: List[rkviewer.canvas.elements.BezierHandle]¶
-
canvas
: Any¶
-
center_el
: rkviewer.canvas.elements.ReactionCenter¶
-
controller
: rkviewer.mvc.IController¶
-
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.
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:
Only compartments are selected. Nodes within these compartments are dragged along with them, but they are not resized.
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.
Otherwise, there are two cases depending on if the selected nodes are in the union of the selected compartments.
If the selected nodes are entirely contained in the list of selected compartments, then everything is moved and resized together, as usual.
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
nodes (
List
[Node
]) –compartments (
List
[Compartment
]) –bounds (
Rect
) –controller (
IController
) –net_index (
int
) –layer (
int
) –
-
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
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]¶
-
property
mode
¶
-
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.
-
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
) –
-
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
nodes (
List
[Node
]) –compartments (
List
[Compartment
]) –
-
-
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_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.
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.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.
-
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
-
contains
(other)[source]¶ Returns whether self contains the other rectangle entirely.
- Parameters
other (
Rect
) –- Return type
bool
-
-
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.
-
elem_abs
()[source]¶ Return the Vec2 obtained by taking the element-wise absolute value of this Vec2.
- Return type
-
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)
-
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)
-
map
(op)[source]¶ Map the given operation across the two elements of the vector.
- Parameters
op (
Callable
[[Union
[float
,int
]],Any
]) –- Return type
-
property
norm
¶ - Return type
Union
[float
,int
]
-
property
norm_sq
¶ - Return type
Union
[float
,int
]
-
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
-
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
]) –
-
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.
-
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.
-
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.
-
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.
-
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.
-
rkviewer.canvas.geometry.
determinant
(v1, v2)[source]¶ Computes the 2D determinant of the two vectors.
-
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.
-
rkviewer.canvas.geometry.
linear_coefficients
(p, q)[source]¶ Given two points that define a line ax + c, return (a, c)
-
rkviewer.canvas.geometry.
orientation
(p1, p2, p3)[source]¶ Compute the orientation of the three points listed in order.
- Parameters
- Return type
-
rkviewer.canvas.geometry.
padded_rect
(rect, padding)[source]¶ Return a rectangle padded by length padding, with the same center as the original.
-
rkviewer.canvas.geometry.
pt_in_circle
(center, radius, point)[source]¶ Returns whether point is inside the circle with the given center and radius.
-
rkviewer.canvas.geometry.
pt_in_rect
(pos, rect)[source]¶ Returns whether the given position is within the rectangle, inclusive.
-
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.
-
rkviewer.canvas.geometry.
rects_overlap
(r1, r2)[source]¶ Returns whether the two given rectangles overlap, counting if they are touching.
-
rkviewer.canvas.geometry.
rotate_unit
(vec, rad)[source]¶ Rotate a vector by rad radians and return the rotated unit vector.
-
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.
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
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
-
-
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
-
Callback
= typing.Callable[[rkviewer.canvas.geometry.Vec2], NoneType]¶
-
OnLeftDown
(device_pos)[source]¶ Trigger a mouse left button down event on the overlay.
- Parameters
device_pos (
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
]) –
-
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¶
-
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) –
-
remove
(el)[source]¶ Remove an element from the set, notifying observers if the set changed.
- Parameters
el (~T) –
-
-
class
rkviewer.canvas.utils.
Subject
(*args, **kwds)[source]¶ Bases:
typing.Generic
Subject abstract base class; encapsulates object of type T.
-
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
]) –