FIX: button state when stop/delete and video stream was enabled
This commit is contained in:
parent
c1484b58ce
commit
df5df4b497
|
@ -85,6 +85,7 @@ class Robot:
|
||||||
]
|
]
|
||||||
self.compose_files = compose_files
|
self.compose_files = compose_files
|
||||||
self.processes = []
|
self.processes = []
|
||||||
|
self.video_button = None
|
||||||
robots.add(self)
|
robots.add(self)
|
||||||
|
|
||||||
async def ui_containers(self, element):
|
async def ui_containers(self, element):
|
||||||
|
@ -142,7 +143,9 @@ class Robot:
|
||||||
ui.label(f"""Sysid: {self.sysid}""")
|
ui.label(f"""Sysid: {self.sysid}""")
|
||||||
ui.button("Start", on_click=self.start).classes("m-2")
|
ui.button("Start", on_click=self.start).classes("m-2")
|
||||||
ui.button("Stop", on_click=self.async_stop).classes("m-2")
|
ui.button("Stop", on_click=self.async_stop).classes("m-2")
|
||||||
EnableStreamingButton(sysid=self.sysid).classes("m-2")
|
self.video_button = EnableStreamingButton(sysid=self.sysid).classes(
|
||||||
|
"m-2"
|
||||||
|
)
|
||||||
|
|
||||||
async def delete_robot():
|
async def delete_robot():
|
||||||
await self.async_stop()
|
await self.async_stop()
|
||||||
|
@ -164,6 +167,10 @@ class Robot:
|
||||||
return await run.io_bound(self.stop)
|
return await run.io_bound(self.stop)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
# If video was enabled, and we stop. Button state is wrong.
|
||||||
|
# Stop video if it is enabled.
|
||||||
|
if isinstance(self.video_button, EnableStreamingButton):
|
||||||
|
self.video_button.stop_video()
|
||||||
# Delete gazebo model
|
# Delete gazebo model
|
||||||
self.delete_gz_model(sysid=self.sysid)
|
self.delete_gz_model(sysid=self.sysid)
|
||||||
# Signal all processes to stop
|
# Signal all processes to stop
|
||||||
|
|
|
@ -27,18 +27,25 @@ class EnableStreamingButton(ui.element):
|
||||||
result = await run.cpu_bound(self.enable_streaming, self.sysid, not self._state)
|
result = await run.cpu_bound(self.enable_streaming, self.sysid, not self._state)
|
||||||
if result:
|
if result:
|
||||||
ui.notify("Success", type="positive]")
|
ui.notify("Success", type="positive]")
|
||||||
self._state = not self._state
|
self.set_state(state=not self._state)
|
||||||
self.update()
|
|
||||||
else:
|
else:
|
||||||
self._state = False
|
self.set_state(state=False)
|
||||||
self.update()
|
|
||||||
ui.notify("No Video Streaming Available..", type="negative")
|
ui.notify("No Video Streaming Available..", type="negative")
|
||||||
spinner.delete()
|
spinner.delete()
|
||||||
|
|
||||||
|
def set_state(self, state: bool):
|
||||||
|
self._state = state
|
||||||
|
self.update()
|
||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
self.button._text = f'{"Disable" if self._state else "Enable"}' + " Video"
|
self.button._text = f'{"Disable" if self._state else "Enable"}' + " Video"
|
||||||
self.button.props(f'color={"red" if self._state else "green"}')
|
self.button.props(f'color={"red" if self._state else "green"}')
|
||||||
|
|
||||||
|
def stop_video(self):
|
||||||
|
if self._state != False:
|
||||||
|
self.enable_streaming(sysid=self.sysid, is_streaming=False)
|
||||||
|
self.set_state(state=False)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def enable_streaming(sysid: int, is_streaming: bool) -> bool:
|
def enable_streaming(sysid: int, is_streaming: bool) -> bool:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue