lintrans.gui.plots package
Module contents
This package provides widgets for the visualization plot in the main window and the visual definition dialog.
Submodules
lintrans.gui.plots.classes module
This module provides superclasses for plotting transformations.
- class lintrans.gui.plots.classes.BackgroundPlot
Bases:
QWidget
This class provides a background for plotting, as well as setup for a Qt widget.
This class provides a background (untransformed) plane, and all the backend details for a Qt application, but does not provide useful functionality. To be useful, this class must be subclassed and behaviour must be implemented by the subclass.
Warning
This class should never be directly instantiated, only subclassed.
Note
I would make this class have
metaclass=abc.ABCMeta
, but I can’t because it subclassesQWidget
, and every superclass of a class must have the same metaclass, andQWidget
is not an abstract class.- _COLOUR_BACKGROUND_AXES: QColor = <PyQt5.QtGui.QColor object>
This is the colour of the background axes.
- _COLOUR_BACKGROUND_GRID: QColor = <PyQt5.QtGui.QColor object>
This is the colour of the background grid lines.
- _PEN_NONE: QPen = <PyQt5.QtGui.QPen object>
This is a pen with
Qt::NoPen
. SeeQt::PenStyle
.
- _WIDTH_BACKGROUND_GRID: float = 0.3
This is the width of the background grid lines, as a multiple of the
QPainter
line width.
- __init__(*args, **kwargs)
Create the widget and setup backend stuff for rendering.
Note
*args
and**kwargs
are passed the superclass constructor (QWidget
).
- property _canvas_origin: Tuple[int, int]
Return the canvas coords of the grid origin.
The return value is intended to be unpacked and passed to a
QPainter.drawLine()
call.See
canvas_coords()
.
- _draw_background(painter: QPainter, draw_grid: bool) None
Draw the background grid.
Note
This method is just a utility method for subclasses to use to render the background grid.
- _grid_coords(x: int, y: int) Tuple[float, float]
Convert a coordinate from canvas coords to grid coords.
- canvas_coords(x: float, y: float) Tuple[int, int]
Convert a coordinate from grid coords to canvas coords.
This method is intended to be used like
painter.drawLine(*self.canvas_coords(x1, y1), *self.canvas_coords(x2, y2))
or like
painter.drawLine(*self._canvas_origin, *self.canvas_coords(x, y))
See
_canvas_origin
.
- abstract paintEvent(event: QPaintEvent) None
Handle a
QPaintEvent
.Note
This method is abstract and must be overridden by all subclasses.
- wheelEvent(event: QWheelEvent) None
Handle a
QWheelEvent
by zooming in or our of the grid.
- class lintrans.gui.plots.classes.InteractivePlot
Bases:
BackgroundPlot
This class represents an interactive plot, which may allow the user to click and/or drag point(s).
- _CURSOR_EPSILON: int = 5
This is the distance (in pixels) that the cursor needs to be from the point to drag it.
- _SNAP_DIST = 0.1
This is the distance (in grid coords) that the cursor needs to be from an integer point to snap to it.
- _is_within_epsilon(cursor_pos: Tuple[float, float], point: Tuple[float, float]) bool
Check if the cursor position (in canvas coords) is within range of the given point.
- _round_to_int_coord(point: Tuple[float, float]) Tuple[float, float]
Take a coordinate in grid coords and round it to an integer coordinate if it’s within
_SNAP_DIST
.If the point is not close enough, we just return the original point.
- abstract mouseMoveEvent(event: QMouseEvent) None
Handle the mouse moving on the widget.
- abstract mousePressEvent(event: QMouseEvent) None
Handle the mouse being pressed.
- abstract mouseReleaseEvent(event: QMouseEvent) None
Handle the mouse being released.
- class lintrans.gui.plots.classes.VectorGridPlot
Bases:
BackgroundPlot
This class represents a background plot, with vectors and their grid drawn on top.
This class should be subclassed to be used for visualization and matrix definition widgets. All useful behaviour should be implemented by any subclass.
Warning
This class should never be directly instantiated, only subclassed.
- _ARROWHEAD_LENGTH = 0.15
This is the minimum length (in grid coord size) of the arrowhead parts.
- _COLOUR_EIGEN = <PyQt5.QtGui.QColor object>
This is the colour of the eigenvectors and eigenlines (the spans of the eigenvectors).
- _COLOUR_I = <PyQt5.QtGui.QColor object>
This is the colour of the i basis vector and associated transformed grid lines.
- _COLOUR_J = <PyQt5.QtGui.QColor object>
This is the colour of the j basis vector and associated transformed grid lines.
- _COLOUR_TEXT = <PyQt5.QtGui.QColor object>
This is the colour of the text.
- _MAX_PARALLEL_LINES = 150
This is the maximum number of parallel transformed grid lines that will be drawn.
The user can zoom out further, but we will stop drawing grid lines beyond this number.
- _WIDTH_TRANSFORMED_GRID = 0.8
This is the width of the transformed grid lines, as a multiple of the
QPainter
line width.
- _WIDTH_VECTOR_LINE = 1.8
This is the width of the transformed basis vector lines, as a multiple of the
QPainter
line width.
- __init__(*args, **kwargs)
Create the widget with
point_i
andpoint_j
attributes.Note
*args
and**kwargs
are passed to the superclass constructor (BackgroundPlot
).
- _draw_arrowhead_away_from_origin(painter: QPainter, point: Tuple[float, float]) None
Draw an arrowhead at
point
, pointing away from the origin.
- _draw_basis_vectors(painter: QPainter) None
Draw arrowheads at the tips of the basis vectors.
- Parameters
painter (QPainter) – The painter to draw the basis vectors with
- _draw_determinant_parallelogram(painter: QPainter) None
Draw the parallelogram of the determinant of the matrix.
- Parameters
painter (QPainter) – The painter to draw the parallelogram with
- _draw_determinant_text(painter: QPainter) None
Write the string value of the determinant in the middle of the parallelogram.
- Parameters
painter (QPainter) – The painter to draw the determinant text with
- _draw_eigenlines(painter: QPainter) None
Draw the eigenlines. These are the invariant lines, or the spans of the eigenvectors.
- Parameters
painter (QPainter) – The painter to draw the eigenlines with
- _draw_eigenvectors(painter: QPainter) None
Draw the eigenvectors of the displayed matrix transformation.
- Parameters
painter (QPainter) – The painter to draw the eigenvectors with
- _draw_oblique_line(painter: QPainter, m: float, c: float) bool
Draw an oblique line, using the equation y = mx + c.
We only draw the part of the line that fits within the canvas, returning True if we were able to draw a line within the boundaries, and False if we couldn’t draw a line
- _draw_pair_of_oblique_lines(painter: QPainter, m: float, c: float) bool
Draw a pair of oblique lines, using the equation y = mx + c.
This method just calls
_draw_oblique_line()
withc
and-c
, and returns True if either call returned True.
- _draw_parallel_lines(painter: QPainter, vector: Tuple[float, float], point: Tuple[float, float]) None
Draw a set of evenly spaced grid lines parallel to
vector
intersectingpoint
.
- _draw_position_vector(painter: QPainter, point: Tuple[float, float], colour: QColor) None
Draw a vector from the origin to the given point.
- _draw_text_at_vector_tip(painter: QPainter, point: Tuple[float, float], text: str, font: Optional[QFont] = None) None
Draw the given text at the point as if it were the tip of a vector, using the custom font if given.
- _draw_transformed_grid(painter: QPainter) None
Draw the transformed version of the grid, given by the basis vectors.
Note
This method draws the grid, but not the basis vectors. Use
_draw_basis_vectors()
to draw them.- Parameters
painter (QPainter) – The painter to draw the grid lines with
- property _eigs: Iterable[Tuple[float, VectorType]]
Return the eigenvalues and eigenvectors zipped together to be iterated over.
- Return type
Iterable[Tuple[float, VectorType]]
- property _matrix: MatrixType
Return the assembled matrix of the basis vectors.
- abstract paintEvent(event: QPaintEvent) None
Handle a
QPaintEvent
.Note
This method is abstract and must be overridden by all subclasses.
lintrans.gui.plots.widgets module
This module provides the actual widgets that can be used to visualize transformations in the GUI.
- class lintrans.gui.plots.widgets.DefineMatrixVisuallyWidget
Bases:
VisualizeTransformationWidget
,InteractivePlot
This widget allows the user to visually define a matrix.
This is just the widget itself. If you want the dialog, use
DefineVisuallyDialog
.- __init__(*args, display_settings: DisplaySettings, polygon_points: List[Tuple[float, float]], **kwargs)
Create the widget and enable mouse tracking.
*args
and**kwargs
are passed tosuper()
.
- mouseMoveEvent(event: QMouseEvent) None
Handle the mouse moving on the canvas.
- mousePressEvent(event: QMouseEvent) None
Set the dragged point if the cursor is within
_CURSOR_EPSILON
.
- mouseReleaseEvent(event: QMouseEvent) None
Handle the mouse click being released by unsetting the dragged point.
- class lintrans.gui.plots.widgets.DefinePolygonWidget
Bases:
InteractivePlot
This widget allows the user to define a polygon by clicking and dragging points on the canvas.
- _BRUSH_DEFINE_POLYGON_VERTEX: QBrush = <PyQt5.QtGui.QBrush object>
This is the brush used to draw the inside of the vertices when defining a polygon.
- _BRUSH_NONE: QBrush = <PyQt5.QtGui.QBrush object>
This is a brush with
Qt::NoBrush
. SeeQt::BrushStyle
.
- __init__(*args, polygon_points: List[Tuple[float, float]], **kwargs)
Create the widget with a list of points and a dragged point index.
- mouseMoveEvent(event: QMouseEvent) None
Handle mouse movement by dragging the selected point.
- mousePressEvent(event: QMouseEvent) None
Handle the mouse being clicked by adding a point or setting the dragged point index to an existing point.
- mouseReleaseEvent(event: QMouseEvent) None
Handle the mouse click being released by unsetting the dragged point index.
- paintEvent(event: QPaintEvent) None
Draw the polygon on the canvas.
- class lintrans.gui.plots.widgets.VisualizeTransformationWidget
Bases:
VectorGridPlot
This widget is used in the main window to visualize transformations.
It handles all the rendering itself, and the only method that the user needs to care about is
plot_matrix()
, which allows you to visualize the given matrix transformation.- __init__(*args, display_settings: DisplaySettings, polygon_points: List[Tuple[float, float]], **kwargs)
Create the widget and assign its display settings, passing
*args
and**kwargs
to super.
- _draw_polygon_from_points(painter: QPainter, points: List[Tuple[float, float]]) None
Draw a polygon from a given list of points.
This is a helper method for
_draw_untransformed_polygon()
and_draw_transformed_polygon()
.
- _draw_untransformed_polygon(painter: QPainter) None
Draw the original untransformed polygon with a dashed line.
- paintEvent(event: QPaintEvent) None
Handle a
QPaintEvent
by drawing the background grid and the transformed grid.The transformed grid is defined by the basis vectors i and j, which can be controlled with the
plot_matrix()
method.