Merge branch 'overlay' into develop

This commit is contained in:
misyaguziya
2024-04-27 05:50:27 +09:00
3 changed files with 31 additions and 12 deletions

View File

@@ -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:

View File

@@ -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"])

View File

@@ -7,7 +7,7 @@ from PIL import Image
def checkSteamvrRunning():
for proc in psutil.process_iter():
if "vrserver" in proc.name().lower() or "vrcompositor" in proc.name().lower():
if "vrserver.exe" == proc.name().lower():
return True
return False
@@ -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