Merge branch 'view' into UI_2.0

This commit is contained in:
Sakamoto Shiina
2023-09-15 09:57:47 +09:00
6 changed files with 249 additions and 51 deletions

134
view.py
View File

@@ -350,6 +350,7 @@ class View():
self.view_variable.CALLBACK_SET_OSC_IP_ADDRESS = config_window_registers.get("callback_set_osc_ip_address", None)
self.view_variable.CALLBACK_SET_OSC_PORT = config_window_registers.get("callback_set_osc_port", None)
# self._insertSampleConversationToTextbox()
@@ -438,22 +439,23 @@ class View():
@staticmethod
def _printToTextbox_Info(info_message):
vrct_gui.printToTextbox(
target_type="INFO",
target_type="SYSTEM",
original_message=info_message,
translated_message="",
# translated_message="",
)
def printToTextbox_SentMessage(self, original_message, translated_message):
self._printToTextbox_Sent(original_message, translated_message)
def printToTextbox_SentMessage(self, original_message, translated_message, actual_sent_message=None):
self._printToTextbox_Sent(original_message, translated_message, actual_sent_message)
@staticmethod
def _printToTextbox_Sent(original_message, translated_message):
def _printToTextbox_Sent(original_message, translated_message, actual_sent_message=None):
vrct_gui.printToTextbox(
target_type="SEND",
target_type="SENT",
original_message=original_message,
translated_message=translated_message,
actual_sent_message=actual_sent_message,
)
@@ -463,7 +465,7 @@ class View():
@staticmethod
def _printToTextbox_Received(original_message, translated_message):
vrct_gui.printToTextbox(
target_type="RECEIVE",
target_type="RECEIVED",
original_message=original_message,
translated_message=translated_message,
)
@@ -626,4 +628,122 @@ class View():
# These conversation is generated by ChatGPT
def _insertSampleConversationToTextbox(self):
self.printToTextbox_enableTranscriptionSend()
self.printToTextbox_enableTranscriptionReceive()
conversation_data_without_translation = [
{
"me": "おはよう。",
},
{
"me": "おはよう。",
"target": "やぁ。",
},
{
"me": "今日の天気はどうかな?",
"target": "天気予報を見てないけど、晴れるといいね。",
},
{
"me": "そうだね。昨日は雨だったから。",
"target": "それで、今日の予定は?",
},
]
for data in conversation_data_without_translation:
if data.get("me", None) is not None:
self.printToTextbox_SentMessage(data.get("me", None), data.get("me_t", None))
if data.get("target", None) is not None:
self.printToTextbox_ReceivedMessage(data.get("target", None), data.get("target_t", None))
self.printToTextbox_enableTranslation()
conversation_data = [
{
"me": "I have work in the morning, but I'm meeting friends for dinner in the evening.",
"me_t": "아침에 일이 있지만 저녁에 친구들과 만나 저녁 식사할 예정이에요.",
"target": "재미있어 보여요! 무엇을 먹을 예정이에요?",
"target_t": "Sounds fun! What are you planning to eat?"
},
{
"me": "We're going to an Italian restaurant, and I'm going to have pizza.",
"me_t": "우리는 이탈리안 레스토랑에 가서 피자를 먹을 거에요.",
"target": "그걸 듣자마자 배가 고파져요. 언젠가 함께하고 싶어요.",
"target_t": "Just hearing that makes me hungry. I'd love to join you sometime."
},
{
"me": "Let's plan it for next time!",
"me_t": "다음 번에 계획해 봐요!",
"target": "그래요!",
"target_t": "Sure!"
},
{
"me": "When would be a good time for you?",
"me_t": "너에게 언제가 좋을까?",
"target": "나는 주말이 가장 좋을 것 같아요. 토요일은 어때요?",
"target_t": "I think the weekend works best for me. How about Saturday?"
},
{
"me": "Saturday sounds perfect. What time would be convenient?",
"me_t": "토요일이 완벽해 보여. 편한 시간은 언제인가요?",
"target": "저는 저녁이 괜찮아요. 7시쯤 괜찮을까요?",
"target_t": "Evening works for me. Is around 7 PM okay?"
},
{
"me": "7 PM works great. Do you have any preferences for food other than Italian?",
"me_t": "7시가 아주 적당해. 이탈리안 음식 이외에 어떤 음식을 좋아하세요?",
"target": "특별한 선호도는 없어요. 무엇이든 괜찮아요. 추천 디저트가 있다면 알려주세요.",
"target_t": "I don't have any particular preferences, so anything is fine. If there's a recommended dessert, let me know."
},
{
"me": "朝は仕事があるけど、夜は友達と食事に行く予定だよ。",
"me_t": "I have work in the morning, but I'm meeting friends for dinner in the evening.",
"target": "Sounds fun! What are you planning to eat?",
"target_t": "楽しそう!何を食べる予定?",
},
{
"me": "イタリアンレストランに行って、ピザを食べるつもりだよ。",
"me_t": "We're going to an Italian restaurant, and I'm going to have pizza.",
"target": "Just hearing that makes me hungry. I'd love to join you sometime.",
"target_t": "それ聞いただけでおなかすいたよ。私も一緒に行きたいな。",
},
{
"me": "次回にぜひ一緒に行こう!",
"me_t": "Let's plan it for next time!",
"target": "Sure!",
"target_t": "そうだね!",
},
{
"me": "次回はいつがいいかな?",
"me_t": "When would be a good time for you?",
"target": "I think the weekend works best for me. How about Saturday?",
"target_t": "私は週末が一番いいかな。土曜日はどう?"
},
{
"me": "土曜日はちょうどいいね。何時ごろが良いかな?",
"me_t": "Saturday sounds perfect. What time would be convenient?",
"target": "Evening works for me. Is around 7 PM okay?",
"target_t": "夜がいいかな。7時くらいからがちょうど良いかな。"
},
{
"me": "7時からはちょうどいいよ。イタリアン以外の食べ物について何か好みがある",
"me_t": "7 PM works great. Do you have any preferences for food other than Italian?",
"target": "I don't have any particular preferences, so anything is fine. If there's a recommended dessert, let me know.",
"target_t": "特に好みはないから、何でも大丈夫。おすすめのデザートがあれば教えてね。"
},
]
for data in conversation_data:
if data.get("me", None) is not None:
# actual_sent_message = config.MESSAGE_FORMAT.replace("[message]", data.get("me", None))
# actual_sent_message = actual_sent_message.replace("[translation]", data.get("me_t", None))
self.printToTextbox_SentMessage(data.get("me", None), data.get("me_t", None))
# self.printToTextbox_SentMessage(data.get("me", None), data.get("me_t", None), actual_sent_message)
if data.get("target", None) is not None:
self.printToTextbox_ReceivedMessage(data.get("target", None), data.get("target_t", None))
view = View()

