diff --git a/Qt_Interface/BlurObject.py b/Qt_Interface/BlurObject.py index 238a543..3c0a398 100644 --- a/Qt_Interface/BlurObject.py +++ b/Qt_Interface/BlurObject.py @@ -112,6 +112,17 @@ def serialize(self): return out + @staticmethod + def deserialize(data, videoWidget): + strand = BlurStrand(videoWidget.video, videoWidget.video_resolution) + points = [] + for point in data["points"]: + points.append(BlurPoint.deserialize(point)) + + strand.__points = points + strand.complete(False) + return strand + @@ -202,4 +213,8 @@ def serialize(self): "resolution": self.resolution } + @staticmethod + def deserialize(data): + return BlurPoint(data["frame"], (data["x"], data["y"]), data["size"], data["resolution"]) + \ No newline at end of file diff --git a/Qt_Interface/Sidebar.py b/Qt_Interface/Sidebar.py index 0f96425..29f0d48 100644 --- a/Qt_Interface/Sidebar.py +++ b/Qt_Interface/Sidebar.py @@ -1,6 +1,7 @@ from PyQt5.QtGui import QKeySequence from Video import VideoWidget +from BlurObject import * from PyQt5.QtCore import QDir from PyQt5.QtWidgets import QDockWidget, QFileDialog, QShortcut, QVBoxLayout, QPushButton, QWidget from PyQt5.QtCore import Qt @@ -33,6 +34,11 @@ def __init__(self, parent, video_blurring_window): self.saveButton.clicked.connect(self.save) self.layout().addWidget(self.saveButton) + self.loadButton = QPushButton() + self.loadButton.setText("Load Session") + self.loadButton.clicked.connect(self.openFile) + self.layout().addWidget(self.loadButton) + self.saveShortcut = QShortcut(QKeySequence('Ctrl+S'), self) self.saveShortcut.activated.connect(self.save) @@ -116,3 +122,33 @@ def save(self): with open(self.__save_location, "w") as file: file.write(json.dumps(data)) + def openFile(self): + path, _ = QFileDialog.getOpenFileName(None, "Load", QDir.currentPath(), "Video Blur File (*.vibf)") + if (not path): # user cancels selection + return + + # Remove existing videos + for widget in VideoWidget.Widgets: + widget.deleteLater() + + self.__save_location = path + self.saveButton.setText("Save") + + with open(path, "r") as file: + lines = file.readlines() + filetext = "".join(lines) + data = json.loads(filetext) + + for video in data["videos"]: + # Load Video to UI + widget = self._load(self, video["name"]) + if (isinstance(widget, QDockWidget)): + self.videoSpace.addDockWidget(Qt.LeftDockWidgetArea, widget) + else: + self.videoSpace.layout().addWidget(widget) + + # Load blurstrands + print(video.keys()) + for strand in video["blurstrands"]: + BlurStrand.deserialize(strand, widget) +