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_change_display_settings() None[source]

Open the dialog to change the display settings.

_dialog_change_global_settings() None[source]

Open the dialog to change the global settings.

_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 subclass DefineMatrixDialog.

Parameters

dialog_class (Type[lintrans.gui.dialogs.define_new_matrix.DefineMatrixDialog]) – The dialog class to instantiate

_dialog_define_polygon() None[source]

Open the dialog to define a polygon.

_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

_open_info_panel() None[source]

Open the info panel and register a callback to undefine matrices.

_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.

_reset_transformation() None[source]

Reset the visualized transformation back to the identity.

_reset_zoom() None[source]

Reset the zoom level back to normal.

_save_session() None[source]

Save the session to the given file.

If self._save_filename is None, 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.

Parameters
  • title (str) – The window title of the dialog box

  • text (str) – The simple error message

  • info (Optional[str]) – The more informative error message

_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.

keyPressEvent(event: QKeyEvent) None[source]

Handle a QKeyEvent by scrolling through expression history.

open_session_file(filename: str) None[source]

Open the given session file.

If the selected file is not a valid lintrans session file, we just show an error message, but if it’s valid, we load it and set it as the default filename for saving.

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.main_window.main(filename: Optional[str]) NoReturn[source]

Run the GUI by creating and showing an instance of LintransMainWindow.

Parameters

filename (Optional[str]) – A session file to optionally open at startup

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
input_vector: Tuple[float, float]
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
matrix_wrapper: MatrixWrapper
polygon_points: List[Tuple[float, float]]
save_to_file(filename: str) None[source]

Save the session state to a file, creating parent directories as needed.

lintrans.gui.session._return_none() None[source]

Return None.

This function only exists to make the defaultdict in Session pickle-able.

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.

animation_time: int

This is the number of milliseconds that an animation takes.

applicative_animation: bool

There are two types of simple animation, transitional and applicative.

Let C be the matrix representing the currently displayed transformation, and let T be the target matrix. Transitional animation means that we animate directly from C from T, and applicative animation means that we animate from C to TC, so we apply T to C.

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_basis_vectors: bool

This controls whether we want to draw the transformed basis vectors.

draw_determinant_parallelogram: bool

This controls whether or not we should shade the parallelogram representing the determinant of the matrix.

draw_eigenlines: bool

This controls whether we should draw the eigenlines of the transformation.

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.

label_basis_vectors: bool

This controls whether we want to label the i and j basis vectors.

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() returns None

lintrans.gui.validate module

This simple module provides a MatrixExpressionValidator class to validate matrix expression input.

class lintrans.gui.validate.MatrixExpressionValidator[source]

Bases: QValidator

This class validates matrix expressions in a Qt input box.

validate(text: str, pos: int) Tuple[QValidator.State, str, int][source]

Validate the given text according to the rules defined in the matrices module.