Skip to content

Commit a9c40d1

Browse files
committed
Titles: Use files model add_files(), new counter
- Switch from TitleFileName-N for numbered filenames, to Windows-esque "TitleFileName (N)", because the previous value would trigger the image sequence import logic
1 parent dc18a20 commit a9c40d1

File tree

2 files changed

+18
-54
lines changed

2 files changed

+18
-54
lines changed

src/windows/main_window.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ def actionEditTitle_trigger(self, event):
403403
for f in self.selected_files():
404404
if f.data.get("path").endswith(".svg"):
405405
file_path = f.data.get("path")
406+
file_id = f.id
406407
break
407408

408409
if not file_path:
@@ -415,11 +416,10 @@ def actionEditTitle_trigger(self, event):
415416
result = win.exec_()
416417

417418
# Update file thumbnail
418-
self.FileUpdated.emit(selected_file_id)
419+
self.FileUpdated.emit(file_id)
419420

420421
# Force update of clips
421-
clips = Clip.filter(file_id=selected_file_id)
422-
for c in clips:
422+
for c in Clip.filter(file_id=file_id):
423423
# update clip
424424
c.data["reader"]["path"] = file_path
425425
c.save()

src/windows/title_editor.py

+15-51
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
from classes import info, ui_util, settings
4747
from classes.logger import log
4848
from classes.app import get_app
49-
from classes.query import File
5049
from classes.metrics import track_metric_screen
5150
from windows.views.titles_listview import TitlesListView
5251

@@ -163,8 +162,11 @@ def display_svg(self):
163162
reader.Open()
164163

165164
# Save thumbnail image and close readers
166-
reader.GetFrame(1).Thumbnail(tmp_filename, self.graphicsView.width(), self.graphicsView.height(), "", "",
167-
"#000", False, "png", 85, 0.0)
165+
reader.GetFrame(1).Thumbnail(
166+
tmp_filename,
167+
self.graphicsView.width(),
168+
self.graphicsView.height(),
169+
"", "", "#000", False, "png", 85, 0.0)
168170
reader.Close()
169171
clip.Close()
170172

@@ -234,20 +236,20 @@ def load_svg_template(self):
234236
self.txtFileName.setText(os.path.basename(self.edit_file_path))
235237
self.txtFileName.setEnabled(False)
236238
else:
237-
name = _("TitleFileName-%d")
239+
name = _("TitleFileName (%d)")
238240
offset = 0
239241
if self.duplicate and self.edit_file_path:
240242
# Re-use current name
241243
name = os.path.basename(self.edit_file_path)
242-
# Splits the filename into (base-part)(optional "-")(number)(.svg)
243-
match = re.match(r"^(.*?)(-?)([0-9]*)(\.svg)?$", name)
244-
# Make sure the new title ends with "-%d" by default
245-
name = match.group(1) + "-%d"
244+
# Splits the filename into "[base-part][optional space]([number]).svg
245+
match = re.match(r"^(.*?)(\s*)\(([0-9]*)\)\.svg$", name)
246+
# Make sure the new title has " (%d)" appended by default
247+
name = match.group(1) + " (%d)"
246248
if match.group(3):
247249
# Filename already contained a number -> start counting from there
248250
offset = int(match.group(3))
249-
# -> only use "-" if it was there before
250-
name = match.group(1) + match.group(2) + "%d"
251+
# -> only include space(s) if there before
252+
name = match.group(1) + match.group(2) + "(%d)"
251253
# Find an unused file name
252254
for i in range(1, 1000):
253255
curname = name % (offset + i)
@@ -676,48 +678,10 @@ def accept(self):
676678
self.writeToFile(self.xmldoc)
677679

678680
# Add file to project
679-
self.add_file(self.filename)
681+
app.window.files_model.add_files(self.filename)
680682

681683
# Close window
682-
super(TitleEditor, self).accept()
683-
684-
def add_file(self, filepath):
685-
filename = os.path.basename(filepath)
686-
687-
# Add file into project
688-
_ = get_app()._tr
689-
690-
# Check for this path in our existing project data
691-
file = File.get(path=filepath)
692-
693-
# If this file is already found, exit
694-
if file:
695-
return
696-
697-
# Load filepath in libopenshot clip object (which will try multiple readers to open it)
698-
clip = openshot.Clip(filepath)
699-
700-
# Get the JSON for the clip's internal reader
701-
try:
702-
reader = clip.Reader()
703-
file_data = json.loads(reader.Json())
704-
705-
# Set media type
706-
file_data["media_type"] = "image"
707-
708-
# Save new file to the project data
709-
file = File()
710-
file.data = file_data
711-
file.save()
712-
return True
713-
714-
except Exception as ex:
715-
# Handle exception
716-
log.error('Could not import {}: {}'.format(filename, str(ex)))
717-
msg = QMessageBox()
718-
msg.setText(_("{} is not a valid video, audio, or image file.".format(filename)))
719-
msg.exec_()
720-
return False
684+
super().accept()
721685

722686
def btnAdvanced_clicked(self):
723687
_ = self.app._tr
@@ -744,5 +708,5 @@ def btnAdvanced_clicked(self):
744708

745709
except OSError:
746710
msg = QMessageBox()
747-
msg.setText(_("Please install {} to use this function").format(prog.capitalize()))
711+
msg.setText(_("Please install %s to use this function" % prog))
748712
msg.exec_()

0 commit comments

Comments
 (0)