🐛[bugfix] Model : overlayのバグを修正

fontのバスを修正
翻訳の変数の型がstr -> listに変更になったため、修正
This commit is contained in:
misyaguziya
2024-11-16 02:41:23 +09:00
parent ea12cbc083
commit 59f544396c
3 changed files with 27 additions and 28 deletions

View File

@@ -92,7 +92,6 @@ class Overlay:
for i, size in enumerate(self.settings.keys()): for i, size in enumerate(self.settings.keys()):
self.handle[size] = self.overlay.createOverlay(f"VRCT{i}", f"VRCT{i}") self.handle[size] = self.overlay.createOverlay(f"VRCT{i}", f"VRCT{i}")
self.overlay.showOverlay(self.handle[size]) self.overlay.showOverlay(self.handle[size])
self.initialized = True
for size in self.settings.keys(): for size in self.settings.keys():
self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)), size) self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)), size)
@@ -109,6 +108,7 @@ class Overlay:
self.settings[size]["tracker"], self.settings[size]["tracker"],
size size
) )
self.initialized = True
except Exception as e: except Exception as e:
printLog("error:Could not initialise OpenVR", e) printLog("error:Could not initialise OpenVR", e)
@@ -248,6 +248,7 @@ class Overlay:
self.mainloop() self.mainloop()
def startOverlay(self): def startOverlay(self):
if self.checkSteamvrRunning() and self.initialized is False:
self.thread_overlay = Thread(target=self.main) self.thread_overlay = Thread(target=self.main)
self.thread_overlay.daemon = True self.thread_overlay.daemon = True
self.thread_overlay.start() self.thread_overlay.start()
@@ -315,6 +316,8 @@ if __name__ == "__main__":
overlay_image = OverlayImage() overlay_image = OverlayImage()
overlay = Overlay(settings_dict) overlay = Overlay(settings_dict)
overlay.startOverlay() overlay.startOverlay()
while overlay.initialized is False:
time.sleep(1) time.sleep(1)
# Example usage # Example usage

View File

@@ -51,10 +51,12 @@ class OverlayImage:
font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular") font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular")
img = Image.new("RGBA", (base_width, base_height), (0, 0, 0, 0)) img = Image.new("RGBA", (base_width, base_height), (0, 0, 0, 0))
draw = ImageDraw.Draw(img) draw = ImageDraw.Draw(img)
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
try: try:
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf")
font = ImageFont.truetype(font_path, font_size) font = ImageFont.truetype(font_path, font_size)
except Exception: except Exception:
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
font = ImageFont.truetype(font_path, font_size) font = ImageFont.truetype(font_path, font_size)
text_width = draw.textlength(text, font) text_width = draw.textlength(text, font)
@@ -126,10 +128,12 @@ class OverlayImage:
img = Image.new("RGBA", (0, 0), (0, 0, 0, 0)) img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
draw = ImageDraw.Draw(img) draw = ImageDraw.Draw(img)
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
try: try:
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf")
font = ImageFont.truetype(font_path, font_size) font = ImageFont.truetype(font_path, font_size)
except Exception: except Exception:
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
font = ImageFont.truetype(font_path, font_size) font = ImageFont.truetype(font_path, font_size)
text_width = draw.textlength(text, font) text_width = draw.textlength(text, font)
@@ -158,10 +162,12 @@ class OverlayImage:
img = Image.new("RGBA", (0, 0), (0, 0, 0, 0)) img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
draw = ImageDraw.Draw(img) draw = ImageDraw.Draw(img)
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", "NotoSansJP-Regular.ttf")
try: try:
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", "NotoSansJP-Regular.ttf")
font = ImageFont.truetype(font_path, font_size) font = ImageFont.truetype(font_path, font_size)
except Exception: except Exception:
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", "NotoSansJP-Regular.ttf")
font = ImageFont.truetype(font_path, font_size) font = ImageFont.truetype(font_path, font_size)
text_height = font_size + ui_padding text_height = font_size + ui_padding

View File

