Main Window: Sidebar features系のCALLBACK変数をview.pyに移動。処理もリファクタリング。

そのCALLBACK関数の引数でTrue/Falseの値を受け取れるようになったので、view.pyが提供していたgetButtonStatus系関数も削除。
This commit is contained in:
Sakamoto Shiina
2023-09-02 03:42:06 +09:00
parent 66413a60dd
commit cc94added0
5 changed files with 35 additions and 47 deletions

16
main.py
View File

@@ -169,16 +169,16 @@ def callbackSelectedTabNo3():
# command func
def callbackToggleTranslation():
config.ENABLE_TRANSLATION = view.getTranslationButtonStatus()
def callbackToggleTranslation(is_turned_on):
config.ENABLE_TRANSLATION = is_turned_on
if config.ENABLE_TRANSLATION is True:
view.printToTextbox_enableTranslation()
else:
view.printToTextbox_disableTranslation()
def callbackToggleTranscriptionSend():
def callbackToggleTranscriptionSend(is_turned_on):
view.setMainWindowAllWidgetsStatusToDisabled()
config.ENABLE_TRANSCRIPTION_SEND = view.getTranscriptionSendButtonStatus()
config.ENABLE_TRANSCRIPTION_SEND = is_turned_on
if config.ENABLE_TRANSCRIPTION_SEND is True:
view.printToTextbox_enableTranscriptionSend()
th_startTranscriptionSendMessage = Thread(target=startTranscriptionSendMessage)
@@ -190,9 +190,9 @@ def callbackToggleTranscriptionSend():
th_stopTranscriptionSendMessage.daemon = True
th_stopTranscriptionSendMessage.start()
def callbackToggleTranscriptionReceive():
def callbackToggleTranscriptionReceive(is_turned_on):
view.setMainWindowAllWidgetsStatusToDisabled()
config.ENABLE_TRANSCRIPTION_RECEIVE = view.getTranscriptionReceiveButtonStatus()
config.ENABLE_TRANSCRIPTION_RECEIVE = is_turned_on
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
view.printToTextbox_enableTranscriptionReceive()
th_startTranscriptionReceiveMessage = Thread(target=startTranscriptionReceiveMessage)
@@ -204,8 +204,8 @@ def callbackToggleTranscriptionReceive():
th_stopTranscriptionReceiveMessage.daemon = True
th_stopTranscriptionReceiveMessage.start()
def callbackToggleForeground():
config.ENABLE_FOREGROUND = view.getForegroundButtonStatus()
def callbackToggleForeground(is_turned_on):
config.ENABLE_FOREGROUND = is_turned_on
if config.ENABLE_FOREGROUND is True:
view.printToTextbox_enableForeground()
view.foregroundOn()

21
view.py
View File

