46
46
from classes import info , ui_util , settings
47
47
from classes .logger import log
48
48
from classes .app import get_app
49
- from classes .query import File
50
49
from classes .metrics import track_metric_screen
51
50
from windows .views .titles_listview import TitlesListView
52
51
@@ -163,8 +162,11 @@ def display_svg(self):
163
162
reader .Open ()
164
163
165
164
# 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 )
168
170
reader .Close ()
169
171
clip .Close ()
170
172
@@ -234,20 +236,20 @@ def load_svg_template(self):
234
236
self .txtFileName .setText (os .path .basename (self .edit_file_path ))
235
237
self .txtFileName .setEnabled (False )
236
238
else :
237
- name = _ ("TitleFileName-%d " )
239
+ name = _ ("TitleFileName (%d) " )
238
240
offset = 0
239
241
if self .duplicate and self .edit_file_path :
240
242
# Re-use current name
241
243
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) "
246
248
if match .group (3 ):
247
249
# Filename already contained a number -> start counting from there
248
250
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) "
251
253
# Find an unused file name
252
254
for i in range (1 , 1000 ):
253
255
curname = name % (offset + i )
@@ -676,48 +678,10 @@ def accept(self):
676
678
self .writeToFile (self .xmldoc )
677
679
678
680
# Add file to project
679
- self . add_file (self .filename )
681
+ app . window . files_model . add_files (self .filename )
680
682
681
683
# 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 ()
721
685
722
686
def btnAdvanced_clicked (self ):
723
687
_ = self .app ._tr
@@ -744,5 +708,5 @@ def btnAdvanced_clicked(self):
744
708
745
709
except OSError :
746
710
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 ))
748
712
msg .exec_ ()
0 commit comments