From dcdcf1aeea8a9bc6114be53472935214e71a7a49 Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Sat, 27 Apr 2024 05:45:45 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Model=20:=20=20?= =?UTF-8?q?steamVR=E3=81=8C=E8=B5=B7=E5=8B=95=E3=81=97=E3=81=A6=E3=82=8B?= =?UTF-8?q?=E6=9C=80=E4=B8=AD=E3=81=AE=E3=81=BFoverlay=E3=81=8C=E5=8B=95?= =?UTF-8?q?=E4=BD=9C=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller.py | 2 +- model.py | 9 +++------ models/overlay/overlay.py | 30 ++++++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/controller.py b/controller.py index 67d492ff..cdefcc1b 100644 --- a/controller.py +++ b/controller.py @@ -161,7 +161,7 @@ def receiveSpeakerMessage(message): xsoverlay_message = messageFormatter("RECEIVED", translation, message) model.notificationXSOverlay(xsoverlay_message) - if model.th_overlay is None: + if model.overlay.initialized is False: model.startOverlay() if config.ENABLE_OVERLAY_SMALL_LOG is True: diff --git a/model.py b/model.py index e41f4a04..eda9cb46 100644 --- a/model.py +++ b/model.py @@ -608,17 +608,14 @@ class Model: def startOverlay(self): if self.overlay.initialized is False: + print("self.overlay.init()") self.overlay.init() + if self.overlay.initialized is True: - self.th_overlay = threadFnc(self.overlay.startOverlay) + self.th_overlay = Thread(target=self.overlay.startOverlay) self.th_overlay.daemon = True self.th_overlay.start() - def stopOverlay(self): - if isinstance(self.th_overlay, threadFnc): - self.th_overlay.stop() - self.th_overlay = None - def updateOverlayPosition(self): if self.overlay.initialized is True: pos = (config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"], config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"]) diff --git a/models/overlay/overlay.py b/models/overlay/overlay.py index 232a0ffd..e8cb9e0e 100644 --- a/models/overlay/overlay.py +++ b/models/overlay/overlay.py @@ -156,17 +156,19 @@ class Overlay: "Ui_scaling": ui_scaling, } self.settings = settings + self.system = None def init(self): try: if checkSteamvrRunning() is True: - openvr.init(openvr.VRApplication_Overlay) + self.system = openvr.init(openvr.VRApplication_Background) self.initialized = True except Exception as e: print("Could not initialise OpenVR") + print(e) async def mainLoop(self): - while True: + while self.checkActive() is True: startTime = time.monotonic() self.uiManager.update() @@ -175,12 +177,32 @@ class Overlay: await asyncio.sleep(sleepTime) async def initMain(self): - self.uiManager = UIManager("Overlay_Speaker2log", "SOverlay_Speaker2log_UI", self.settings) - await self.mainLoop() + if self.initialized is True: + self.uiManager = UIManager("Overlay_Speaker2log", "SOverlay_Speaker2log_UI", self.settings) + await self.mainLoop() def startOverlay(self): asyncio.run(self.initMain()) + def shutdown(self): + self.system = None + self.initialized = False + openvr.shutdown() + + def checkActive(self): + try: + if self.system is not None and self.initialized is True: + new_event = openvr.VREvent_t() + while self.system.pollNextEvent(new_event): + if new_event.eventType == openvr.VREvent_Quit: + self.shutdown() + return False + return True + except Exception as e: + print("Could not check SteamVR running") + print(e) + return False + if __name__ == '__main__': from overlay_image import OverlayImage from threading import Thread, Event