2024-01-17 12:11:49 +00:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
import gi
|
|
|
|
|
|
|
|
gi.require_version("Gtk", "4.0")
|
|
|
|
gi.require_version("Adw", "1")
|
|
|
|
from gi.repository import Adw
|
|
|
|
|
|
|
|
|
2024-03-03 09:51:34 +00:00
|
|
|
class ViewStack:
|
2024-01-17 12:11:49 +00:00
|
|
|
"""
|
|
|
|
This is a singleton.
|
|
|
|
It is initialized with the first call of use()
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
2024-03-03 09:51:34 +00:00
|
|
|
ViewStack.use().set_visible()
|
2024-01-17 12:11:49 +00:00
|
|
|
|
2024-03-03 09:51:34 +00:00
|
|
|
ViewStack.use() can also be called before the data is needed. e.g. to eliminate/reduce waiting time.
|
2024-01-17 12:11:49 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
2024-03-03 09:51:34 +00:00
|
|
|
_instance: "None | ViewStack" = None
|
2024-01-17 12:11:49 +00:00
|
|
|
view: Adw.ViewStack
|
|
|
|
|
|
|
|
# Make sure the VMS class is used as a singleton
|
|
|
|
def __init__(self) -> None:
|
|
|
|
raise RuntimeError("Call use() instead")
|
|
|
|
|
|
|
|
@classmethod
|
2024-03-03 09:51:34 +00:00
|
|
|
def use(cls: Any) -> "ViewStack":
|
2024-01-17 12:11:49 +00:00
|
|
|
if cls._instance is None:
|
|
|
|
cls._instance = cls.__new__(cls)
|
|
|
|
cls.view = Adw.ViewStack()
|
|
|
|
|
|
|
|
return cls._instance
|