Skip to content

Commit

Permalink
Merge pull request #3520 from ferdnyc/title-tmp-pollution
Browse files Browse the repository at this point in the history
Titles: Don't pollute temp dir with title previews
  • Loading branch information
jonoomph authored May 28, 2020
2 parents 8e1b175 + c6ffe3c commit 62817dc
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/windows/title_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def txtLine_changed(self, txtWidget):

def display_svg(self):
# Create a temp file for this thumbnail image
new_file, tmp_filename = tempfile.mkstemp()
tmp_filename = "%s.png" % tmp_filename
new_file, tmp_filename = tempfile.mkstemp(suffix=".png")
os.close(new_file)

# Create a clip object and get the reader
clip = openshot.Clip(self.filename)
Expand All @@ -161,7 +161,7 @@ def display_svg(self):
# Open reader
reader.Open()

# Save thumbnail image and close readers
# Overwrite temp file with thumbnail image and close readers
reader.GetFrame(1).Thumbnail(
tmp_filename,
self.graphicsView.width(),
Expand All @@ -170,15 +170,23 @@ def display_svg(self):
reader.Close()
clip.Close()

# Attempt to load saved thumbnail
svg = QtGui.QPixmap()
if not svg.load(tmp_filename):
log.error("Couldn't load title preview from {}".format(tmp_filename))
return

# Display temp image
scene = QGraphicsScene(self)
view = self.graphicsView
svg = QtGui.QPixmap(tmp_filename)
svg_scaled = svg.scaled(self.graphicsView.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
scene.addPixmap(svg_scaled)
view.setScene(scene)
view.show()

# Remove temporary file
os.unlink(tmp_filename)

def create_temp_title(self, template_path):

# Set temp file path
Expand Down

0 comments on commit 62817dc

Please sign in to comment.