diff --git a/source/carla_backend_qt.py b/source/carla_backend_qt.py index e960dcc88..7a7230aeb 100644 --- a/source/carla_backend_qt.py +++ b/source/carla_backend_qt.py @@ -74,6 +74,7 @@ class CarlaHostSignals(QObject): TransportModeChangedCallback = pyqtSignal(int) BufferSizeChangedCallback = pyqtSignal(int) SampleRateChangedCallback = pyqtSignal(float) + ProjectLoadFinishedCallback = pyqtSignal() NSMCallback = pyqtSignal(int, int, str) InfoCallback = pyqtSignal(str) ErrorCallback = pyqtSignal(str) diff --git a/source/carla_host.py b/source/carla_host.py index 9d7bbbfd9..2797df3dd 100644 --- a/source/carla_host.py +++ b/source/carla_host.py @@ -466,6 +466,7 @@ class HostWindow(QMainWindow): host.EngineStartedCallback.connect(self.slot_handleEngineStartedCallback) host.EngineStoppedCallback.connect(self.slot_handleEngineStoppedCallback) host.SampleRateChangedCallback.connect(self.slot_handleSampleRateChangedCallback) + host.ProjectLoadFinishedCallback.connect(self.slot_handleProjectLoadFinishedCallback) host.PluginAddedCallback.connect(self.slot_handlePluginAddedCallback) host.PluginRemovedCallback.connect(self.slot_handlePluginRemovedCallback) @@ -557,6 +558,9 @@ class HostWindow(QMainWindow): # -------------------------------------------------------------------------------------------------------- # Files + def makeExtraFilename(self): + return self.fProjectFilename.rsplit(".",1)[0]+".json" + def loadProjectNow(self): if not self.fProjectFilename: return qCritical("ERROR: loading project without filename set") @@ -565,11 +569,9 @@ class HostWindow(QMainWindow): self.projectLoadingStarted() self.fIsProjectLoading = True - self.host.load_project(self.fProjectFilename) - self.fIsProjectLoading = False - self.projectLoadingFinished() + # Project finished loading is sent by engine def loadProjectLater(self, filename): self.fProjectFilename = QFileInfo(filename).absoluteFilePath() @@ -582,6 +584,11 @@ class HostWindow(QMainWindow): self.host.save_project(self.fProjectFilename) + with open(self.makeExtraFilename(), 'w') as fh: + json.dump({ + 'canvas': patchcanvas.saveGroupPositions(), + }, fh) + def projectLoadingStarted(self): self.ui.rack.setEnabled(False) self.ui.graphicsView.setEnabled(False) @@ -591,6 +598,18 @@ class HostWindow(QMainWindow): self.ui.graphicsView.setEnabled(True) QTimer.singleShot(1000, self.slot_canvasRefresh) + extrafile = self.makeExtraFilename() + if not os.path.exists(extrafile): + return + + try: + with open(extrafile, "r") as fh: + canvasdata = json.load(fh)['canvas'] + except: + return + + patchcanvas.restoreGroupPositions(canvasdata) + # -------------------------------------------------------------------------------------------------------- # Files (menu actions) @@ -803,6 +822,11 @@ class HostWindow(QMainWindow): self.fSampleRate = newSampleRate self.refreshTransport(True) + @pyqtSlot() + def slot_handleProjectLoadFinishedCallback(self): + self.fIsProjectLoading = False + self.projectLoadingFinished() + # -------------------------------------------------------------------------------------------------------- # Plugins @@ -2346,6 +2370,8 @@ def engineCallback(host, action, pluginId, value1, value2, value3, valueStr): host.BufferSizeChangedCallback.emit(value1) elif action == ENGINE_CALLBACK_SAMPLE_RATE_CHANGED: host.SampleRateChangedCallback.emit(value3) + elif action == ENGINE_CALLBACK_PROJECT_LOAD_FINISHED: + host.ProjectLoadFinishedCallback.emit() elif action == ENGINE_CALLBACK_NSM: host.NSMCallback.emit(value1, value2, valueStr) elif action == ENGINE_CALLBACK_IDLE: diff --git a/source/patchcanvas.py b/source/patchcanvas.py index 0f814ab3a..7d149a498 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -756,6 +756,52 @@ def getGroupPos(group_id, port_mode=PORT_MODE_OUTPUT): qCritical("PatchCanvas::getGroupPos(%i, %s) - unable to find group" % (group_id, port_mode2str(port_mode))) return QPointF(0, 0) +def saveGroupPositions(): + if canvas.debug: + print("PatchCanvas::getGroupPositions()") + + ret = [] + + for group in canvas.group_list: + if group.split: + pos1 = group.widgets[0].pos() + pos2 = group.widgets[1].pos() + else: + pos1 = group.widgets[0].pos() + pos2 = QPointF(0, 0) + + ret.append({ + "name" : group.group_name, + "pos1x": pos1.x(), + "pos1y": pos1.y(), + "pos2x": pos2.x(), + "pos2y": pos2.y(), + "split": group.split, + }) + + return ret + +def restoreGroupPositions(dataList): + if canvas.debug: + print("PatchCanvas::restoreGroupPositions(...)") + + map = {} + + for group in canvas.group_list: + map[group.group_name] = group + + for data in dataList: + name = data['name'] + group = map.get(name, None) + + if group is None: + continue + + group.widgets[0].setPos(data['pos1x'], data['pos1y']) + + if group.split and group.widgets[1]: + group.widgets[1].setPos(data['pos2x'], data['pos2y']) + def setGroupPos(group_id, group_pos_x, group_pos_y): setGroupPosFull(group_id, group_pos_x, group_pos_y, group_pos_x, group_pos_y)