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

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__()

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

Animate from the start matrix to the target matrix.

_animate_expression() None

Animate from the current matrix to the matrix in the expression box.

_ask_for_session_file() None

Ask the user to select a session file, and then open it and load the session.

_assign_display_settings() None

Assign a new value to self._plot.display_settings and give the expression box focus.

_assign_matrix_wrapper() None

Assign a new value to self._matrix_wrapper and give the expression box focus.

_assign_polygon_points() None

Assign a new value to self._plot.polygon_points and give the expression box focus.

_dialog_change_display_settings() None

Open the dialog to change the display settings.

_dialog_define_matrix(dialog_class: Type[DefineMatrixDialog]) None

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

Open the dialog to define a polygon.

_get_animation_frame(start: MatrixType, target: MatrixType, proportion: float) MatrixType

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

Check if the given matrix will actually fit onto the canvas.

Convert the elements of the matrix to canvas coords and make sure they fit within Qt’s 32-bit integer limit.

Parameters

matrix (MatrixType) – The matrix to check

Returns bool

Whether the matrix is too big to fit on the canvas

_render_expression() None

Render the transformation given by the expression in the input box.

_reset_session() None

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

Reset the visualized transformation back to the identity.

_reset_zoom() None

Reset the zoom level back to normal.

_save_session() None

Save the session to the given file.

If self._save_filename is None, then call _save_session_as() and return.

_save_session_as() None

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

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

Enable or disable the render and animate buttons according to whether the matrix expression is valid.

_update_window_title() None

Update the window title to reflect whether the session has changed since it was last saved.

closeEvent(event: QCloseEvent) None

Handle a QCloseEvent by confirming if the user wants to save, and cancelling animation.

open_session_file(filename: str) None

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.

lintrans.gui.main_window.main(filename: Optional[str]) None

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

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]]) None

Create a Session object with the given data.

__slots__ = ('matrix_wrapper', 'polygon_points')
classmethod load_from_file(filename: str) Tuple[Session, str, bool]

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
polygon_points
save_to_file(filename: str) None

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

lintrans.gui.session._return_none() None

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

Bases: object

This class simply holds some attributes to configure display.

animation_pause_length: int = 400

This is the number of milliseconds that we wait between animations when using comma syntax.

animation_time: int = 1200

This is the number of milliseconds that an animation takes.

applicative_animation: bool = True

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 = True

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 = True

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

draw_determinant_parallelogram: bool = False

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

draw_eigenlines: bool = False

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

draw_eigenvectors: bool = False

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

draw_transformed_grid: bool = True

This controls whether we want to draw the transformed grid. Vectors are handled separately.

draw_transformed_polygon: bool = True

This controls whether we should draw the transformed version of the user-defined polygon.

draw_untransformed_polygon: bool = True

This controls whether we should draw the untransformed version of the user-defined polygon.

label_basis_vectors: bool = False

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

show_determinant_value: bool = True

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 = True

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

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

Bases: QValidator

This class validates matrix expressions in a Qt input box.

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

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