@@ -251,7 +251,7 @@ class Controller:
model.logger.info(f"[SENT] {message}{translation}") model.logger.info(f"[SENT] {message}{translation}")
if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True: if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True:
overlay_image = model.createOverlayImageLargeLog("send", message, translation) overlay_image = model.createOverlayImageLargeLog("send", message, translation[0] if len(translation) > 0 else "")
model.updateOverlayLargeLog(overlay_image) model.updateOverlayLargeLog(overlay_image)
def speakerMessage(self, message) -> None: def speakerMessage(self, message) -> None:
@@ -290,11 +290,11 @@ class Controller:
if config.ENABLE_TRANSCRIPTION_RECEIVE is True: if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
if config.OVERLAY_SMALL_LOG is True and model.overlay.initialized is True: if config.OVERLAY_SMALL_LOG is True and model.overlay.initialized is True:
overlay_image = model.createOverlayImageSmallLog(message, translation) overlay_image = model.createOverlayImageSmallLog(message, translation[0] if len(translation) > 0 else "")
model.updateOverlaySmallLog(overlay_image) model.updateOverlaySmallLog(overlay_image)
if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True: if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True:
overlay_image = model.createOverlayImageLargeLog("receive", message, translation) overlay_image = model.createOverlayImageLargeLog("receive", message, translation[0] if len(translation) > 0 else "")
model.updateOverlayLargeLog(overlay_image) model.updateOverlayLargeLog(overlay_image)
if config.SEND_RECEIVED_MESSAGE_TO_VRC is True: if config.SEND_RECEIVED_MESSAGE_TO_VRC is True:
@@ -361,7 +361,7 @@ class Controller:
model.oscSendMessage(osc_message) model.oscSendMessage(osc_message)
if config.OVERLAY_LARGE_LOG is True: if config.OVERLAY_LARGE_LOG is True:
overlay_image = model.createOverlayImageLargeLog("send", message, translation) overlay_image = model.createOverlayImageLargeLog("send", message, translation[0] if len(translation) > 0 else "")
model.updateOverlayLargeLog(overlay_image) model.updateOverlayLargeLog(overlay_image)
# update textbox message log (Sent) # update textbox message log (Sent)
@@ -1167,7 +1167,6 @@ class Controller:
@staticmethod @staticmethod
def setEnableOverlaySmallLog(*args, **kwargs) -> dict: def setEnableOverlaySmallLog(*args, **kwargs) -> dict:
config.OVERLAY_SMALL_LOG = True config.OVERLAY_SMALL_LOG = True
if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True:
model.startOverlay() model.startOverlay()
return {"status":200, "result":config.OVERLAY_SMALL_LOG} return {"status":200, "result":config.OVERLAY_SMALL_LOG}
@@ -1197,7 +1196,6 @@ class Controller:
@staticmethod @staticmethod
def setEnableOverlayLargeLog(*args, **kwargs) -> dict: def setEnableOverlayLargeLog(*args, **kwargs) -> dict:
config.OVERLAY_LARGE_LOG = True config.OVERLAY_LARGE_LOG = True
if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True:
model.startOverlay() model.startOverlay()
return {"status":200, "result":config.OVERLAY_LARGE_LOG} return {"status":200, "result":config.OVERLAY_LARGE_LOG}
@@ -1356,9 +1354,7 @@ class Controller:
def setEnableTranscriptionSend(self, *args, **kwargs) -> dict: def setEnableTranscriptionSend(self, *args, **kwargs) -> dict:
self.startThreadingTranscriptionSendMessage() self.startThreadingTranscriptionSendMessage()
config.ENABLE_TRANSCRIPTION_SEND = True config.ENABLE_TRANSCRIPTION_SEND = True
if (config.OVERLAY_LARGE_LOG is True and if config.OVERLAY_LARGE_LOG is True:
model.overlay.initialized is False and
model.overlay.checkSteamvrRunning() is True):
model.startOverlay() model.startOverlay()
return {"status":200, "result":config.ENABLE_TRANSCRIPTION_SEND} return {"status":200, "result":config.ENABLE_TRANSCRIPTION_SEND}
@@ -1369,13 +1365,7 @@ class Controller:
def setEnableTranscriptionReceive(self, *args, **kwargs) -> dict: def setEnableTranscriptionReceive(self, *args, **kwargs) -> dict:
self.startThreadingTranscriptionReceiveMessage() self.startThreadingTranscriptionReceiveMessage()
if (config.OVERLAY_SMALL_LOG is True and if (config.OVERLAY_SMALL_LOG is True or config.OVERLAY_LARGE_LOG is True):
model.overlay.initialized is False and
model.overlay.checkSteamvrRunning() is True):
model.startOverlay()
if (config.OVERLAY_LARGE_LOG is True and
model.overlay.initialized is False and
model.overlay.checkSteamvrRunning() is True):
model.startOverlay() model.startOverlay()
config.ENABLE_TRANSCRIPTION_RECEIVE = True config.ENABLE_TRANSCRIPTION_RECEIVE = True
return {"status":200, "result":config.ENABLE_TRANSCRIPTION_RECEIVE} return {"status":200, "result":config.ENABLE_TRANSCRIPTION_RECEIVE}