Files

41 lines
1.5 KiB
Python

from textual.screen import Screen
from textual.containers import Vertical
from textual.widgets import Static, LoadingIndicator, DataTable
from textual import work
from ui.screens.main_screen import MainScreen
from textualeffects.widgets import EffectLabel
from api.node import MeshNode
class PairScreen(Screen):
CSS_PATH = "../assets/pair_screen.tcss"
@work
async def connect_to_node(self, is_retry = False):
if not is_retry:
self.notify("This may take a moment...", title="Discovering nearby nodes...")
self.app.mesh_node = await MeshNode.discover(self.app)
if self.app.mesh_node == None:
self.notify("Check your node is powered on and nearby.\nRetrying...", title="Failed to find a nearby node!", severity="warning")
return self.connect_to_node(True)
self.notify("Hurray! You're on the mesh!", title="Node connected!")
self.app.switch_screen(MainScreen())
async def on_compose(self):
self.connect_to_node()
def compose(self):
with Vertical(id="middle") as center_window:
center_window.border_title = "Pair a Node"
with open("ui/assets/banner.txt", "r") as f:
yield EffectLabel(f.read(), effect="Print")
yield Static("Attempting to connect to a nearby node. Make sure your mesh network node is powered and ready to pair.")
yield LoadingIndicator()