File: Stage.py

package info (click to toggle)
uranium 5.0.0-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,328 kB
  • sloc: python: 31,765; sh: 132; makefile: 12
file content (43 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Copyright (c) 2022 Ultimaker B.V.
# Uranium is released under the terms of the LGPLv3 or higher.

from typing import Union, Dict, Optional

from PyQt6.QtCore import QObject, QUrl

from UM.PluginObject import PluginObject


class Stage(QObject, PluginObject):
    """Stages handle combined views in an Uranium application.

    The active stage decides which QML component to show where.
    Uranium has no notion of specific view locations as that's application specific.
    """

    def __init__(self, parent: Optional[QObject] = None) -> None:
        super().__init__(parent)
        self._components: Dict[str, QUrl] = {}
        self._icon_source: QUrl = QUrl()

    def onStageSelected(self) -> None:
        """Something to do when this Stage is selected"""
        pass

    def onStageDeselected(self) -> None:
        """Something to do when this Stage is deselected"""
        pass

    def addDisplayComponent(self, name: str, source: Union[str, QUrl]) -> None:
        """Add a QML component to the stage"""

        if type(source) == str:
            source = QUrl.fromLocalFile(source)
        self._components[name] = source

    def getDisplayComponent(self, name: str) -> QUrl:
        """Get a QUrl by name."""

        if name in self._components:
            return self._components[name]
        return QUrl()