OpenShot Video Editor  2.0.0
animated_title.py
Go to the documentation of this file.
1 ##
2 #
3 # @file
4 # @brief This file loads the animated title dialog (i.e Blender animation automation)
5 # @author Noah Figg <eggmunkee@hotmail.com>
6 # @author Jonathan Thomas <jonathan@openshot.org>
7 #
8 # @section LICENSE
9 #
10 # Copyright (c) 2008-2018 OpenShot Studios, LLC
11 # (http://www.openshotstudios.com). This file is part of
12 # OpenShot Video Editor (http://www.openshot.org), an open-source project
13 # dedicated to delivering high quality video editing and animation solutions
14 # to the world.
15 #
16 # OpenShot Video Editor is free software: you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation, either version 3 of the License, or
19 # (at your option) any later version.
20 #
21 # OpenShot Video Editor is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
28 #
29 
30 import sys
31 import os
32 import time
33 import uuid
34 import shutil
35 import threading
36 import subprocess
37 import re
38 import math
39 
40 from PyQt5.QtCore import *
41 from PyQt5.QtGui import QIcon, QStandardItemModel, QStandardItem
42 from PyQt5.QtWidgets import *
43 from PyQt5 import uic
44 import openshot # Python module for libopenshot (required video editing module installed separately)
45 
46 from classes import info, ui_util, settings, qt_types, updates
47 from classes.app import get_app
48 from classes.logger import log
49 from classes.query import File
50 from classes.metrics import *
51 from windows.views.blender_listview import BlenderListView
52 
53 try:
54  import json
55 except ImportError:
56  import simplejson as json
57 
58 
59 ##
60 # Animated Title Dialog
61 class AnimatedTitle(QDialog):
62 
63  # Path to ui file
64  ui_path = os.path.join(info.PATH, 'windows', 'ui', 'animated-title.ui')
65 
66  def __init__(self):
67 
68  # Create dialog class
69  QDialog.__init__(self)
70 
71  # Load UI from designer
72  ui_util.load_ui(self, self.ui_path)
73 
74  # Init UI
75  ui_util.init_ui(self)
76 
77  # Track metrics
78  track_metric_screen("animated-title-screen")
79 
80  # Add blender treeview
81  self.blenderTreeView = BlenderListView(self)
82  self.verticalLayout.addWidget(self.blenderTreeView)
83 
84  # Add render button
85  app = get_app()
86  _ = app._tr
87  self.buttonBox.addButton(QPushButton(_('Render')), QDialogButtonBox.AcceptRole)
88  self.buttonBox.addButton(QPushButton(_('Cancel')), QDialogButtonBox.RejectRole)
89 
90  # Init variables
91  self.unique_folder_name = str(uuid.uuid1())
92  self.output_dir = os.path.join(info.USER_PATH, "blender")
94  self.is_rendering = False
95  self.my_blender = None
96 
97  # Clear all child controls
99 
100  ##
101  # Start rendering animation, but don't close window
102  def accept(self):
103 
104  # Render
105  self.blenderTreeView.Render()
106 
107  ##
108  # Actually close window and accept dialog
109  def close(self):
110 
111  # Re-enable interface
112  self.blenderTreeView.enable_interface()
113 
114  # Accept dialog
115  super(AnimatedTitle, self).accept()
116 
117  def closeEvent(self, event):
118 
119  # Stop threads
120  self.blenderTreeView.background.quit()
121 
122  # Re-enable interface
123  self.blenderTreeView.enable_interface()
124 
125  def reject(self):
126 
127  # Stop threads
128  self.blenderTreeView.background.quit()
129 
130  # Cancel dialog
131  super(AnimatedTitle, self).reject()
132 
133  ##
134  # Add an animation to the project file tree
135  def add_file(self, filepath):
136  path, filename = os.path.split(filepath)
137 
138  # Add file into project
139  app = get_app()
140  _ = get_app()._tr
141 
142  # Check for this path in our existing project data
143  file = File.get(path=filepath)
144 
145  # If this file is already found, exit
146  if file:
147  return
148 
149  # Get the JSON for the clip's internal reader
150  try:
151  # Open image sequence in FFmpegReader
152  reader = openshot.FFmpegReader(filepath)
153  reader.Open()
154 
155  # Serialize JSON for the reader
156  file_data = json.loads(reader.Json())
157 
158  # Set media type
159  file_data["media_type"] = "video"
160 
161  # Save new file to the project data
162  file = File()
163  file.data = file_data
164  file.save()
165  return True
166 
167  except:
168  # Handle exception
169  msg = QMessageBox()
170  msg.setText(_("{} is not a valid video, audio, or image file.".format(filename)))
171  msg.exec_()
172  return False
173 
174  ##
175  # Clear all child widgets used for settings
177 
178  # Loop through child widgets
179  for child in self.settingsContainer.children():
180  try:
181  self.settingsContainer.layout().removeWidget(child)
182  child.deleteLater()
183  except:
184  pass
def add_file
Add an animation to the project file tree.
def track_metric_screen
Track a GUI screen being shown.
Definition: metrics.py:96
def get_app
Returns the current QApplication instance of OpenShot.
Definition: app.py:55
def accept
Start rendering animation, but don't close window.
def load_ui
Load a Qt *.ui file, and also load an XML parsed version.
Definition: ui_util.py:66
Animated Title Dialog.
def init_ui
Initialize all child widgets and action of a window or dialog.
Definition: ui_util.py:220
def close
Actually close window and accept dialog.
def clear_effect_controls
Clear all child widgets used for settings.