37 from classes
import info
38 from classes.logger
import log
39 from classes.app
import get_app
44 import simplejson
as json
49 QStandardItemModel.__init__(self)
58 selected_row = self.itemFromIndex(item).row()
59 files.append(self.item(selected_row, 2).text())
60 data.setText(json.dumps(files))
69 log.info(
"updating title model.")
82 self.model.setHorizontalHeaderLabels([_(
"Thumb"), _(
"Name")])
85 titles_dir = os.path.join(info.PATH,
"titles")
89 for filename
in sorted(os.listdir(titles_dir)):
90 titles_list.append(os.path.join(titles_dir, filename))
93 for file
in sorted(os.listdir(info.TITLE_PATH)):
95 if fnmatch.fnmatch(file,
'*.svg'):
96 titles_list.append(os.path.join(info.TITLE_PATH, file))
98 for path
in sorted(titles_list):
99 (parent_path, filename) = os.path.split(path)
100 (fileBaseName, fileExtension) = os.path.splitext(filename)
103 if filename[0] ==
"." or "thumbs.db" in filename.lower()
or filename.lower() ==
"temp.svg":
108 name_parts = fileBaseName.split(
"_")
109 if name_parts[-1].isdigit():
110 suffix_number = name_parts[-1]
113 title_name = fileBaseName.replace(
"_",
" ").capitalize()
117 title_name = title_name.replace(suffix_number,
"%s")
118 title_name = self.app._tr(title_name) % suffix_number
120 title_name = self.app._tr(title_name)
123 thumb_path = os.path.join(info.IMAGES_PATH,
"cache",
"{}.png".format(fileBaseName))
126 if not os.path.exists(thumb_path):
128 thumb_path = os.path.join(info.CACHE_PATH,
"{}.png".format(fileBaseName))
131 if not os.path.exists(thumb_path):
135 clip = openshot.Clip(path)
136 reader = clip.Reader()
142 reader.GetFrame(0).Thumbnail(thumb_path, 98, 64, os.path.join(info.IMAGES_PATH,
"mask.png"),
"",
"#000",
True)
149 msg.setText(_(
"{} is not a valid image file.".format(filename)))
156 col = QStandardItem()
157 icon_pixmap = QPixmap(thumb_path)
158 scaled_pixmap = icon_pixmap.scaled(QSize(93, 62), Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
159 col.setIcon(QIcon(scaled_pixmap))
160 col.setText(title_name)
161 col.setToolTip(title_name)
162 col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsDragEnabled)
166 col = QStandardItem(
"Name")
167 col.setData(title_name, Qt.DisplayRole)
168 col.setText(title_name)
169 col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsDragEnabled)
173 col = QStandardItem(
"Path")
174 col.setData(path, Qt.DisplayRole)
176 col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsDragEnabled)
181 self.model.appendRow(row)
192 self.model.setColumnCount(3)
def get_app
Returns the current QApplication instance of OpenShot.