main.pyからview.pyにいくつか関数移動 続き(messageBoxPressKeyAnyは別の場所に移動になるので別のコミットに。それ以外は完了)
This commit is contained in:
85
main.py
85
main.py
@@ -11,12 +11,12 @@ def sendMicMessage(message):
|
|||||||
if len(message) > 0:
|
if len(message) > 0:
|
||||||
translation = ""
|
translation = ""
|
||||||
if model.checkKeywords(message):
|
if model.checkKeywords(message):
|
||||||
logDetectWordFilter(message)
|
view.printToTextbox_DetectedByWordFilter(detected_message=message)
|
||||||
return
|
return
|
||||||
elif config.ENABLE_TRANSLATION is False:
|
elif config.ENABLE_TRANSLATION is False:
|
||||||
pass
|
pass
|
||||||
elif model.getTranslatorStatus() is False:
|
elif model.getTranslatorStatus() is False:
|
||||||
logAuthenticationError()
|
view.printToTextbox_AuthenticationError()
|
||||||
else:
|
else:
|
||||||
translation = model.getInputTranslate(message)
|
translation = model.getInputTranslate(message)
|
||||||
|
|
||||||
@@ -29,9 +29,9 @@ def sendMicMessage(message):
|
|||||||
osc_message = message
|
osc_message = message
|
||||||
model.oscSendMessage(osc_message)
|
model.oscSendMessage(osc_message)
|
||||||
else:
|
else:
|
||||||
logOSCError()
|
view.printToTextbox_OSCError()
|
||||||
|
|
||||||
logSendMessage(message, translation)
|
view.printToTextbox_SentMessage(message, translation)
|
||||||
|
|
||||||
def startTranscriptionSendMessage():
|
def startTranscriptionSendMessage():
|
||||||
model.startMicTranscript(sendMicMessage)
|
model.startMicTranscript(sendMicMessage)
|
||||||
@@ -48,7 +48,7 @@ def receiveSpeakerMessage(message):
|
|||||||
if config.ENABLE_TRANSLATION is False:
|
if config.ENABLE_TRANSLATION is False:
|
||||||
pass
|
pass
|
||||||
elif model.getTranslatorStatus() is False:
|
elif model.getTranslatorStatus() is False:
|
||||||
logAuthenticationError()
|
view.printToTextbox_AuthenticationError()
|
||||||
else:
|
else:
|
||||||
translation = model.getOutputTranslate(message)
|
translation = model.getOutputTranslate(message)
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ def receiveSpeakerMessage(message):
|
|||||||
xsoverlay_message = config.MESSAGE_FORMAT.replace("[message]", message)
|
xsoverlay_message = config.MESSAGE_FORMAT.replace("[message]", message)
|
||||||
xsoverlay_message = xsoverlay_message.replace("[translation]", translation)
|
xsoverlay_message = xsoverlay_message.replace("[translation]", translation)
|
||||||
model.notificationXSOverlay(xsoverlay_message)
|
model.notificationXSOverlay(xsoverlay_message)
|
||||||
logReceiveMessage(message, translation)
|
view.printToTextbox_ReceivedMessage(message, translation)
|
||||||
|
|
||||||
def startTranscriptionReceiveMessage():
|
def startTranscriptionReceiveMessage():
|
||||||
model.startSpeakerTranscript(receiveSpeakerMessage)
|
model.startSpeakerTranscript(receiveSpeakerMessage)
|
||||||
@@ -74,7 +74,7 @@ def sendChatMessage(message):
|
|||||||
if config.ENABLE_TRANSLATION is False:
|
if config.ENABLE_TRANSLATION is False:
|
||||||
pass
|
pass
|
||||||
elif model.getTranslatorStatus() is False:
|
elif model.getTranslatorStatus() is False:
|
||||||
logAuthenticationError()
|
view.printToTextbox_AuthenticationError()
|
||||||
else:
|
else:
|
||||||
translation = model.getInputTranslate(message)
|
translation = model.getInputTranslate(message)
|
||||||
|
|
||||||
@@ -87,15 +87,14 @@ def sendChatMessage(message):
|
|||||||
osc_message = message
|
osc_message = message
|
||||||
model.oscSendMessage(osc_message)
|
model.oscSendMessage(osc_message)
|
||||||
else:
|
else:
|
||||||
logOSCError()
|
view.printToTextbox_OSCError()
|
||||||
|
|
||||||
# update textbox message log
|
# update textbox message log
|
||||||
logSendMessage(message, translation)
|
view.printToTextbox_SentMessage(message, translation)
|
||||||
|
|
||||||
# delete message in entry message box
|
# delete message in entry message box
|
||||||
if config.ENABLE_AUTO_CLEAR_CHATBOX is True:
|
if config.ENABLE_AUTO_CLEAR_CHATBOX is True:
|
||||||
entry_message_box = getattr(vrct_gui, "entry_message_box")
|
view.clearMessageBox()
|
||||||
entry_message_box.delete(0, customtkinter.END)
|
|
||||||
|
|
||||||
def messageBoxPressKeyEnter(e):
|
def messageBoxPressKeyEnter(e):
|
||||||
model.oscStopSendTyping()
|
model.oscStopSendTyping()
|
||||||
@@ -131,8 +130,7 @@ def setTargetLanguageAndCountry(select):
|
|||||||
|
|
||||||
def callbackSelectedTabNo1():
|
def callbackSelectedTabNo1():
|
||||||
config.SELECTED_TAB_NO = "1"
|
config.SELECTED_TAB_NO = "1"
|
||||||
vrct_gui.YOUR_LANGUAGE = config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO]
|
view.updateGuiVariableByPresetTabNo(config.SELECTED_TAB_NO)
|
||||||
vrct_gui.TARGET_LANGUAGE = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO]
|
|
||||||
languages = config.SELECTED_TAB_YOUR_LANGUAGES
|
languages = config.SELECTED_TAB_YOUR_LANGUAGES
|
||||||
select = languages[config.SELECTED_TAB_NO]
|
select = languages[config.SELECTED_TAB_NO]
|
||||||
language, country = model.getLanguageAndCountry(select)
|
language, country = model.getLanguageAndCountry(select)
|
||||||
@@ -147,8 +145,7 @@ def callbackSelectedTabNo1():
|
|||||||
|
|
||||||
def callbackSelectedTabNo2():
|
def callbackSelectedTabNo2():
|
||||||
config.SELECTED_TAB_NO = "2"
|
config.SELECTED_TAB_NO = "2"
|
||||||
vrct_gui.YOUR_LANGUAGE = config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO]
|
view.updateGuiVariableByPresetTabNo(config.SELECTED_TAB_NO)
|
||||||
vrct_gui.TARGET_LANGUAGE = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO]
|
|
||||||
languages = config.SELECTED_TAB_YOUR_LANGUAGES
|
languages = config.SELECTED_TAB_YOUR_LANGUAGES
|
||||||
select = languages[config.SELECTED_TAB_NO]
|
select = languages[config.SELECTED_TAB_NO]
|
||||||
language, country = model.getLanguageAndCountry(select)
|
language, country = model.getLanguageAndCountry(select)
|
||||||
@@ -163,8 +160,7 @@ def callbackSelectedTabNo2():
|
|||||||
|
|
||||||
def callbackSelectedTabNo3():
|
def callbackSelectedTabNo3():
|
||||||
config.SELECTED_TAB_NO = "3"
|
config.SELECTED_TAB_NO = "3"
|
||||||
vrct_gui.YOUR_LANGUAGE = config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO]
|
view.updateGuiVariableByPresetTabNo(config.SELECTED_TAB_NO)
|
||||||
vrct_gui.TARGET_LANGUAGE = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO]
|
|
||||||
languages = config.SELECTED_TAB_YOUR_LANGUAGES
|
languages = config.SELECTED_TAB_YOUR_LANGUAGES
|
||||||
select = languages[config.SELECTED_TAB_NO]
|
select = languages[config.SELECTED_TAB_NO]
|
||||||
language, country = model.getLanguageAndCountry(select)
|
language, country = model.getLanguageAndCountry(select)
|
||||||
@@ -177,37 +173,6 @@ def callbackSelectedTabNo3():
|
|||||||
config.TARGET_COUNTRY = country
|
config.TARGET_COUNTRY = country
|
||||||
config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE)
|
config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE)
|
||||||
|
|
||||||
# func print textbox
|
|
||||||
def logSendMessage(message, translate):
|
|
||||||
textbox_all = getattr(vrct_gui, "textbox_all")
|
|
||||||
textbox_sent = getattr(vrct_gui, "textbox_sent")
|
|
||||||
vrct_gui.printToTextbox(textbox_all, message, translate, "SEND")
|
|
||||||
vrct_gui.printToTextbox(textbox_sent, message, translate, "SEND")
|
|
||||||
|
|
||||||
def logReceiveMessage(message, translate):
|
|
||||||
textbox_all = getattr(vrct_gui, "textbox_all")
|
|
||||||
textbox_sent = getattr(vrct_gui, "textbox_received")
|
|
||||||
vrct_gui.printToTextbox(textbox_all, message, translate, "RECEIVE")
|
|
||||||
vrct_gui.printToTextbox(textbox_sent, message, translate, "RECEIVE")
|
|
||||||
|
|
||||||
def logDetectWordFilter(message):
|
|
||||||
textbox_all = getattr(vrct_gui, "textbox_all")
|
|
||||||
textbox_system = getattr(vrct_gui, "textbox_system")
|
|
||||||
vrct_gui.printToTextbox(textbox_all, f"Detect WordFilter :{message}", "", "INFO")
|
|
||||||
vrct_gui.printToTextbox(textbox_system, f"Detect WordFilter :{message}", "", "INFO")
|
|
||||||
|
|
||||||
def logAuthenticationError():
|
|
||||||
textbox_all = getattr(vrct_gui, "textbox_all")
|
|
||||||
textbox_system = getattr(vrct_gui, "textbox_system")
|
|
||||||
vrct_gui.printToTextbox(textbox_all, "Auth Key or language setting is incorrect", "", "INFO")
|
|
||||||
vrct_gui.printToTextbox(textbox_system, "Auth Key or language setting is incorrect", "", "INFO")
|
|
||||||
|
|
||||||
def logOSCError():
|
|
||||||
textbox_all = getattr(vrct_gui, "textbox_all")
|
|
||||||
textbox_system = getattr(vrct_gui, "textbox_system")
|
|
||||||
vrct_gui.printToTextbox(textbox_all, "OSC is not enabled, please enable OSC and rejoin", "", "INFO")
|
|
||||||
vrct_gui.printToTextbox(textbox_system, "OSC is not enabled, please enable OSC and rejoin", "", "INFO")
|
|
||||||
|
|
||||||
|
|
||||||
# command func
|
# command func
|
||||||
def callbackToggleTranslation():
|
def callbackToggleTranslation():
|
||||||
@@ -249,18 +214,18 @@ def callbackToggleForeground():
|
|||||||
config.ENABLE_FOREGROUND = view.getForegroundButtonStatus()
|
config.ENABLE_FOREGROUND = view.getForegroundButtonStatus()
|
||||||
if config.ENABLE_FOREGROUND is True:
|
if config.ENABLE_FOREGROUND is True:
|
||||||
view.printToTextbox_enableForeground()
|
view.printToTextbox_enableForeground()
|
||||||
vrct_gui.attributes("-topmost", True)
|
view.foregroundOn()
|
||||||
else:
|
else:
|
||||||
view.printToTextbox_disableForeground()
|
view.printToTextbox_disableForeground()
|
||||||
vrct_gui.attributes("-topmost", False)
|
view.foregroundOff()
|
||||||
|
|
||||||
# create GUI
|
# create GUI
|
||||||
vrct_gui.createGUI()
|
view.createGUI()
|
||||||
|
|
||||||
# init config
|
# init config
|
||||||
if model.authenticationTranslator() is False:
|
if model.authenticationTranslator() is False:
|
||||||
# error update Auth key
|
# error update Auth key
|
||||||
logAuthenticationError()
|
view.printToTextbox_AuthenticationError()
|
||||||
|
|
||||||
# set word filter
|
# set word filter
|
||||||
model.addKeywords()
|
model.addKeywords()
|
||||||
@@ -290,11 +255,17 @@ view.initializer(
|
|||||||
"callback_selected_tab_no_3": callbackSelectedTabNo3,
|
"callback_selected_tab_no_3": callbackSelectedTabNo3,
|
||||||
},
|
},
|
||||||
|
|
||||||
entry_message_box={
|
# 辞書型で関数を渡しても上手く行かず、仕方なくタプルで渡してる。
|
||||||
"bind_Return": messageBoxPressKeyEnter,
|
# 本当はコメントアウト(以下とview.py内33,34行目)しているようにできたらいいけど、
|
||||||
"bind_Any_KeyPress": messageBoxPressKeyAny,
|
# _tkinter.TclError: unknown option "-bind_Any_KeyPress"みたいにエラーがでる。
|
||||||
},
|
entry_message_box=None,
|
||||||
|
# entry_message_box={
|
||||||
|
# "bind_Return": messageBoxPressKeyEnter,
|
||||||
|
# "bind_Any_KeyPress": messageBoxPressKeyAny,
|
||||||
|
# },
|
||||||
|
entry_message_box_bind_Return=messageBoxPressKeyEnter,
|
||||||
|
entry_message_box_bind_Any_KeyPress=messageBoxPressKeyAny,
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
vrct_gui.startMainLoop()
|
view.startMainLoop()
|
||||||
74
view.py
74
view.py
@@ -1,14 +1,14 @@
|
|||||||
from customtkinter import StringVar
|
from customtkinter import StringVar, END as CTK_END
|
||||||
from vrct_gui import vrct_gui
|
from vrct_gui import vrct_gui
|
||||||
|
|
||||||
from config import config
|
from config import config
|
||||||
|
|
||||||
class view():
|
class View():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def initializer(self, sidebar_features, language_presets, entry_message_box):
|
def initializer(self, sidebar_features, language_presets, entry_message_box, entry_message_box_bind_Return, entry_message_box_bind_Any_KeyPress):
|
||||||
|
|
||||||
vrct_gui.CALLBACK_TOGGLE_TRANSLATION = sidebar_features["callback_toggle_translation"]
|
vrct_gui.CALLBACK_TOGGLE_TRANSLATION = sidebar_features["callback_toggle_translation"]
|
||||||
vrct_gui.CALLBACK_TOGGLE_TRANSCRIPTION_SEND = sidebar_features["callback_toggle_transcription_send"]
|
vrct_gui.CALLBACK_TOGGLE_TRANSCRIPTION_SEND = sidebar_features["callback_toggle_transcription_send"]
|
||||||
@@ -30,8 +30,11 @@ class view():
|
|||||||
|
|
||||||
|
|
||||||
entry_message_box = getattr(vrct_gui, "entry_message_box")
|
entry_message_box = getattr(vrct_gui, "entry_message_box")
|
||||||
entry_message_box.bind("<Return>", lambda: entry_message_box["bind_Return"])
|
# entry_message_box.bind("<Return>", lambda e: entry_message_box["bind_Return"](e))
|
||||||
entry_message_box.bind("<Any-KeyPress>", lambda: entry_message_box["bind_Any_KeyPress"])
|
# entry_message_box.bind("<Any-KeyPress>", lambda e: entry_message_box["bind_Any_KeyPress"](e))
|
||||||
|
entry_message_box.bind("<Return>", entry_message_box_bind_Return)
|
||||||
|
entry_message_box.bind("<Any-KeyPress>", entry_message_box_bind_Any_KeyPress)
|
||||||
|
|
||||||
entry_message_box.bind("<FocusIn>", self._foregroundOffForcefully)
|
entry_message_box.bind("<FocusIn>", self._foregroundOffForcefully)
|
||||||
entry_message_box.bind("<FocusOut>", self._foregroundOnForcefully)
|
entry_message_box.bind("<FocusOut>", self._foregroundOnForcefully)
|
||||||
|
|
||||||
@@ -45,15 +48,25 @@ class view():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _foregroundOffForcefully(self, _e):
|
|
||||||
if config.ENABLE_FOREGROUND:
|
|
||||||
vrct_gui.attributes("-topmost", False)
|
|
||||||
|
|
||||||
def _foregroundOnForcefully(self, _e):
|
def _foregroundOnForcefully(self, _e):
|
||||||
if config.ENABLE_FOREGROUND:
|
if config.ENABLE_FOREGROUND:
|
||||||
vrct_gui.attributes("-topmost", True)
|
self.foregroundOn()
|
||||||
|
|
||||||
|
def _foregroundOffForcefully(self, _e):
|
||||||
|
if config.ENABLE_FOREGROUND:
|
||||||
|
self.foregroundOff()
|
||||||
|
|
||||||
|
|
||||||
|
def foregroundOn(self):
|
||||||
|
vrct_gui.attributes("-topmost", True)
|
||||||
|
|
||||||
|
def foregroundOff(self):
|
||||||
|
vrct_gui.attributes("-topmost", False)
|
||||||
|
|
||||||
|
|
||||||
|
def updateGuiVariableByPresetTabNo(self, tab_no:str):
|
||||||
|
vrct_gui.YOUR_LANGUAGE = config.SELECTED_TAB_YOUR_LANGUAGES[tab_no]
|
||||||
|
vrct_gui.TARGET_LANGUAGE = config.SELECTED_TAB_TARGET_LANGUAGES[tab_no]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -88,14 +101,51 @@ class view():
|
|||||||
self._printToTextbox_Info("Stop foreground")
|
self._printToTextbox_Info("Stop foreground")
|
||||||
|
|
||||||
|
|
||||||
|
def printToTextbox_AuthenticationError(self):
|
||||||
|
self._printToTextbox_Info("Auth Key or language setting is incorrect")
|
||||||
|
|
||||||
|
def printToTextbox_OSCError(self):
|
||||||
|
self._printToTextbox_Info("OSC is not enabled, please enable OSC and rejoin")
|
||||||
|
|
||||||
|
def printToTextbox_DetectedByWordFilter(self, detected_message):
|
||||||
|
self._printToTextbox_Info(f"Detect WordFilter :{detected_message}")
|
||||||
|
|
||||||
|
|
||||||
def _printToTextbox_Info(self, info_message):
|
def _printToTextbox_Info(self, info_message):
|
||||||
vrct_gui.printToTextbox(vrct_gui.textbox_all, info_message, "", "INFO")
|
vrct_gui.printToTextbox(vrct_gui.textbox_all, info_message, "", "INFO")
|
||||||
vrct_gui.printToTextbox(vrct_gui.textbox_system, info_message, "", "INFO")
|
vrct_gui.printToTextbox(vrct_gui.textbox_system, info_message, "", "INFO")
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def printToTextbox_SentMessage(self, original_message, translated_message):
|
||||||
|
self._printToTextbox_Sent(original_message, translated_message)
|
||||||
|
|
||||||
|
def _printToTextbox_Sent(self, original_message, translated_message):
|
||||||
|
vrct_gui.printToTextbox(vrct_gui.textbox_all, original_message, translated_message, "SEND")
|
||||||
|
vrct_gui.printToTextbox(vrct_gui.textbox_sent, original_message, translated_message, "SEND")
|
||||||
|
|
||||||
|
|
||||||
|
def printToTextbox_ReceivedMessage(self, original_message, translated_message):
|
||||||
|
self._printToTextbox_Received(original_message, translated_message)
|
||||||
|
|
||||||
|
def _printToTextbox_Received(self, original_message, translated_message):
|
||||||
|
vrct_gui.printToTextbox(vrct_gui.textbox_all, original_message, translated_message, "RECEIVE")
|
||||||
|
vrct_gui.printToTextbox(vrct_gui.textbox_received, original_message, translated_message, "RECEIVE")
|
||||||
|
|
||||||
|
|
||||||
def getTextFromMessageBox(self):
|
def getTextFromMessageBox(self):
|
||||||
return vrct_gui.entry_message_box.get()
|
return vrct_gui.entry_message_box.get()
|
||||||
|
|
||||||
view = view()
|
def clearMessageBox(self):
|
||||||
|
vrct_gui.entry_message_box.delete(0, CTK_END)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def createGUI(self):
|
||||||
|
vrct_gui.createGUI()
|
||||||
|
|
||||||
|
def startMainLoop(self):
|
||||||
|
vrct_gui.startMainLoop()
|
||||||
|
|
||||||
|
view = View()
|
||||||
Reference in New Issue
Block a user