@@ -37,6 +37,18 @@ class View():
)
self.view_variable = SimpleNamespace(
# Main Window
CALLBACK_TOGGLE_TRANSLATION=None,
CALLBACK_TOGGLE_TRANSCRIPTION_SEND=None,
CALLBACK_TOGGLE_TRANSCRIPTION_RECEIVE=None,
CALLBACK_TOGGLE_FOREGROUND=None,
# CALLBACK_SELECTED_TAB_NO_1=None,
# CALLBACK_SELECTED_TAB_NO_2=None,
# CALLBACK_SELECTED_TAB_NO_3=None,
# Config Window
# Appearance Tab
VAR_LABEL_TRANSPARENCY=StringVar(value="Transparency"),
@@ -310,15 +322,6 @@ class View():
def getTranslationButtonStatus(self):
return vrct_gui.translation_switch_box.get()
def getTranscriptionSendButtonStatus(self):
return vrct_gui.transcription_send_switch_box.get()
def getTranscriptionReceiveButtonStatus(self):
return vrct_gui.transcription_receive_switch_box.get()
def getForegroundButtonStatus(self):
return vrct_gui.foreground_switch_box.get()
def printToTextbox_enableTranslation(self):
self._printToTextbox_Info("翻訳機能をONにしました")

View File

@@ -5,7 +5,7 @@ from customtkinter import CTkFrame
from ..ui_utils import createButtonWithImage, getImagePath
def createMainWindowWidgets(vrct_gui, settings, view_variable):
def createMainWindowWidgets(vrct_gui, settings):
vrct_gui.protocol("WM_DELETE_WINDOW", vrct_gui.quitVRCT)
# self.IS_DEVELOPER_MODE = False

View File

@@ -2,48 +2,33 @@ from customtkinter import CTkOptionMenu, CTkFont, CTkFrame, CTkLabel, CTkSwitch,
from ...ui_utils import getImageFileFromUiUtils, openImageKeepAspectRatio, retag, getLatestHeight, bindEnterAndLeaveColor, bindButtonPressColor, bindEnterAndLeaveFunction, bindButtonReleaseFunction, bindButtonPressAndReleaseFunction, bindButtonFunctionAndColor, switchActiveTabAndPassiveTab, switchTabsColor
from time import sleep
from utils import callFunctionIfCallable
def createSidebar(settings, main_window):
from vrct_gui import vrct_gui
changeMainWindowWidgetsStatus = vrct_gui.changeMainWindowWidgetsStatus
def toggleSidebarFeatureSelectedMarkIfTurnedOn(is_turned_on, mark):
mark.place(relx=0.85) if is_turned_on else mark.place(relx=-1)
def toggleTranslationFeature():
if callable(main_window.CALLBACK_TOGGLE_TRANSLATION) is True:
main_window.CALLBACK_TOGGLE_TRANSLATION()
is_turned_on = getattr(main_window, "translation_switch_box").get()
print(is_turned_on)
is_turned_on = main_window.translation_switch_box.get()
callFunctionIfCallable(main_window.CALLBACK_TOGGLE_TRANSLATION, is_turned_on)
toggleSidebarFeatureSelectedMarkIfTurnedOn(is_turned_on, main_window.translation_selected_mark)
def toggleTranscriptionSendFeature():
if callable(main_window.CALLBACK_TOGGLE_TRANSCRIPTION_SEND) is True:
main_window.CALLBACK_TOGGLE_TRANSCRIPTION_SEND()
is_turned_on = getattr(main_window, "transcription_send_switch_box").get()
print(is_turned_on)
is_turned_on = main_window.transcription_send_switch_box.get()
callFunctionIfCallable(main_window.CALLBACK_TOGGLE_TRANSCRIPTION_SEND, is_turned_on)
toggleSidebarFeatureSelectedMarkIfTurnedOn(is_turned_on, main_window.transcription_send_selected_mark)
def toggleTranscriptionReceiveFeature():
if callable(main_window.CALLBACK_TOGGLE_TRANSCRIPTION_RECEIVE) is True:
main_window.CALLBACK_TOGGLE_TRANSCRIPTION_RECEIVE()
is_turned_on = getattr(main_window, "transcription_receive_switch_box").get()
print(is_turned_on)
is_turned_on = main_window.transcription_receive_switch_box.get()
callFunctionIfCallable(main_window.CALLBACK_TOGGLE_TRANSCRIPTION_RECEIVE, is_turned_on)
toggleSidebarFeatureSelectedMarkIfTurnedOn(is_turned_on, main_window.transcription_receive_selected_mark)
def toggleForegroundFeature():
if callable(main_window.CALLBACK_TOGGLE_FOREGROUND) is True:
main_window.CALLBACK_TOGGLE_FOREGROUND()
is_turned_on = getattr(main_window, "foreground_switch_box").get()
print(is_turned_on)
is_turned_on = main_window.foreground_switch_box.get()
callFunctionIfCallable(main_window.CALLBACK_TOGGLE_FOREGROUND, is_turned_on)
toggleSidebarFeatureSelectedMarkIfTurnedOn(is_turned_on, main_window.foreground_selected_mark)

View File

@@ -20,10 +20,10 @@ class VRCT_GUI(CTk):
self.YOUR_LANGUAGE = "Japanese\n(Japan)"
self.TARGET_LANGUAGE = "English\n(United States)"
self.CALLBACK_TOGGLE_TRANSLATION = None
self.CALLBACK_TOGGLE_TRANSCRIPTION_SEND = None
self.CALLBACK_TOGGLE_TRANSCRIPTION_RECEIVE = None
self.CALLBACK_TOGGLE_FOREGROUND = None
# self.CALLBACK_TOGGLE_TRANSLATION = None
# self.CALLBACK_TOGGLE_TRANSCRIPTION_SEND = None
# self.CALLBACK_TOGGLE_TRANSCRIPTION_RECEIVE = None
# self.CALLBACK_TOGGLE_FOREGROUND = None
self.CALLBACK_SELECTED_TAB_NO_1 = None
self.CALLBACK_SELECTED_TAB_NO_2 = None
self.CALLBACK_SELECTED_TAB_NO_3 = None
@@ -33,7 +33,7 @@ class VRCT_GUI(CTk):
self.settings = settings
self.view_variable = view_variable
createMainWindowWidgets(vrct_gui=self, settings=self.settings.main, view_variable=self.view_variable)
createMainWindowWidgets(vrct_gui=self, settings=self.settings.main)
self.config_window = ConfigWindow(vrct_gui=self, settings=self.settings.config_window, view_variable=self.view_variable)
# self.information_window = ToplevelWindowInformation(self)