Skip to content

Commit 7119481

Browse files
authored
Titles: Re-establish user template location (#3376)
info.USER_TITLES_PATH now points to / creates a new directory in $HOME/.openshot_qt named 'title_templates'. Its contents will be included when building the titles model. (SVG files only.)
1 parent 1a5c1d4 commit 7119481

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/classes/info.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,23 @@
5656
THUMBNAIL_PATH = os.path.join(USER_PATH, "thumbnail")
5757
CACHE_PATH = os.path.join(USER_PATH, "cache")
5858
BLENDER_PATH = os.path.join(USER_PATH, "blender")
59-
ASSETS_PATH = os.path.join(USER_PATH, "assets")
6059
TITLE_PATH = os.path.join(USER_PATH, "title")
6160
TRANSITIONS_PATH = os.path.join(USER_PATH, "transitions")
6261
PREVIEW_CACHE_PATH = os.path.join(USER_PATH, "preview-cache")
6362
USER_PROFILES_PATH = os.path.join(USER_PATH, "profiles")
6463
USER_PRESETS_PATH = os.path.join(USER_PATH, "presets")
65-
64+
USER_TITLES_PATH = os.path.join(USER_PATH, "title_templates")
6665
# User files
6766
BACKUP_FILE = os.path.join(BACKUP_PATH, "backup.osp")
6867
USER_DEFAULT_PROJECT = os.path.join(USER_PATH, "default.project")
6968

7069
# Create user paths if they do not exist
7170
# (this is where temp files are stored... such as cached thumbnails)
72-
for folder in [USER_PATH, BACKUP_PATH, RECOVERY_PATH, THUMBNAIL_PATH, CACHE_PATH,
73-
BLENDER_PATH, ASSETS_PATH, TITLE_PATH, TRANSITIONS_PATH,
74-
PREVIEW_CACHE_PATH, USER_PROFILES_PATH, USER_PRESETS_PATH]:
71+
for folder in [
72+
USER_PATH, BACKUP_PATH, RECOVERY_PATH, THUMBNAIL_PATH, CACHE_PATH,
73+
BLENDER_PATH, TITLE_PATH, TRANSITIONS_PATH, PREVIEW_CACHE_PATH,
74+
USER_PROFILES_PATH, USER_PRESETS_PATH, USER_TITLES_PATH,
75+
]:
7576
if not os.path.exists(os.fsencode(folder)):
7677
os.makedirs(folder, exist_ok=True)
7778

src/windows/models/titles_model.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,18 @@ def update_model(self, clear=True):
8686
titles_list.append(os.path.join(titles_dir, filename))
8787

8888
# Add user-defined titles (if any)
89-
for file in sorted(os.listdir(info.TITLE_PATH)):
90-
# pretty up the filename for display purposes
91-
if fnmatch.fnmatch(file, '*.svg'):
92-
titles_list.append(os.path.join(info.TITLE_PATH, file))
89+
for filename in sorted(os.listdir(info.USER_TITLES_PATH)):
90+
if fnmatch.fnmatch(filename, '*.svg'):
91+
titles_list.append(os.path.join(info.USER_TITLES_PATH, filename))
9392

9493
for path in sorted(titles_list):
9594
filename = os.path.basename(path)
9695
fileBaseName = os.path.splitext(filename)[0]
9796

9897
# Skip hidden files (such as .DS_Store, etc...)
99-
if filename[0] == "." or "thumbs.db" in filename.lower() or filename.lower() == "temp.svg":
98+
if (filename[0] == "."
99+
or "thumbs.db" in filename.lower()
100+
or filename.lower() == "temp.svg"):
100101
continue
101102

102103
# split the name into parts (looking for a number)
@@ -135,16 +136,19 @@ def update_model(self, clear=True):
135136
reader.Open()
136137

137138
# Save thumbnail
138-
reader.GetFrame(0).Thumbnail(thumb_path, 98, 64, os.path.join(info.IMAGES_PATH, "mask.png"),
139-
"", "#000", True, "png", 85)
139+
reader.GetFrame(0).Thumbnail(
140+
thumb_path, 98, 64,
141+
os.path.join(info.IMAGES_PATH, "mask.png"),
142+
"", "#000", True, "png", 85
143+
)
140144
reader.Close()
141145
clip.Close()
142146

143-
except:
147+
except Exception as ex:
144148
# Handle exception
145-
log.info('Invalid title image file: %s' % filename)
149+
log.info('Failed to open {} as title: {}'.format(filename, ex))
146150
msg = QMessageBox()
147-
msg.setText(_("{} is not a valid image file.".format(filename)))
151+
msg.setText(_("%s is not a valid image file." % filename))
148152
msg.exec_()
149153
continue
150154

0 commit comments

Comments
 (0)