Skip to content

Commit d7402b1

Browse files
committed
Bumping version to 3.1.0, min libopenshot version to 0.3.1, adding new release to appdata.xml.
1 parent b1af290 commit d7402b1

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/windows/title_editor.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@
3333
import functools
3434
import subprocess
3535
import tempfile
36+
import threading
3637

3738
# TODO: Is there a defusedxml substitute for getDOMImplementation?
3839
# Is one even necessary, or is it safe to use xml.dom.minidom for that?
3940
from xml.dom import minidom
4041

41-
from PyQt5.QtCore import Qt, pyqtSlot, QTimer
42+
from PyQt5.QtCore import Qt, pyqtSlot, QTimer, pyqtSignal
4243
from PyQt5 import QtGui
4344
from PyQt5.QtWidgets import (
44-
QWidget, QGraphicsScene,
45+
QWidget,
4546
QMessageBox, QDialog, QColorDialog, QFontDialog,
4647
QPushButton, QLineEdit, QLabel
4748
)
@@ -63,6 +64,7 @@ class TitleEditor(QDialog):
6364

6465
# Path to ui file
6566
ui_path = os.path.join(info.PATH, 'windows', 'ui', 'title-editor.ui')
67+
thumbnailReady = pyqtSignal(object)
6668

6769
def __init__(self, *args, edit_file_path=None, duplicate=False, **kwargs):
6870

@@ -71,7 +73,7 @@ def __init__(self, *args, edit_file_path=None, duplicate=False, **kwargs):
7173

7274
# A timer to pause until user input stops before updating the svg
7375
self.update_timer = QTimer(self)
74-
self.update_timer.setInterval(300)
76+
self.update_timer.setInterval(50)
7577
self.update_timer.setSingleShot(True)
7678
self.update_timer.timeout.connect(self.save_and_reload)
7779

@@ -97,6 +99,7 @@ def __init__(self, *args, edit_file_path=None, duplicate=False, **kwargs):
9799
log.debug('Removing custom LD_LIBRARY_PATH from environment variables when launching Inkscape')
98100

99101
# Initialize variables
102+
self.is_thread_busy = False
100103
self.template_name = ""
101104
imp = minidom.getDOMImplementation()
102105
self.xmldoc = imp.createDocument(None, "any", None)
@@ -129,6 +132,9 @@ def __init__(self, *args, edit_file_path=None, duplicate=False, **kwargs):
129132
# Disable Save button on window load
130133
self.buttonBox.button(self.buttonBox.Save).setEnabled(False)
131134

135+
# Connect thumbnail listener
136+
self.thumbnailReady.connect(self.display_pixmap)
137+
132138
# If editing existing title svg file
133139
if self.edit_file_path:
134140
# Hide list of templates
@@ -143,6 +149,10 @@ def __init__(self, *args, edit_file_path=None, duplicate=False, **kwargs):
143149
# Display image (slight delay to allow screen to be shown first)
144150
QTimer.singleShot(50, self.display_svg)
145151

152+
def display_pixmap(self, display_pixmap):
153+
"""Display pixmap of SVG on UI thread"""
154+
self.lblPreviewLabel.setPixmap(display_pixmap)
155+
146156
def txtLine_changed(self, txtWidget):
147157

148158
# Loop through child widgets (and remove them)
@@ -194,7 +204,7 @@ def display_svg(self):
194204
display_pixmap = QtGui.QIcon(tmp_filename).pixmap(self.lblPreviewLabel.size())
195205

196206
# Display temp image
197-
self.lblPreviewLabel.setPixmap(display_pixmap)
207+
self.thumbnailReady.emit(display_pixmap)
198208

199209
# Remove temporary file
200210
os.unlink(tmp_filename)
@@ -375,8 +385,19 @@ def writeToFile(self, xmldoc):
375385

376386
def save_and_reload(self):
377387
"""Something changed, so update temp SVG and redisplay"""
388+
if not self.is_thread_busy:
389+
t = threading.Thread(target=self.save_and_reload_thread, daemon=True)
390+
t.start()
391+
else:
392+
# Keep retrying until we succeed
393+
self.update_timer.start()
394+
395+
def save_and_reload_thread(self):
396+
"""Run inside thread, to update and display new SVG - so we don't block the main UI thread"""
397+
self.is_thread_busy = True
378398
self.writeToFile(self.xmldoc)
379399
self.display_svg()
400+
self.is_thread_busy = False
380401

381402
@pyqtSlot(QtGui.QColor)
382403
def color_callback(self, save_fn, refresh_fn, color):

0 commit comments

Comments
 (0)