MainTab package

Data management layer for DistrictHeatingSim application.

This module implements the Model layer of the MVP pattern, providing three core managers: - ProjectConfigManager: Configuration and user preferences - DataManager: Central data storage for analysis results - ProjectFolderManager: Project folder structure and navigation

author:

Dipl.-Ing. (FH) Jonas Pfeiffer

class districtheatingsim.gui.MainTab.main_data_manager.ProjectConfigManager(config_path: str | None = None, file_paths_path: str | None = None)[source]

Bases: object

Manages application configuration and resource paths.

Handles JSON-based configuration storage including user preferences, recent projects, and resource path resolution for both development and PyInstaller builds.

Parameters:
  • config_path (str) – Path to config.json (optional, uses default if None)

  • file_paths_path (str) – Path to file_paths.json (optional, uses default if None)

Note

Configuration files are stored with UTF-8 encoding for international character support.

__init__(config_path: str | None = None, file_paths_path: str | None = None)[source]

Initialize configuration manager with automatic data loading.

Parameters:
  • config_path (str) – Custom path to configuration file

  • file_paths_path (str) – Custom path to file paths configuration

get_default_config_path() str[source]

Get the default path to recent_projects.json.

Returns:

Absolute path to the default configuration file

Return type:

str

get_default_file_paths_path() str[source]

Get the default path to file_paths.json.

Returns:

Absolute path to the default file paths configuration file

Return type:

str

load_config() dict[str, Any][source]

Load application configuration from JSON file with UTF-8 encoding.

Returns:

Configuration dictionary (empty if file doesn’t exist)

Return type:

dict

load_file_paths() dict[str, str][source]

Load file path mappings from JSON configuration with UTF-8 encoding.

Returns:

File paths dictionary mapping resource IDs to relative paths (empty if file doesn’t exist)

Return type:

dict

save_config(config: dict[str, Any]) None[source]

Save configuration data to JSON file with UTF-8 encoding.

Parameters:

config (dict) – Configuration data to save

Raises:

Exception – If file cannot be written

save_file_paths(file_paths: dict[str, str]) None[source]

Save file paths configuration to JSON file with UTF-8 encoding.

Parameters:

file_paths (dict) – File paths data to save

Raises:

Exception – If file cannot be written

get_last_project() str[source]

Retrieve the path of the most recently opened project.

Returns:

Path to last opened project (empty string if none)

Return type:

str

set_last_project(path: str) None[source]

Set the most recently opened project and update recent projects list.

Automatically manages recent projects history (max 5 entries) with duplicate prevention and configuration persistence.

Parameters:

path (str) – Path to the project directory

get_recent_projects() list[str][source]

Retrieve the list of recently opened projects.

Returns:

List of project paths (max 5 entries, most recent first)

Return type:

list of str

get_relative_path(key: str) str[source]

Get relative path from file paths configuration.

Parameters:

key (str) – Configuration key for desired resource path

Returns:

Relative path string

Return type:

str

Raises:

KeyError – If key not found in file paths configuration

get_resource_path(key: str) str[source]

Get absolute path to resource with PyInstaller compatibility.

Parameters:

key (str) – Configuration key for desired resource

Returns:

Absolute path to resource

Return type:

str

class districtheatingsim.gui.MainTab.main_data_manager.DataManager[source]

Bases: object

Central storage for transient, in-memory runtime data (map layers).

Per-project state — including the TRY (weather) and COP (heat-pump) file paths — lives in ProjectFolderManager, which persists it to project_settings.json. Read those paths from the folder manager, not here.

__init__()[source]

Initialize the data manager with empty data structures.

class districtheatingsim.gui.MainTab.main_data_manager.ProjectFolderManager(config_manager: ProjectConfigManager | None = None)[source]

Bases: QObject

Manages project folder structure and variant navigation.

Handles project folder hierarchy, variant switching, and emits signals when project/variant folders change for UI synchronization.

Parameters:

