Merge branch 'controller' into for_webui

This commit is contained in:
misyaguziya
2024-10-29 15:29:37 +09:00
4 changed files with 45 additions and 0 deletions

View File

@@ -693,6 +693,19 @@ class Model:
} }
return self.overlay_image.createOverlayImageShort(message, your_language, translation, target_language, ui_type) 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): def clearOverlayImage(self):
self.overlay.clearImage() self.overlay.clearImage()

View File

@@ -229,3 +229,25 @@ class OverlayImage:
background = Image.alpha_composite(background, decoration_image) background = Image.alpha_composite(background, decoration_image)
img = Image.alpha_composite(background, img) img = Image.alpha_composite(background, img)
return 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)
return img

View File

@@ -1435,6 +1435,14 @@ class Controller:
model.oscStopSendTyping() model.oscStopSendTyping()
return {"status":200, "result":True} 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: def swapYourLanguageAndTargetLanguage(self, *args, **kwargs) -> dict:
your_languages = config.SELECTED_YOUR_LANGUAGES your_languages = config.SELECTED_YOUR_LANGUAGES
your_language_primary = your_languages[config.SELECTED_TAB_NO]["primary"] your_language_primary = your_languages[config.SELECTED_TAB_NO]["primary"]

View File

@@ -84,6 +84,8 @@ mapping = {
"/run/typing_message_box": {"status": False, "variable":controller.typingMessageBox}, "/run/typing_message_box": {"status": False, "variable":controller.typingMessageBox},
"/run/stop_typing_message_box": {"status": False, "variable":controller.stopTypingMessageBox}, "/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/swap_your_language_and_target_language": {"status": True, "variable":controller.swapYourLanguageAndTargetLanguage},
"/run/update_software": {"status": True, "variable":controller.updateSoftware}, "/run/update_software": {"status": True, "variable":controller.updateSoftware},