35 from xml.dom
import minidom
38 from PyQt5.QtGui import QIcon, QStandardItemModel, QStandardItem, QFont
40 from PyQt5
import uic, QtSvg, QtGui
41 from PyQt5.QtWebKitWidgets
import QWebView
44 from classes
import info, ui_util, settings, qt_types, updates
45 from classes.logger
import log
46 from classes.app
import get_app
47 from classes.query
import File
49 from windows.views.titles_listview
import TitlesListView
54 import simplejson
as json
62 ui_path = os.path.join(info.PATH,
'windows',
'ui',
'title-editor.ui')
64 def __init__(self, edit_file_path=None, duplicate=False):
67 QDialog.__init__(self)
88 imp = minidom.getDOMImplementation()
89 self.
xmldoc = imp.createDocument(
None,
"any",
None)
116 self.widget.setVisible(
False)
131 for child
in self.settingsContainer.children():
132 if type(child) == QTextEdit
and child.objectName() !=
"txtFileName":
133 text_list.append(child.toPlainText())
137 if len(self.
tspan_node[i].childNodes) > 0
and i <= (len(text_list) - 1):
138 new_text_node = self.xmldoc.createTextNode(text_list[i])
139 old_text_node = self.
tspan_node[i].childNodes[0]
151 scene = QGraphicsScene(self)
152 view = self.graphicsView
154 svg_scaled = svg.scaled(self.graphicsView.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
155 scene.addPixmap(svg_scaled)
162 self.
filename = os.path.join(info.TITLE_PATH,
"temp.svg")
165 shutil.copy(template_path, self.
filename)
180 self.
tspan_node = self.xmldoc.getElementsByTagName(
'tspan')
184 for child
in self.settingsContainer.children():
186 self.settingsContainer.layout().removeWidget(child)
192 self.
text_node = self.xmldoc.getElementsByTagName(
'text')
193 self.
rect_node = self.xmldoc.getElementsByTagName(
'rect')
197 label_line_text = _(
"File Name:")
198 label.setText(label_line_text)
199 label.setToolTip(label_line_text)
203 self.txtFileName.setObjectName(
"txtFileName")
209 self.txtFileName.setEnabled(
False)
212 for i
in range(1, 1000):
213 possible_path = os.path.join(info.ASSETS_PATH,
"%s.svg" % _(
"TitleFileName-%d") % i)
214 if not os.path.exists(possible_path):
215 self.txtFileName.setText(_(
"TitleFileName-%d") % i)
217 self.txtFileName.setFixedHeight(28)
218 self.settingsContainer.layout().addRow(label, self.
txtFileName)
225 title_text.append(text)
229 label_line_text = _(
"Line %s:") % str(i + 1)
230 label.setText(label_line_text)
231 label.setToolTip(label_line_text)
235 widget.setText(_(text))
236 widget.setFixedHeight(28)
237 widget.textChanged.connect(functools.partial(self.
txtLine_changed, widget))
238 self.settingsContainer.layout().addRow(label, widget)
243 label.setText(_(
"Font:"))
244 label.setToolTip(_(
"Font:"))
246 self.btnFont.setText(_(
"Change Font"))
247 self.settingsContainer.layout().addRow(label, self.
btnFont)
252 label.setText(_(
"Text:"))
253 label.setToolTip(_(
"Text:"))
255 self.btnFontColor.setText(_(
"Text Color"))
256 self.settingsContainer.layout().addRow(label, self.
btnFontColor)
261 label.setText(_(
"Background:"))
262 label.setToolTip(_(
"Background:"))
264 self.btnBackgroundColor.setText(_(
"Background Color"))
270 label.setText(_(
"Advanced:"))
271 label.setToolTip(_(
"Advanced:"))
273 self.btnAdvanced.setText(_(
"Use Advanced Editor"))
274 self.settingsContainer.layout().addRow(label, self.
btnAdvanced)
282 if len(title_text) >= 1:
283 self.btnFont.setEnabled(
True)
284 self.btnFontColor.setEnabled(
True)
285 self.btnBackgroundColor.setEnabled(
True)
286 self.btnAdvanced.setEnabled(
True)
288 self.btnFont.setEnabled(
False)
289 self.btnFontColor.setEnabled(
False)
295 if not self.filename.endswith(
"svg"):
298 file = open(self.filename.encode(
'UTF-8'),
"wb")
299 file.write(bytes(xmldoc.toxml(),
'UTF-8'))
301 except IOError
as inst:
302 log.error(
"Error writing SVG title")
309 col = QColorDialog.getColor(Qt.white, self, _(
"Select a Color"),
310 QColorDialog.DontUseNativeDialog | QColorDialog.ShowAlphaChannel)
314 self.btnFontColor.setStyleSheet(
"background-color: %s" % col.name())
328 col = QColorDialog.getColor(Qt.white, self, _(
"Select a Color"),
329 QColorDialog.DontUseNativeDialog | QColorDialog.ShowAlphaChannel)
333 self.btnBackgroundColor.setStyleSheet(
"background-color: %s" % col.name())
347 font, ok = QFontDialog.getFont(QFont(), caption=_(
"Change Font"))
351 fontinfo = QtGui.QFontInfo(font)
367 if item.startswith(value):
378 s = node.attributes[
"style"].value
397 opacity = float(txt[8:])
409 color = QtGui.QColor(color)
411 alpha = int(opacity * 65535.0)
412 self.btnFontColor.setStyleSheet(
"background-color: %s; opacity %s" % (color.name(), alpha))
421 s = self.
rect_node[0].attributes[
"style"].value
440 opacity = float(txt[8:])
454 color = QtGui.QColor(color)
456 alpha = int(opacity * 65535.0)
458 self.btnBackgroundColor.setStyleSheet(
"background-color: %s; opacity %s" % (color.name(), alpha))
467 s = text_child.attributes[
"style"].value
490 s = tspan_child.attributes[
"style"].value
516 s = self.
rect_node[0].attributes[
"style"].value
520 ar.append(
"fill:" + color)
522 ar[fill] =
"fill:" + color
526 ar.append(
"opacity:" + str(alpha))
528 ar[opacity] =
"opacity:" + str(alpha)
542 s = text_child.attributes[
"style"].value
547 ar.append(
"fill:" + color)
549 ar[fill] =
"fill:" + color
553 ar.append(
"opacity:" + str(alpha))
555 ar[opacity] =
"opacity:" + str(alpha)
558 text_child.setAttribute(
"style", t.join(ar))
565 s = tspan_child.attributes[
"style"].value
570 ar.append(
"fill:" + color)
572 ar[fill] =
"fill:" + color
574 tspan_child.setAttribute(
"style", t.join(ar))
590 file_name =
"%s.svg" % self.txtFileName.toPlainText().strip()
591 file_path = os.path.join(info.ASSETS_PATH, file_name)
593 if self.txtFileName.toPlainText().strip():
596 ret = QMessageBox.question(self, _(
"Title Editor"), _(
"%s already exists.\nDo you want to replace it?") % file_name,
597 QMessageBox.No | QMessageBox.Yes)
598 if ret == QMessageBox.No:
612 super(TitleEditor, self).
accept()
615 path, filename = os.path.split(filepath)
622 file = File.get(path=filepath)
629 clip = openshot.Clip(filepath)
633 reader = clip.Reader()
634 file_data = json.loads(reader.Json())
637 file_data[
"media_type"] =
"image"
641 file.data = file_data
648 msg.setText(_(
"{} is not a valid video, audio, or image file.".format(filename)))
660 prog = s.get(
"title_editor")
664 log.info(
"Advanced title editor command: {} {} ".format(prog, self.
filename))
666 p = subprocess.Popen([prog, self.
filename])
677 msg.setText(_(
"Please install {} to use this function").format(prog.capitalize()))
def set_bg_style
sets the background color
def track_metric_screen
Track a GUI screen being shown.
def get_app
Returns the current QApplication instance of OpenShot.
def set_font_color_elements
def set_font_style
sets the font properties
def load_svg_template
Load an SVG title and init all textboxes and controls.
def find_in_list
when passed a partial value, function will return the list index
def update_background_color_button
Updates the color shown on the background color button.
def load_ui
Load a Qt *.ui file, and also load an XML parsed version.
def update_font_color_button
Updates the color shown on the font color button.
def init_ui
Initialize all child widgets and action of a window or dialog.
def writeToFile
writes a new svg file containing the user edited data
def btnBackgroundColor_clicked
def get_settings
Get the current QApplication's settings instance.