lintrans.gui package
Module contents
This package supplies the main GUI and associated dialogs for visualization.
Subpackages
Submodules
lintrans.gui.main_window module
This module provides the LintransMainWindow
class, which provides the main window for the GUI.
- class lintrans.gui.main_window.LintransMainWindow[source]
Bases:
QMainWindow
This class provides a main window for the GUI using the Qt framework.
This class should not be used directly, instead call
main()
to create the GUI.- __init__()[source]
Create the main window object, and create and arrange every widget in it.
This doesn’t show the window, it just constructs it. Use
main()
to show the GUI.
- _animate_between_matrices(matrix_start: MatrixType, matrix_target: MatrixType) None [source]
Animate from the start matrix to the target matrix.
- _animate_expression() None [source]
Animate from the current matrix to the matrix in the expression box.
- _ask_for_session_file() None [source]
Ask the user to select a session file, and then open it and load the session.
- _assign_display_settings() None [source]
Assign a new value to
self._plot.display_settings
and give the expression box focus.
- _assign_matrix_wrapper() None [source]
Assign a new value to
self._matrix_wrapper
and give the expression box focus.
- _assign_polygon_points() None [source]
Assign a new value to
self._plot.polygon_points
and give the expression box focus.
- _dialog_define_matrix(dialog_class: Type[DefineMatrixDialog]) None [source]
Open a generic definition dialog to define a new matrix.
The class for the desired dialog is passed as an argument. We create an instance of this class and the dialog is opened asynchronously and modally (meaning it blocks interaction with the main window) with the proper method connected to the
QDialog.accepted()
signal.Note
dialog_class
must subclassDefineMatrixDialog
.- Parameters
dialog_class (Type[lintrans.gui.dialogs.define_new_matrix.DefineMatrixDialog]) – The dialog class to instantiate
- _extend_expression_history(text: str) None [source]
Extend the expression history with the given expression.
- _get_animation_frame(start: MatrixType, target: MatrixType, proportion: float) MatrixType [source]
Get the matrix to render for this frame of the animation.
This method will smoothen the determinant if that setting in enabled and if the determinant is positive. It also animates rotation-like matrices using a logarithmic spiral to rotate around and scale continuously. Essentially, it just makes things look good when animating.
- Parameters
start (MatrixType) – The starting matrix
start – The target matrix
proportion (float) – How far we are through the loop
- _is_matrix_too_big(matrix: MatrixType) bool [source]
Check if the given matrix will actually fit on the grid.
We’re checking against a 1000x1000 grid here, which is far less than the actual space we have available. But even when fully zoomed out 1080p monitor, the grid is only roughly 170x90, so 1000x1000 is plenty.
- Parameters
matrix (MatrixType) – The matrix to check
- Returns bool
Whether the matrix is too big to fit on the canvas
- _prompt_update(version: str) None [source]
Open a modal dialog to prompt the user to update lintrans.
- _render_expression() None [source]
Render the transformation given by the expression in the input box.
- _reset_session() None [source]
Ask the user if they want to reset the current session.
Resetting the session means setting the matrix wrapper to a new instance, and rendering I.
- _save_session() None [source]
Save the session to the given file.
If
self._save_filename
isNone
, then call_save_session_as()
and return.
- _save_session_as() None [source]
Ask the user for a file to save the session to, and then call
_save_session()
.Note
If the user doesn’t select a file to save the session to, then the session just doesn’t get saved, and
_save_session()
is never called.
- _show_error_message(title: str, text: str, info: Optional[str] = None, *, warning: bool = False) None [source]
Show an error message in a dialog box.
- _update_render_buttons() None [source]
Enable or disable the render and animate buttons according to whether the matrix expression is valid.
- _update_window_title() None [source]
Update the window title to reflect whether the session has changed since it was last saved.
- check_for_updates_and_prompt() None [source]
Update lintrans depending on the user’s choice of update type.
If they chose ‘prompt’, then this method will open a prompt dialog (after checking if a new version actually exists). See
_prompt_update()
.
- closeEvent(event: QCloseEvent) None [source]
Handle a
QCloseEvent
by confirming if the user wants to save, and cancelling animation.
- class lintrans.gui.main_window._UpdateChecker[source]
Bases:
QObject
A simple class to act as a worker for a
QThread
.- check_for_updates_and_emit() None [source]
Check for updates, and emit
signal_prompt_update
if there’s a new version.This method exists to be run in a background thread to trigger a prompt if a new version is found.
- finished: pyqtSignal
A signal that is emitted when the worker has finished. Intended to be used for cleanup.
- signal_prompt_update: pyqtSignal
A signal that is emitted if a new version is found. The argument is the new version string.
lintrans.gui.session module
This module provides the Session
class, which provides a way to save and load sessions.
- class lintrans.gui.session.Session[source]
Bases:
object
Hold information about a session and provide methods to save and load that data.
- __init__(*, matrix_wrapper: MatrixWrapper, polygon_points: List[Tuple[float, float]], display_settings: DisplaySettings, input_vector: Tuple[float, float]) None [source]
Create a
Session
object with the given data.
- __slots__ = ('matrix_wrapper', 'polygon_points', 'display_settings', 'input_vector')
- display_settings: DisplaySettings
- classmethod load_from_file(filename: str) Tuple[Session, str, bool] [source]
Return the session state that was previously saved to
filename
along with some extra information.The tuple we return has the
Session
object (with some possibly None arguments), the lintrans version that the file was saved under, and whether the file had any extra attributes that this version doesn’t support.- Raises
AttributeError – For specific older versions of
Session
before it used__slots__
EOFError – If the file doesn’t contain a pickled Python object
FileNotFoundError – If the file doesn’t exist
ValueError – If the file contains a pickled object of the wrong type
- matrix_wrapper: MatrixWrapper
lintrans.gui.settings module
This module contains the DisplaySettings
class, which holds configuration for display.
- class lintrans.gui.settings.DisplaySettings[source]
Bases:
object
This class simply holds some attributes to configure display.
- animation_pause_length: int
This is the number of milliseconds that we wait between animations when using comma syntax.
- applicative_animation: bool
There are two types of simple animation, transitional and applicative.
Let
C
be the matrix representing the currently displayed transformation, and letT
be the target matrix. Transitional animation means that we animate directly fromC
fromT
, and applicative animation means that we animate fromC
toTC
, so we applyT
toC
.
- draw_background_grid: bool
This controls whether we want to draw the background grid.
The background axes will always be drawn. This makes it easy to identify the center of the space.
- draw_determinant_parallelogram: bool
This controls whether or not we should shade the parallelogram representing the determinant of the matrix.
- draw_eigenvectors: bool
This controls whether we should draw the eigenvectors of the transformation.
- draw_input_vector: bool
This controls whether we should draw the input vector in the main viewport.
- draw_output_vector: bool
This controls whether we should draw the output vector in the main viewport.
- draw_transformed_grid: bool
This controls whether we want to draw the transformed grid. Vectors are handled separately.
- draw_transformed_polygon: bool
This controls whether we should draw the transformed version of the user-defined polygon.
- draw_untransformed_polygon: bool
This controls whether we should draw the untransformed version of the user-defined polygon.
- classmethod load_from_file(filename: str) Tuple[str, DisplaySettings] [source]
Return the display settings that were previously saved to
filename
along with some extra information.The tuple we return has the version of lintrans that was used to save the file, and the data itself.
- Raises
EOFError – If the file doesn’t contain a pickled Python object
FileNotFoundError – If the file doesn’t exist
ValueError – If the file contains a pickled object of the wrong type
- save_to_file(filename: str) None [source]
Save the display settings to a file, creating parent directories as needed.
- show_determinant_value: bool
This controls whether we should write the text value of the determinant inside the parallelogram.
The text only gets draw if
draw_determinant_parallelogram
is also True.
- smoothen_determinant: bool
This controls whether we want the determinant to change smoothly during the animation.
Note
Even if this is
True
, it will be ignored if we’re animating from a positive det matrix to a negative det matrix, or vice versa, because if we try to smoothly animate that determinant, things blow up and the app often crashes.
lintrans.gui.utility module
This module provides utility functions for the whole GUI, such as qapp()
.
- lintrans.gui.utility.qapp() QCoreApplication [source]
Return the equivalent of the global
qApp
pointer.- Raises
RuntimeError – If
QCoreApplication.instance()
returnsNone
lintrans.gui.validate module
This simple module provides a MatrixExpressionValidator
class to validate matrix expression input.