radioviz.views.main_window
Main window implementation for the RadioViz application.
This module contains the main window class that serves as the central hub for the application’s GUI, managing sub-windows, menus, tool docks, and overall application layout. It handles file operations, window management, and integrates with the application’s controller layer.
Classes
|
Main application window for RadioViz. |
- class radioviz.views.main_window.MainWindow(main_controller: MainController | None = None)[source]
Bases:
QMainWindowMain application window for RadioViz.
This class implements the primary window of the RadioViz application, handling the main GUI components including MDI area for sub-windows, menu bars, tool docks, and overall application layout management.
- Variables:
controller (MainController) – The main application controller instance
Initialize the main window.
Creates the main application window with all required UI components including menus, tool docks, and MDI area for sub-windows.
- Parameters:
main_controller (Optional[MainController]) – Optional main controller instance, defaults to None
- _close_active_window() None[source]
Close the currently active window.
Sends a request to the windows manager to close the currently active window.
- _close_all_windows() None[source]
Close all open windows.
Sends a request to the windows manager to close all currently open windows.
Create the File menu.
Sets up the File menu with actions for opening files, viewing recent files, and exiting the application.
- Parameters:
bar (QMenuBar) – The menu bar to add the menu to
Create the Help menu.
Sets up the Help menu with About and Qt information actions.
- Parameters:
bar (QMenuBar) – The menu bar to add the menu to
Create all application menus.
Initializes and sets up all menu bars including File, View, Tools, Window, and Help menus with their respective actions and sub-menus.
Create the Tools menu.
Sets up the Tools menu with dynamically built tool menus based on available tools.
- Parameters:
bar (QMenuBar) – The menu bar to add the menu to
Create the View menu.
Sets up the View menu with options for tool view management and layout restoration.
- Parameters:
bar (QMenuBar) – The menu bar to add the menu to
Create the Window menu.
Sets up the Window menu with actions for window management including cascading, tiling, and switching between windows.
- Parameters:
bar (QMenuBar) – The menu bar to add the menu to
- _format_dependency_text(counts: dict[str, int]) str[source]
Create a human‑readable description of tool dependencies.
The function receives a mapping where keys are tool identifiers and values are the number of items that depend on the image. It returns a concise string summarising the dependencies, or a default message when no dependencies are present.
- Parameters:
counts (dict) – Mapping of tool IDs to dependency counts.
- Returns:
Description of the dependencies, e.g.
'Excluding will also remove: 2 toolA item(s), 1 toolB item(s)'. Returns'No dependent tools'when the mapping is empty or all counts are zero.- Return type:
str
- _init_default_layout() None[source]
Initialize default window layout.
Saves the initial window state for later restoration.
- _on_cancelled_loading(path: Path) None[source]
Handle cancelled image loading.
Cancels the image loading process and closes the progress dialog.
- Parameters:
path (Path) – Path of the file whose loading was cancelled
- _on_load_failed(path: Path, exc: Exception) None[source]
Handle image loading failure.
Displays an error message when image loading fails.
- Parameters:
path (Path) – Path of the file that failed to load
exc (Exception) – Exception that occurred during loading
- _on_load_progress(path: Path, progress: int) None[source]
Handle image loading progress updates.
Updates the progress dialog when loading images.
- Parameters:
path (Path) – Path of the file being loaded
progress (int) – Current loading progress percentage
- _on_nonpersistent_image_selection_requested(items: list[dict[str, Any]]) None[source]
Process a request to select non‑persistent images.
The method builds a list of
UnsavedImageItemobjects from the supplieditemsdictionaries, presents them in anUnsavedImagesDialog, and reacts to the user’s choice:If the dialog is cancelled, the
nonpersistent_images_selectedsignal is emitted withFalseand an empty exclusion list.If the user confirms, the method ensures that each selected image has a saved file (prompting a SaveAs operation when necessary). Should any save operation fail, the signal is emitted with
False.Finally, it emits the signal with
Trueand a list of image IDs that the user chose to exclude.
- Parameters:
items (list[dict]) – List of dictionaries describing the images. Each dictionary must contain an
'image_id'key and may optionally include'name'and'dependency_counts'entries.- Returns:
None– the outcome is communicated via thenonpersistent_images_selectedsignal.- Return type:
None
- _on_window_closed(window: SubWindow[Any]) None[source]
Handle window closing event.
Removes the window from the application’s window manager when closed.
- Parameters:
window (SubWindow[Any]) – The window that was closed
- _on_xyz_metadata_requested(payload: dict[str, Any]) None[source]
Prompt the user to provide a DAT sidecar for a XYZ file.
- Parameters:
payload (dict) – Payload containing the XYZ path and expected DAT path.
- _open_file_dialog() None[source]
Open file dialog for selecting TIFF files.
Displays a file dialog to select one or more TIFF and XYZ files for loading into the application.
- static _open_online_help() None[source]
Open the online documentation in a web browser.
Uses subprocess on Linux to suppress console output from browser sessions.
Rebuild the recent files menu.
Updates the recent files menu with the currently stored recent files.
- _rebuild_window_list() None[source]
Rebuild the window list menu.
Updates the window list menu with currently open windows.
- _show_message(text: str, level: str, timeout_ms: int = 3000) None[source]
Display a message in the status bar or dialog.
Shows messages in the status bar or as dialog boxes depending on the message level.
- Parameters:
text (str) – Message text to display
level (str) – Message level (‘info’, ‘warning’, or ‘error’)
timeout_ms (int) – Timeout in milliseconds for status bar messages, defaults to 3000
- _synch_ui_state() None[source]
Synchronize UI state with application state.
Updates the UI components based on the current application state, enabling/disabling menus and tool docks appropriately.
- _tool_global_docks() None[source]
Create and configure global tool docks.
Sets up all tool docks defined in the controller, adding them to the main window with appropriate docking positions and tabification.
- _update_close_status(close_active: bool, close_all: bool) None[source]
Update the close and close-all menu item enabled states.
Enables or disables the close and close-all menu items based on whether there is an active window and whether there are any open windows respectively.
- Parameters:
close_active (bool) – Whether the close active window action should be enabled
close_all (bool) – Whether the close all windows action should be enabled
- _update_export(active_window: SubWindow[Any]) None[source]
Update the export menu item enabled state.
Enables or disables the export menu item based on whether the active window implements the Exportable interface and can perform export operations.
- Parameters:
active_window (SubWindow[Any]) – The currently active sub-window
- _update_metadata_action(active_window: SubWindow[Any]) None[source]
Update the image metadata action enabled state.
Enables the metadata action only when the active window is an image window.
- Parameters:
active_window (SubWindow[Any]) – The currently active sub-window
- _update_save_status(active_window: SubWindow[Any]) None[source]
Update the save and save-as menu item enabled states.
Enables or disables the save and save-as menu items based on whether the active window implements the Savable interface and can perform save operations.
- Parameters:
active_window (SubWindow[Any]) – The currently active sub-window
- activate_next_window() None[source]
Activate the next window in the window list.
Switches focus to the next window in the sequence.
- activate_previous_window() None[source]
Activate the previous window in the window list.
Switches focus to the previous window in the sequence.
- activate_window() None[source]
Activate the currently active window.
Sets focus to the currently active window in the MDI area.
- closeEvent(event: QEvent) None[source]
Handle window close event.
Saves the window state and geometry before closing.
- Parameters:
event – The close event
- create_subwindow_view(window_request: WindowRequest) SubWindow[Any][source]
Create a new sub-window view.
Creates and initializes a new sub-window based on the provided window request.
- Parameters:
window_request (WindowRequest) – Request specifying the window to create
- Returns:
The created sub-window instance
- Return type:
SubWindow[Any]
- eventFilter(obj: Any, event: QEvent) bool[source]
Filter events for the MDI area.
Handles drag and drop events for the MDI area.
- Parameters:
obj – Object that received the event
event – The event to filter
- Returns:
True if event was handled, False otherwise
- Return type:
bool
- export() None[source]
Export the active window content.
Opens an export dialog to allow the user to specify export parameters and exports the currently active window’s content using the export coordinator.
This method checks if the active window implements the Exportable interface before attempting to export. If the active window does not support exporting, the operation is skipped.
- static handle_drag_enter(event: QEvent) None[source]
Handle drag enter event.
Accepts drag operations that contain URLs (files).
- Parameters:
event – The drag enter event
- handle_drop(event: QEvent) None[source]
Handle drop event.
Processes dropped files, loading TIFF files and showing warnings for unsupported files.
- Parameters:
event – The drop event
- load_workspace() None[source]
Load a workspace from a file.
Opens a file dialog to allow the user to select a workspace file to load and restores the workspace state including all windows and their configurations.
The user can choose between light (.json) and full (.h5) workspace formats. Previously saved workspace data will be restored in the application.
- on_active_window_changed(window: SubWindow[Any]) None[source]
Handle active window change.
Updates the application state when the active window changes.
- Parameters:
window (SubWindow[Any]) – The newly activated window
- restore_default_layout() None[source]
Restore default window layout.
Restores the default window layout configuration.
- restore_layout() None[source]
Restore saved window layout.
Restores the previously saved window geometry and state from settings.
- save() None[source]
Save the active window.
Saves the currently active window’s content using the save coordinator.
This method checks if the active window implements the Savable interface before attempting to save. If the active window does not support saving, the operation is skipped.
- save_as() None[source]
Save the active window with a new filename.
Opens a file dialog to allow the user to specify a new filename and saves the currently active window’s content using the save coordinator.
This method checks if the active window implements the Savable interface before attempting to save. If the active window does not support saving, the operation is skipped.
- save_workspace() None[source]
Save the current workspace to a file.
Opens a file dialog to allow the user to specify a filename and save the current workspace state in either JSON or HDF5 format.
The user can choose between light (.json) and full (.h5) workspace formats. The saved workspace includes all open windows and their configurations.
Set active window from menu selection.
Activates a window based on its index in the window list menu.
- Parameters:
window_id (int) – Index of the window to activate
- show_about_dialog() None[source]
Show the application’s About dialog.
Displays the About dialog containing application information.
Show the context menu.
Displays a context menu built from tool menus compatible with the active window plus any window-specific menus.
- Parameters:
pos (QPoint) – Position where to show the menu
window_controller (SubWindowController[Any]) – The window controller from where the context menu is shown