Source code for spinningdiskanalyzer.main
"""Main module that starts the application"""
from . import meta
from . import logger
from .frontend import Window
from PySide6.QtWidgets import QApplication
from PySide6.QtGui import QIcon
from PySide6.QtGui import QPalette
from platform import system
from pathlib import Path
from logging import getLogger
[docs]
def start():
"""Starts the application."""
# Set up debug logger and mark application start.
logger.setup()
log = getLogger(__name__)
log.info(f'{meta.title} {meta.version}')
log.debug(f'current folder: {Path.cwd()}')
# Initialize Qt.
app = QApplication([])
app.setStyle('Fusion')
# Check if window theme is dark or light.
color_foreground = app.palette().color(QPalette.Text).value()
color_background = app.palette().color(QPalette.Base).value()
dark_theme = (color_foreground > color_background)
# Select corresponding icon sets.
here = Path(__file__).parent
if dark_theme:
icons = here/'frontend'/'icons'/'dark'
else:
icons = here/'frontend'/'icons'/'light'
if not icons.is_dir():
raise RuntimeError(f'Icons folder "{icons}" does not exist')
QIcon.setFallbackSearchPaths([str(icons)])
# Use the program logo as the application icon.
file = here/'logo.ico'
if not file.exists():
log.error(f'Application icon "{file}" not found.')
app.setWindowIcon(QIcon(str(file)))
# On Windows, register this program so that the icon is also used
# in the Taskbar. Otherwise it would get the standard Python icon.
if system() == 'Windows':
from ctypes import windll
windll.shell32.SetCurrentProcessExplicitAppUserModelID(meta.title)
# Create main window.
window = Window()
window.show()
# Run the application's event loop.
app.exec()
# Stop event logger after the application exited.
log.info('Application exited.')
# Fence application entry point against module imports.
if __name__ == '__main__':
start()