Move GUI toolkit from tkinter to nicegui for easier prototyping #7
|
@ -66,22 +66,10 @@ class Robot:
|
|||
self.processes = []
|
||||
robots.add(self)
|
||||
|
||||
async def ui(self, element):
|
||||
adocker = aiodocker.Docker()
|
||||
with element:
|
||||
robot_ui = ui.element().classes("w-full outline p-4")
|
||||
with robot_ui:
|
||||
ui.label(f"{self.robot_type}")
|
||||
ui.label(f"""Sysid: {self.sysid}""")
|
||||
ui.button("Start", on_click=self.start).classes("m-2")
|
||||
ui.button("Stop", on_click=self.async_stop).classes("m-2")
|
||||
async def delete_robot():
|
||||
await self.async_stop()
|
||||
robots.remove(self)
|
||||
element.remove(robot_ui)
|
||||
ui.button("Delete", on_click=delete_robot).classes("m-2")
|
||||
async def ui_containers(self, element):
|
||||
docker_elements = {}
|
||||
container_status = {}
|
||||
with element:
|
||||
while True:
|
||||
#Poll for data that changes
|
||||
for container in self.containers():
|
||||
|
@ -92,7 +80,7 @@ class Robot:
|
|||
|
||||
container_status[container] = f"{container.name} {container.status} {health}"
|
||||
if container not in docker_elements:
|
||||
docker_elements[container] = ui.element()
|
||||
docker_elements[container] = ui.element().classes("w-full")
|
||||
with docker_elements[container]:
|
||||
ui.label().bind_text(container_status, container)
|
||||
logelement = ui.expansion("Logs").style('margin: 10px;').classes('w-full')
|
||||
|
@ -100,10 +88,31 @@ class Robot:
|
|||
#Check for containers that have been removed
|
||||
removed = set(docker_elements.keys()) - set(self.containers())
|
||||
for container in removed:
|
||||
robot_ui.remove(docker_elements[container])
|
||||
self.robot_ui.remove(docker_elements[container])
|
||||
docker_elements.pop(container)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
async def ui(self, element):
|
||||
adocker = aiodocker.Docker()
|
||||
|
||||
with element:
|
||||
self.robot_ui = ui.element().classes("w-full outline p-4")
|
||||
with self.robot_ui:
|
||||
ui.label(f"{self.robot_type}")
|
||||
ui.label(f"""Sysid: {self.sysid}""")
|
||||
ui.button("Start", on_click=self.start).classes("m-2")
|
||||
ui.button("Stop", on_click=self.async_stop).classes("m-2")
|
||||
async def delete_robot():
|
||||
await self.async_stop()
|
||||
robots.remove(self)
|
||||
element.remove(robot_ui)
|
||||
ui.button("Delete", on_click=delete_robot).classes("m-2")
|
||||
with ui.tabs() as tabs:
|
||||
tab_containers = ui.tab('Containers')
|
||||
with ui.tab_panels(tabs, value=tab_containers):
|
||||
tab = ui.tab_panel(tab_containers).classes("w-full")
|
||||
asyncio.create_task(self.ui_containers(tab))
|
||||
|
||||
async def async_stop(self):
|
||||
return await run.io_bound(self.stop)
|
||||
|
||||
|
|
Loading…
Reference in New Issue