Skip to content

Commit

Permalink
Load Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tlsharkey committed May 5, 2021
1 parent b5cff98 commit 43209e8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Qt_Interface/BlurObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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




Expand Down Expand Up @@ -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"])


36 changes: 36 additions & 0 deletions Qt_Interface/Sidebar.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

0 comments on commit 43209e8

Please sign in to comment.