OpenShot Video Editor  2.0.0
add_to_timeline_model.py
Go to the documentation of this file.
1 ##
2 #
3 # @file
4 # @brief This file contains the add to timeline model
5 # @author Jonathan Thomas <jonathan@openshot.org>
6 #
7 # @section LICENSE
8 #
9 # Copyright (c) 2008-2018 OpenShot Studios, LLC
10 # (http://www.openshotstudios.com). This file is part of
11 # OpenShot Video Editor (http://www.openshot.org), an open-source project
12 # dedicated to delivering high quality video editing and animation solutions
13 # to the world.
14 #
15 # OpenShot Video Editor is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation, either version 3 of the License, or
18 # (at your option) any later version.
19 #
20 # OpenShot Video Editor is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
27 #
28 
29 import os
30 
31 from PyQt5.QtCore import Qt
32 from PyQt5.QtGui import *
33 
34 from classes import info
35 from classes.logger import log
36 from classes.app import get_app
37 
38 
39 class TimelineModel():
40  def update_model(self, files=[], clear=True):
41  log.info("updating timeline model.")
42  app = get_app()
43 
44  # Get window to check filters
45  win = app.window
46  _ = app._tr
47 
48  # Set files list (if found)
49  if files:
50  log.info('set files to %s' % files)
51  self.files = files
52 
53  # Clear all items
54  if clear:
55  self.model.clear()
56 
57  # Add Headers
58  self.model.setHorizontalHeaderLabels([_("Thumb"), _("Name")])
59 
60  log.info(self.files)
61 
62  for file in self.files:
63  # Get attributes from file
64  path, filename = os.path.split(file.data["path"])
65  title = filename
66 
67  # Get thumbnail path
68  if (file.data["media_type"] == "video" or file.data["media_type"] == "image"):
69  # Determine thumb path
70  thumb_path = os.path.join(info.THUMBNAIL_PATH, "%s.png" % file.data["id"])
71  else:
72  # Audio file
73  thumb_path = os.path.join(info.PATH, "images", "AudioThumbnail.png")
74 
75  row = []
76 
77  # Look for friendly name attribute (optional)
78  name = filename
79  if 'name' in file.data.keys():
80  name = file.data['name']
81 
82  # Append thumbnail
83  col = QStandardItem()
84  col.setIcon(QIcon(thumb_path))
85  col.setText((name[:9] + '...') if len(name) > 10 else name)
86  col.setToolTip(filename)
87  col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
88  row.append(col)
89 
90  # Append Name
91  col = QStandardItem("Name")
92  col.setData(filename, Qt.DisplayRole)
93  col.setText((name[:20] + '...') if len(name) > 15 else name)
94  col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
95  row.append(col)
96 
97  # Append Path
98  col = QStandardItem("Path")
99  col.setData(path, Qt.DisplayRole)
100  col.setText(path)
101  col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
102  row.append(col)
103 
104  # Add row
105  self.model.appendRow(row)
106 
107  # Process events in QT (to keep the interface responsive)
108  app.processEvents()
109 
110  def __init__(self, *args):
111 
112  # Create standard model
113  self.app = get_app()
114  self.model = QStandardItemModel()
115  self.model.setColumnCount(2)
116  self.model_paths = {}
117  self.files = []
def get_app
Returns the current QApplication instance of OpenShot.
Definition: app.py:55