From 313682cbbdf3e2a88e36ccc3922db7da8e8799d4 Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Sat, 4 May 2024 17:25:39 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20[WIP/TEST]=20Model=20:=20Overlay?= =?UTF-8?q?=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E8=B5=B7=E5=8B=95=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=82=89=E3=81=97=E3=81=A3=E3=81=B1=E3=81=AA=E3=81=97?= =?UTF-8?q?=E3=81=AB=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller.py | 10 ++++----- models/overlay/overlay_2.py | 43 ++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/controller.py b/controller.py index 48eb42db..fb505fdc 100644 --- a/controller.py +++ b/controller.py @@ -427,12 +427,11 @@ def callbackToggleTranscriptionReceive(is_turned_on): view.changeTranscriptionDisplayStatus("SPEAKER_OFF") if config.ENABLE_TRANSCRIPTION_RECEIVE is True and config.ENABLE_OVERLAY_SMALL_LOG is True: - if model.overlay.initialized is False: + if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: model.startOverlay() print("model.startOverlay()") elif config.ENABLE_TRANSCRIPTION_RECEIVE is False: - model.shutdownOverlay() - print("model.shutdownOverlay()") + pass def callbackToggleForeground(is_turned_on): config.ENABLE_FOREGROUND = is_turned_on @@ -882,12 +881,11 @@ def callbackSetEnableOverlaySmallLog(value): config.ENABLE_OVERLAY_SMALL_LOG = value if config.ENABLE_OVERLAY_SMALL_LOG is True and config.ENABLE_TRANSCRIPTION_RECEIVE is True: - if model.overlay.initialized is False: + if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: model.startOverlay() print("model.startOverlay()") elif config.ENABLE_OVERLAY_SMALL_LOG is False: - model.shutdownOverlay() - print("model.shutdownOverlay()") + pass def callbackSetOverlaySmallLogSettings(value, set_type:str): print("callbackSetOverlaySmallLogSettings", value, set_type) diff --git a/models/overlay/overlay_2.py b/models/overlay/overlay_2.py index 9ea8e532..929be276 100644 --- a/models/overlay/overlay_2.py +++ b/models/overlay/overlay_2.py @@ -1,5 +1,6 @@ +import os import ctypes -import psutil +from psutil import process_iter # from os import path as os_path import ctypes import time @@ -8,12 +9,6 @@ from PIL import Image # from queue import Queue from threading import Thread -def checkSteamvrRunning() -> bool: - for proc in psutil.process_iter(): - if "vrserver.exe" == proc.name().lower(): - return True - return False - def mat34Id(): arr = openvr.HmdMatrix34_t() arr[0][0] = 1 @@ -44,22 +39,21 @@ class Overlay: def init(self): try: - if checkSteamvrRunning() is True: - self.system = openvr.init(openvr.VRApplication_Background) - self.overlay = openvr.IVROverlay() - self.handle = self.overlay.createOverlay("Overlay_Speaker2log", "SOverlay_Speaker2log_UI") + self.system = openvr.init(openvr.VRApplication_Background) + self.overlay = openvr.IVROverlay() + self.handle = self.overlay.createOverlay("Overlay_Speaker2log", "SOverlay_Speaker2log_UI") - self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0))) - self.setColor(self.settings['Color']) - self.updateColor() - self.setTransparency(self.settings['Transparency']) - self.updateTransparency() - self.setUiScaling(self.settings['Ui_scaling']) - self.updateUiScaling() - self.setPosition((self.settings["Normalized_icon_X_position"], self.settings["Normalized_icon_Y_position"])) - self.updatePosition() - self.overlay.showOverlay(self.handle) - self.initialized = True + self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0))) + self.setColor(self.settings['Color']) + self.updateColor() + self.setTransparency(self.settings['Transparency']) + self.updateTransparency() + self.setUiScaling(self.settings['Ui_scaling']) + self.updateUiScaling() + self.setPosition((self.settings["Normalized_icon_X_position"], self.settings["Normalized_icon_Y_position"])) + self.updatePosition() + self.overlay.showOverlay(self.handle) + self.initialized = True except Exception as e: print("Could not initialise OpenVR", e) @@ -195,6 +189,11 @@ class Overlay: self.system = None self.initialized = False + @staticmethod + def checkSteamvrRunning() -> bool: + _proc_name = "vrmonitor.exe" if os.name == 'nt' else "vrmonitor" + return _proc_name in (p.name() for p in process_iter()) + if __name__ == '__main__': from overlay_image import OverlayImage overlay_image = OverlayImage()