hydraveil-gui/gui/v2/infrastructure/navigator.py
2026-06-13 16:19:11 -04:00

33 lines
1.1 KiB
Python
Executable file

import importlib
from gui.v2.infrastructure.page_registry import PAGE_REGISTRY
class Navigator:
def __init__(self, page_stack, custom_window):
self.page_stack = page_stack
self.custom_window = custom_window
self._instances = {}
def navigate(self, name):
page = self._instances.get(name)
if page is None:
if name not in PAGE_REGISTRY:
self._warn_not_migrated(name)
return
module_path, class_name = PAGE_REGISTRY[name]
module = importlib.import_module(module_path)
cls = getattr(module, class_name)
page = cls(self.page_stack, self.custom_window)
self.page_stack.addWidget(page)
self._instances[name] = page
self.page_stack.setCurrentIndex(self.page_stack.indexOf(page))
def get_cached(self, name):
return self._instances.get(name)
def _warn_not_migrated(self, name):
try:
self.custom_window.update_status(f"Page '{name}' not migrated yet.")
except Exception:
pass