config_manager (ProjectConfigManager) – Configuration manager instance (creates new if None)

Signal project_folder_changed:

Emitted when project/variant folder changes (str)

project_folder_changed

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

crs_changed

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

__init__(config_manager: ProjectConfigManager | None = None)[source]

Initialize the project folder manager.

Parameters:

config_manager (ProjectConfigManager) – Configuration manager instance (creates new if None)

emit_project_and_variant_folder() None[source]

Emit signal for current project and variant folder state.

Creates default “Variante 1” if no variant folder exists.

set_project_folder(path: str) None[source]

Set the project folder and update configuration.

Validates variant folder and emits signals to notify connected components. Creates default “Variante 1” if no valid variant exists.

Parameters:

path (str) – Path to the project directory

set_variant_folder(variant_name: str) None[source]

Set the current variant folder and emit change signal.

Parameters:

variant_name (str) – Name of the variant folder (e.g., “Variante 1”)

get_variant_folder() str[source]

Get the current variant folder path.

Returns:

Current variant folder path (or project folder if no variant)

Return type:

str

load_project_settings() None[source]

Load per-project settings (CRS, active energy configs, TRY/COP paths) from project_settings.json.

save_project_settings() None[source]

Persist per-project settings to project_settings.json.

get_active_energy_config(variant_folder: str) str[source]

Return the active energy system config name for a variant folder.

Parameters:

variant_folder (str) – Absolute path to the variant folder.

Returns:

Config name (e.g. "Standard" or "Solar+BHKW").

Return type:

str

set_active_energy_config(variant_folder: str, config_name: str) None[source]

Persist the active energy system config name for a variant folder.

Parameters:
  • variant_folder (str) – Absolute path to the variant folder.

  • config_name (str) – Config name to store.

set_project_crs(crs: str) None[source]

Set the projected CRS for this project and persist it.

Parameters:

crs (str) – EPSG code string, e.g. "EPSG:25833"

set_calculation_year(year: int) None[source]

Set the heat-demand profile calculation year and persist it.

Parameters:

year (int) – Four-digit year (e.g. 2023) used for BDEW/VDI 4655 profiles.

set_try_filename(path: str | None) None[source]

Copy the selected TRY file into the project folder and persist the path.

The file is copied to <project>/Klimadaten/ so the project stays self-contained and portable across machines.

Parameters:

path (str or None) – Absolute path to the TRY .dat file, or None to clear.

set_cop_filename(path: str | None) None[source]

Copy the selected COP data file into the project folder and persist the path.

The file is copied to <project>/Wärmepumpendaten/ so the project stays self-contained and portable across machines.

Parameters:

path (str or None) – Absolute path to the COP data file, or None to clear.

load_last_project() None[source]

Load the most recently opened project from configuration.

Validates project existence before loading. Emits default state if project invalid or missing.

Main presenter module for DistrictHeatingSim application.

Implements the Presenter component of the MVP pattern, handling business logic for project management, variant creation, and coordination between view and data management layers.

author:

Dipl.-Ing. (FH) Jonas Pfeiffer

class districtheatingsim.gui.MainTab.main_presenter.HeatSystemPresenter(view, folder_manager, data_manager, config_manager)[source]

Bases: object

Presenter for district heating project management (MVP pattern).

Coordinates between view and data management layers, handling business logic for project creation, variant management, and folder structure operations.

Parameters:
__init__(view, folder_manager, data_manager, config_manager)[source]

Initialize presenter with manager dependencies.

Parameters:
create_new_project(folder_path: str, project_name: str) bool[source]

Create new district heating project with standardized folder structure.

Creates project with “Eingangsdaten allgemein”, “Definition Quartier IST”, and “Variante 1” folders. Initializes building data CSV and registers project with folder manager.

Parameters:
  • folder_path (str) – Base directory for new project

  • project_name (str) – Name of project folder

Returns:

True if successful, False otherwise

Return type:

bool

open_existing_project(folder_path: str) None[source]

Open existing district heating project.

