From 2fadf7f1e9f76eecc79cc2fce21a97d50f0de3c4 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:23:33 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Model=20:=20Ove?= =?UTF-8?q?rlay=20=E4=BB=BB=E6=84=8F=E3=81=AE=E3=83=86=E3=82=AD=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92Overlay=E3=81=A7=E8=A1=A8=E7=A4=BA=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=A8=E3=83=B3=E3=83=89=E3=83=9D=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/model.py | 13 +++++++++++++ src-python/models/overlay/overlay_image.py | 22 ++++++++++++++++++++++ src-python/webui_controller.py | 8 ++++++++ src-python/webui_mainloop.py | 2 ++ 4 files changed, 45 insertions(+) diff --git a/src-python/model.py b/src-python/model.py index fa22b622..8011aad7 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -689,6 +689,19 @@ class Model: } return self.overlay_image.createOverlayImageShort(message, your_language, translation, target_language, ui_type) + def createOverlayImage(self, message): + ui_language = config.UI_LANGUAGE + convert_languages = { + "en": "Japanese", + "jp": "Japanese", + "ko":"Korean", + "zh-Hans":"Chinese Simplified", + "zh-Hant":"Chinese Traditional", + } + language = convert_languages.get(ui_language, "Japanese") + ui_type = config.OVERLAY_UI_TYPE + return self.overlay_image.createOverlayImage(message, language, ui_type) + def clearOverlayImage(self): self.overlay.clearImage() diff --git a/src-python/models/overlay/overlay_image.py b/src-python/models/overlay/overlay_image.py index c3150f5e..23e24c93 100644 --- a/src-python/models/overlay/overlay_image.py +++ b/src-python/models/overlay/overlay_image.py @@ -225,6 +225,28 @@ class OverlayImage: draw = ImageDraw.Draw(background) draw.rounded_rectangle([(0, 0), img.size], radius=30, fill=background_color, outline=background_outline_color, width=5) + decoration_image = self.createDecorationImage(ui_type, img.size) + background = Image.alpha_composite(background, decoration_image) + img = Image.alpha_composite(background, img) + return img + + def createOverlayImage(self, message, your_language, ui_type="default"): + ui_size = self.getUiSize() + height = ui_size["height"] + width = ui_size["width"] + font_size = ui_size["font_size"] + + ui_colors = self.getUiColors(ui_type) + text_color = ui_colors["text_color"] + background_color = ui_colors["background_color"] + background_outline_color = ui_colors["background_outline_color"] + + img = self.createTextboxShort(message, your_language, text_color, width, height, font_size) + + background = Image.new("RGBA", img.size, (0, 0, 0, 0)) + draw = ImageDraw.Draw(background) + draw.rounded_rectangle([(0, 0), img.size], radius=30, fill=background_color, outline=background_outline_color, width=5) + decoration_image = self.createDecorationImage(ui_type, img.size) background = Image.alpha_composite(background, decoration_image) img = Image.alpha_composite(background, img) diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index 9664cbd4..4a13f81d 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -1392,6 +1392,14 @@ class Controller: model.oscStopSendTyping() return {"status":200, "result":True} + @staticmethod + def sendTextOverlaySmallLog(data, *args, **kwargs) -> dict: + if config.OVERLAY_SMALL_LOG is True: + if model.overlay.initialized is True: + overlay_image = model.createOverlayImage(data) + model.updateOverlay(overlay_image) + return {"status":200, "result":data} + def swapYourLanguageAndTargetLanguage(self, *args, **kwargs) -> dict: your_languages = config.SELECTED_YOUR_LANGUAGES your_language_primary = your_languages[config.SELECTED_TAB_NO]["primary"] diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index ab3f5b88..3b017876 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -82,6 +82,8 @@ mapping = { "/run/typing_message_box": {"status": False, "variable":controller.typingMessageBox}, "/run/stop_typing_message_box": {"status": False, "variable":controller.stopTypingMessageBox}, + "/run/send_text_overlay_small_log": {"status": True, "variable":controller.sendTextOverlaySmallLog}, + "/run/swap_your_language_and_target_language": {"status": True, "variable":controller.swapYourLanguageAndTargetLanguage}, "/run/update_software": {"status": True, "variable":controller.updateSoftware},