Skip to content

Commit

Permalink
Use friendly name for files on the timeline (instead of filename). Th…
Browse files Browse the repository at this point in the history
…is includes "split" clip names and names modified in the Profile Files dialog. Also, fixing thumbnails on "Add to Timeline" dialog for split clips.
  • Loading branch information
jonoomph committed Jun 23, 2024
1 parent 86e6f08 commit 23c71d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
5 changes: 1 addition & 4 deletions src/windows/add_to_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def accept(self):
new_clip["position"] = position
new_clip["layer"] = track_num
new_clip["file_id"] = file.id
new_clip["title"] = filename
new_clip["title"] = file.data.get("name", filename)
new_clip["reader"] = file.data

# Skip any clips that are missing a 'reader' attribute
Expand Down Expand Up @@ -453,9 +453,6 @@ def __init__(self, files=None, position=0.0):
# Update data in model
self.treeFiles.timeline_model.update_model(files)

# Refresh view
self.treeFiles.refresh_view()

# Init start position
self.txtStartTime.setValue(position)

Expand Down
31 changes: 16 additions & 15 deletions src/windows/models/add_to_timeline_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from classes import info
from classes.logger import log
from classes.app import get_app
from classes.thumbnail import GetThumbPath


class TimelineModel():
Expand Down Expand Up @@ -60,14 +61,22 @@ def update_model(self, files=[], clear=True):
for file in self.files:
# Get attributes from file
path, filename = os.path.split(file.data["path"])

# Get thumbnail path
if (file.data["media_type"] == "video" or file.data["media_type"] == "image"):
# Determine thumb path
thumb_path = os.path.join(info.THUMBNAIL_PATH, "%s.png" % file.data["id"])
media_type = file.data.get("media_type")

# Generate thumbnail for file (if needed)
if media_type in ["video", "image"]:
# Check for start and end attributes (optional)
thumbnail_frame = 1
if 'start' in file.data:
fps = file.data["fps"]
fps_float = float(fps["num"]) / float(fps["den"])
thumbnail_frame = round(float(file.data['start']) * fps_float) + 1

# Get thumb path
thumb_icon = QIcon(GetThumbPath(file.id, thumbnail_frame))
else:
# Audio file
thumb_path = os.path.join(info.PATH, "images", "AudioThumbnail.svg")
thumb_icon = QIcon(os.path.join(info.PATH, "images", "AudioThumbnail.svg"))

row = []

Expand All @@ -76,8 +85,7 @@ def update_model(self, files=[], clear=True):

# Append thumbnail
col = QStandardItem()
col.setIcon(QIcon(thumb_path))
col.setText((name[:9] + '...') if len(name) > 10 else name)
col.setIcon(thumb_icon)
col.setToolTip(filename)
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
row.append(col)
Expand All @@ -89,13 +97,6 @@ def update_model(self, files=[], clear=True):
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
row.append(col)

# Append Path
col = QStandardItem("Path")
col.setData(path, Qt.DisplayRole)
col.setText(path)
col.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
row.append(col)

# Add row
self.model.appendRow(row)

Expand Down
2 changes: 1 addition & 1 deletion src/windows/views/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3094,7 +3094,7 @@ def callback(self, data, callback_data):
# Append missing attributes to Clip JSON
new_clip = json.loads(c.Json())
new_clip["file_id"] = file.id
new_clip["title"] = filename
new_clip["title"] = file.data.get("name", filename)
new_clip["reader"] = file.data

# Skip any clips that are missing a 'reader' attribute
Expand Down

0 comments on commit 23c71d8

Please sign in to comment.