View File

@@ -1,35 +1,120 @@
from datetime import datetime
from customtkinter import CTkFont
def _printToTextbox(settings, target_textbox, original_message=None, translated_message=None, tags=None):
def _printToTextbox(vrct_gui, settings, target_type, original_message=None, translated_message=None, actual_sent_message=None, tags=None, disable_print_to_textbox_all:bool=False):
now_raw_data = datetime.now()
now = now_raw_data.strftime('%H:%M:%S')
now_hm = now_raw_data.strftime('%H:%M')
# now = now_raw_data.strftime("%H:%M:%S")
now_hm = now_raw_data.strftime("%H:%M")
# set target textbox widget
target_textbox.tag_config("NORMAL_TEXT", foreground=settings.ctm.TEXTBOX_TEXT_COLOR)
is_only_one_message = True if original_message is None or translated_message is None or translated_message == "" else False
target_textbox.tag_config("ERROR", foreground="#FF0000")
match (target_type):
case "SYSTEM":
target_textbox = vrct_gui.textbox_system
case "SENT":
target_textbox = vrct_gui.textbox_sent
case "RECEIVED":
target_textbox = vrct_gui.textbox_received
case (_):
raise ValueError(f"No matching case for target_type: {target_type}")
target_textbox.tag_config("INFO", justify="center")
target_textbox.tag_config("INFO_COLOR", foreground="#1BFF00")
target_textbox.tag_config("SEND", justify="left")
target_textbox.tag_config("SEND_COLOR", foreground="#0378e2")
def printEachTextbox(target_textbox):
target_textbox.tag_config("JUSTIFY_CENTER", justify="center")
target_textbox.tag_config("JUSTIFY_RIGHT", justify="right")
target_textbox.tag_config("JUSTIFY_LEFT", justify="left")
target_textbox.tag_config("RECEIVE", justify="left")
target_textbox.tag_config("RECEIVE_COLOR", foreground="#ffa500")
# common tag settings
# target_textbox._textbox.tag_configure("START", spacing1=16)
target_textbox._textbox.tag_configure("LABEL", font=CTkFont(family=settings.FONT_FAMILY, size=12, weight="normal"))
target_textbox._textbox.tag_configure("TIMESTAMP", font=CTkFont(family=settings.FONT_FAMILY, size=12, weight="normal"), foreground=settings.ctm.TEXTBOX_TIMESTAMP_TEXT_COLOR)
target_textbox._textbox.tag_configure("SECONDARY_TEXT_FONT", font=CTkFont(family=settings.FONT_FAMILY, size=12, weight="normal"))
target_textbox._textbox.tag_configure("MAIN_TEXT_FONT", font=CTkFont(family=settings.FONT_FAMILY, size=16, weight="normal"))
target_textbox._textbox.tag_configure("START", spacing1=10)
# System Tag Settings
target_textbox.tag_config("SYSTEM_FOR_FIRST_INSERT", spacing1=16)
target_textbox.tag_config("SYSTEM_TAG", foreground=settings.ctm.TEXTBOX_SYSTEM_TAG_TEXT_COLOR)
target_textbox.tag_config("SYSTEM_TEXT", foreground=settings.ctm.TEXTBOX_TEXT_SUB_COLOR)
target_textbox._textbox.tag_configure("SYSTEM_TEXT_FONT", font=CTkFont(family=settings.FONT_FAMILY, size=12, weight="normal"))
target_textbox._textbox.tag_configure("LABEL", font=CTkFont(family=settings.FONT_FAMILY, size=12, weight="normal"))
target_textbox._textbox.tag_configure("TIMESTAMP", font=CTkFont(family=settings.FONT_FAMILY, size=12, weight="normal"))
target_textbox._textbox.tag_configure("ORIGINAL_MESSAGE", font=CTkFont(family=settings.FONT_FAMILY, size=12, weight="normal"))
target_textbox._textbox.tag_configure("TRANSLATED_MESSAGE", font=CTkFont(family=settings.FONT_FAMILY, size=16, weight="normal"))
# Sent Tag Settings
target_textbox.tag_config("SENT_FOR_FIRST_INSERT", spacing1=16)
target_textbox.tag_config("SENT_TAG", foreground=settings.ctm.TEXTBOX_SENT_TAG_TEXT_COLOR)
target_textbox.tag_config("SENT_TEXT", foreground=settings.ctm.TEXTBOX_TEXT_COLOR)
target_textbox.tag_config("SENT_SUB_TEXT", foreground=settings.ctm.TEXTBOX_TEXT_SUB_COLOR)
target_textbox._textbox.tag_configure("SENT_MAIN_TEXT_FONT", font=CTkFont(family=settings.FONT_FAMILY, size=16, weight="normal"))
target_textbox._textbox.tag_configure("SENT_SECONDARY_TEXT_FONT", font=CTkFont(family=settings.FONT_FAMILY, size=12, weight="normal"))
target_textbox.configure(state='normal')
target_textbox.insert("end", f"[{tags}] ", ("START", "LABEL", tags, f"{tags}_COLOR"))
target_textbox.insert("end", f"{now_hm} ", ("TIMESTAMP", tags))
target_textbox.insert("end", f"{original_message}\n", ("ORIGINAL_MESSAGE", "NORMAL_TEXT", tags))
target_textbox.insert("end", f"{translated_message}\n", ("TRANSLATED_MESSAGE", "NORMAL_TEXT", tags))
target_textbox.configure(state='disabled')
target_textbox.see("end")
# Received Tag Settings
target_textbox.tag_config("RECEIVED_FOR_FIRST_INSERT", spacing1=16)
target_textbox.tag_config("RECEIVED_TAG", foreground=settings.ctm.TEXTBOX_RECEIVED_TAG_TEXT_COLOR)
target_textbox.tag_config("RECEIVED_TEXT", foreground=settings.ctm.TEXTBOX_TEXT_COLOR)
target_textbox.tag_config("RECEIVED_SUB_TEXT", foreground=settings.ctm.TEXTBOX_TEXT_SUB_COLOR)
target_textbox._textbox.tag_configure("RECEIVED_MAIN_TEXT_FONT", font=CTkFont(family=settings.FONT_FAMILY, size=16, weight="normal"))
target_textbox._textbox.tag_configure("RECEIVED_SECONDARY_TEXT_FONT", font=CTkFont(family=settings.FONT_FAMILY, size=12, weight="normal"))
FAKE_MARGIN = " "
# insert
target_textbox.configure(state="normal")
target_textbox.insert("end", "\n")
match (target_type):
case "SYSTEM":
target_textbox.insert("end", "System", ("SYSTEM_TAG", "SYSTEM_FOR_FIRST_INSERT", "JUSTIFY_CENTER"))
target_textbox.insert("end", FAKE_MARGIN+original_message+FAKE_MARGIN, ("SYSTEM_TEXT", "SYSTEM_TEXT_FONT", "JUSTIFY_CENTER"))
target_textbox.insert("end", now_hm, ("TIMESTAMP", "JUSTIFY_CENTER"))
case "SENT":
target_textbox.insert("end", now_hm, ("TIMESTAMP", "SENT_FOR_FIRST_INSERT", "JUSTIFY_RIGHT"))
target_textbox.insert("end", FAKE_MARGIN+"Sent", ("SENT_TAG"))
target_textbox.insert("end", "\n")
if is_only_one_message is False:
target_textbox.insert("end", original_message, ("SENT_SUB_TEXT", "SENT_SECONDARY_TEXT_FONT", "JUSTIFY_RIGHT"))
target_textbox.insert("end", "\n")
target_textbox.insert("end", translated_message, ("SENT_TEXT", "SENT_MAIN_TEXT_FONT", "JUSTIFY_RIGHT"))
# _actual_sent_message = "" if actual_sent_message is None else actual_sent_message
# target_textbox.insert("end", _actual_sent_message, ("SENT_TEXT", "SENT_MAIN_TEXT_FONT", "JUSTIFY_RIGHT"))
else:
target_textbox.insert("end", original_message, ("SENT_TEXT", "SENT_MAIN_TEXT_FONT", "JUSTIFY_RIGHT"))
case "RECEIVED":
target_textbox.insert("end", "Received", ("RECEIVED_TAG", "RECEIVED_FOR_FIRST_INSERT", "JUSTIFY_LEFT"))
target_textbox.insert("end", FAKE_MARGIN+now_hm, ("TIMESTAMP"))
if is_only_one_message is False:
target_textbox.insert("end", "\n")
target_textbox.insert("end", original_message, ("RECEIVED_SUB_TEXT", "RECEIVED_SECONDARY_TEXT_FONT"))
target_textbox.insert("end", "\n")
target_textbox.insert("end", translated_message, ("RECEIVED_TEXT", "RECEIVED_MAIN_TEXT_FONT", "JUSTIFY_LEFT"))
else:
target_textbox.insert("end", "\n")
target_textbox.insert("end", original_message, ("RECEIVED_TEXT", "RECEIVED_MAIN_TEXT_FONT", "JUSTIFY_LEFT"))
target_textbox.configure(state="disabled")
target_textbox.see("end")
printEachTextbox(target_textbox)
# To automatically print the same log to the textbox_all widget as well.
if disable_print_to_textbox_all is not True: printEachTextbox(vrct_gui.textbox_all)
# target_textbox.tag_config("ERROR", foreground="#FF0000")
# target_textbox.tag_config("SYSTEM", justify="center")
# target_textbox.tag_config("SYSTEM_TAG", foreground="#1BFF00")
# target_textbox.tag_config("SENT", justify="left")
# target_textbox.tag_config("SENT_COLOR", foreground="#0378e2")
# target_textbox.tag_config("RECEIVED", justify="left")
# target_textbox.tag_config("RECEIVED_COLOR", foreground="#ffa500")
# target_textbox.configure(state="normal")
# target_textbox.insert("end", f"[{tags}] ", ("START", "LABEL", tags, f"{tags}_COLOR"))
# target_textbox.insert("end", f"{now_hm} ", ("TIMESTAMP", tags))
# target_textbox.insert("end", f"{original_message}\n", ("SECONDARY_TEXT_FONT", "MAIN_TEXT_COLOR", tags))
# target_textbox.insert("end", f"{translated_message}\n", ("MAIN_TEXT_FONT", "MAIN_TEXT_COLOR", tags))
# target_textbox.configure(state="disabled")
# target_textbox.see("end")

