From cbe98f652dd97a68008291fd05d66376f4340907 Mon Sep 17 00:00:00 2001 From: AccentuSoft Date: Tue, 20 Sep 2022 18:14:50 +0300 Subject: [PATCH] Fix error when renaming project. --- Core/Interface/CentralPane.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Core/Interface/CentralPane.py b/Core/Interface/CentralPane.py index 7c833fd..2babfc1 100644 --- a/Core/Interface/CentralPane.py +++ b/Core/Interface/CentralPane.py @@ -194,14 +194,17 @@ class TabbedPane(QtWidgets.QTabWidget): self.syncedTabs = [] self.nodeCreationThreads = [] - self.canvasDBPath = Path( - self.mainWindow.SETTINGS.value("Project/BaseDir")) / "Project Files" / "CanvasTabs.lscanvas" - self.tabsNotesPath = Path(self.mainWindow.SETTINGS.value("Project/FilesDir")).joinpath("CanvasNotes.lsnotes") self.tabsNotesDict = {} self.previousTab = None self.currentChanged.connect(self.currentTabChangedListener) + def getCanvasDBPath(self): + return Path(self.mainWindow.SETTINGS.value("Project/BaseDir")) / "Project Files" / "CanvasTabs.lscanvas" + + def getTabsNotesPath(self): + return Path(self.mainWindow.SETTINGS.value("Project/FilesDir")).joinpath("CanvasNotes.lsnotes") + def addCanvas(self, canvasName='New Graph', graph=None, positions=None, a=0, b=0, c=0, d=0) -> bool: if not self.isCanvasNameAvailable(canvasName): return False @@ -603,8 +606,10 @@ class TabbedPane(QtWidgets.QTabWidget): if len(self.canvasTabs) == 0: return - canvasDBPathTmp = self.canvasDBPath.with_suffix(self.canvasDBPath.suffix + '.tmp') - canvasNotesPathTmp = self.tabsNotesPath.with_suffix(self.tabsNotesPath.suffix + '.tmp') + canvasDBPath = self.getCanvasDBPath() + tabsNotesPath = self.getTabsNotesPath() + canvasDBPathTmp = canvasDBPath.with_suffix(canvasDBPath.suffix + '.tmp') + canvasNotesPathTmp = tabsNotesPath.with_suffix(tabsNotesPath.suffix + '.tmp') # Save canvases with open(canvasDBPathTmp, "wb") as canvasDBFile: @@ -614,7 +619,7 @@ class TabbedPane(QtWidgets.QTabWidget): self.resourceHandler.deconstructGraphForFileDump(self.canvasTabs[canvasName].scene().sceneGraph), self.canvasTabs[canvasName].scene().scenePos] dump(saveJson, canvasDBFile) - move(canvasDBPathTmp, self.canvasDBPath) + move(canvasDBPathTmp, canvasDBPath) # Save canvas notes currIndex = self.currentIndex() @@ -624,11 +629,12 @@ class TabbedPane(QtWidgets.QTabWidget): self.tabsNotesDict[canvasTabName] = self.mainWindow.dockbarTwo.getNotesText() with open(canvasNotesPathTmp, "wb") as canvasNotesFileTmp: dump(self.tabsNotesDict, canvasNotesFileTmp) - move(canvasNotesPathTmp, self.tabsNotesPath) + move(canvasNotesPathTmp, tabsNotesPath) def open(self) -> None: + tabsNotesPath = self.getTabsNotesPath() try: - with open(self.tabsNotesPath, 'rb') as notesFile: + with open(tabsNotesPath, 'rb') as notesFile: # Load the content into the Notes pane. self.tabsNotesDict = load(notesFile) except ValueError: @@ -637,15 +643,16 @@ class TabbedPane(QtWidgets.QTabWidget): except FileNotFoundError: # Create new placeholder notes file if it doesn't exist. try: - self.tabsNotesPath.touch(0o700, exist_ok=False) + tabsNotesPath.touch(0o700, exist_ok=False) self.mainWindow.MESSAGEHANDLER.info('Created new Tab Notes file.') except FileExistsError: self.mainWindow.MESSAGEHANDLER.error('Race condition occurred while trying to create ' 'Tab Notes file.') - if Path(self.canvasDBPath).exists(): + canvasDBPath = self.getCanvasDBPath() + if Path(canvasDBPath).exists(): try: - with open(self.canvasDBPath, "rb") as canvasDBFile: + with open(canvasDBPath, "rb") as canvasDBFile: savedJson = load(canvasDBFile) for canvasName in savedJson: self.addCanvas(canvasName,