Merge branch 'overlay' into for_webui
This commit is contained in:
@@ -738,19 +738,6 @@ class Config:
|
|||||||
self._SEND_MESSAGE_BUTTON_TYPE = value
|
self._SEND_MESSAGE_BUTTON_TYPE = value
|
||||||
self.saveConfig(inspect.currentframe().f_code.co_name, value)
|
self.saveConfig(inspect.currentframe().f_code.co_name, value)
|
||||||
|
|
||||||
@property
|
|
||||||
@json_serializable('OVERLAY_SETTINGS')
|
|
||||||
def OVERLAY_SETTINGS(self):
|
|
||||||
return self._OVERLAY_SETTINGS
|
|
||||||
|
|
||||||
@OVERLAY_SETTINGS.setter
|
|
||||||
def OVERLAY_SETTINGS(self, value):
|
|
||||||
if isinstance(value, dict) and set(value.keys()) == set(self.OVERLAY_SETTINGS.keys()):
|
|
||||||
for key, value in value.items():
|
|
||||||
if isinstance(value, (int, float)):
|
|
||||||
self._OVERLAY_SETTINGS[key] = float(value)
|
|
||||||
self.saveConfig(inspect.currentframe().f_code.co_name, self.OVERLAY_SETTINGS)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@json_serializable('OVERLAY_SMALL_LOG')
|
@json_serializable('OVERLAY_SMALL_LOG')
|
||||||
def OVERLAY_SMALL_LOG(self):
|
def OVERLAY_SMALL_LOG(self):
|
||||||
@@ -778,18 +765,46 @@ class Config:
|
|||||||
case "display_duration" | "fadeout_duration":
|
case "display_duration" | "fadeout_duration":
|
||||||
if isinstance(value, int):
|
if isinstance(value, int):
|
||||||
self._OVERLAY_SMALL_LOG_SETTINGS[key] = value
|
self._OVERLAY_SMALL_LOG_SETTINGS[key] = value
|
||||||
|
case "opacity" | "ui_scaling":
|
||||||
|
if isinstance(value, (int, float)):
|
||||||
|
self._OVERLAY_SMALL_LOG_SETTINGS[key] = float(value)
|
||||||
self.saveConfig(inspect.currentframe().f_code.co_name, self.OVERLAY_SMALL_LOG_SETTINGS)
|
self.saveConfig(inspect.currentframe().f_code.co_name, self.OVERLAY_SMALL_LOG_SETTINGS)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@json_serializable('OVERLAY_UI_TYPE')
|
@json_serializable('OVERLAY_LARGE_LOG')
|
||||||
def OVERLAY_UI_TYPE(self):
|
def OVERLAY_LARGE_LOG(self):
|
||||||
return self._OVERLAY_UI_TYPE
|
return self._OVERLAY_LARGE_LOG
|
||||||
|
|
||||||
@OVERLAY_UI_TYPE.setter
|
@OVERLAY_LARGE_LOG.setter
|
||||||
def OVERLAY_UI_TYPE(self, value):
|
def OVERLAY_LARGE_LOG(self, value):
|
||||||
|
if isinstance(value, bool):
|
||||||
|
self._OVERLAY_LARGE_LOG = value
|
||||||
|
self.saveConfig(inspect.currentframe().f_code.co_name, value)
|
||||||
|
|
||||||
|
@property
|
||||||
|
@json_serializable('OVERLAY_LARGE_LOG_SETTINGS')
|
||||||
|
def OVERLAY_LARGE_LOG_SETTINGS(self):
|
||||||
|
return self._OVERLAY_LARGE_LOG_SETTINGS
|
||||||
|
|
||||||
|
@OVERLAY_LARGE_LOG_SETTINGS.setter
|
||||||
|
def OVERLAY_LARGE_LOG_SETTINGS(self, value):
|
||||||
|
if isinstance(value, dict) and set(value.keys()) == set(self.OVERLAY_LARGE_LOG_SETTINGS.keys()):
|
||||||
|
for key, value in value.items():
|
||||||
|
match (key):
|
||||||
|
case "tracker":
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
self._OVERLAY_UI_TYPE = value
|
# "HMD", "LeftHand", "RightHand"
|
||||||
# self.saveConfig(inspect.currentframe().f_code.co_name, value)
|
self._OVERLAY_LARGE_LOG_SETTINGS[key] = value
|
||||||
|
case "x_pos" | "y_pos" | "z_pos" | "x_rotation" | "y_rotation" | "z_rotation":
|
||||||
|
if isinstance(value, (int, float)):
|
||||||
|
self._OVERLAY_LARGE_LOG_SETTINGS[key] = float(value)
|
||||||
|
case "display_duration" | "fadeout_duration":
|
||||||
|
if isinstance(value, int):
|
||||||
|
self._OVERLAY_LARGE_LOG_SETTINGS[key] = value
|
||||||
|
case "opacity" | "ui_scaling":
|
||||||
|
if isinstance(value, (int, float)):
|
||||||
|
self._OVERLAY_LARGE_LOG_SETTINGS[key] = float(value)
|
||||||
|
self.saveConfig(inspect.currentframe().f_code.co_name, self.OVERLAY_LARGE_LOG_SETTINGS)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@json_serializable('SEND_MESSAGE_TO_VRC')
|
@json_serializable('SEND_MESSAGE_TO_VRC')
|
||||||
@@ -1063,10 +1078,6 @@ class Config:
|
|||||||
self._AUTO_CLEAR_MESSAGE_BOX = True
|
self._AUTO_CLEAR_MESSAGE_BOX = True
|
||||||
self._SEND_ONLY_TRANSLATED_MESSAGES = False
|
self._SEND_ONLY_TRANSLATED_MESSAGES = False
|
||||||
self._SEND_MESSAGE_BUTTON_TYPE = "show"
|
self._SEND_MESSAGE_BUTTON_TYPE = "show"
|
||||||
self._OVERLAY_SETTINGS = {
|
|
||||||
"opacity": 1.0,
|
|
||||||
"ui_scaling": 1.0,
|
|
||||||
}
|
|
||||||
self._OVERLAY_SMALL_LOG = False
|
self._OVERLAY_SMALL_LOG = False
|
||||||
self._OVERLAY_SMALL_LOG_SETTINGS = {
|
self._OVERLAY_SMALL_LOG_SETTINGS = {
|
||||||
"x_pos": 0.0,
|
"x_pos": 0.0,
|
||||||
@@ -1077,8 +1088,24 @@ class Config:
|
|||||||
"z_rotation": 0.0,
|
"z_rotation": 0.0,
|
||||||
"display_duration": 5,
|
"display_duration": 5,
|
||||||
"fadeout_duration": 2,
|
"fadeout_duration": 2,
|
||||||
|
"opacity": 1.0,
|
||||||
|
"ui_scaling": 1.0,
|
||||||
|
"tracker": "HMD",
|
||||||
|
}
|
||||||
|
self._OVERLAY_LARGE_LOG = False
|
||||||
|
self._OVERLAY_LARGE_LOG_SETTINGS = {
|
||||||
|
"x_pos": 0.0,
|
||||||
|
"y_pos": 0.0,
|
||||||
|
"z_pos": 0.0,
|
||||||
|
"x_rotation": 0.0,
|
||||||
|
"y_rotation": 0.0,
|
||||||
|
"z_rotation": 0.0,
|
||||||
|
"display_duration": 5,
|
||||||
|
"fadeout_duration": 2,
|
||||||
|
"opacity": 1.0,
|
||||||
|
"ui_scaling": 0.5,
|
||||||
|
"tracker": "LeftHand",
|
||||||
}
|
}
|
||||||
self._OVERLAY_UI_TYPE = "default"
|
|
||||||
self._SEND_MESSAGE_TO_VRC = True
|
self._SEND_MESSAGE_TO_VRC = True
|
||||||
self._SEND_RECEIVED_MESSAGE_TO_VRC = False
|
self._SEND_RECEIVED_MESSAGE_TO_VRC = False
|
||||||
self._LOGGER_FEATURE = False
|
self._LOGGER_FEATURE = False
|
||||||
|
|||||||
@@ -81,20 +81,14 @@ class Model:
|
|||||||
self.translator = Translator()
|
self.translator = Translator()
|
||||||
self.keyword_processor = KeywordProcessor()
|
self.keyword_processor = KeywordProcessor()
|
||||||
self.overlay = Overlay(
|
self.overlay = Overlay(
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"],
|
{
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"],
|
"small": config.OVERLAY_SMALL_LOG_SETTINGS,
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS["z_pos"],
|
"large": config.OVERLAY_LARGE_LOG_SETTINGS,
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS["x_rotation"],
|
}
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS["y_rotation"],
|
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS["z_rotation"],
|
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS["display_duration"],
|
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS["fadeout_duration"],
|
|
||||||
config.OVERLAY_SETTINGS["opacity"],
|
|
||||||
config.OVERLAY_SETTINGS["ui_scaling"],
|
|
||||||
)
|
)
|
||||||
|
self.overlay_small_log_pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS
|
||||||
|
self.overlay_large_log_pre_settings = config.OVERLAY_LARGE_LOG_SETTINGS
|
||||||
self.overlay_image = OverlayImage()
|
self.overlay_image = OverlayImage()
|
||||||
self.pre_overlay_message = None
|
|
||||||
self.th_overlay = None
|
|
||||||
self.mic_audio_queue = None
|
self.mic_audio_queue = None
|
||||||
self.mic_mute_status = None
|
self.mic_mute_status = None
|
||||||
self.kks = kakasi()
|
self.kks = kakasi()
|
||||||
@@ -683,20 +677,12 @@ class Model:
|
|||||||
self.speaker_energy_recorder.stop()
|
self.speaker_energy_recorder.stop()
|
||||||
self.speaker_energy_recorder = None
|
self.speaker_energy_recorder = None
|
||||||
|
|
||||||
def createOverlayImageShort(self, message, translation):
|
def createOverlayImageSmallLog(self, message, translation):
|
||||||
your_language = config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["primary"]["language"]
|
your_language = config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["primary"]["language"]
|
||||||
target_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["primary"]["language"]
|
target_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["primary"]["language"]
|
||||||
ui_type = config.OVERLAY_UI_TYPE
|
return self.overlay_image.createOverlayImageSmallLog(message, your_language, translation, target_language)
|
||||||
self.pre_overlay_message = {
|
|
||||||
"message" : message,
|
|
||||||
"your_language" : your_language,
|
|
||||||
"translation" : translation,
|
|
||||||
"target_language" : target_language,
|
|
||||||
"ui_type" : ui_type,
|
|
||||||
}
|
|
||||||
return self.overlay_image.createOverlayImageShort(message, your_language, translation, target_language, ui_type)
|
|
||||||
|
|
||||||
def createOverlayImage(self, message):
|
def createOverlayImageSystemMessage(self, message):
|
||||||
ui_language = config.UI_LANGUAGE
|
ui_language = config.UI_LANGUAGE
|
||||||
convert_languages = {
|
convert_languages = {
|
||||||
"en": "Japanese",
|
"en": "Japanese",
|
||||||
@@ -706,19 +692,19 @@ class Model:
|
|||||||
"zh-Hant":"Chinese Traditional",
|
"zh-Hant":"Chinese Traditional",
|
||||||
}
|
}
|
||||||
language = convert_languages.get(ui_language, "Japanese")
|
language = convert_languages.get(ui_language, "Japanese")
|
||||||
ui_type = config.OVERLAY_UI_TYPE
|
return self.overlay_image.createOverlayImageSmallLog(message, language)
|
||||||
return self.overlay_image.createOverlayImage(message, language, ui_type)
|
|
||||||
|
|
||||||
def clearOverlayImage(self):
|
def clearOverlayImageSmallLog(self):
|
||||||
self.overlay.clearImage()
|
self.overlay.clearImage("small")
|
||||||
|
|
||||||
def updateOverlay(self, img):
|
def updateOverlaySmallLog(self, img):
|
||||||
self.overlay.updateImage(img)
|
self.overlay.updateImage(img, "small")
|
||||||
|
|
||||||
def startOverlay(self):
|
def updateOverlaySmallLogSettings(self):
|
||||||
self.overlay.startOverlay()
|
for key in self.overlay_small_log_pre_settings.keys():
|
||||||
|
if self.overlay_small_log_pre_settings[key] != config.OVERLAY_SMALL_LOG_SETTINGS[key]:
|
||||||
def updateOverlayPosition(self):
|
match (key):
|
||||||
|
case "x_pos" | "y_pos" | "z_pos" | "x_rotation" | "y_rotation" | "z_rotation" | "tracker":
|
||||||
self.overlay.updatePosition(
|
self.overlay.updatePosition(
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"],
|
config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"],
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"],
|
config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"],
|
||||||
@@ -726,21 +712,63 @@ class Model:
|
|||||||
config.OVERLAY_SMALL_LOG_SETTINGS["x_rotation"],
|
config.OVERLAY_SMALL_LOG_SETTINGS["x_rotation"],
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS["y_rotation"],
|
config.OVERLAY_SMALL_LOG_SETTINGS["y_rotation"],
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS["z_rotation"],
|
config.OVERLAY_SMALL_LOG_SETTINGS["z_rotation"],
|
||||||
|
config.OVERLAY_SMALL_LOG_SETTINGS["tracker"],
|
||||||
|
"small",
|
||||||
)
|
)
|
||||||
|
case "display_duration":
|
||||||
|
self.overlay.updateDisplayDuration(config.OVERLAY_SMALL_LOG_SETTINGS["display_duration"], "small")
|
||||||
|
case "fadeout_duration":
|
||||||
|
self.overlay.updateFadeoutDuration(config.OVERLAY_SMALL_LOG_SETTINGS["fadeout_duration"], "small")
|
||||||
|
case "opacity":
|
||||||
|
self.overlay.updateOpacity(config.OVERLAY_SMALL_LOG_SETTINGS["opacity"], "small", True)
|
||||||
|
case "ui_scaling":
|
||||||
|
self.overlay.updateUiScaling(config.OVERLAY_SMALL_LOG_SETTINGS["ui_scaling"], "small")
|
||||||
|
case _:
|
||||||
|
pass
|
||||||
|
break
|
||||||
|
self.overlay_small_log_pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS
|
||||||
|
|
||||||
def updateOverlayTimes(self):
|
def createOverlayImageLargeLog(self, message_type:str, message:str, translation:str):
|
||||||
display_duration = config.OVERLAY_SMALL_LOG_SETTINGS["display_duration"]
|
your_language = config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["primary"]["language"]
|
||||||
self.overlay.updateDisplayDuration(display_duration)
|
target_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["primary"]["language"]
|
||||||
fadeout_duration = config.OVERLAY_SMALL_LOG_SETTINGS["fadeout_duration"]
|
return self.overlay_image.createOverlayImageLargeLog(message_type, message, your_language, translation, target_language)
|
||||||
self.overlay.updateFadeoutDuration(fadeout_duration)
|
|
||||||
|
|
||||||
def updateOverlayImageOpacity(self):
|
def clearOverlayImageLargeLog(self):
|
||||||
opacity = config.OVERLAY_SETTINGS["opacity"]
|
self.overlay.clearImage("large")
|
||||||
self.overlay.updateOpacity(opacity, with_fade=True)
|
|
||||||
|
|
||||||
def updateOverlayImageUiScaling(self):
|
def updateOverlayLargeLog(self, img):
|
||||||
ui_scaling = config.OVERLAY_SETTINGS["ui_scaling"]
|
self.overlay.updateImage(img, "large")
|
||||||
self.overlay.updateUiScaling(ui_scaling)
|
|
||||||
|
def updateOverlayLargeLogSettings(self):
|
||||||
|
for key in self.overlay_large_log_pre_settings.keys():
|
||||||
|
if self.overlay_large_log_pre_settings[key] != config.OVERLAY_LARGE_LOG_SETTINGS[key]:
|
||||||
|
match (key):
|
||||||
|
case "x_pos" | "y_pos" | "z_pos" | "x_rotation" | "y_rotation" | "z_rotation" | "tracker":
|
||||||
|
self.overlay.updatePosition(
|
||||||
|
config.OVERLAY_LARGE_LOG_SETTINGS["x_pos"],
|
||||||
|
config.OVERLAY_LARGE_LOG_SETTINGS["y_pos"],
|
||||||
|
config.OVERLAY_LARGE_LOG_SETTINGS["z_pos"],
|
||||||
|
config.OVERLAY_LARGE_LOG_SETTINGS["x_rotation"],
|
||||||
|
config.OVERLAY_LARGE_LOG_SETTINGS["y_rotation"],
|
||||||
|
config.OVERLAY_LARGE_LOG_SETTINGS["z_rotation"],
|
||||||
|
config.OVERLAY_LARGE_LOG_SETTINGS["tracker"],
|
||||||
|
"large",
|
||||||
|
)
|
||||||
|
case "display_duration":
|
||||||
|
self.overlay.updateDisplayDuration(config.OVERLAY_LARGE_LOG_SETTINGS["display_duration"], "large")
|
||||||
|
case "fadeout_duration":
|
||||||
|
self.overlay.updateFadeoutDuration(config.OVERLAY_LARGE_LOG_SETTINGS["fadeout_duration"], "large")
|
||||||
|
case "opacity":
|
||||||
|
self.overlay.updateOpacity(config.OVERLAY_LARGE_LOG_SETTINGS["opacity"], "large", True)
|
||||||
|
case "ui_scaling":
|
||||||
|
self.overlay.updateUiScaling(config.OVERLAY_LARGE_LOG_SETTINGS["ui_scaling"], "large")
|
||||||
|
case _:
|
||||||
|
pass
|
||||||
|
break
|
||||||
|
self.overlay_large_log_pre_settings = config.OVERLAY_LARGE_LOG_SETTINGS
|
||||||
|
|
||||||
|
def startOverlay(self):
|
||||||
|
self.overlay.startOverlay()
|
||||||
|
|
||||||
def shutdownOverlay(self):
|
def shutdownOverlay(self):
|
||||||
self.overlay.shutdownOverlay()
|
self.overlay.shutdownOverlay()
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ try:
|
|||||||
from . import overlay_utils as utils
|
from . import overlay_utils as utils
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import overlay_utils as utils
|
import overlay_utils as utils
|
||||||
from utils import printLog
|
try:
|
||||||
|
from utils import printLog
|
||||||
|
except ImportError:
|
||||||
|
def printLog(*args):
|
||||||
|
print(*args)
|
||||||
|
|
||||||
def mat34Id(array):
|
def mat34Id(array):
|
||||||
arr = openvr.HmdMatrix34_t()
|
arr = openvr.HmdMatrix34_t()
|
||||||
@@ -63,114 +67,111 @@ def getRightHandBaseMatrix():
|
|||||||
return arr
|
return arr
|
||||||
|
|
||||||
class Overlay:
|
class Overlay:
|
||||||
def __init__(self, x_pos, y_pos, z_pos, x_rotation, y_rotation, z_rotation, display_duration, fadeout_duration, opacity, ui_scaling):
|
def __init__(self, settings_dict):
|
||||||
self.initialized = False
|
|
||||||
settings = {
|
|
||||||
"color": [1, 1, 1],
|
|
||||||
"opacity": opacity,
|
|
||||||
"x_pos": x_pos,
|
|
||||||
"y_pos": y_pos,
|
|
||||||
"z_pos": z_pos,
|
|
||||||
"x_rotation": x_rotation,
|
|
||||||
"y_rotation": y_rotation,
|
|
||||||
"z_rotation": z_rotation,
|
|
||||||
"display_duration": display_duration,
|
|
||||||
"fadeout_duration": fadeout_duration,
|
|
||||||
"ui_scaling": ui_scaling,
|
|
||||||
}
|
|
||||||
self.settings = settings
|
|
||||||
self.system = None
|
self.system = None
|
||||||
self.overlay = None
|
self.overlay = None
|
||||||
self.handle = None
|
self.handle = None
|
||||||
self.lastUpdate = time.monotonic()
|
self.initialized = False
|
||||||
self.thread_overlay = None
|
|
||||||
self.fadeRatio = 1
|
|
||||||
self.loop = True
|
self.loop = True
|
||||||
|
self.thread_overlay = None
|
||||||
|
|
||||||
|
self.settings = {}
|
||||||
|
self.lastUpdate = {}
|
||||||
|
self.fadeRatio = {}
|
||||||
|
for key, value in settings_dict.items():
|
||||||
|
self.settings[key] = value
|
||||||
|
self.lastUpdate[key] = time.monotonic()
|
||||||
|
self.fadeRatio[key] = 1
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
try:
|
try:
|
||||||
self.system = openvr.init(openvr.VRApplication_Background)
|
self.system = openvr.init(openvr.VRApplication_Background)
|
||||||
self.overlay = openvr.IVROverlay()
|
self.overlay = openvr.IVROverlay()
|
||||||
self.overlay_system = openvr.IVRSystem()
|
self.overlay_system = openvr.IVRSystem()
|
||||||
self.handle = self.overlay.createOverlay("Overlay_Speaker2log", "Overlay_Speaker2log_UI")
|
self.handle = {}
|
||||||
self.overlay.showOverlay(self.handle)
|
for i, size in enumerate(self.settings.keys()):
|
||||||
|
self.handle[size] = self.overlay.createOverlay(f"VRCT{i}", f"VRCT{i}")
|
||||||
|
self.overlay.showOverlay(self.handle[size])
|
||||||
self.initialized = True
|
self.initialized = True
|
||||||
|
|
||||||
self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)))
|
for size in self.settings.keys():
|
||||||
self.updateColor(self.settings["color"])
|
self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)), size)
|
||||||
self.updateOpacity(self.settings["opacity"])
|
self.updateColor([1, 1, 1], size)
|
||||||
self.updateUiScaling(self.settings["ui_scaling"])
|
self.updateOpacity(self.settings[size]["opacity"], size, True)
|
||||||
|
self.updateUiScaling(self.settings[size]["ui_scaling"], size)
|
||||||
self.updatePosition(
|
self.updatePosition(
|
||||||
self.settings["x_pos"],
|
self.settings[size]["x_pos"],
|
||||||
self.settings["y_pos"],
|
self.settings[size]["y_pos"],
|
||||||
self.settings["z_pos"],
|
self.settings[size]["z_pos"],
|
||||||
self.settings["x_rotation"],
|
self.settings[size]["x_rotation"],
|
||||||
self.settings["y_rotation"],
|
self.settings[size]["y_rotation"],
|
||||||
self.settings["z_rotation"],
|
self.settings[size]["z_rotation"],
|
||||||
|
self.settings[size]["tracker"],
|
||||||
|
size
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
printLog("error:Could not initialise OpenVR", e)
|
printLog("error:Could not initialise OpenVR", e)
|
||||||
|
|
||||||
def updateImage(self, img):
|
def updateImage(self, img, size):
|
||||||
if self.initialized is True:
|
if self.initialized is True:
|
||||||
width, height = img.size
|
width, height = img.size
|
||||||
img = img.tobytes()
|
img = img.tobytes()
|
||||||
img = (ctypes.c_char * len(img)).from_buffer_copy(img)
|
img = (ctypes.c_char * len(img)).from_buffer_copy(img)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.overlay.setOverlayRaw(self.handle, img, width, height, 4)
|
self.overlay.setOverlayRaw(self.handle[size], img, width, height, 4)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
printLog("error:Could not update image", e)
|
printLog("error:Could not update image", e)
|
||||||
self.initialized = False
|
self.initialized = False
|
||||||
self.reStartOverlay()
|
self.reStartOverlay()
|
||||||
while self.initialized is False:
|
while self.initialized is False:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
self.overlay.setOverlayRaw(self.handle, img, width, height, 4)
|
self.overlay.setOverlayRaw(self.handle[size], img, width, height, 4)
|
||||||
self.updateOpacity(self.settings["opacity"])
|
self.updateOpacity(self.settings[size]["opacity"], size, True)
|
||||||
self.lastUpdate = time.monotonic()
|
self.lastUpdate[size] = time.monotonic()
|
||||||
|
|
||||||
def clearImage(self):
|
def clearImage(self, size):
|
||||||
if self.initialized is True:
|
if self.initialized is True:
|
||||||
self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)))
|
self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)), size)
|
||||||
|
|
||||||
def updateColor(self, col):
|
def updateColor(self, col, size):
|
||||||
"""
|
"""
|
||||||
col is a 3-tuple representing (r, g, b)
|
col is a 3-tuple representing (r, g, b)
|
||||||
"""
|
"""
|
||||||
self.settings["color"] = col
|
|
||||||
if self.initialized is True:
|
if self.initialized is True:
|
||||||
r, g, b = self.settings["color"]
|
r, g, b = col
|
||||||
self.overlay.setOverlayColor(self.handle, r, g, b)
|
self.overlay.setOverlayColor(self.handle[size], r, g, b)
|
||||||
|
|
||||||
def updateOpacity(self, opacity, with_fade=False):
|
def updateOpacity(self, opacity, size, with_fade=True):
|
||||||
self.settings["opacity"] = opacity
|
self.settings[size]["opacity"] = opacity
|
||||||
|
|
||||||
if self.initialized is True:
|
if self.initialized is True:
|
||||||
if with_fade is True:
|
if with_fade is True:
|
||||||
if self.fadeRatio > 0:
|
if self.fadeRatio[size] > 0:
|
||||||
self.overlay.setOverlayAlpha(self.handle, self.fadeRatio * self.settings["opacity"])
|
self.overlay.setOverlayAlpha(self.handle[size], self.fadeRatio[size] * self.settings[size]["opacity"])
|
||||||
else:
|
else:
|
||||||
self.overlay.setOverlayAlpha(self.handle, self.settings["opacity"])
|
self.overlay.setOverlayAlpha(self.handle[size], self.settings[size]["opacity"])
|
||||||
|
|
||||||
def updateUiScaling(self, ui_scaling):
|
def updateUiScaling(self, ui_scaling, size):
|
||||||
self.settings["ui_scaling"] = ui_scaling
|
self.settings[size]["ui_scaling"] = ui_scaling
|
||||||
if self.initialized is True:
|
if self.initialized is True:
|
||||||
self.overlay.setOverlayWidthInMeters(self.handle, self.settings["ui_scaling"])
|
self.overlay.setOverlayWidthInMeters(self.handle[size], self.settings[size]["ui_scaling"])
|
||||||
|
|
||||||
def updatePosition(self, x_pos, y_pos, z_pos, x_rotation, y_rotation, z_rotation, tracker="HMD"):
|
def updatePosition(self, x_pos, y_pos, z_pos, x_rotation, y_rotation, z_rotation, tracker, size):
|
||||||
"""
|
"""
|
||||||
x_pos, y_pos, z_pos are floats representing the position of overlay
|
x_pos, y_pos, z_pos are floats representing the position of overlay
|
||||||
x_rotation, y_rotation, z_rotation are floats representing the rotation of overlay
|
x_rotation, y_rotation, z_rotation are floats representing the rotation of overlay
|
||||||
tracker is a string representing the tracker to use ("HMD", "LeftHand", "RightHand")
|
tracker is a string representing the tracker to use ("HMD", "LeftHand", "RightHand")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.settings["x_pos"] = x_pos
|
self.settings[size]["x_pos"] = x_pos
|
||||||
self.settings["y_pos"] = y_pos
|
self.settings[size]["y_pos"] = y_pos
|
||||||
self.settings["z_pos"] = z_pos
|
self.settings[size]["z_pos"] = z_pos
|
||||||
self.settings["x_rotation"] = x_rotation
|
self.settings[size]["x_rotation"] = x_rotation
|
||||||
self.settings["y_rotation"] = y_rotation
|
self.settings[size]["y_rotation"] = y_rotation
|
||||||
self.settings["z_rotation"] = z_rotation
|
self.settings[size]["z_rotation"] = z_rotation
|
||||||
|
self.settings[size]["tracker"] = tracker
|
||||||
|
|
||||||
match tracker:
|
match tracker:
|
||||||
case "HMD":
|
case "HMD":
|
||||||
@@ -186,23 +187,23 @@ class Overlay:
|
|||||||
base_matrix = getHMDBaseMatrix()
|
base_matrix = getHMDBaseMatrix()
|
||||||
trackerIndex = openvr.k_unTrackedDeviceIndex_Hmd
|
trackerIndex = openvr.k_unTrackedDeviceIndex_Hmd
|
||||||
|
|
||||||
translation = (self.settings["x_pos"], self.settings["y_pos"], - self.settings["z_pos"])
|
translation = (self.settings[size]["x_pos"], self.settings[size]["y_pos"], - self.settings[size]["z_pos"])
|
||||||
rotation = (self.settings["x_rotation"], self.settings["y_rotation"], self.settings["z_rotation"])
|
rotation = (self.settings[size]["x_rotation"], self.settings[size]["y_rotation"], self.settings[size]["z_rotation"])
|
||||||
transform = utils.transform_matrix(base_matrix, translation, rotation)
|
transform = utils.transform_matrix(base_matrix, translation, rotation)
|
||||||
self.transform = mat34Id(transform)
|
transform = mat34Id(transform)
|
||||||
|
|
||||||
if self.initialized is True:
|
if self.initialized is True:
|
||||||
self.overlay.setOverlayTransformTrackedDeviceRelative(
|
self.overlay.setOverlayTransformTrackedDeviceRelative(
|
||||||
self.handle,
|
self.handle[size],
|
||||||
trackerIndex,
|
trackerIndex,
|
||||||
self.transform
|
transform
|
||||||
)
|
)
|
||||||
|
|
||||||
def updateDisplayDuration(self, display_duration):
|
def updateDisplayDuration(self, display_duration, size):
|
||||||
self.settings["display_duration"] = display_duration
|
self.settings[size]["display_duration"] = display_duration
|
||||||
|
|
||||||
def updateFadeoutDuration(self, fadeout_duration):
|
def updateFadeoutDuration(self, fadeout_duration, size):
|
||||||
self.settings["fadeout_duration"] = fadeout_duration
|
self.settings[size]["fadeout_duration"] = fadeout_duration
|
||||||
|
|
||||||
def checkActive(self):
|
def checkActive(self):
|
||||||
try:
|
try:
|
||||||
@@ -216,26 +217,27 @@ class Overlay:
|
|||||||
printLog("error:Could not check SteamVR running", e)
|
printLog("error:Could not check SteamVR running", e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def evaluateOpacityFade(self, lastUpdate, currentTime):
|
def evaluateOpacityFade(self, lastUpdate, currentTime, size):
|
||||||
if (currentTime - lastUpdate) > self.settings["display_duration"]:
|
if (currentTime - lastUpdate) > self.settings[size]["display_duration"]:
|
||||||
timeThroughInterval = currentTime - lastUpdate - self.settings["display_duration"]
|
timeThroughInterval = currentTime - lastUpdate - self.settings[size]["display_duration"]
|
||||||
self.fadeRatio = 1 - timeThroughInterval / self.settings["fadeout_duration"]
|
self.fadeRatio[size] = 1 - timeThroughInterval / self.settings[size]["fadeout_duration"]
|
||||||
if self.fadeRatio < 0:
|
if self.fadeRatio[size] < 0:
|
||||||
self.fadeRatio = 0
|
self.fadeRatio[size] = 0
|
||||||
self.overlay.setOverlayAlpha(self.handle, self.fadeRatio * self.settings["opacity"])
|
self.overlay.setOverlayAlpha(self.handle[size], self.fadeRatio[size] * self.settings[size]["opacity"])
|
||||||
|
|
||||||
def update(self):
|
def update(self, size):
|
||||||
currTime = time.monotonic()
|
currTime = time.monotonic()
|
||||||
if self.settings["fadeout_duration"] != 0:
|
if self.settings[size]["fadeout_duration"] != 0:
|
||||||
self.evaluateOpacityFade(self.lastUpdate, currTime)
|
self.evaluateOpacityFade(self.lastUpdate[size], currTime, size)
|
||||||
else:
|
else:
|
||||||
self.updateOpacity(self.settings["opacity"])
|
self.updateOpacity(self.settings[size]["opacity"], size, True)
|
||||||
|
|
||||||
def mainloop(self):
|
def mainloop(self):
|
||||||
self.loop = True
|
self.loop = True
|
||||||
while self.checkActive() is True and self.loop is True:
|
while self.checkActive() is True and self.loop is True:
|
||||||
startTime = time.monotonic()
|
startTime = time.monotonic()
|
||||||
self.update()
|
for size in self.settings.keys():
|
||||||
|
self.update(size)
|
||||||
sleepTime = (1 / 16) - (time.monotonic() - startTime)
|
sleepTime = (1 / 16) - (time.monotonic() - startTime)
|
||||||
if sleepTime > 0:
|
if sleepTime > 0:
|
||||||
time.sleep(sleepTime)
|
time.sleep(sleepTime)
|
||||||
@@ -255,8 +257,10 @@ class Overlay:
|
|||||||
self.loop = False
|
self.loop = False
|
||||||
self.thread_overlay.join()
|
self.thread_overlay.join()
|
||||||
self.thread_overlay = None
|
self.thread_overlay = None
|
||||||
if isinstance(self.overlay, openvr.IVROverlay) and isinstance(self.handle, int):
|
if isinstance(self.overlay, openvr.IVROverlay):
|
||||||
self.overlay.destroyOverlay(self.handle)
|
for size in self.settings.keys():
|
||||||
|
if isinstance(self.handle[size], int):
|
||||||
|
self.overlay.destroyOverlay(self.handle[size])
|
||||||
self.overlay = None
|
self.overlay = None
|
||||||
if isinstance(self.system, openvr.IVRSystem):
|
if isinstance(self.system, openvr.IVRSystem):
|
||||||
openvr.shutdown()
|
openvr.shutdown()
|
||||||
@@ -273,45 +277,67 @@ class Overlay:
|
|||||||
return _proc_name in (p.name() for p in process_iter())
|
return _proc_name in (p.name() for p in process_iter())
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# from overlay_image import OverlayImage
|
from overlay_image import OverlayImage
|
||||||
# overlay_image = OverlayImage()
|
|
||||||
|
|
||||||
# overlay = Overlay(0, 0, 1, 1, 0, 1, 1)
|
small_settings = {
|
||||||
# overlay.startOverlay()
|
"x_pos": 0.0,
|
||||||
# time.sleep(1)
|
"y_pos": 0.0,
|
||||||
|
"z_pos": 0.0,
|
||||||
|
"x_rotation": 0.0,
|
||||||
|
"y_rotation": 0.0,
|
||||||
|
"z_rotation": 0.0,
|
||||||
|
"display_duration": 5,
|
||||||
|
"fadeout_duration": 2,
|
||||||
|
"opacity": 1.0,
|
||||||
|
"ui_scaling": 0.5,
|
||||||
|
"tracker": "HMD",
|
||||||
|
}
|
||||||
|
|
||||||
# # Example usage
|
large_settings = {
|
||||||
# img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese")
|
"x_pos": 0.0,
|
||||||
# overlay.updateImage(img)
|
"y_pos": 0.0,
|
||||||
# time.sleep(100000)
|
"z_pos": 0.0,
|
||||||
|
"x_rotation": 0.0,
|
||||||
|
"y_rotation": 0.0,
|
||||||
|
"z_rotation": 0.0,
|
||||||
|
"display_duration": 5,
|
||||||
|
"fadeout_duration": 0,
|
||||||
|
"opacity": 1.0,
|
||||||
|
"ui_scaling": 0.5,
|
||||||
|
"tracker": "LeftHand",
|
||||||
|
}
|
||||||
|
|
||||||
# for i in range(100):
|
settings_dict = {
|
||||||
# print(i)
|
"small": small_settings,
|
||||||
# overlay = Overlay(0, 0, 1, 1, 1, 1, 1)
|
"large": large_settings
|
||||||
# overlay.startOverlay()
|
}
|
||||||
# time.sleep(1)
|
|
||||||
|
|
||||||
# # Example usage
|
overlay_image = OverlayImage()
|
||||||
# img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese", ui_type="sakura")
|
overlay = Overlay(settings_dict)
|
||||||
# overlay.updateImage(img)
|
overlay.startOverlay()
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
# Example usage
|
||||||
|
img = overlay_image.createOverlayImageLargeLog("send", "こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese")
|
||||||
|
overlay.updateImage(img, "large")
|
||||||
|
|
||||||
|
img = overlay_image.createOverlayImageSmallLog("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese")
|
||||||
|
overlay.updateImage(img, "small")
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
img = overlay_image.createOverlayImageSmallLog("こんにちは、世界!さようなら2", "Japanese", "Hello,World!Goodbye", "Japanese")
|
||||||
|
overlay.updateImage(img, "small")
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
for i in range(100):
|
||||||
|
print(i)
|
||||||
|
# Example usage
|
||||||
|
img = overlay_image.createOverlayImageSmallLog(f"こんにちは、世界!さようなら_{i}", "Japanese", "Hello,World!Goodbye", "Japanese")
|
||||||
|
overlay.updateImage(img, "small")
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
# img = overlay_image.createOverlayImageSmallLog("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese")
|
||||||
|
# overlay.updateImage(img, "small")
|
||||||
# time.sleep(0.5)
|
# time.sleep(0.5)
|
||||||
|
|
||||||
# img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese")
|
overlay.shutdownOverlay()
|
||||||
# overlay.updateImage(img)
|
|
||||||
# time.sleep(0.5)
|
|
||||||
|
|
||||||
# overlay.shutdownOverlay()
|
|
||||||
|
|
||||||
x_pos = 0
|
|
||||||
y_pos = 0
|
|
||||||
z_pos = 0
|
|
||||||
x_rotation = 0
|
|
||||||
y_rotation = 0
|
|
||||||
z_rotation = 0
|
|
||||||
|
|
||||||
base_matrix = getLeftHandBaseMatrix()
|
|
||||||
translation = (x_pos * z_pos, y_pos * z_pos, z_pos)
|
|
||||||
rotation = (x_rotation, y_rotation, z_rotation)
|
|
||||||
transform = utils.transform_matrix(base_matrix, translation, rotation)
|
|
||||||
transform = mat34Id(transform)
|
|
||||||
print(transform)
|
|
||||||
@@ -1,16 +1,9 @@
|
|||||||
from os import path as os_path
|
from os import path as os_path
|
||||||
# from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
class OverlayImage:
|
class OverlayImage:
|
||||||
# TEXT_COLOR_LARGE = (223, 223, 223)
|
|
||||||
# TEXT_COLOR_SMALL = (190, 190, 190)
|
|
||||||
# TEXT_COLOR_SEND = (70, 161, 146)
|
|
||||||
# TEXT_COLOR_RECEIVE = (220, 20, 60)
|
|
||||||
# TEXT_COLOR_TIME = (120, 120, 120)
|
|
||||||
# FONT_SIZE_LARGE = HEIGHT
|
|
||||||
# FONT_SIZE_SMALL = int(FONT_SIZE_LARGE * 2 / 3)
|
|
||||||
LANGUAGES = {
|
LANGUAGES = {
|
||||||
"Japanese": "NotoSansJP-Regular",
|
"Japanese": "NotoSansJP-Regular",
|
||||||
"Korean": "NotoSansKR-Regular",
|
"Korean": "NotoSansKR-Regular",
|
||||||
@@ -19,183 +12,56 @@ class OverlayImage:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
self.message_log = []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def concatenateImagesVertically(img1: Image, img2: Image) -> Image:
|
def concatenateImagesVertically(img1: Image, img2: Image, margin: int = 0) -> Image:
|
||||||
dst = Image.new("RGBA", (img1.width, img1.height + img2.height))
|
total_height = img1.height + img2.height + margin
|
||||||
|
dst = Image.new("RGBA", (img1.width, total_height))
|
||||||
dst.paste(img1, (0, 0))
|
dst.paste(img1, (0, 0))
|
||||||
dst.paste(img2, (0, img1.height))
|
dst.paste(img2, (0, img1.height + margin))
|
||||||
return dst
|
return dst
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def addImageMargin(image: Image, top: int, right: int, bottom: int, left: int, color: Tuple[int, int, int, int]) -> Image:
|
def addImageMargin(image: Image, top: int, right: int, bottom: int, left: int, color: Tuple[int, int, int, int]) -> Image:
|
||||||
width, height = image.size
|
new_width = image.width + right + left
|
||||||
new_width = width + right + left
|
new_height = image.height + top + bottom
|
||||||
new_height = height + top + bottom
|
|
||||||
result = Image.new(image.mode, (new_width, new_height), color)
|
result = Image.new(image.mode, (new_width, new_height), color)
|
||||||
result.paste(image, (left, top))
|
result.paste(image, (left, top))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# def create_textimage(self, message_type, size, text, language):
|
@staticmethod
|
||||||
# font_size = self.FONT_SIZE_LARGE if size == "large" else self.FONT_SIZE_SMALL
|
def getUiSizeSmallLog() -> dict:
|
||||||
# text_color = self.TEXT_COLOR_LARGE if size == "large" else self.TEXT_COLOR_SMALL
|
|
||||||
# anchor = "lm" if message_type == "receive" else "rm"
|
|
||||||
# text_x = 0 if message_type == "receive" else self.WIDTH
|
|
||||||
# align = "left" if message_type == "receive" else "right"
|
|
||||||
|
|
||||||
# font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular")
|
|
||||||
# img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
|
||||||
# draw = ImageDraw.Draw(img)
|
|
||||||
# font = ImageFont.truetype(os_path.join(os_path.dirname(__file__), "fonts", f"{font_family}.ttf"), font_size)
|
|
||||||
# # font = ImageFont.truetype(os_path.join("./fonts", f"{font_family}.ttf"), font_size)
|
|
||||||
# text_width = draw.textlength(text, font)
|
|
||||||
# character_width = text_width // len(text)
|
|
||||||
# character_line_num = int(self.WIDTH // character_width)
|
|
||||||
# if len(text) > character_line_num:
|
|
||||||
# text = "\n".join([text[i:i+character_line_num] for i in range(0, len(text), character_line_num)])
|
|
||||||
|
|
||||||
# n_num = len(text.split("\n")) - 1
|
|
||||||
# text_height = int(font_size*(n_num+2))
|
|
||||||
|
|
||||||
# img = Image.new("RGBA", (self.WIDTH, text_height), (0, 0, 0, 0))
|
|
||||||
# draw = ImageDraw.Draw(img)
|
|
||||||
|
|
||||||
# text_y = text_height // 2
|
|
||||||
|
|
||||||
# draw.multiline_text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font, align=align)
|
|
||||||
# return img
|
|
||||||
|
|
||||||
# def create_textimage_message_type(self, message_type):
|
|
||||||
# anchor = "lm" if message_type == "receive" else "rm"
|
|
||||||
# text = "Receive" if message_type == "receive" else "Send"
|
|
||||||
# text_color = self.TEXT_COLOR_RECEIVE if message_type == "receive" else self.TEXT_COLOR_SEND
|
|
||||||
# text_color_time = self.TEXT_COLOR_TIME
|
|
||||||
|
|
||||||
# now = datetime.now()
|
|
||||||
# formatted_time = now.strftime("%H:%M")
|
|
||||||
# font_size = self.FONT_SIZE_SMALL
|
|
||||||
# img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
|
||||||
# draw = ImageDraw.Draw(img)
|
|
||||||
# font = ImageFont.truetype(os_path.join(os_path.dirname(__file__), "fonts", "NotoSansJP-Regular.ttf"), font_size)
|
|
||||||
# # font = ImageFont.truetype(os_path.join("./fonts", "NotoSansJP-Regular.ttf"), font_size)
|
|
||||||
# text_height = font_size*2
|
|
||||||
# text_width = draw.textlength(formatted_time, font)
|
|
||||||
# character_width = text_width // len(formatted_time)
|
|
||||||
# img = Image.new("RGBA", (self.WIDTH, text_height), (0, 0, 0, 0))
|
|
||||||
# draw = ImageDraw.Draw(img)
|
|
||||||
# text_y = text_height // 2
|
|
||||||
# text_time_x = 0 if message_type == "receive" else self.WIDTH - (text_width + character_width)
|
|
||||||
# text_x = (text_width + character_width) if message_type == "receive" else self.WIDTH
|
|
||||||
|
|
||||||
# draw.text((text_time_x, text_y), formatted_time, text_color_time, anchor=anchor, stroke_width=0, font=font)
|
|
||||||
# draw.text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font)
|
|
||||||
# return img
|
|
||||||
|
|
||||||
# def create_textbox(self, message_type, message, your_language, translation, target_language):
|
|
||||||
# message_type_img = self.create_textimage_message_type(message_type)
|
|
||||||
# if len(translation) > 0 and target_language is not None:
|
|
||||||
# img = self.create_textimage(message_type, "small", message, your_language)
|
|
||||||
# translation_img = self.create_textimage(message_type, "large",translation, target_language)
|
|
||||||
# img = self.concatenateImagesVertically(img, translation_img)
|
|
||||||
# else:
|
|
||||||
# img = self.create_textimage(message_type, "large", message, your_language)
|
|
||||||
# return self.concatenateImagesVertically(message_type_img, img)
|
|
||||||
|
|
||||||
# def create_overlay_image_long(self, message_type, message, your_language, translation="", target_language=None):
|
|
||||||
# if len(self.log_data) > 10:
|
|
||||||
# self.log_data.pop(0)
|
|
||||||
|
|
||||||
# self.log_data.append(
|
|
||||||
# {
|
|
||||||
# "message_type":message_type,
|
|
||||||
# "message":message,
|
|
||||||
# "your_language":your_language,
|
|
||||||
# "translation":translation,
|
|
||||||
# "target_language":target_language,
|
|
||||||
# }
|
|
||||||
# )
|
|
||||||
|
|
||||||
# imgs = []
|
|
||||||
# for log in self.log_data:
|
|
||||||
# message_type = log["message_type"]
|
|
||||||
# message = log["message"]
|
|
||||||
# your_language = log["your_language"]
|
|
||||||
# translation = log["translation"]
|
|
||||||
# target_language = log["target_language"]
|
|
||||||
# img = self.create_textbox(message_type, message, your_language, translation, target_language)
|
|
||||||
# imgs.append(img)
|
|
||||||
|
|
||||||
# img = imgs[0]
|
|
||||||
# for i in imgs[1:]:
|
|
||||||
# img = self.concatenateImagesVertically(img, i)
|
|
||||||
# img = self.addImageMargin(img, 0, 20, 0, 20, (0, 0, 0, 0))
|
|
||||||
|
|
||||||
# width, height = img.size
|
|
||||||
# background = Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
|
||||||
# draw = ImageDraw.Draw(background)
|
|
||||||
# draw.rounded_rectangle([(0, 0), (width, height)], radius=15, fill=self.BACKGROUND_COLOR, outline=self.BACKGROUND_OUTLINE_COLOR, width=5)
|
|
||||||
# img = Image.alpha_composite(background, img)
|
|
||||||
# return img
|
|
||||||
|
|
||||||
def getUiSize(self):
|
|
||||||
return {
|
return {
|
||||||
"width": int(960*4),
|
"width": 3840,
|
||||||
"height": int(23*4),
|
"height": 92,
|
||||||
"font_size": int(23*4),
|
"font_size": 92,
|
||||||
}
|
}
|
||||||
|
|
||||||
def getUiColors(self, ui_type):
|
@staticmethod
|
||||||
match ui_type:
|
def getUiColorSmallLog() -> dict:
|
||||||
case "default":
|
colors = {
|
||||||
background_color = (41, 42, 45)
|
"background_color": (41, 42, 45),
|
||||||
background_outline_color = (41, 42, 45)
|
"background_outline_color": (41, 42, 45),
|
||||||
text_color = (223, 223, 223)
|
"text_color": (223, 223, 223)
|
||||||
case "sakura":
|
|
||||||
background_color = (225, 40, 30)
|
|
||||||
background_outline_color = (255, 255, 255)
|
|
||||||
text_color = (223, 223, 223)
|
|
||||||
return {
|
|
||||||
"background_color": background_color,
|
|
||||||
"background_outline_color": background_outline_color,
|
|
||||||
"text_color": text_color
|
|
||||||
}
|
}
|
||||||
|
return colors
|
||||||
|
|
||||||
def createDecorationImage(self, ui_type, image_size):
|
def createTextboxSmallLog(self, text:str, language:str, text_color:tuple, base_width:int, base_height:int, font_size:int) -> Image:
|
||||||
decoration_image = Image.new("RGBA", image_size, (0, 0, 0, 0))
|
|
||||||
match ui_type:
|
|
||||||
case "default":
|
|
||||||
pass
|
|
||||||
case "sakura":
|
|
||||||
margin = 7
|
|
||||||
alpha_ratio = 0.4
|
|
||||||
overlay_tl = Image.open(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "img", "overlay_tl_sakura.png"))
|
|
||||||
overlay_br = Image.open(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "img", "overlay_br_sakura.png"))
|
|
||||||
if overlay_tl.size[1] > image_size[1]:
|
|
||||||
overlay_tl = overlay_tl.resize((image_size[1]-margin, image_size[1]-margin))
|
|
||||||
if overlay_br.size[1] > image_size[1]:
|
|
||||||
overlay_br = overlay_br.resize((image_size[1]-margin, image_size[1]-margin))
|
|
||||||
|
|
||||||
alpha = overlay_tl.getchannel("A")
|
|
||||||
alpha = alpha.point(lambda x: x * alpha_ratio)
|
|
||||||
overlay_tl.putalpha(alpha)
|
|
||||||
alpha = overlay_br.getchannel("A")
|
|
||||||
alpha = alpha.point(lambda x: x * alpha_ratio)
|
|
||||||
overlay_br.putalpha(alpha)
|
|
||||||
decoration_image.paste(overlay_tl, (margin, margin))
|
|
||||||
decoration_image.paste(overlay_br, (image_size[0]-overlay_br.size[0]-margin, image_size[1]-overlay_br.size[1]-margin))
|
|
||||||
return decoration_image
|
|
||||||
|
|
||||||
def createTextboxShort(self, text, language, text_color, base_width, base_height, font_size):
|
|
||||||
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 = ImageFont.truetype(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf"), font_size)
|
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
|
||||||
|
try:
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
except Exception:
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
|
||||||
text_width = draw.textlength(text, font)
|
text_width = draw.textlength(text, font)
|
||||||
character_width = text_width // len(text)
|
character_width = text_width // len(text)
|
||||||
character_line_num = int((base_width) // character_width) - 12
|
character_line_num = (base_width // character_width) - 12
|
||||||
if len(text) > character_line_num:
|
if len(text) > character_line_num:
|
||||||
text = "\n".join([text[i:i+character_line_num] for i in range(0, len(text), character_line_num)])
|
text = "\n".join([text[i:i + character_line_num] for i in range(0, len(text), character_line_num)])
|
||||||
text_height = font_size * (len(text.split("\n")) + 1) + 20
|
text_height = font_size * (len(text.split("\n")) + 1) + 20
|
||||||
img = Image.new("RGBA", (base_width, text_height), (0, 0, 0, 0))
|
img = Image.new("RGBA", (base_width, text_height), (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(img)
|
draw = ImageDraw.Draw(img)
|
||||||
@@ -205,49 +71,178 @@ class OverlayImage:
|
|||||||
draw.text((text_x, text_y), text, text_color, anchor="mm", stroke_width=0, font=font, align="center")
|
draw.text((text_x, text_y), text, text_color, anchor="mm", stroke_width=0, font=font, align="center")
|
||||||
return img
|
return img
|
||||||
|
|
||||||
def createOverlayImageShort(self, message, your_language, translation="", target_language=None, ui_type="default"):
|
def createOverlayImageSmallLog(self, message:str, your_language:str, translation:str="", target_language:str=None) -> Image:
|
||||||
ui_size = self.getUiSize()
|
ui_size = self.getUiSizeSmallLog()
|
||||||
height = ui_size["height"]
|
width, height, font_size = ui_size["width"], ui_size["height"], ui_size["font_size"]
|
||||||
width = ui_size["width"]
|
|
||||||
font_size = ui_size["font_size"]
|
|
||||||
|
|
||||||
ui_colors = self.getUiColors(ui_type)
|
ui_colors = self.getUiColorSmallLog()
|
||||||
text_color = ui_colors["text_color"]
|
text_color = ui_colors["text_color"]
|
||||||
background_color = ui_colors["background_color"]
|
background_color = ui_colors["background_color"]
|
||||||
background_outline_color = ui_colors["background_outline_color"]
|
background_outline_color = ui_colors["background_outline_color"]
|
||||||
|
|
||||||
img = self.createTextboxShort(message, your_language, text_color, width, height, font_size)
|
img = self.createTextboxSmallLog(message, your_language, text_color, width, height, font_size)
|
||||||
if len(translation) > 0 and target_language is not None:
|
if translation and target_language:
|
||||||
translation_img = self.createTextboxShort(translation, target_language, text_color, width, height, font_size)
|
translation_img = self.createTextboxSmallLog(translation, target_language, text_color, width, height, font_size)
|
||||||
img = self.concatenateImagesVertically(img, translation_img)
|
img = self.concatenateImagesVertically(img, translation_img)
|
||||||
|
|
||||||
background = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
background = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(background)
|
draw = ImageDraw.Draw(background)
|
||||||
draw.rounded_rectangle([(0, 0), img.size], radius=30, fill=background_color, outline=background_outline_color, width=5)
|
draw.rounded_rectangle([(0, 0), img.size], radius=50, fill=background_color, outline=background_outline_color, width=5)
|
||||||
|
|
||||||
decoration_image = self.createDecorationImage(ui_type, img.size)
|
return Image.alpha_composite(background, img)
|
||||||
background = Image.alpha_composite(background, decoration_image)
|
|
||||||
img = Image.alpha_composite(background, img)
|
@staticmethod
|
||||||
|
def getUiSizeLargeLog() -> dict:
|
||||||
|
return {
|
||||||
|
"width": 960,
|
||||||
|
"font_size_large": 30,
|
||||||
|
"font_size_small": 20,
|
||||||
|
"margin": 25,
|
||||||
|
"radius": 25,
|
||||||
|
"padding": 10,
|
||||||
|
"clause_margin": 20,
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def getUiColorLargeLog() -> dict:
|
||||||
|
return {
|
||||||
|
"background_color": (41, 42, 45),
|
||||||
|
"background_outline_color": (41, 42, 45),
|
||||||
|
"text_color_large": (223, 223, 223),
|
||||||
|
"text_color_small": (190, 190, 190),
|
||||||
|
"text_color_send": (97, 151, 180),
|
||||||
|
"text_color_receive": (168, 97, 180),
|
||||||
|
"text_color_time": (120, 120, 120)
|
||||||
|
}
|
||||||
|
|
||||||
|
def createTextImageLargeLog(self, message_type:str, size:str, text:str, language:str) -> Image:
|
||||||
|
ui_size = self.getUiSizeLargeLog()
|
||||||
|
font_size = ui_size["font_size_large"] if size == "large" else ui_size["font_size_small"]
|
||||||
|
text_color = self.getUiColorLargeLog()[f"text_color_{size}"]
|
||||||
|
anchor = "lm" if message_type == "receive" else "rm"
|
||||||
|
text_x = 0 if message_type == "receive" else ui_size["width"]
|
||||||
|
align = "left" if message_type == "receive" else "right"
|
||||||
|
font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular")
|
||||||
|
|
||||||
|
img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
||||||
|
draw = ImageDraw.Draw(img)
|
||||||
|
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
|
||||||
|
try:
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
except Exception:
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
|
||||||
|
text_width = draw.textlength(text, font)
|
||||||
|
character_width = text_width // len(text)
|
||||||
|
character_line_num = int((ui_size["width"] // character_width) - 1)
|
||||||
|
if len(text) > character_line_num:
|
||||||
|
text = "\n".join([text[i:i + character_line_num] for i in range(0, len(text), character_line_num)])
|
||||||
|
text_height = font_size * len(text.split("\n")) + ui_size["padding"]
|
||||||
|
img = Image.new("RGBA", (ui_size["width"], text_height), (0, 0, 0, 0))
|
||||||
|
draw = ImageDraw.Draw(img)
|
||||||
|
text_y = text_height // 2
|
||||||
|
draw.multiline_text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font, align=align)
|
||||||
return img
|
return img
|
||||||
|
|
||||||
def createOverlayImage(self, message, your_language, ui_type="default"):
|
def createTextImageMessageType(self, message_type:str, date_time:str) -> Image:
|
||||||
ui_size = self.getUiSize()
|
ui_size = self.getUiSizeLargeLog()
|
||||||
height = ui_size["height"]
|
font_size = ui_size["font_size_small"]
|
||||||
width = ui_size["width"]
|
ui_padding = ui_size["padding"]
|
||||||
font_size = ui_size["font_size"]
|
|
||||||
|
|
||||||
ui_colors = self.getUiColors(ui_type)
|
ui_color = self.getUiColorLargeLog()
|
||||||
text_color = ui_colors["text_color"]
|
text_color = ui_color[f"text_color_{message_type}"]
|
||||||
background_color = ui_colors["background_color"]
|
text_color_time = ui_color["text_color_time"]
|
||||||
background_outline_color = ui_colors["background_outline_color"]
|
|
||||||
|
|
||||||
img = self.createTextboxShort(message, your_language, text_color, width, height, font_size)
|
anchor = "lm" if message_type == "receive" else "rm"
|
||||||
|
text = "Receive" if message_type == "receive" else "Send"
|
||||||
|
|
||||||
background = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
||||||
|
draw = ImageDraw.Draw(img)
|
||||||
|
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", "NotoSansJP-Regular.ttf")
|
||||||
|
try:
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
except Exception:
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
|
||||||
|
text_height = font_size + ui_padding
|
||||||
|
text_width = draw.textlength(date_time, font)
|
||||||
|
character_width = text_width // len(date_time)
|
||||||
|
img = Image.new("RGBA", (ui_size["width"], text_height), (0, 0, 0, 0))
|
||||||
|
draw = ImageDraw.Draw(img)
|
||||||
|
text_y = text_height // 2
|
||||||
|
text_time_x = 0 if message_type == "receive" else ui_size["width"] - (text_width + character_width)
|
||||||
|
text_x = (text_width + character_width) if message_type == "receive" else ui_size["width"]
|
||||||
|
draw.text((text_time_x, text_y), date_time, text_color_time, anchor=anchor, stroke_width=0, font=font)
|
||||||
|
draw.text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font)
|
||||||
|
return img
|
||||||
|
|
||||||
|
def createTextboxLargeLog(self, message_type:str, message:str, your_language:str, translation:str, target_language:str, date_time:str) -> Image:
|
||||||
|
message_type_img = self.createTextImageMessageType(message_type, date_time)
|
||||||
|
if translation and target_language:
|
||||||
|
img = self.createTextImageLargeLog(message_type, "small", message, your_language)
|
||||||
|
translation_img = self.createTextImageLargeLog(message_type, "large", translation, target_language)
|
||||||
|
img = self.concatenateImagesVertically(img, translation_img)
|
||||||
|
else:
|
||||||
|
img = self.createTextImageLargeLog(message_type, "large", message, your_language)
|
||||||
|
return self.concatenateImagesVertically(message_type_img, img)
|
||||||
|
|
||||||
|
def createOverlayImageLargeLog(self, message_type:str, message:str, your_language:str, translation:str="", target_language:str=None) -> Image:
|
||||||
|
ui_color = self.getUiColorLargeLog()
|
||||||
|
background_color = ui_color["background_color"]
|
||||||
|
background_outline_color = ui_color["background_outline_color"]
|
||||||
|
|
||||||
|
ui_size = self.getUiSizeLargeLog()
|
||||||
|
ui_margin = ui_size["margin"]
|
||||||
|
ui_radius = ui_size["radius"]
|
||||||
|
ui_clause_margin = ui_size["clause_margin"]
|
||||||
|
|
||||||
|
self.message_log.append({
|
||||||
|
"message_type": message_type,
|
||||||
|
"message": message,
|
||||||
|
"your_language": your_language,
|
||||||
|
"translation": translation,
|
||||||
|
"target_language": target_language,
|
||||||
|
"datetime": datetime.now().strftime("%H:%M")
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(self.message_log) > 10:
|
||||||
|
self.message_log = self.message_log[-10:]
|
||||||
|
|
||||||
|
imgs = [
|
||||||
|
self.createTextboxLargeLog(
|
||||||
|
log["message_type"],
|
||||||
|
log["message"],
|
||||||
|
log["your_language"],
|
||||||
|
log["translation"],
|
||||||
|
log["target_language"],
|
||||||
|
log["datetime"]) for log in self.message_log
|
||||||
|
]
|
||||||
|
|
||||||
|
img = imgs[0]
|
||||||
|
for i in imgs[1:]:
|
||||||
|
img = self.concatenateImagesVertically(img, i, ui_clause_margin)
|
||||||
|
img = self.addImageMargin(img, ui_margin, ui_margin, ui_margin, ui_margin, (0, 0, 0, 0))
|
||||||
|
|
||||||
|
width, height = img.size
|
||||||
|
background = Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(background)
|
draw = ImageDraw.Draw(background)
|
||||||
draw.rounded_rectangle([(0, 0), img.size], radius=30, fill=background_color, outline=background_outline_color, width=5)
|
draw.rounded_rectangle([(0, 0), (width, height)], radius=ui_radius, fill=background_color, outline=background_outline_color, width=5)
|
||||||
|
return Image.alpha_composite(background, img)
|
||||||
|
|
||||||
decoration_image = self.createDecorationImage(ui_type, img.size)
|
if __name__ == "__main__":
|
||||||
background = Image.alpha_composite(background, decoration_image)
|
overlay = OverlayImage()
|
||||||
img = Image.alpha_composite(background, img)
|
img = overlay.createOverlayImageSmallLog("Hello, World!", "English", "こんにちは、世界!", "Japanese")
|
||||||
return img
|
img.save("overlay_small.png")
|
||||||
|
img = overlay.createOverlayImageLargeLog("send", "Hello, World!", "English", "こんにちは、世界!", "Japanese")
|
||||||
|
img = overlay.createOverlayImageLargeLog("receive", "こんにちは、世界!", "Japanese", "Hello, World!", "English")
|
||||||
|
img = overlay.createOverlayImageLargeLog("send", "Hello, World!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "English", "aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああこんにちは、世界!", "Japanese")
|
||||||
|
img = overlay.createOverlayImageLargeLog("receive", "こんにちは、世界!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "Japanese", "Hello, World!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "English")
|
||||||
|
img = overlay.createOverlayImageLargeLog("send", "Hello, World!", "English", "こんにちは、世界!", "Japanese")
|
||||||
|
img = overlay.createOverlayImageLargeLog("receive", "こんにちは、世界!", "Japanese", "Hello, World!", "English")
|
||||||
|
img = overlay.createOverlayImageLargeLog("send", "Hello, World!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "English", "aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああこんにちは、世界!", "Japanese")
|
||||||
|
img = overlay.createOverlayImageLargeLog("receive", "こんにちは、世界!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "Japanese", "Hello, World!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "English")
|
||||||
|
img = overlay.createOverlayImageLargeLog("send", "Hello, World!", "English", "こんにちは、世界!", "Japanese")
|
||||||
|
img = overlay.createOverlayImageLargeLog("receive", "こんにちは、世界!", "Japanese", "Hello, World!", "English")
|
||||||
|
img = overlay.createOverlayImageLargeLog("send", "Hello, World!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "English", "aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああこんにちは、世界!", "Japanese")
|
||||||
|
img = overlay.createOverlayImageLargeLog("receive", "こんにちは、世界!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "Japanese", "Hello, World!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "English")
|
||||||
|
img.save("overlay_large.png")
|
||||||
@@ -250,11 +250,9 @@ class Controller:
|
|||||||
translation = " (" + "/".join(translation) + ")"
|
translation = " (" + "/".join(translation) + ")"
|
||||||
model.logger.info(f"[SENT] {message}{translation}")
|
model.logger.info(f"[SENT] {message}{translation}")
|
||||||
|
|
||||||
# if config.OVERLAY_SMALL_LOG is True:
|
if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True:
|
||||||
# overlay_image = model.createOverlayImageShort(message, translation)
|
overlay_image = model.createOverlayImageLargeLog("send", message, translation)
|
||||||
# model.updateOverlay(overlay_image)
|
model.updateOverlayLargeLog(overlay_image)
|
||||||
# overlay_image = model.createOverlayImageLong("send", message, translation)
|
|
||||||
# model.updateOverlay(overlay_image)
|
|
||||||
|
|
||||||
def speakerMessage(self, message) -> None:
|
def speakerMessage(self, message) -> None:
|
||||||
if isinstance(message, bool) and message is False:
|
if isinstance(message, bool) and message is False:
|
||||||
@@ -291,12 +289,13 @@ class Controller:
|
|||||||
transliteration = model.convertMessageToTransliteration(message)
|
transliteration = model.convertMessageToTransliteration(message)
|
||||||
|
|
||||||
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
|
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
|
||||||
if config.OVERLAY_SMALL_LOG is True:
|
if config.OVERLAY_SMALL_LOG is True and model.overlay.initialized is True:
|
||||||
if model.overlay.initialized is True:
|
overlay_image = model.createOverlayImageSmallLog(message, translation)
|
||||||
overlay_image = model.createOverlayImageShort(message, translation)
|
model.updateOverlaySmallLog(overlay_image)
|
||||||
model.updateOverlay(overlay_image)
|
|
||||||
# overlay_image = model.createOverlayImageLong("receive", message, translation)
|
if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True:
|
||||||
# model.updateOverlay(overlay_image)
|
overlay_image = model.createOverlayImageLargeLog("receive", message, translation)
|
||||||
|
model.updateOverlayLargeLog(overlay_image)
|
||||||
|
|
||||||
if config.SEND_RECEIVED_MESSAGE_TO_VRC is True:
|
if config.SEND_RECEIVED_MESSAGE_TO_VRC is True:
|
||||||
osc_message = self.messageFormatter("RECEIVED", translation, [message])
|
osc_message = self.messageFormatter("RECEIVED", translation, [message])
|
||||||
@@ -361,11 +360,9 @@ class Controller:
|
|||||||
osc_message = self.messageFormatter("SEND", translation, [message])
|
osc_message = self.messageFormatter("SEND", translation, [message])
|
||||||
model.oscSendMessage(osc_message)
|
model.oscSendMessage(osc_message)
|
||||||
|
|
||||||
# if config.OVERLAY_SMALL_LOG is True:
|
if config.OVERLAY_LARGE_LOG is True:
|
||||||
# overlay_image = model.createOverlayImageShort(message, translation)
|
overlay_image = model.createOverlayImageLargeLog("send", message, translation)
|
||||||
# model.updateOverlay(overlay_image)
|
model.updateOverlayLargeLog(overlay_image)
|
||||||
# overlay_image = model.createOverlayImageLong("send", message, translation)
|
|
||||||
# model.updateOverlay(overlay_image)
|
|
||||||
|
|
||||||
# update textbox message log (Sent)
|
# update textbox message log (Sent)
|
||||||
if config.LOGGER_FEATURE is True:
|
if config.LOGGER_FEATURE is True:
|
||||||
@@ -1163,27 +1160,6 @@ class Controller:
|
|||||||
config.SEND_MESSAGE_BUTTON_TYPE = data
|
config.SEND_MESSAGE_BUTTON_TYPE = data
|
||||||
return {"status":200, "result":config.SEND_MESSAGE_BUTTON_TYPE}
|
return {"status":200, "result":config.SEND_MESSAGE_BUTTON_TYPE}
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def getOverlaySettings(*args, **kwargs) -> dict:
|
|
||||||
return {"status":200, "result":config.OVERLAY_SETTINGS}
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def setOverlaySettings(data, *args, **kwargs) -> dict:
|
|
||||||
config.OVERLAY_SETTINGS = data
|
|
||||||
model.updateOverlayImageOpacity()
|
|
||||||
model.updateOverlayImageUiScaling()
|
|
||||||
return {"status":200, "result":config.OVERLAY_SETTINGS}
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def getOverlaySmallLogSettings(*args, **kwargs) -> dict:
|
|
||||||
return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS}
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def setOverlaySmallLogSettings(data, *args, **kwargs) -> dict:
|
|
||||||
config.OVERLAY_SMALL_LOG_SETTINGS = data
|
|
||||||
model.updateOverlayPosition()
|
|
||||||
return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS}
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getOverlaySmallLog(*args, **kwargs) -> dict:
|
def getOverlaySmallLog(*args, **kwargs) -> dict:
|
||||||
return {"status":200, "result":config.OVERLAY_SMALL_LOG}
|
return {"status":200, "result":config.OVERLAY_SMALL_LOG}
|
||||||
@@ -1191,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 config.OVERLAY_SMALL_LOG is True and config.ENABLE_TRANSCRIPTION_RECEIVE is True:
|
|
||||||
if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is 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}
|
||||||
@@ -1200,10 +1175,51 @@ class Controller:
|
|||||||
def setDisableOverlaySmallLog(*args, **kwargs) -> dict:
|
def setDisableOverlaySmallLog(*args, **kwargs) -> dict:
|
||||||
config.OVERLAY_SMALL_LOG = False
|
config.OVERLAY_SMALL_LOG = False
|
||||||
if config.OVERLAY_SMALL_LOG is False:
|
if config.OVERLAY_SMALL_LOG is False:
|
||||||
model.clearOverlayImage()
|
model.clearOverlayImageSmallLog()
|
||||||
|
if config.OVERLAY_LARGE_LOG is False:
|
||||||
model.shutdownOverlay()
|
model.shutdownOverlay()
|
||||||
return {"status":200, "result":config.OVERLAY_SMALL_LOG}
|
return {"status":200, "result":config.OVERLAY_SMALL_LOG}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def getOverlaySmallLogSettings(*args, **kwargs) -> dict:
|
||||||
|
return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def setOverlaySmallLogSettings(data, *args, **kwargs) -> dict:
|
||||||
|
config.OVERLAY_SMALL_LOG_SETTINGS = data
|
||||||
|
model.updateOverlaySmallLogSettings()
|
||||||
|
return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def getOverlayLargeLog(*args, **kwargs) -> dict:
|
||||||
|
return {"status":200, "result":config.OVERLAY_LARGE_LOG}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def setEnableOverlayLargeLog(*args, **kwargs) -> dict:
|
||||||
|
config.OVERLAY_LARGE_LOG = True
|
||||||
|
if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True:
|
||||||
|
model.startOverlay()
|
||||||
|
return {"status":200, "result":config.OVERLAY_LARGE_LOG}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def setDisableOverlayLargeLog(*args, **kwargs) -> dict:
|
||||||
|
config.OVERLAY_LARGE_LOG = False
|
||||||
|
if config.OVERLAY_LARGE_LOG is False:
|
||||||
|
model.clearOverlayImageLargeLog()
|
||||||
|
if config.OVERLAY_SMALL_LOG is False:
|
||||||
|
model.shutdownOverlay()
|
||||||
|
return {"status":200, "result":config.OVERLAY_LARGE_LOG}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def getOverlayLargeLogSettings(*args, **kwargs) -> dict:
|
||||||
|
return {"status":200, "result":config.OVERLAY_LARGE_LOG_SETTINGS}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def setOverlayLargeLogSettings(data, *args, **kwargs) -> dict:
|
||||||
|
config.OVERLAY_LARGE_LOG_SETTINGS = data
|
||||||
|
model.updateOverlayLargeLogSettings()
|
||||||
|
return {"status":200, "result":config.OVERLAY_LARGE_LOG_SETTINGS}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getSendMessageToVrc(*args, **kwargs) -> dict:
|
def getSendMessageToVrc(*args, **kwargs) -> dict:
|
||||||
return {"status":200, "result":config.SEND_MESSAGE_TO_VRC}
|
return {"status":200, "result":config.SEND_MESSAGE_TO_VRC}
|
||||||
@@ -1340,6 +1356,10 @@ 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
|
||||||
|
model.overlay.initialized is False and
|
||||||
|
model.overlay.checkSteamvrRunning() is True):
|
||||||
|
model.startOverlay()
|
||||||
return {"status":200, "result":config.ENABLE_TRANSCRIPTION_SEND}
|
return {"status":200, "result":config.ENABLE_TRANSCRIPTION_SEND}
|
||||||
|
|
||||||
def setDisableTranscriptionSend(self, *args, **kwargs) -> dict:
|
def setDisableTranscriptionSend(self, *args, **kwargs) -> dict:
|
||||||
@@ -1349,8 +1369,13 @@ 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:
|
if (config.OVERLAY_SMALL_LOG is True and
|
||||||
if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() 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}
|
||||||
@@ -1380,8 +1405,8 @@ class Controller:
|
|||||||
def sendTextOverlaySmallLog(data, *args, **kwargs) -> dict:
|
def sendTextOverlaySmallLog(data, *args, **kwargs) -> dict:
|
||||||
if config.OVERLAY_SMALL_LOG is True:
|
if config.OVERLAY_SMALL_LOG is True:
|
||||||
if model.overlay.initialized is True:
|
if model.overlay.initialized is True:
|
||||||
overlay_image = model.createOverlayImage(data)
|
overlay_image = model.createOverlayImageSystemMessage(data)
|
||||||
model.updateOverlay(overlay_image)
|
model.updateOverlaySmallLog(overlay_image)
|
||||||
return {"status":200, "result":data}
|
return {"status":200, "result":data}
|
||||||
|
|
||||||
def swapYourLanguageAndTargetLanguage(self, *args, **kwargs) -> dict:
|
def swapYourLanguageAndTargetLanguage(self, *args, **kwargs) -> dict:
|
||||||
|
|||||||
@@ -247,15 +247,19 @@ mapping = {
|
|||||||
"/run/download_whisper_weight": {"status": True, "variable":controller.downloadWhisperWeight},
|
"/run/download_whisper_weight": {"status": True, "variable":controller.downloadWhisperWeight},
|
||||||
|
|
||||||
# VR
|
# VR
|
||||||
"/get/data/overlay_settings": {"status": True, "variable":controller.getOverlaySettings},
|
"/get/data/overlay_small_log": {"status": True, "variable":controller.getOverlaySmallLog},
|
||||||
"/set/data/overlay_settings": {"status": True, "variable":controller.setOverlaySettings},
|
"/set/enable/overlay_small_log": {"status": True, "variable":controller.setEnableOverlaySmallLog},
|
||||||
|
"/set/disable/overlay_small_log": {"status": True, "variable":controller.setDisableOverlaySmallLog},
|
||||||
|
|
||||||
"/get/data/overlay_small_log_settings": {"status": True, "variable":controller.getOverlaySmallLogSettings},
|
"/get/data/overlay_small_log_settings": {"status": True, "variable":controller.getOverlaySmallLogSettings},
|
||||||
"/set/data/overlay_small_log_settings": {"status": True, "variable":controller.setOverlaySmallLogSettings},
|
"/set/data/overlay_small_log_settings": {"status": True, "variable":controller.setOverlaySmallLogSettings},
|
||||||
|
|
||||||
"/get/data/overlay_small_log": {"status": True, "variable":controller.getOverlaySmallLog},
|
"/get/data/overlay_large_log": {"status": True, "variable":controller.getOverlayLargeLog},
|
||||||
"/set/enable/overlay_small_log": {"status": True, "variable":controller.setEnableOverlaySmallLog},
|
"/set/enable/overlay_large_log": {"status": True, "variable":controller.setEnableOverlayLargeLog},
|
||||||
"/set/disable/overlay_small_log": {"status": True, "variable":controller.setDisableOverlaySmallLog},
|
"/set/disable/overlay_large_log": {"status": True, "variable":controller.setDisableOverlayLargeLog},
|
||||||
|
|
||||||
|
"/get/data/overlay_large_log_settings": {"status": True, "variable":controller.getOverlayLargeLogSettings},
|
||||||
|
"/set/data/overlay_large_log_settings": {"status": True, "variable":controller.setOverlayLargeLogSettings},
|
||||||
|
|
||||||
# Others
|
# Others
|
||||||
"/get/data/auto_clear_message_box": {"status": True, "variable":controller.getAutoClearMessageBox},
|
"/get/data/auto_clear_message_box": {"status": True, "variable":controller.getAutoClearMessageBox},
|
||||||
|
|||||||
Reference in New Issue
Block a user