View File

@@ -13,7 +13,7 @@ class ConfigWindow(CTkToplevel):
# configure window
self.after(200, lambda: self.iconbitmap(getImagePath("vrct_logo_mark_black.ico")))
self.title("test config_window.py")
self.title("Settings")
self.geometry(f"{1080}x{680}")

View File

@@ -145,12 +145,12 @@ def createTextbox(settings, main_window, view_variable):
corner_radius=settings.uism.TEXTBOX_CORNER_RADIUS,
fg_color=settings.ctm.TEXTBOX_BG_COLOR,
text_color="lime", # Textbox's text_color is set when printing. so this is for prevent from non-setting text_color like the gloves used in food factories are blue.
wrap="word",
))
textbox_widget = getattr(main_window, textbox_setting["textbox_attr_name"])
textbox_widget.grid(row=0, column=0, padx=settings.uism.TEXTBOX_PADX, pady=0, sticky="nsew")
textbox_widget.grid_remove()
textbox_widget.configure(state="disabled")
# print_textbox(main_window, textbox_widget, "send", textbox_setting["textbox_attr_name"], "SEND")
column+=1

View File

@@ -38,6 +38,7 @@ class ColorThemeManager():
self.DARK_200_COLOR = "#f1f2f6"
self.DARK_300_COLOR = "#e9eaee"
self.DARK_400_COLOR = "#c7c8cc"
self.DARK_450_COLOR = "#b8b9bd"
self.DARK_500_COLOR = "#a9aaae"
self.DARK_600_COLOR = "#7f8084"
self.DARK_700_COLOR = "#6a6c6f"
@@ -95,6 +96,13 @@ class ColorThemeManager():
self.main.TEXTBOX_BG_COLOR = self.DARK_900_COLOR
self.main.TEXTBOX_TEXT_COLOR = self.main.BASIC_TEXT_COLOR
self.main.TEXTBOX_TEXT_SUB_COLOR = self.DARK_450_COLOR
self.main.TEXTBOX_SYSTEM_TAG_TEXT_COLOR = self.PRIMARY_300_COLOR
self.main.TEXTBOX_SENT_TAG_TEXT_COLOR = "#6197b4"
self.main.TEXTBOX_RECEIVED_TAG_TEXT_COLOR = "#a861b4"
self.main.TEXTBOX_ERROR_TAG_TEXT_COLOR = "#c27583"
self.main.TEXTBOX_TIMESTAMP_TEXT_COLOR = self.DARK_600_COLOR
self.main.TEXTBOX_TAB_BG_PASSIVE_COLOR = self.DARK_850_COLOR
self.main.TEXTBOX_TAB_BG_ACTIVE_COLOR = self.main.TEXTBOX_BG_COLOR
self.main.TEXTBOX_TAB_BG_HOVERED_COLOR = self.DARK_800_COLOR

View File

@@ -125,29 +125,14 @@ class VRCT_GUI(CTk):
target_names=target_names,
)
def printToTextbox(self, target_type, original_message=None, translated_message=None):
match (target_type):
case "INFO":
target_textbox = self.textbox_system
case "SEND":
target_textbox = self.textbox_sent
case "RECEIVE":
target_textbox = self.textbox_received
case (_):
raise ValueError(f"No matching case for target_type: {target_type}")
def printToTextbox(self, target_type, original_message=None, translated_message=None, actual_sent_message=None):
_printToTextbox(
vrct_gui=self,
settings=self.settings.main,
target_textbox=target_textbox,
original_message=original_message,
translated_message=translated_message,
tags=target_type,
)
# To automatically print the same log to the textbox_all widget as well.
_printToTextbox(
settings=self.settings.main,
target_textbox=self.textbox_all,
target_type=target_type,
original_message=original_message,
translated_message=translated_message,
actual_sent_message=actual_sent_message,
tags=target_type,
)