app.widgets.misc package#

Submodules#

app.widgets.misc.menu_bar module#

class app.widgets.misc.menu_bar.MenuBar(parent=None)[source]#

Bases: QMenuBar

connect_actions(handlers) None[source]#

Connects menu actions to their corresponding handler functions.

Iterates through a predefined set of menu actions and links them to the corresponding handler functions provided in the handlers dictionary. Each action is enabled if a handler is available, and disabled otherwise.

This modular approach allows dynamic configuration of the menu bar based on context or application state.

Parameters:

handlers (dict) – A dictionary mapping action keys (e.g., ‘new’, ‘open’, ‘exit’) to their corresponding function references.

Behavior:
  • Enables and connects actions that have handlers defined.

  • Disables actions for which no handler is provided.

Example

handlers = {

‘new’: self.create_new_file, ‘open’: self.load_file_dialog, ‘exit’: self.close_app

}

Notes

The following action keys are supported:
  • ‘new’, ‘open’, ‘exit’

  • ‘undo’, ‘redo’

  • ‘minimize’, ‘maximize’, ‘restore’

  • ‘configure_render’

  • ‘about’

app.widgets.misc.render_config_edit module#

class app.widgets.misc.render_config_edit.RenderConfig(project_folder)[source]#

Bases: QMainWindow

RenderConfig Class#

Main configuration panel for render settings in the FlapKine application.

This class provides a GUI window that allows users to configure video rendering, camera parameters, lighting settings, STL export, and axis reflection for a 3D rendering pipeline. The settings are loaded from and saved to a config.json file within the specified project folder.

project_folder#

Path to the folder containing the configuration file.

Type:

str

frame_format#

Dropdown for selecting the frame image format (e.g., PNG, JPEG, TIFF).

Type:

QComboBox

resolution_x#

Spin box to specify horizontal resolution.

Type:

QSpinBox

resolution_y#

Spin box to specify vertical resolution.

Type:

QSpinBox

camera_location_x, camera_location_y, camera_location_z

Spin boxes to specify camera position in 3D space.

Type:

QDoubleSpinBox

camera_rotation_alpha, camera_rotation_beta, camera_rotation_gamma

Spin boxes to specify camera rotation in Euler angles.

Type:

QDoubleSpinBox

light_location_x, light_location_y, light_location_z

Spin boxes to specify light source position in 3D space.

Type:

QDoubleSpinBox

light_power#

Spin box to control light energy (intensity).

Type:

QSpinBox

stl_enable#

Checkbox to toggle STL mesh saving.

Type:

QCheckBox

reflect_xy, reflect_yz, reflect_xz

Checkboxes to select the reflection axis (only one can be active at a time).

Type:

QCheckBox

ok_button#

Button to save the current configuration and close the window.

Type:

QPushButton

__init__(project_folder):

Initializes the main window and constructs the interface.

initUI():

Builds and arranges all GUI components and groups.

_create_video_settings():

Constructs the video configuration group box.

_create_camera_settings():

Constructs the camera configuration group box.

_create_light_settings():

Constructs the lighting configuration group box.

_create_other_settings():

Constructs the STL and reflection settings panel.

_assemble_config_group():

Collects all config panels into a grouped layout.

_styled_groupbox(title, color, border_color, layout, font_size):

Returns a styled QGroupBox with custom appearance.

_labeled_widget(label_text, widget):

Returns a QWidget with an inline label and the given widget.

process_default_config():

Loads the saved configuration from config.json and updates the UI.

save_config():

Saves the current UI state into config.json in the project folder.

toggle_checkboxes(checked_box):

Ensures only one reflection checkbox is active at a time.

center():

Positions the window at the center of the screen.

center()[source]#

Centers the application window on the screen.

Calculates screen and window dimensions, then moves the window to the center position.

initUI()[source]#

Initialize and configure the user interface components of the render configuration panel.

This method sets up the main window layout and populates it with grouped sections for configuring video, camera, and lighting settings. It also adds additional controls such as STL export toggle and axis reflection options. A confirmation button is included to save and apply the chosen configuration settings.

UI Components Initialized#

  • Video settings group

  • Camera settings group

  • Lighting settings group

  • STL export and reflection axis controls

  • ‘Ok’ confirmation button with icon

  • Main vertical layout containing all components

process_default_config()[source]#

Load and apply default configuration values from the project directory.

This method reads a config.json file from the project folder and populates all render configuration widgets with the corresponding values, including video resolution, camera position and orientation, lighting parameters, STL saving, and reflection axis toggles.

Configuration File Structure Expected:
  • VideoRender: { resolution_x, resolution_y }

  • Camera: { location: [x, y, z], rotation_euler: [alpha, beta, gamma] }

  • Light: { location: [x, y, z], energy }

  • STL: bool

  • Reflect: “XY” | “YZ” | “XZ” | None

Raises:
  • FileNotFoundError – If config.json is not found in the project directory.

  • KeyError – If required keys are missing in the config file.

save_config()[source]#

Collect and save the current render configuration to config.json.

This method gathers all UI state values (video format, resolution, camera parameters, lighting setup, STL export preference, and reflection axis) and serializes them into a dictionary. The config is then saved as a JSON file in the project directory under config.json.

Config Structure:
  • VideoRender:
    • OutputPath: str (default ‘data/images’)

    • STLPath: str (default ‘data/stl’)

    • FrameFormat: str (‘PNG’, ‘JPEG’, ‘TIFF’)

    • resolution_x: int

    • resolution_y: int

    • film_transparent: bool (always False)

  • Camera:
    • location: list[float, float, float]

    • rotation_euler: list[float, float, float]

  • Light:
    • location: list[float, float, float]

    • energy: int

  • STL: bool

  • Reflect: str | None (“XY”, “YZ”, “XZ”, or None)

