🚧 [WIP/TEST] Model : Overlayの処理を最小限までに削除

This commit is contained in:
misyaguziya
2024-05-03 23:05:42 +09:00
parent 6f318a8b05
commit 0577756dc1
4 changed files with 40 additions and 34 deletions

View File

@@ -162,11 +162,8 @@ def receiveSpeakerMessage(message):
model.notificationXSOverlay(xsoverlay_message)
if config.ENABLE_OVERLAY_SMALL_LOG is True:
if model.overlay.initialized is False:
model.startOverlay()
print("model.startOverlay()")
# overlay_image = model.createOverlayImageShort(message, translation)
model.updateOverlay(1)
overlay_image = model.createOverlayImageShort(message, translation)
model.updateOverlay(overlay_image)
print("model.updateOverlay(overlay_image)")
# overlay_image = model.createOverlayImageLong("receive", message, translation)
# model.updateOverlay(overlay_image)
@@ -192,7 +189,6 @@ def startTranscriptionReceiveMessage():
def stopTranscriptionReceiveMessage():
model.stopSpeakerTranscript()
model.shutdownOverlay()
view.setMainWindowAllWidgetsStatusToNormal()
def startThreadingTranscriptionReceiveMessage():
@@ -429,6 +425,14 @@ def callbackToggleTranscriptionReceive(is_turned_on):
stopThreadingTranscriptionReceiveMessage()
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:
model.startOverlay()
print("model.startOverlay()")
elif config.ENABLE_TRANSCRIPTION_RECEIVE is False:
model.shutdownOverlay()
print("model.shutdownOverlay()")
def callbackToggleForeground(is_turned_on):
config.ENABLE_FOREGROUND = is_turned_on
if config.ENABLE_FOREGROUND is True:
@@ -876,8 +880,13 @@ def callbackSetEnableOverlaySmallLog(value):
print("callbackSetEnableOverlaySmallLog", value)
config.ENABLE_OVERLAY_SMALL_LOG = value
if config.ENABLE_OVERLAY_SMALL_LOG is False:
model.clearOverlayImage()
if config.ENABLE_OVERLAY_SMALL_LOG is True and config.ENABLE_TRANSCRIPTION_RECEIVE is True:
if model.overlay.initialized is False:
model.startOverlay()
print("model.startOverlay()")
elif config.ENABLE_OVERLAY_SMALL_LOG is False:
model.shutdownOverlay()
print("model.shutdownOverlay()")
def callbackSetOverlaySmallLogSettings(value, set_type:str):
print("callbackSetOverlaySmallLogSettings", value, set_type)

View File

@@ -606,7 +606,7 @@ class Model:
self.overlay.clearImage()
def updateOverlay(self, img):
self.overlay.setImage(img)
self.overlay.updateImage(img)
def startOverlay(self):
self.overlay.startOverlay()

View File

@@ -1,11 +1,11 @@
import ctypes
import psutil
from os import path as os_path
# from os import path as os_path
import ctypes
import time
import openvr
from PIL import Image
from queue import Queue
# from queue import Queue
from threading import Thread
def checkSteamvrRunning() -> bool:
@@ -38,7 +38,7 @@ class Overlay:
self.system = None
self.overlay = None
self.handle = None
self.image_queue = Queue()
# self.image_queue = Queue()
self.lastUpdate = time.monotonic()
self.thread_overlay = None
@@ -49,8 +49,7 @@ class Overlay:
self.overlay = openvr.IVROverlay()
self.handle = self.overlay.createOverlay("Overlay_Speaker2log", "SOverlay_Speaker2log_UI")
self.setImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)))
self.updateImage()
self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)))
self.setColor(self.settings['Color'])
self.updateColor()
self.setTransparency(self.settings['Transparency'])
@@ -64,21 +63,23 @@ class Overlay:
except Exception as e:
print("Could not initialise OpenVR", e)
def setImage(self, img):
self.image_queue.put(img)
# def setImage(self, img):
# self.image_queue.put(img)
def updateImage(self):
_ = self.image_queue.get()
img = Image.open(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "img", "test_chatbox.png"))
def updateImage(self, img):
# _ = self.image_queue.get()
# img = Image.open(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "img", "test_chatbox.png"))
width, height = img.size
img = img.tobytes()
img = (ctypes.c_char * len(img)).from_buffer_copy(img)
self.overlay.setOverlayRaw(self.handle, img, width, height, 4)
self.updateTransparency()
self.lastUpdate = time.monotonic()
def clearImage(self):
while self.image_queue.empty() is False:
self.image_queue.get()
self.setImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)))
# while self.image_queue.empty() is False:
# self.image_queue.get()
self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)))
def setColor(self, col):
"""
@@ -154,13 +155,8 @@ class Overlay:
self.overlay.setOverlayAlpha(self.handle, self.fadeRatio * self.settings['Transparency'])
def update(self):
if self.image_queue.empty() is False:
self.updateImage()
self.updateTransparency()
self.lastUpdate = time.monotonic()
self.updateUiScaling()
self.updatePosition()
# self.updateUiScaling()
# self.updatePosition()
currTime = time.monotonic()
if self.settings['Fade_interval'] != 0:
@@ -175,6 +171,7 @@ class Overlay:
sleepTime = (1 / 16) - (time.monotonic() - startTime)
if sleepTime > 0:
time.sleep(sleepTime)
self.shutdown()
def main(self):
self.init()
@@ -210,11 +207,11 @@ if __name__ == '__main__':
# Example usage
img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese", ui_type="sakura")
overlay.setImage(img)
overlay.updateImage(img)
time.sleep(0.5)
img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese")
overlay.setImage(img)
overlay.updateImage(img)
time.sleep(0.5)
overlay.shutdown()

View File

@@ -140,9 +140,9 @@ class OverlayImage:
def getUiSize(self):
return {
"width": int(960*4),
"height": int(23*4),
"font_size": int(23*4),
"width": int(960),
"height": int(23),
"font_size": int(23),
}
def getUiColors(self, ui_type):