Skip to content

Commit 62817dc

Browse files
authored
Merge pull request #3520 from ferdnyc/title-tmp-pollution
Titles: Don't pollute temp dir with title previews
2 parents 8e1b175 + c6ffe3c commit 62817dc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/windows/title_editor.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ def txtLine_changed(self, txtWidget):
151151

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

157157
# Create a clip object and get the reader
158158
clip = openshot.Clip(self.filename)
@@ -161,7 +161,7 @@ def display_svg(self):
161161
# Open reader
162162
reader.Open()
163163

164-
# Save thumbnail image and close readers
164+
# Overwrite temp file with thumbnail image and close readers
165165
reader.GetFrame(1).Thumbnail(
166166
tmp_filename,
167167
self.graphicsView.width(),
@@ -170,15 +170,23 @@ def display_svg(self):
170170
reader.Close()
171171
clip.Close()
172172

173+
# Attempt to load saved thumbnail
174+
svg = QtGui.QPixmap()
175+
if not svg.load(tmp_filename):
176+
log.error("Couldn't load title preview from {}".format(tmp_filename))
177+
return
178+
173179
# Display temp image
174180
scene = QGraphicsScene(self)
175181
view = self.graphicsView
176-
svg = QtGui.QPixmap(tmp_filename)
177182
svg_scaled = svg.scaled(self.graphicsView.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
178183
scene.addPixmap(svg_scaled)
179184
view.setScene(scene)
180185
view.show()
181186

187+
# Remove temporary file
188+
os.unlink(tmp_filename)
189+
182190
def create_temp_title(self, template_path):
183191

184192
# Set temp file path

0 commit comments

Comments
 (0)