Skip to content

startup_splash

startup_splash

Attributes

Classes

NyxStartupSplash(screen=None)

Bases: QSplashScreen

Splash screen showing the log messages logged while the editor starts.

The layout is in device independent pixels of the background, which is shown at SIZE.

Initialize NyxStartupSplash.

Parameters:

Name Type Description Default
screen QScreen | None

screen to appear on, primary if None.

None
Source code in src/nyx/editor/widgets/startup_splash.py
33
34
35
36
37
38
39
40
41
def __init__(self, screen: QtGui.QScreen | None = None) -> None:
    """Initialize NyxStartupSplash.

    Args:
        screen (QtGui.QScreen | None): screen to appear on, primary if None.
    """
    super().__init__(screen, self._create_background_pixmap())
    self._signal_handler: QSignalHandler | None = None
    self.setWindowFlag(QtCore.Qt.WindowType.WindowStaysOnTopHint)
Attributes
APP_ICON_SOURCE = ':/icons/nyx.png' class-attribute instance-attribute
BACKGROUND_PIXMAP_SOURCE = ':/images/splash_background' class-attribute instance-attribute
FOOTER_GAP = 16 class-attribute instance-attribute
FOOTER_PIXEL_SIZE = 13 class-attribute instance-attribute
FOOTER_RECT = QtCore.QRect(64, 346, 512, 24) class-attribute instance-attribute
LOGO_RECT = QtCore.QRect(64, 135, 128, 128) class-attribute instance-attribute
SECONDARY_COLOR = QtGui.QColor(143, 149, 168) class-attribute instance-attribute
SIZE = QtCore.QSize(640, 400) class-attribute instance-attribute
SUBTITLE_PIXEL_SIZE = 16 class-attribute instance-attribute
SUBTITLE_RECT = QtCore.QRect(TEXT_LEFT, 204, 400, 28) class-attribute instance-attribute
SUBTITLE_TEXT = 'Python nodal execution graph' class-attribute instance-attribute
TEXT_LEFT = 216 class-attribute instance-attribute
TITLE_COLOR = QtGui.QColor(232, 230, 223) class-attribute instance-attribute
TITLE_PIXEL_SIZE = 40 class-attribute instance-attribute
TITLE_RECT = QtCore.QRect(TEXT_LEFT, 146, 400, 64) class-attribute instance-attribute
VERSION_TEXT = f'v{__version__}' class-attribute instance-attribute
Functions
connect_to_logger(signal_handler)

Show the records of a logger signal handler as the splash message.

Parameters:

Name Type Description Default
signal_handler QSignalHandler

handler to listen to.

required
Source code in src/nyx/editor/widgets/startup_splash.py
103
104
105
106
107
108
109
110
111
def connect_to_logger(self, signal_handler: QSignalHandler) -> None:
    """Show the records of a logger signal handler as the splash message.

    Args:
        signal_handler (QSignalHandler): handler to listen to.
    """
    self.disconnect_from_logger()
    self._signal_handler = signal_handler
    signal_handler.emitter.record_logged.connect(self._on_record_logged)
disconnect_from_logger()

Stop showing log records.

Source code in src/nyx/editor/widgets/startup_splash.py
113
114
115
116
117
118
def disconnect_from_logger(self) -> None:
    """Stop showing log records."""
    if self._signal_handler is None:
        return
    self._signal_handler.emitter.record_logged.disconnect(self._on_record_logged)
    self._signal_handler = None
drawContents(painter)

Draw the message at the left of the footer, elided to leave the version.

Parameters:

Name Type Description Default
painter QPainter

painter of the splash.

required
Source code in src/nyx/editor/widgets/startup_splash.py
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
def drawContents(self, painter: QtGui.QPainter) -> None:
    """Draw the message at the left of the footer, elided to leave the version.

    Args:
        painter (QtGui.QPainter): painter of the splash.
    """
    font = self._font(self.FOOTER_PIXEL_SIZE)
    metrics = QtGui.QFontMetrics(font)
    available_width = (
        self.FOOTER_RECT.width()
        - metrics.horizontalAdvance(self.VERSION_TEXT)
        - self.FOOTER_GAP
    )
    painter.setFont(font)
    painter.setPen(self.SECONDARY_COLOR)
    painter.drawText(
        self.FOOTER_RECT,
        QtCore.Qt.AlignmentFlag.AlignLeft | QtCore.Qt.AlignmentFlag.AlignVCenter,
        metrics.elidedText(
            self.message(), QtCore.Qt.TextElideMode.ElideRight, available_width
        ),
    )
event(event)

Handle events without QSplashScreen.event.

QSplashScreen.event makes the show event block for a second on macOS, before the first message can be shown. Skipping it, the splash paints its pixmap and contents itself, and the rest is handled by QWidget.

Parameters:

Name Type Description Default
event QEvent

event.

required

Returns:

Type Description
bool

event was handled.

Source code in src/nyx/editor/widgets/startup_splash.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
def event(self, event: QtCore.QEvent) -> bool:
    """Handle events without `QSplashScreen.event`.

    `QSplashScreen.event` makes the show event block for a second on macOS,
    before the first message can be shown. Skipping it, the splash paints its
    pixmap and contents itself, and the rest is handled by `QWidget`.

    Args:
        event (QtCore.QEvent): event.

    Returns:
        bool: event was handled.
    """
    if event.type() != QtCore.QEvent.Type.Paint:
        return QtWidgets.QWidget.event(self, event)
    painter = QtGui.QPainter(self)
    painter.drawPixmap(0, 0, self.pixmap())
    self.drawContents(painter)
    return True
finish(main_window)

Close the splash once the main window is shown.

Parameters:

Name Type Description Default
main_window QWidget

window that replaces the splash.

required
Source code in src/nyx/editor/widgets/startup_splash.py
173
174
175
176
177
178
179
180
def finish(self, main_window: QtWidgets.QWidget) -> None:
    """Close the splash once the main window is shown.

    Args:
        main_window (QtWidgets.QWidget): window that replaces the splash.
    """
    self.disconnect_from_logger()
    super().finish(main_window)
show_log_message(message)

Show a message in the footer.

Parameters:

Name Type Description Default
message str

text to show.

required
Source code in src/nyx/editor/widgets/startup_splash.py
120
121
122
123
124
125
126
127
128
def show_log_message(self, message: str) -> None:
    """Show a message in the footer.

    Args:
        message (str): text to show.
    """
    self.showMessage(message.splitlines()[0] if message else "")
    # Startup blocks the event loop, the message is only painted when it spins.
    QtWidgets.QApplication.processEvents()