Side Effects#

  • Overwrites the config.json file in the project folder.

  • Closes the configuration window after saving.

toggle_checkboxes(checked_box)[source]#

Enforce mutual exclusivity among axis reflection checkboxes.

Ensures that only one of the reflection axis checkboxes (XY, YZ, XZ) can be active at a time. When a checkbox is toggled on, all others are programmatically toggled off.

Parameters:
  • checked_box (QCheckBox) – The checkbox that was just toggled to the ‘checked’ state.

  • Behavior

  • --------

  • checked (- If checked_box is) –

    • Automatically unchecks the other two axis checkboxes.

  • unchecked (- If checked_box is) –

    • No action is taken (multiple checkboxes can be off simultaneously).

app.widgets.misc.render_worker module#

class app.widgets.misc.render_worker.RenderSignals[source]#

Bases: QObject

RenderSignals Class#

Defines custom signals for tracking the progress and completion status of the rendering process in the FlapKine application. This class is used to communicate between the rendering worker thread and the main GUI, allowing for real-time updates on rendering progress and notification upon completion.

progress_signal#

Signal emitted periodically during rendering to indicate the progress percentage (0.0 to 100.0).

Type:

pyqtSignal(float)

finished#

Signal emitted once the rendering task is fully completed.

Type:

pyqtSignal()

None()#

This class only defines signals and does not implement any methods.

finished#

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

progress_signal#

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

class app.widgets.misc.render_worker.Worker(project_folder, angles, scene_data, reflect)[source]#

Bases: QRunnable

Worker Class#

High-performance QRunnable designed to handle offscreen VTK rendering and real-time video encoding for the FlapKine application. The class avoids disk-based frame dumps by directly feeding rendered frames to OpenCV’s video writer. It supports STL export, real-time progress updates, and efficient rendering pipeline integration with PyQt5’s multithreading model.

project_folder#

Path to the project directory containing configuration and data folders.

Type:

str

angles#

List of angles (typically camera azimuth or rotation values) used to render frames.

Type:

list of float

scene_data#

Scene object responsible for generating STL meshes for each frame.

Type:

Any

reflect#

A 3-element tuple indicating whether to reflect the STL mesh along the XY, YZ, and XZ planes respectively.

Type:

tuple of bool

signals#

Custom signal object to emit rendering progress and completion signals.

Type:

RenderSignals

__init__(project_folder, angles, scene_data, reflect):

Initializes the worker with project-specific configuration and rendering parameters.

run():

Executes the rendering pipeline. Renders each frame using VTK, optionally saves STL files, and writes each rendered frame to a video file using OpenCV. Emits progress and completion signals accordingly.

stl_mesh_to_vtk(stl_mesh):

Converts a mesh object into vtkPolyData using deduplicated vertices via NumPy for efficient rendering.

run()[source]#

Executes the background rendering and encoding process.

This method is invoked when the Worker QRunnable is started via a thread pool. It performs offscreen rendering of a 3D scene using VTK, generates STL meshes frame-by-frame, and directly encodes each rendered frame into an .mp4 video using OpenCV. It also optionally exports STL files and emits real-time progress updates through RenderSignals.

Workflow:
  1. Loads rendering configuration from config.json in the project folder.

  2. Prepares output directories for STL and video data.

  3. Initializes the VTK rendering pipeline (renderer, camera, lighting, actor).

  4. Iterates over the list of specified angles to:
    • Generate STL mesh using scene_data

    • Optionally save STL to disk

    • Convert mesh to vtkPolyData

    • Render the scene offscreen and capture frame

    • Convert VTK image to NumPy array and write to video

  5. Emits progress_signal every two frames (or final frame).

  6. Releases the OpenCV writer and emits finished signal on completion.

Signals Emitted:
  • progress_signal (float): Percentage of frames rendered.

  • finished: Emitted once rendering and encoding are complete.

stl_mesh_to_vtk(stl_mesh)[source]#

Converts a mesh object to vtkPolyData for rendering in VTK.

This method performs a memory-efficient STL conversion by flattening and deduplicating vertex data using NumPy. The resulting unique vertex list and associated triangle indices are used to construct a vtkPolyData object, which is compatible with VTK’s rendering pipeline.

Parameters:

stl_mesh (mesh.Mesh) – The STL mesh object containing 3D geometry in the form of triangle vectors.

Returns:

A VTK-compatible representation of the mesh, ready for visualization.

Return type:

vtkPolyData

app.widgets.misc.video_player module#

class app.widgets.misc.video_player.VideoPlayer(width=640, height=480)[source]#

Bases: QWidget

VideoPlayer Class#

A lightweight QWidget-based video player for embedding video playback within PyQt5 GUIs.

This player uses QMediaPlayer and QVideoWidget to load and display local video files with support for resizing and basic control operations like pause/play.

video_widget#

Widget used to render video content within the layout.

Type:

QVideoWidget

media_player#

Media player responsible for managing video playback and rendering to video_widget.

Type:

QMediaPlayer

__init__(width=640, height=480):

Initializes the video player layout, media pipeline, and default video dimensions.

setMedia(video_path):

Loads a local video file from the specified path and prepares it for playback.

resizeEvent(event):

Handles resizing of the widget to ensure the video maintains full screen coverage.

resizeEvent(event)[source]#

Resizes the video widget to fit the available window space.

Ensures that the embedded video stretches appropriately while maintaining layout behavior.

Parameters:

event (QResizeEvent) – Resize event triggered when the widget is resized by the user or layout system.

setMedia(video_path)[source]#

Loads and prepares a video file for playback.

Parameters:

video_path (str) – Absolute or relative path to the local video file to be loaded.

Notes

  • Video is automatically paused after loading. Use media_player.play() to begin playback.

Module contents#