Registers project folder with folder manager, triggering automatic synchronization of all application components.

Parameters:

folder_path (str) – Path to existing project folder

create_project_copy() bool[source]

Create complete copy of current project with user-specified name.

Prompts user for new project name via dialog, then creates exact duplicate including all data files, analysis results, and structure. Automatically activates the copied project.

Returns:

True if successful, False if cancelled or failed

Return type:

bool

create_project_variant() bool[source]

Create new analysis variant within current project.

Creates sequentially numbered variant (Variante X) with standardized subfolder structure (Ergebnisse, Gebäudedaten, Lastgang, Wärmenetz). Automatically activates new variant.

Returns:

True if successful, False if failed

Return type:

bool

create_project_variant_copy() bool[source]

Create exact copy of current variant with sequential numbering.

Duplicates all data, analysis results, and configuration settings. Automatically activates new variant copy.

Returns:

True if successful, False if failed

Return type:

bool

Main GUI view module for DistrictHeatingSim application.

This module implements the main window with a multi-tab interface for district heating system simulation. Follows the View component of the MVP pattern, managing UI elements, menu system, theme management, and tab coordination.

author:

Dipl.-Ing. (FH) Jonas Pfeiffer

class districtheatingsim.gui.MainTab.main_view.HeatSystemDesignGUI(folder_manager, data_manager)[source]

Bases: QMainWindow

Main application window with multi-tab interface for district heating analysis.

Implements the View component of the MVP pattern, managing UI elements, menu system, theme switching, and tab coordination for the complete district heating workflow.

Parameters:

Note

Tabs can be dynamically shown/hidden via the menu system to customize the workflow.

__init__(folder_manager, data_manager)[source]

Initialize main application window with manager dependencies.

Sets up basic window structure, defers UI creation until presenter is set.

Parameters:
set_presenter(presenter) None[source]

Set presenter and initialize complete user interface.

Completes MVP pattern setup by connecting presenter and triggering full UI initialization including menus, tabs, dialogs, and theme.

Parameters:

presenter (HeatSystemPresenter) – Business logic controller

initUI() None[source]

Initialize the user interface with stacked widget architecture.

init_welcome_screen() None[source]

Initialize the welcome screen widget.

init_main_interface() None[source]

Initialize the main application interface widget.

show_welcome_screen() None[source]

Zeige den Welcome Screen und setze base_path auf leer.

show_main_interface() None[source]

Switch to showing the main interface.

add_theme_toggle_to_main_interface()[source]

Add theme toggle switch to the main interface next to menu bar.

on_main_theme_toggle(checked)[source]

Handle theme toggle from main interface.

on_project_selected(project_path: str)[source]

Handle project selection from welcome screen.

on_new_project_requested()[source]

Handle new project creation request from welcome screen.

show_save_dialog(title: str, info_text: str, accept_text: str) str[source]

Show standardized save dialog for project operations.

Parameters:
  • title (str) – Dialog window title

  • info_text (str) – Informative text explaining the operation

  • accept_text (str) – Text for accept button

Returns:

User choice: ‘save’, ‘discard’, ‘cancel’, or ‘continue’

Return type:

str

on_back_to_welcome()[source]

Return to the welcome screen from main interface. Give user choice to save, discard, or cancel if project is loaded.

on_theme_change_requested(theme_path: str)[source]

Handle theme change request from welcome screen.

apply_theme()[source]

Apply the time-based default theme to the entire application.

apply_current_theme_to_welcome_screen()[source]

Apply the current application theme to the welcome screen.

sync_theme_toggle_state()[source]

Synchronize the theme toggle switch with the current theme.

initMenuBar() None[source]

Initialize menu bar with File, Data, Theme, and Tabs menus.

Creates professional menu system with project management, recent projects, variant handling, data configuration, and tab visibility control.

initTabs() None[source]

Initialize multi-tab interface for district heating analysis workflow.

