diff --git a/DBC_Converter.py b/DBC_Converter.py index e7ebe96..821afc7 100644 --- a/DBC_Converter.py +++ b/DBC_Converter.py @@ -74,9 +74,14 @@ import json import subprocess import shutil # 파일 복사를 위해 shutil 모듈 추가 +# 전역 변수로 채널 정보와 파일 경로를 저장 +channel_info = {} +file_paths = [] + class MainView(QtWidgets.QMainWindow): def __init__(self): super().__init__() + global channel_info, file_paths if hasattr(sys, '_MEIPASS'): base_path = sys._MEIPASS # 실행 파일 내에서 파일 경로 설정 @@ -87,8 +92,8 @@ class MainView(QtWidgets.QMainWindow): self.setWindowIcon(QtGui.QIcon(icon_path)) # 프로그램 아이콘 설정 self.version = "1.0.0" # 프로그램 버전 설정 self.default_save_path = os.path.join(os.path.expanduser("~"), "Desktop") # 바탕화면 경로 설정 - self.file_paths = [] # 파일 경로 저장 리스트 - self.channel_info = {} # 채널 정보 초기화 + self.file_paths = file_paths # 파일 경로 저장 리스트 + self.channel_info = channel_info # 채널 정보 초기화 self.channel_options = ["CH0", "CH1", "CH2", "CH3", "CH4", "CH5"] # 채널 옵션 설정 self.loadSettings() # 설정 로드 self.setupUI(base_path) # UI 설정 @@ -98,15 +103,13 @@ class MainView(QtWidgets.QMainWindow): self.tree.itemSelectionChanged.connect(self.onFileSelectionChanged) def loadSettings(self): + global channel_info, file_paths self.settings_file = "settings.json" if os.path.exists(self.settings_file): with open(self.settings_file, "r", encoding="utf-8") as file: self.settings = json.load(file) # 설정 파일 로드 self.default_save_path = self.settings.get("default_save_path", os.path.join(os.path.expanduser("~"), "Desktop")) self.last_opened_dir = self.settings.get("last_opened_dir", os.path.expanduser("~")) - # JSON 파일 내의 file_paths와 channel_info 정보 지우기 - self.settings["file_paths"] = [] - self.settings["channel_info"] = {} self.saveSettings() else: self.settings = {"theme": "light"} # 기본 설정 @@ -114,6 +117,7 @@ class MainView(QtWidgets.QMainWindow): self.last_opened_dir = os.path.expanduser("~") def saveSettings(self): + global channel_info, file_paths self.settings["default_save_path"] = self.default_save_path self.settings["file_paths"] = self.file_paths self.settings["last_opened_dir"] = self.last_opened_dir @@ -356,6 +360,7 @@ class MainView(QtWidgets.QMainWindow): dialog.move(dialog_geometry.topLeft()) def FilesOpen(self): + global file_paths file_paths, _ = QtWidgets.QFileDialog.getOpenFileNames( self, "파일 열기", self.last_opened_dir, "DBC 파일 (*.dbc);;모든 파일 (*.*)" ) @@ -512,6 +517,7 @@ class MainView(QtWidgets.QMainWindow): self.alert_text.append("") # 한 줄 띄우기 def convertFiles(self): + global channel_info, file_paths if not self.file_paths: self.showWarning("경고", "변환할 파일이 없습니다") self.updateAlertText("변환 실패", ["변환할 파일이 없습니다"]) @@ -532,26 +538,26 @@ class MainView(QtWidgets.QMainWindow): os.makedirs(tx_output_dir, exist_ok=True) os.makedirs(common_output_dir, exist_ok=True) os.makedirs(dbc_output_dir, exist_ok=True) # DBC 파일 저장 경로 생성 - channel_info = self.settings.get("channel_info", {}).get(os.path.basename(file_path), "CH0") + channel = channel_info.get(os.path.basename(file_path), "CH0") try: shutil.copy(file_path, dbc_output_dir) # DBC 파일 복사 if hasattr(sys, '_MEIPASS'): script_path = os.path.join(sys._MEIPASS, "DBC_Converter_RX.py") else: script_path = "DBC_Converter_RX.py" - subprocess.run(["python", script_path, file_path, rx_output_dir, json.dumps({os.path.basename(file_path): channel_info})], check=True) + subprocess.run(["python", script_path, file_path, rx_output_dir, channel], check=True) if hasattr(sys, '_MEIPASS'): script_path = os.path.join(sys._MEIPASS, "DBC_Converter_TX.py") else: script_path = "DBC_Converter_TX.py" - subprocess.run(["python", script_path, file_path, tx_output_dir, json.dumps({os.path.basename(file_path): channel_info})], check=True) + subprocess.run(["python", script_path, file_path, tx_output_dir, channel], check=True) if hasattr(sys, '_MEIPASS'): script_path = os.path.join(sys._MEIPASS, "DBC_Converter_Common.py") else: script_path = "DBC_Converter_Common.py" - subprocess.run(["python", script_path, file_path, common_output_dir, json.dumps({os.path.basename(file_path): channel_info})], check=True) + subprocess.run(["python", script_path, file_path, common_output_dir, channel], check=True) self.updateAlertText(f"변환 성공", [file_path]) except subprocess.CalledProcessError as e: @@ -609,12 +615,10 @@ class MainView(QtWidgets.QMainWindow): dialog.close() def updateChannelInfo(self, directory, filename, channel): + global channel_info file_path = os.path.join(directory, filename) file_name = os.path.basename(file_path) - if "channel_info" not in self.settings: - self.settings["channel_info"] = {} - - self.settings["channel_info"][file_name] = channel + channel_info[file_name] = channel self.saveSettings() print(f"[INFO] Updated channel info for {file_name} to {channel}") @@ -623,8 +627,6 @@ class MainView(QtWidgets.QMainWindow): def onClose(self, event): self.file_paths = [] # 파일 경로 초기화 - self.settings["file_paths"] = [] # 설정 파일 경로 초기화 - self.settings["channel_info"] = {} # 채널 정보 초기화 self.saveSettings() # 설정 저장 event.accept() # 종료 이벤트 수락 diff --git a/DBC_Converter_RX.py b/DBC_Converter_RX.py index 81d423e..b92b09d 100644 --- a/DBC_Converter_RX.py +++ b/DBC_Converter_RX.py @@ -195,19 +195,17 @@ if __name__ == "__main__": output_dir = sys.argv[2] channel = sys.argv[3] - channel = json.loads(channel) - - if list(channel.values())[-1] == "CH0": + if channel == "CH0": channel = 0 - elif list(channel.values())[-1] == "CH1": + elif channel == "CH1": channel = 1 - elif list(channel.values())[-1] == "CH2": + elif channel == "CH2": channel = 2 - elif list(channel.values())[-1] == "CH3": + elif channel == "CH3": channel = 3 - elif list(channel.values())[-1] == "CH4": + elif channel == "CH4": channel = 4 - elif list(channel.values())[-1] == "CH5": + elif channel == "CH5": channel = 5 else: print("[ERROR] Invalid channel specified. Must be one of CH0, CH1, CH2, CH3, CH4, or CH5.") diff --git a/DBC_Converter_TX.py b/DBC_Converter_TX.py index e4f8142..6ecc9a1 100644 --- a/DBC_Converter_TX.py +++ b/DBC_Converter_TX.py @@ -173,19 +173,17 @@ if __name__ == "__main__": output_dir = sys.argv[2] channel = sys.argv[3] - channel = json.loads(channel) - - if list(channel.values())[-1] == "CH0": + if channel == "CH0": channel = 0 - elif list(channel.values())[-1] == "CH1": + elif channel == "CH1": channel = 1 - elif list(channel.values())[-1] == "CH2": + elif channel == "CH2": channel = 2 - elif list(channel.values())[-1] == "CH3": + elif channel == "CH3": channel = 3 - elif list(channel.values())[-1] == "CH4": + elif channel == "CH4": channel = 4 - elif list(channel.values())[-1] == "CH5": + elif channel == "CH5": channel = 5 else: print("[ERROR] Invalid channel specified. Must be one of CH0, CH1, CH2, CH3, CH4, or CH5.")