Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add a splash widget #16

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions qtapputils/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from .range import RangeSpinBox, RangeWidget
from .waitingspinner import WaitingSpinner
from .path import PathBoxWidget, CheckboxPathBoxWidget
from .splash import SplashScreen
27 changes: 27 additions & 0 deletions qtapputils/widgets/splash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © QtAppUtils Project Contributors
# https://github.com/jnsebgosselin/apputils
#
# This file is part of QtAppUtils.
# Licensed under the terms of the MIT License.
# -----------------------------------------------------------------------------

# ---- Third party imports
from qtpy.QtCore import Qt
from qtpy.QtGui import QPixmap
from qtpy.QtWidgets import QSplashScreen


class SplashScreen(QSplashScreen):
def __init__(self, imgpath: str, msg=None):
super().__init__(QPixmap(imgpath))
if msg is not None:
self.showMessage(msg)
self.show()
self.activateWindow()
self.raise_()

def showMessage(self, msg):
"""Override Qt method."""
super().showMessage(msg, Qt.AlignBottom | Qt.AlignCenter)
Binary file added qtapputils/widgets/tests/test_splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions qtapputils/widgets/tests/test_splash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © QtAppUtils Project Contributors
# https://github.com/jnsebgosselin/apputils
#
# This file is part of QtAppUtils.
# Licensed under the terms of the MIT License.
# -----------------------------------------------------------------------------

"""
Tests for widgets in the splash.py module.
"""

# ---- Standard imports
import os.path as osp

# ---- Third party imports
import pytest
from qtpy.QtWidgets import QWidget

# ---- Local imports
from qtapputils.widgets import SplashScreen


# =============================================================================
# ---- Tests for the PathBoxWidget
# =============================================================================
def test_splash(qtbot):
"""Test that getting a file name is working as expected."""
splash = SplashScreen(
imgpath=osp.join(osp.dirname(__file__), 'test_splash.png'),
msg='Initializing splash test...'
)

assert splash.isVisible() is True
assert splash.message() == 'Initializing splash test...'

splash.showMessage('Create main widget...')
assert splash.message() == 'Create main widget...'

main = QWidget()
splash.finish(main)
main.show()

assert splash.isVisible() is False


if __name__ == "__main__":
pytest.main(['-x', __file__, '-v', '-rw'])
Loading
Loading