Creates tabs for project definition, building data, network visualization, network calculation, energy system design, and variant comparison. Supports dynamic tab visibility control.

Initialize application logo and window icon.

Loads logo via ConfigManager with fallback paths for both development and packaged application scenarios.

update_project_folder_label(base_path: str) None[source]

Update project folder status label with current project path.

Parameters:

base_path (str) – Current project/variant folder path

show_error_message(message: str) None[source]

Display standardized error message dialog.

Parameters:

message (str) – Error message text to display

show_message(title: str, message: str) None[source]

Show a success/info message dialog.

on_create_new_project() None[source]

Handle new project creation with user input and validation.

Prompts for save if project loaded, collects project name, and creates standardized project structure via presenter.

on_open_existing_project(folder_path: str | None = None) None[source]

Handle opening existing projects with variant selection support.

Prompts for save, discovers variants, and loads selected project.

Parameters:

folder_path (str or None) – Direct path to project folder (optional)

get_available_variants(project_path: str) list[str][source]

Discover available project variants in specified project directory.

Thin GUI wrapper over project_structure.discover_variants() that surfaces a missing project path as an error dialog.

Parameters:

project_path (str) – Path to main project directory

Returns:

List of valid variant folder names

Return type:

list of str

on_create_project_copy() None[source]

Handle project copy creation with user feedback.

Prompts for save, creates complete project duplicate via presenter, and displays success message.

on_open_variant() None[source]

Handle variant selection within current project.

Prompts for save, discovers variants, and switches to selected variant.

on_create_project_variant() None[source]

Handle creation of new project variant.

Prompts for save, creates new variant via presenter, and displays success message.

on_create_project_variant_copy() None[source]

Handle creation of variant copy with data preservation.

Prompts for save, creates variant copy via presenter, and displays success message.

show_temporary_success_message(message: str, duration_ms: int = 2000) None[source]

Display auto-dismissing success message.

Parameters:
  • message (str) – Success message to display

  • duration_ms (int) – Display duration in milliseconds (default: 2000)

on_importResultsAction() None[source]

Load all available project data and results.

Silently loads building data, network data, and energy system results without individual confirmation dialogs. Shows single success message.

save_all_project_results() bool[source]

Zentrale Speicherlogik für alle Projektergebnisse. Ruft die jeweiligen Save-Methoden der einzelnen Tabs/Presenter auf. Sollte vor dem Schließen der Anwendung und beim Wechsel des Projekts/Variante aufgerufen werden. Vor dem Speichern wird ein Warn-Dialog angezeigt, der auf fehlende Versionierung und mögliche Überschreibung hinweist. Bricht der Nutzer den Dialog ab, wird die Aktion abgebrochen.

Returns:

True wenn erfolgreich gespeichert, False wenn abgebrochen

Return type:

bool

applyTheme(theme_path: str) None[source]

Apply visual theme to application.

Loads and applies Qt stylesheet with fallback for missing resources.

Parameters:

theme_path (str) – Configuration key for theme stylesheet path

openTemperatureDataSelection() None[source]

Open temperature data configuration dialog and update system settings.

Displays dialog for TRY (Test Reference Year) selection and triggers system-wide temperature data update.

openCOPDataSelection() None[source]

Open heat pump COP data configuration dialog and update settings.

Displays dialog for heat pump performance data selection and triggers system-wide COP data update.

restoreDataFilesFromProject() None[source]

Restore TRY and COP filenames from the loaded project settings.

Called whenever the project/variant folder changes. If the project has previously saved paths, they are written back to the data manager and shown in the selection dialogs. The dialog defaults remain as fallback when no project-level path is stored.

updateTemperatureData() None[source]

Persist the TRY file selected in the dialog to both the data manager and the project settings so it is restored on next project open.

updateHeatPumpData() None[source]

Persist the COP file selected in the dialog to both the data manager and the project settings so it is restored on next project open.

closeEvent(event)[source]

Save all project results before closing the application. Only if a project is loaded. Allows user to cancel application closure.