-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_file_rename_utility.py
2746 lines (2639 loc) · 163 KB
/
linux_file_rename_utility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3
"""
Application: Linux File Rename Utility
Author: BSFEMA
Note: I would appreciate it if you kept my attribution as the original author in any fork or remix that is made.
Purpose: To provide Linux with a good file rename utility.
I didn't particularly like any of the existing rename utilities available on Linux and I didn't like having to run a Windows one in Wine either...
This was also a good excuse to learn Gtk and Glade programming with Python.
Command Line Parameters: If the first parameter is a valid folder path, then that will be used to start renaming files from. If this value isn't provided, then the starting path will be where this application file is located. The intention is that you can call this application from a context menu from a file browser (e.g. Nemo) and it would automatically load up that folder.
If the first parameter is a valid file path, it will use the folder that the file resides in instead.
If you pass it a list of files (e.g. 'file:///home/user_name/file1.txt' 'file:///home/user_name/file2.txt'), it will use the folder that the first file resides in instead. It will then auto-select all the files that exist in that folder. The intention is that you can use Linux File Rename Utility as the "Bulk Rename" utility in Nemo.
If no parameter is passed, then it will use the folder where the "linux_file_rename_utility.py" file is located.
"""
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
import sys
import os
import re
import datetime
from operator import itemgetter
import fnmatch
default_folder_path = "" # The path for the filechooser and data grid to work against. This is the base folder to work against.
application_Settings = [] # Holds user's custom widget defaults specified in ~/.config/BSFEMA/settings.txt
files_Full = [] # Holds all of the file information
files = [] # Holds only the file information for displaying in the data grid
directory_counts = dict() # Holds the all of the sub-directories used and the counts (for the 'Per Folder' option).
rename_pairs = [] # Holds the current name, new name, status, full path, type
rename_pairs_from_file = {} # Holds an imported dictionary of: <original file name>/<new file name>
settings_file_to_load = "" # The path to the default settings file.
rename_pairs_file_to_load = "" # The path to the rename pair file to import.
konami_code = [] # Easter Egg to see if the Konami code has been entered in the About dialog.
previous_selection = [[], 0, "", True] # [ [list of selected rows], len(model), "default_folder_path", [Boolean = should it treeview_Data_Grid_selection_changed] ]
parameter_files = [] # Holds the file(s) locations passed in via the command line. To be auto selected.
alert_color_foreground = "black" # The foreground color of data grid cell when there is a problem
alert_color_background = "red" # The background color of data grid cell when there is a problem
regex_or_wildcards = "Wildcards" # Whether the 'Use RegEx' or 'Use Wildcards' radio button is enabled
class Main():
def __init__(self):
# Setup Glade Gtk
self.builder = gtk.Builder()
self.builder.add_from_file(os.path.join(sys.path[0], "linux_file_rename_utility.glade")) # Looking where the python script is located
self.builder.connect_signals(self)
# Get UI components
window = self.builder.get_object("main_window")
window.connect("delete-event", gtk.main_quit)
window.set_title('Linux File Rename Utility')
window.set_default_icon_from_file(os.path.join(sys.path[0], "linux_file_rename_utility.svg")) # Setting the "default" icon makes it usable in the about dialog. (This will take .ico, .png, and .svg images.)
# Set the default data grid height (400)
self.set_scrollwindow_Data_Grid_height(400) # "400" is the default value
window.show()
# Initialize "Box (1-8)" booleans to False, this is to tell if they are modified later. This needs to happen here before any of the Box options are called/modified
self.box_1 = False
self.box_2 = False
self.box_3 = False
self.box_4 = False
self.box_5 = False
self.box_6 = False
self.box_7 = False
self.box_8 = False
self.rename_pairs_file = False
# This allows the use css styling
provider = gtk.CssProvider()
provider.load_from_path(os.path.join(sys.path[0], "linux_file_rename_utility.css")) # Looking where the python script is located
gtk.StyleContext().add_provider_for_screen(gdk.Screen.get_default(), provider, gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
# Set initial_load to True so that the data grid doesn't refresh multiple times when various settings are being initialized
self.initial_load = True
# Set filechooser_Folder_Selecter and entry_Folder_path values to the default_folder_path
filechooser_Folder_Selecter = self.builder.get_object("filechooser_Folder_Selecter")
filechooser_Folder_Selecter.set_current_folder(default_folder_path)
entry_Folder_path = self.builder.get_object("entry_Folder_path")
entry_Folder_path.set_text(default_folder_path)
# Set spinner direction default to "HORIZONTAL"
self.set_spinner_orientation("HORIZONTAL") # "HORIZONTAL" is the default (for smaller screens)
# Set various objects to their defaults:
# Set combo_Extension to default value (1st entry)
combo_Extension = self.builder.get_object("combo_Extension")
combo_Extension.set_entry_text_column(0)
combo_Extension.set_active(0)
# Set combo_Numbering to default value (1st entry)
combo_Numbering = self.builder.get_object("combo_Numbering")
combo_Numbering.set_entry_text_column(0)
combo_Numbering.set_active(0)
# Set combo_Append_Folder_Name to default value (1st entry)
combo_Append_Folder_Name = self.builder.get_object("combo_Append_Folder_Name")
combo_Append_Folder_Name.set_entry_text_column(0)
combo_Append_Folder_Name.set_active(0)
# Set combo_Remove_Crop to default value (1st entry)
combo_Remove_Crop = self.builder.get_object("combo_Remove_Crop")
combo_Remove_Crop.set_entry_text_column(0)
combo_Remove_Crop.set_active(0)
# Set combo_Case to default value (1st entry)
combo_Case = self.builder.get_object("combo_Case")
combo_Case.set_entry_text_column(0)
combo_Case.set_active(0)
# Set combo_Name to default value (1st entry)
combo_Name = self.builder.get_object("combo_Name")
combo_Name.set_entry_text_column(0)
combo_Name.set_active(0)
# Apply custom user application settings
self.apply_application_settings()
# Set the checkboxes in the box_Files section to the 'default' values if the settings are not in the custom user application settings
if self.file_folders_default == True:
checkbox_Folders = self.builder.get_object("checkbox_Folders")
checkbox_Folders.set_active(True)
checkbox_Subfolders = self.builder.get_object("checkbox_Subfolders")
checkbox_Files = self.builder.get_object("checkbox_Files")
checkbox_Files.set_active(True)
checkbox_Hidden = self.builder.get_object("checkbox_Hidden")
# Set initial_load to False as the application settings should now be setup correctly
self.initial_load = False
self.repaint_GUI() # Make sure GUI is up to date
watch_cursor = gdk.Cursor(gdk.CursorType.WATCH)
window.get_window().set_cursor(watch_cursor) # Set curror to 'Waiting'
self.repaint_GUI() # Make sure GUI is up to date
# Setup the data grid
treeview_Data_Grid = self.builder.get_object("treeview_Data_Grid")
treeview_Data_Grid.get_selection().set_mode(gtk.SelectionMode.MULTIPLE) # Now it can multiselect rows
treeview_Data_Grid.get_selection().connect("changed", self.treeview_Data_Grid_selection_changed)
self.clear_Data_Grid()
populate_files_Full(self.builder.get_object("entry_Mask").get_text(),
self.builder.get_object("checkbox_Folders").get_active(),
self.builder.get_object("checkbox_Subfolders").get_active(),
self.builder.get_object("checkbox_Files").get_active(),
self.builder.get_object("checkbox_Hidden").get_active(),
self.builder.get_object("spin_File_Name_Min").get_value_as_int(),
self.builder.get_object("spin_File_Name_Max").get_value_as_int(),
)
self.load_Data_Grid()
self.resize_column_widths()
# Setup the Status Labels
box_Status = self.builder.get_object("box_Status")
box_Status.get_style_context().add_class('grey-border')
label_Status_Rows = self.builder.get_object("label_Status_Rows")
label_Status_Rows.set_text("")
label_Status_Rows.get_style_context().add_class('grey-border')
label_Status_Selected = self.builder.get_object("label_Status_Selected")
label_Status_Selected.set_text("")
label_Status_Selected.get_style_context().add_class('grey-border')
label_Status_Renamed = self.builder.get_object("label_Status_Renamed")
label_Status_Renamed.set_text("")
label_Status_Renamed.get_style_context().add_class('grey-border')
label_Status_Failed = self.builder.get_object("label_Status_Failed")
label_Status_Failed.set_text("")
label_Status_Failed.get_style_context().add_class('grey-border')
self.update_status_labels()
self.repaint_GUI() # Make sure GUI is up to date
window.get_window().set_cursor(None) # Set curror back to 'None'
self.repaint_GUI() # Make sure GUI is up to date
global previous_selection
global parameter_files
if len(parameter_files) > 0: # If there are files passed from the command line, have them selected in the data grid
self.apply_parameter_files_to_selection()
selection = treeview_Data_Grid.get_selection()
model, items = selection.get_selected_rows()
previous_selection = [[], len(model), default_folder_path, True] # Set the row count and path, This saves a full loop in treeview_Data_Grid_selection_changed later
""" ************************************************************************************************************ """
# These are the various widget's signal handler functions: UI elements other than buttons & dialogs
""" ************************************************************************************************************ """
def repaint_GUI(self):
# Defect #2 - Implement a waiting cursor to give an indication when the data grid is taking a long time to load.
# Unfortunately, I haven't found an easier/better way to implement this...
while gtk.events_pending():
gtk.main_iteration_do(False)
def box_9_files_section_changed(self, widget): # Clear and rebuild data grid
if not self.initial_load:
self.repaint_GUI() # Make sure GUI is up to date
window = self.builder.get_object("main_window")
watch_cursor = gdk.Cursor(gdk.CursorType.WATCH)
window.get_window().set_cursor(watch_cursor) # Set curror to 'Waiting'
self.repaint_GUI() # Make sure GUI is up to date
self.clear_Data_Grid()
populate_files_Full(self.builder.get_object("entry_Mask").get_text(),
self.builder.get_object("checkbox_Folders").get_active(),
self.builder.get_object("checkbox_Subfolders").get_active(),
self.builder.get_object("checkbox_Files").get_active(),
self.builder.get_object("checkbox_Hidden").get_active(),
self.builder.get_object("spin_File_Name_Min").get_value_as_int(),
self.builder.get_object("spin_File_Name_Max").get_value_as_int(),
)
self.load_Data_Grid()
self.resize_column_widths()
self.update_status_labels()
self.repaint_GUI() # Make sure GUI is up to date
window.get_window().set_cursor(None) # Set curror back to 'None'
self.repaint_GUI() # Make sure GUI is up to date
def entry_Extension_changed(self, widget):
self.check_settings_for_box_8()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def combo_Extension_changed(self, widget):
entry_Extension = self.builder.get_object("entry_Extension")
if widget.get_text() in ('Fixed', 'Extra'):
entry_Extension.set_editable(True)
else:
entry_Extension.set_text("")
entry_Extension.set_editable(False)
self.check_settings_for_box_8()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def widgets_Numbering_changed(self, widget): # This is for all "Numbering" widgets except "combo_Numbering"
self.check_settings_for_box_7()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def entry_Remove_Crop_changed(self, widget):
self.check_settings_for_box_4()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def combo_Remove_Crop_changed(self, widget):
entry_Remove_Crop = self.builder.get_object("entry_Remove_Crop")
if widget.get_text() in ('Before First', 'Before Last', 'After First', 'After Last'):
entry_Remove_Crop.set_editable(True)
else:
entry_Remove_Crop.set_text("")
entry_Remove_Crop.set_editable(False)
self.check_settings_for_box_4()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def combo_Numbering_changed(self, widget):
spin_Numbering_At = self.builder.get_object("spin_Numbering_At")
if widget.get_text() == 'Insert':
spin_Numbering_At.set_editable(True)
spin_Numbering_At.set_value(0)
else:
spin_Numbering_At.set_editable(False)
spin_Numbering_At.set_value(0)
self.check_settings_for_box_7()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def combo_Append_Folder_Name_changed(self, widget):
entry_Append_Folder_Name_Separator = self.builder.get_object("entry_Append_Folder_Name_Separator")
if widget.get_text() == 'None':
entry_Append_Folder_Name_Separator.set_text('')
entry_Append_Folder_Name_Separator.set_editable(False)
else:
entry_Append_Folder_Name_Separator.set_editable(True)
self.check_settings_for_box_6()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def entry_Append_Folder_Name_Separator_changed(self, widget):
self.check_settings_for_box_6()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def entry_Add_changed(self, widget): # This is for all "entry_Add" and "spin_Add" widgets
self.check_settings_for_box_5()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def spin_Remove_changed(self, widget): # This is for all "spin_Remove" widgets
spin_Remove_From = self.builder.get_object("spin_Remove_From")
spin_Remove_To = self.builder.get_object("spin_Remove_To")
if spin_Remove_From.get_value() > spin_Remove_To.get_value(): # Make sure that To is >= From
spin_Remove_To.set_value(spin_Remove_From.get_value())
self.check_settings_for_box_4()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def combo_Case_changed(self, widget):
self.check_settings_for_box_3()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def combo_Name_changed(self, widget):
entry_Name_Fixed = self.builder.get_object("entry_Name_Fixed")
if widget.get_text() == 'Fixed':
entry_Name_Fixed.set_editable(True)
else:
entry_Name_Fixed.set_text('')
entry_Name_Fixed.set_editable(False)
self.check_settings_for_box_1()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def entry_Name_Fixed_changed(self, widget):
self.check_settings_for_box_1()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def entry_Replace_Search_changed(self, widget): # This is for all "entry_Replace" widgets
self.check_settings_for_box_2()
self.treeview_Data_Grid_selection_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def filechooser_Folder_Selecter_fileset(self, widget):
entry_Folder_path = self.builder.get_object("entry_Folder_path")
entry_Folder_path.set_text(widget.get_filename())
def entry_Folder_Path_changed(self, widget):
if not self.initial_load:
self.repaint_GUI() # Make sure GUI is up to date
window = self.builder.get_object("main_window")
watch_cursor = gdk.Cursor(gdk.CursorType.WATCH)
window.get_window().set_cursor(watch_cursor) # Set curror to 'Waiting'
self.repaint_GUI() # Make sure GUI is up to date
current_path = widget.get_text()
if os.path.isdir(current_path):
widget.get_style_context().remove_class('red-foreground')
# widget.get_style_context().add_class('black-foreground')
# Reload the data grid now that a new (real) folder is selected
global default_folder_path
if current_path[-1:] == "/": # remove the final "/" from a path
current_path = current_path[:-1]
default_folder_path = current_path # Now that the edited text is a folder, set the default_folder_path to use that
self.clear_Data_Grid()
populate_files_Full(self.builder.get_object("entry_Mask").get_text(),
self.builder.get_object("checkbox_Folders").get_active(),
self.builder.get_object("checkbox_Subfolders").get_active(),
self.builder.get_object("checkbox_Files").get_active(),
self.builder.get_object("checkbox_Hidden").get_active(),
self.builder.get_object("spin_File_Name_Min").get_value_as_int(),
self.builder.get_object("spin_File_Name_Max").get_value_as_int(),
)
self.load_Data_Grid()
self.resize_column_widths()
self.update_status_labels()
else:
# widget.get_style_context().remove_class('black-foreground')
widget.get_style_context().add_class('red-foreground')
self.repaint_GUI() # Make sure GUI is up to date
window.get_window().set_cursor(None) # Set curror back to 'None'
self.repaint_GUI() # Make sure GUI is up to date
def checkbox_Save_History_toggled(self, widget):
# This doesn't really have any 'action' at the moment, as it's just a setting to be toggled
pass
def radio_Use_RegEx_toggled(self, widget):
global regex_or_wildcards
radio_Use_RegEx = self.builder.get_object("radio_Use_RegEx")
if radio_Use_RegEx.get_active(): regex_or_wildcards = "RegEx"
else: regex_or_wildcards = "Wildcards"
self.box_9_files_section_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def radio_Use_Wildcards_toggled(self, widget):
global regex_or_wildcards
radio_Use_Wildcards = self.builder.get_object("radio_Use_Wildcards")
if radio_Use_Wildcards.get_active(): regex_or_wildcards = "Wildcards"
else: regex_or_wildcards = "RegEx"
self.box_9_files_section_changed("Nothing") # The function takes a "treeselection_object" parameter, but it doesn't use it, so I'm passing it "Nothing"...
def apply_parameter_files_to_selection(self): # Set the commandline parameter files as selected rows
# model[item][6] = Full_Path
# model[item][8] = Type
treeview_Data_Grid = self.builder.get_object("treeview_Data_Grid")
treeselection = treeview_Data_Grid.get_selection()
model, items = treeselection.get_selected_rows()
if len(model) > 0:
for loop in range(len(model)): # Loop through all rows in the data grid
if model[loop][8] == "Folder":
if model[loop][6][-1:] == "/": # If there is a trailing "/" in the folder path (should be there...)
if model[loop][6][:-1] in parameter_files:
treeselection.select_path(loop)
else:
if model[loop][6] in parameter_files:
treeselection.select_path(loop)
else: # File
if model[loop][6] in parameter_files:
treeselection.select_path(loop)
def treeview_Data_Grid_select_all(self, event):
treeview_Data_Grid = self.builder.get_object("treeview_Data_Grid")
treeselection = treeview_Data_Grid.get_selection()
treeselection.select_all()
def treeview_Data_Grid_select_none(self, event):
treeview_Data_Grid = self.builder.get_object("treeview_Data_Grid")
treeselection = treeview_Data_Grid.get_selection()
treeselection.unselect_all()
def treeview_Data_Grid_select_inverse(self, event):
treeview_Data_Grid = self.builder.get_object("treeview_Data_Grid")
treeselection = treeview_Data_Grid.get_selection()
model, items = treeselection.get_selected_rows()
temp_indexes = [] # Holds the rows indexes of the currently selected rows
temp_treepaths = [] # Holds the TreePath objects of the currently selected rows
if len(model) > 0:
for item in items: # Build list of the currently selected rows
temp_indexes.append(int(str(item)))
temp_treepaths.append(item)
for x in range(len(temp_treepaths)): # Unselect the currently selected rows
treeselection.unselect_path(temp_treepaths[x])
for x in range(len(model)): # Select the currently unselected rows
if x not in temp_indexes:
treeselection.select_path(x)
def treeview_Data_Grid_toggle_full_path(self, event):
treeviewcolumn_Full_Path = self.builder.get_object("treeviewcolumn_Full_Path")
if treeviewcolumn_Full_Path.get_visible():
treeviewcolumn_Full_Path.set_visible(False)
else:
treeviewcolumn_Full_Path.set_visible(True)
def treeview_Data_Grid_toggle_local_path(self, event):
treeviewcolumn_Local_Path = self.builder.get_object("treeviewcolumn_Local_Path")
if treeviewcolumn_Local_Path.get_visible():
treeviewcolumn_Local_Path.set_visible(False)
else:
treeviewcolumn_Local_Path.set_visible(True)
def treeview_Data_Grid_toggle_file_type(self, event):
treeviewcolumn_Type = self.builder.get_object("treeviewcolumn_Type")
if treeviewcolumn_Type.get_visible():
treeviewcolumn_Type.set_visible(False)
else:
treeviewcolumn_Type.set_visible(True)
def treeview_Data_Grid_toggle_hidden(self, event):
treeviewcolumn_Hidden = self.builder.get_object("treeviewcolumn_Hidden")
if treeviewcolumn_Hidden.get_visible():
treeviewcolumn_Hidden.set_visible(False)
else:
treeviewcolumn_Hidden.set_visible(True)
def treeview_Data_Grid_toggle_size(self, event):
treeviewcolumn_Size = self.builder.get_object("treeviewcolumn_Size")
if treeviewcolumn_Size.get_visible():
treeviewcolumn_Size.set_visible(False)
else:
treeviewcolumn_Size.set_visible(True)
def treeview_Data_Grid_toggle_date_modified(self, event):
treeviewcolumn_Date_Modified = self.builder.get_object("treeviewcolumn_Date_Modified")
if treeviewcolumn_Date_Modified.get_visible():
treeviewcolumn_Date_Modified.set_visible(False)
else:
treeviewcolumn_Date_Modified.set_visible(True)
def treeview_Data_Grid_button_press_event(self, widget, event):
# event.button == 1 # Is mouse left click
# event.button == 2 # Is mouse scrollwheel click
# event.button == 3 # Is mouse right click
if event.button == 3: # right click
# print(str(int(event.x)) + " x " + str(int(event.x))) # Where clicked
# model, path = treeview.get_path_at_pos(int(event.x), int(event.y))
menu = gtk.Menu()
# Select All
select_all = gtk.MenuItem(label="Select All")
select_all.connect("activate", self.treeview_Data_Grid_select_all)
select_all.show()
menu.append(select_all)
# Select None
select_none = gtk.MenuItem(label="Select None")
select_none.connect("activate", self.treeview_Data_Grid_select_none)
select_none.show()
menu.append(select_none)
# Select Inverse
select_inverse = gtk.MenuItem(label="Select Inverse")
select_inverse.connect("activate", self.treeview_Data_Grid_select_inverse)
select_inverse.show()
menu.append(select_inverse)
# Separator_1
separator_1 = gtk.SeparatorMenuItem()
separator_1.show()
menu.append(separator_1)
# Data Grid - treeviewcolumn_Size
file_size = gtk.MenuItem(label="Toggle \'Size\' column")
file_size.connect("activate", self.treeview_Data_Grid_toggle_size)
file_size.show()
menu.append(file_size)
# Data Grid - treeviewcolumn_Date_Modified
date_modified = gtk.MenuItem(label="Toggle \'Date Modified\' column")
date_modified.connect("activate", self.treeview_Data_Grid_toggle_date_modified)
date_modified.show()
menu.append(date_modified)
# Separator_2
separator_2 = gtk.SeparatorMenuItem()
separator_2.show()
menu.append(separator_2)
# Data Grid - treeviewcolumn_Full_Path
full_path = gtk.MenuItem(label="Toggle \'Full Path\' column")
full_path.connect("activate", self.treeview_Data_Grid_toggle_full_path)
full_path.show()
menu.append(full_path)
# Data Grid - treeviewcolumn_Local_Path
local_path = gtk.MenuItem(label="Toggle \'Local Path\' column")
local_path.connect("activate", self.treeview_Data_Grid_toggle_local_path)
local_path.show()
menu.append(local_path)
# Data Grid - treeviewcolumn_Type
file_type = gtk.MenuItem(label="Toggle \'Type\' column")
file_type.connect("activate", self.treeview_Data_Grid_toggle_file_type)
file_type.show()
menu.append(file_type)
# Data Grid - treeviewcolumn_Hidden
file_hidden = gtk.MenuItem(label="Toggle \'Hidden\' column")
file_hidden.connect("activate", self.treeview_Data_Grid_toggle_hidden)
file_hidden.show()
menu.append(file_hidden)
menu.popup(None, None, None, None, event.button, event.time)
def set_spinner_orientation(self, direction): # set the direction of all spinner widgets to Horizontal or Vertical
spin_Remove_First = self.builder.get_object("spin_Remove_First")
spin_Remove_Last = self.builder.get_object("spin_Remove_Last")
spin_Remove_From = self.builder.get_object("spin_Remove_From")
spin_Remove_To = self.builder.get_object("spin_Remove_To")
spin_Add_Insert = self.builder.get_object("spin_Add_Insert")
spin_Numbering_At = self.builder.get_object("spin_Numbering_At")
spin_Numbering_Start = self.builder.get_object("spin_Numbering_Start")
spin_Numbering_Increment = self.builder.get_object("spin_Numbering_Increment")
spin_Numbering_Padding = self.builder.get_object("spin_Numbering_Padding")
spin_File_Name_Min = self.builder.get_object("spin_File_Name_Min")
spin_File_Name_Max = self.builder.get_object("spin_File_Name_Max")
if direction.upper() == "HORIZONTAL":
spin_Remove_First.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Remove_Last.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Remove_From.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Remove_To.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Add_Insert.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Numbering_At.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Numbering_Start.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Numbering_Increment.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Numbering_Padding.set_orientation(gtk.Orientation.HORIZONTAL)
spin_File_Name_Min.set_orientation(gtk.Orientation.HORIZONTAL)
spin_File_Name_Max.set_orientation(gtk.Orientation.HORIZONTAL)
elif direction.upper() == "VERTICAL":
spin_Remove_First.set_orientation(gtk.Orientation.VERTICAL)
spin_Remove_Last.set_orientation(gtk.Orientation.VERTICAL)
spin_Remove_From.set_orientation(gtk.Orientation.VERTICAL)
spin_Remove_To.set_orientation(gtk.Orientation.VERTICAL)
spin_Add_Insert.set_orientation(gtk.Orientation.VERTICAL)
spin_Numbering_At.set_orientation(gtk.Orientation.VERTICAL)
spin_Numbering_Start.set_orientation(gtk.Orientation.VERTICAL)
spin_Numbering_Increment.set_orientation(gtk.Orientation.VERTICAL)
spin_Numbering_Padding.set_orientation(gtk.Orientation.VERTICAL)
spin_File_Name_Min.set_orientation(gtk.Orientation.VERTICAL)
spin_File_Name_Max.set_orientation(gtk.Orientation.VERTICAL)
else: # "HORIZONTAL" is the default
spin_Remove_First.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Remove_Last.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Remove_From.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Remove_To.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Add_Insert.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Numbering_At.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Numbering_Start.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Numbering_Increment.set_orientation(gtk.Orientation.HORIZONTAL)
spin_Numbering_Padding.set_orientation(gtk.Orientation.HORIZONTAL)
spin_File_Name_Min.set_orientation(gtk.Orientation.HORIZONTAL)
spin_File_Name_Max.set_orientation(gtk.Orientation.HORIZONTAL)
def set_scrollwindow_Data_Grid_height(self, new_height): # Set the height of the data grid
scrollwindow_Data_Grid = self.builder.get_object("scrollwindow_Data_Grid")
if int(new_height) >= 0:
scrollwindow_Data_Grid.set_size_request(scrollwindow_Data_Grid.get_allocated_width(), int(new_height))
else:
scrollwindow_Data_Grid.set_size_request(scrollwindow_Data_Grid.get_allocated_width(), 400) # Default is 400
""" ************************************************************************************************************ """
# These are the various widget's signal handler functions: UI elements that are buttons & dialogs
""" ************************************************************************************************************ """
def button_Rename_Pairs_clicked(self, widget):
global rename_pairs_from_file
global rename_pairs_file_to_load
# Clear out the existing rename_pairs_from_file and remove the red border from the button
rename_pairs_from_file.clear()
self.rename_pairs_file = False
button_Rename_Pairs = self.builder.get_object("button_Rename_Pairs")
button_Rename_Pairs.get_style_context().remove_class('red-border')
open_dialog = gtk.FileChooserDialog(title="Please choose a rename pairs \'.txt\' file", parent=None, action=gtk.FileChooserAction.OPEN)
open_dialog.set_current_folder(default_folder_path)
open_dialog.add_buttons(gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL, gtk.STOCK_OPEN, gtk.ResponseType.OK)
open_dialog.set_local_only(False)
open_dialog.set_modal(True)
# *.txt filter
filter = gtk.FileFilter()
filter.set_name("txt files")
filter.add_pattern("*.txt")
open_dialog.add_filter(filter)
response = open_dialog.run()
file = ""
if response == gtk.ResponseType.OK:
file = open_dialog.get_filename()
elif response == gtk.ResponseType.CANCEL:
file = ""
open_dialog.destroy()
if file != "":
rename_pairs_file_to_load = file # Update path the rename pairs file
read_in_rename_pairs_file() # Read in the rename pairs file
if len(rename_pairs_from_file) > 0: # If rename_pairs_from_file has any rename pairs, set the border of the button to red
button_Rename_Pairs.get_style_context().add_class('red-border')
self.rename_pairs_file = True
def button_Refresh_clicked(self, widget):
self.repaint_GUI() # Make sure GUI is up to date
window = self.builder.get_object("main_window")
watch_cursor = gdk.Cursor(gdk.CursorType.WATCH)
window.get_window().set_cursor(watch_cursor) # Set curror to 'Waiting'
self.repaint_GUI() # Make sure GUI is up to date
self.clear_Data_Grid()
populate_files_Full(self.builder.get_object("entry_Mask").get_text(),
self.builder.get_object("checkbox_Folders").get_active(),
self.builder.get_object("checkbox_Subfolders").get_active(),
self.builder.get_object("checkbox_Files").get_active(),
self.builder.get_object("checkbox_Hidden").get_active(),
self.builder.get_object("spin_File_Name_Min").get_value_as_int(),
self.builder.get_object("spin_File_Name_Max").get_value_as_int(),
)
self.load_Data_Grid()
self.resize_column_widths()
self.update_status_labels()
self.repaint_GUI() # Make sure GUI is up to date
window.get_window().set_cursor(None) # Set curror back to 'None'
self.repaint_GUI() # Make sure GUI is up to date
def button_Refresh_and_Reselect_clicked(self, widget):
self.repaint_GUI() # Make sure GUI is up to date
window = self.builder.get_object("main_window")
watch_cursor = gdk.Cursor(gdk.CursorType.WATCH)
window.get_window().set_cursor(watch_cursor) # Set curror to 'Waiting'
self.repaint_GUI() # Make sure GUI is up to date
# Save selected rows
treeview_Data_Grid = self.builder.get_object("treeview_Data_Grid")
treeselection = treeview_Data_Grid.get_selection()
model, items = treeselection.get_selected_rows()
temp_indexes = [] # Holds the rows indexes of the currently selected rows
temp_treepaths = [] # Holds the TreePath objects of the currently selected rows
if len(model) > 0:
for item in items: # Build list of the currently selected rows
temp_indexes.append(int(str(item)))
temp_treepaths.append(item)
self.clear_Data_Grid()
populate_files_Full(self.builder.get_object("entry_Mask").get_text(),
self.builder.get_object("checkbox_Folders").get_active(),
self.builder.get_object("checkbox_Subfolders").get_active(),
self.builder.get_object("checkbox_Files").get_active(),
self.builder.get_object("checkbox_Hidden").get_active(),
self.builder.get_object("spin_File_Name_Min").get_value_as_int(),
self.builder.get_object("spin_File_Name_Max").get_value_as_int(),
)
self.load_Data_Grid()
self.resize_column_widths()
self.update_status_labels()
# Re-select selected rows
for x in range(len(temp_treepaths)): # Unselect the currently selected rows
treeselection.select_path(temp_treepaths[x])
for x in range(len(model)): # Select the currently unselected rows
if x in temp_indexes:
treeselection.select_path(x)
self.repaint_GUI() # Make sure GUI is up to date
window.get_window().set_cursor(None) # Set curror back to 'None'
self.repaint_GUI() # Make sure GUI is up to date
def button_Reset_clicked(self, widget):
# I need to get all box 1-9 elements and manually reset them to default... I wish there was a better way...
# Set data grid selection to none, that will speed this up
treeview_Data_Grid = self.builder.get_object("treeview_Data_Grid")
treeselection = treeview_Data_Grid.get_selection()
treeselection.unselect_all()
# box 1
combo_Name = self.builder.get_object("combo_Name")
combo_Name_Entry = self.builder.get_object("combo_Name_Entry")
combo_Name.set_entry_text_column(0)
combo_Name.set_active(0)
entry_Name_Fixed = self.builder.get_object("entry_Name_Fixed")
entry_Name_Fixed.set_text("")
# box 2
entry_Replace_Search = self.builder.get_object("entry_Replace_Search")
entry_Replace_Search.set_text("")
checkbox_Replace_Case = self.builder.get_object("checkbox_Replace_Case")
checkbox_Replace_Case.set_active(False) # Default is unchecked (i.e. case insensitive)
entry_Replace_With = self.builder.get_object("entry_Replace_With")
entry_Replace_With.set_text("")
# box 3
combo_Case = self.builder.get_object("combo_Case")
combo_Case_Entry = self.builder.get_object("combo_Case_Entry")
combo_Case.set_entry_text_column(0)
combo_Case.set_active(0)
# box 4
spin_Remove_First = self.builder.get_object("spin_Remove_First")
spin_Remove_First.set_value(0)
spin_Remove_Last = self.builder.get_object("spin_Remove_Last")
spin_Remove_Last.set_value(0)
spin_Remove_From = self.builder.get_object("spin_Remove_From")
spin_Remove_From.set_value(0)
spin_Remove_To = self.builder.get_object("spin_Remove_To")
spin_Remove_To.set_value(0)
combo_Remove_Crop = self.builder.get_object("combo_Remove_Crop")
combo_Remove_Crop_Entry = self.builder.get_object("combo_Remove_Crop_Entry")
combo_Remove_Crop.set_entry_text_column(0)
combo_Remove_Crop.set_active(0)
entry_Remove_Crop = self.builder.get_object("entry_Remove_Crop")
entry_Remove_Crop.set_text("")
# box 5
entry_Add_Insert = self.builder.get_object("entry_Add_Insert")
entry_Add_Insert.set_text("")
entry_Add_Suffix = self.builder.get_object("entry_Add_Suffix")
entry_Add_Suffix.set_text("")
entry_Add_Prefix = self.builder.get_object("entry_Add_Prefix")
entry_Add_Prefix.set_text("")
spin_Add_Insert = self.builder.get_object("spin_Add_Insert")
spin_Add_Insert.set_value(0)
# box 6
combo_Append_Folder_Name = self.builder.get_object("combo_Append_Folder_Name")
combo_Append_Folder_Name_Entry = self.builder.get_object("combo_Append_Folder_Name_Entry")
combo_Append_Folder_Name.set_entry_text_column(0)
combo_Append_Folder_Name.set_active(0)
entry_Append_Folder_Name_Separator = self.builder.get_object("entry_Append_Folder_Name_Separator")
entry_Append_Folder_Name_Separator.set_text("")
# box 7
combo_Numbering = self.builder.get_object("combo_Numbering")
combo_Numbering_Entry = self.builder.get_object("combo_Numbering_Entry")
combo_Numbering.set_entry_text_column(0)
combo_Numbering.set_active(0)
spin_Numbering_At = self.builder.get_object("spin_Numbering_At")
spin_Numbering_At.set_value(0)
spin_Numbering_Increment = self.builder.get_object("spin_Numbering_Increment")
spin_Numbering_Increment.set_value(1)
spin_Numbering_Padding = self.builder.get_object("spin_Numbering_Padding")
spin_Numbering_Padding.set_value(1)
spin_Numbering_Start = self.builder.get_object("spin_Numbering_Start")
spin_Numbering_Start.set_value(1)
checkbox_Numbering_Per_Folder = self.builder.get_object("checkbox_Numbering_Per_Folder")
checkbox_Numbering_Per_Folder.set_active(False)
entry_Numbering_Separator = self.builder.get_object("entry_Numbering_Separator")
entry_Numbering_Separator.set_text("")
# box 8
combo_Extension = self.builder.get_object("combo_Extension")
combo_Extension_entry = self.builder.get_object("combo_Extension_entry")
combo_Extension.set_entry_text_column(0)
combo_Extension.set_active(0)
entry_Extension = self.builder.get_object("entry_Extension")
entry_Extension.set_text("")
# box 9
checkbox_Folders = self.builder.get_object("checkbox_Folders")
checkbox_Folders.set_active(True)
checkbox_Subfolders = self.builder.get_object("checkbox_Subfolders")
checkbox_Subfolders.set_active(False)
checkbox_Files = self.builder.get_object("checkbox_Files")
checkbox_Files.set_active(True)
checkbox_Hidden = self.builder.get_object("checkbox_Hidden")
checkbox_Hidden.set_active(False)
radio_Use_Wildcards = self.builder.get_object("radio_Use_Wildcards")
radio_Use_Wildcards.set_active(True)
entry_Mask = self.builder.get_object("entry_Mask")
entry_Mask.set_text("*.*")
spin_File_Name_Min = self.builder.get_object("spin_File_Name_Min")
spin_File_Name_Min.set_value(0)
spin_File_Name_Max = self.builder.get_object("spin_File_Name_Max")
spin_File_Name_Max.set_value(0)
# Import Rename Pairs button
global rename_pairs_from_file
rename_pairs_from_file.clear()
button_Rename_Pairs = self.builder.get_object("button_Rename_Pairs")
button_Rename_Pairs.get_style_context().remove_class('red-border')
# Re-Apply custom settings
self.apply_application_settings()
self.update_status_labels()
def button_Rename_clicked(self, widget):
# Map between model[item][] and files_Full[]
# model[item][0] = files_Full[4] = Current_Name
# model[item][1] = files_Full[5] = New_Name
# model[item][2] = files_Full[2] = Sub_Directory
# model[item][3] = files_Full[6] = Size
# model[item][4] = files_Full[7] = Date_Modified
# model[item][5] = files_Full[9] = Status
# model[item][6] = files_Full[0] = Full_Path
# model[item][7] = files_Full[1] = Local_Path
# model[item][8] = files_Full[3] = Type
# model[item][9] = files_Full[8] = Hidden
global directory_counts
global rename_pairs
for data in directory_counts:
directory_counts[data] = 0
# Clear out the rename_pairs
rename_pairs.clear()
# Get selected rows and rename them
treeview_Data_Grid = self.builder.get_object("treeview_Data_Grid")
selection = treeview_Data_Grid.get_selection()
model, items = selection.get_selected_rows()
if len(items) > 0: # Don't bother renaming if there isn't at least one selected item
if items:
for item in items:
# Populate the rename_pairs with the selected rows
if model[item][5] != "No change...": # Don't need to include rows are "No change..."
rename_pairs.append([model[item][0], model[item][1], model[item][5], model[item][6], model[item][8]])
# Call the rename function
self.rename_files()
# Update the Status column with the status (file rename success) from rename_files()
if items:
# This isn't the best implementation, but it is much improved!
# 3000 records used to take [94.98 seconds], but it now takes [0.5 seconds]
# Make a dictionary from rename_pairs
pair = {} # original name = [new name, status, full path (with the new name)]
for loop in range(len(rename_pairs)):
pair[rename_pairs[loop][0]] = [rename_pairs[loop][1], rename_pairs[loop][2], rename_pairs[loop][3]]
# Loop through all of the items (i.e. selected rows in data grid) matching Full Path to then get Status
for item in range(len(items)):
# items[item].get_indices() = This is the current row in model[] that is selected and we are looping over
# If data grid rows [1,3,8] are selected, then the indices will be [0,2,7], so model[0]=row 1 & model[7]=row 8
if model[items[item].get_indices()][0] in pair: # If the file in question is in the pair dict, then work on it, else do nothing as it wasn't renamed
if model[items[item].get_indices()][6] == pair[model[items[item].get_indices()][0]][2]: # If the model[][Full_Path] == rename_pairs[Full_Path] (meaning this file was renamed)
model[items[item].get_indices()][5] = pair[model[items[item].get_indices()][0]][1] # Update the model[][Status] to the rename_pairs[Status]
if model[items[item].get_indices()][5] == "Renamed!":
model[items[item].get_indices()][0] = pair[model[items[item].get_indices()][0]][0] # Update model[][Current Name] to the rename_pairs[New Name]
model[items[item].get_indices()][6] = update_full_path_with_new_name(model[items[item].get_indices()][6], model[items[item].get_indices()][0], model[items[item].get_indices()][8]) # Update Full Path to the new full path with the updated rename_pairs[New Name]
model[items[item].get_indices()][7] = update_local_path_with_new_value(model[items[item].get_indices()][6], model[items[item].get_indices()][0], model[items[item].get_indices()][8]) # Update Local Path
self.save_history()
self.update_status_labels()
def button_About_clicked(self, widget): # Creates the About Dialog
about = gtk.AboutDialog()
about.connect("key-press-event", self.about_dialog_key_press) # Easter Egg: Check to see if Konami code has been entered
about.set_program_name("Linux File Rename Utility")
about.set_version("Version 1.16")
about.set_copyright("Copyright (c) BSFEMA")
about.set_comments("Python application using Gtk and Glade for renaming files/folders in Linux")
about.set_license_type(gtk.License(7)) # License = MIT_X11
about.set_website("https://github.com/BSFEMA/linux_file_rename_utility")
about.set_website_label("https://github.com/BSFEMA/linux_file_rename_utility")
about.set_authors(["BSFEMA"])
about.set_artists(["BSFEMA"])
about.set_documenters(["BSFEMA"])
about.run()
about.destroy()
def about_dialog_key_press(self, widget, event): # Easter Egg: Check to see if Konami code has been entered
global konami_code
keyname = gdk.keyval_name(event.keyval)
if len(konami_code) == 10:
konami_code.pop(0)
konami_code.append(keyname)
else:
konami_code.append(keyname)
if (konami_code == ['Up', 'Up', 'Down', 'Down', 'Left', 'Right', 'Left', 'Right', 'b', 'a']) or (konami_code == ['Up', 'Up', 'Down', 'Down', 'Left', 'Right', 'Left', 'Right', 'B', 'A']):
self.dialog_BSFEMA(self)
# print("Konami code entered: " + str(konami_code))
konami_code.clear()
def dialog_BSFEMA(self, widget): # Creates the "BSFEMA" dialog that just spins my logo
dialog = gtk.Dialog(title="BSFEMA", parent=None)
dialog.add_buttons(gtk.STOCK_OK, gtk.ResponseType.OK)
dialog.set_modal(True)
# dialog.set_default_size(200, 200)
area = dialog.get_content_area()
dialog.image = gtk.Image()
dialog.image.set_from_file(os.path.join(sys.path[0], "linux_file_rename_utility.svg"))
dialog.image.get_style_context().add_class('spinner')
area.add(dialog.image)
dialog.show_all()
dialog.run()
dialog.destroy()
def button_Open_Settings_clicked(self, widget):
global settings_file_to_load
open_dialog = gtk.FileChooserDialog(title="Please choose a \'settings.txt\' file", parent=None, action=gtk.FileChooserAction.OPEN)
open_dialog.set_current_folder(os.path.expanduser("~/.config/BSFEMA/"))
open_dialog.add_buttons(gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL, gtk.STOCK_OPEN, gtk.ResponseType.OK)
open_dialog.set_local_only(False)
open_dialog.set_modal(True)
# *.txt filter
filter = gtk.FileFilter()
filter.set_name("txt files")
filter.add_pattern("*.txt")
open_dialog.add_filter(filter)
response = open_dialog.run()
file = ""
if response == gtk.ResponseType.OK:
file = open_dialog.get_filename()
elif response == gtk.ResponseType.CANCEL:
file = ""
open_dialog.destroy()
if file != "":
settings_file_to_load = file # Update path the application settings
read_in_application_settings() # Read in new application settings
self.apply_application_settings() # Apply custom user application settings
def button_SaveAs_Settings_clicked(self, widget): # Saves Settings to settings.txt
saveas_dialog = gtk.FileChooserDialog(title="Please save a \'settings.txt\' file", parent=None, action=gtk.FileChooserAction.SAVE)
saveas_dialog.set_current_folder(os.path.expanduser("~/.config/BSFEMA/"))
saveas_dialog.add_buttons(gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL, gtk.STOCK_SAVE_AS, gtk.ResponseType.OK)
saveas_dialog.set_local_only(False)
saveas_dialog.set_modal(True)
# *.txt filter
filter = gtk.FileFilter()
filter.set_name("txt files")
filter.add_pattern("*.txt")
saveas_dialog.add_filter(filter)
response = saveas_dialog.run()
if response == gtk.ResponseType.OK:
file = saveas_dialog.get_filename()
elif response == gtk.ResponseType.CANCEL:
file = ""
else:
file = ""
saveas_dialog.destroy()
if file != "":
# make sure that the file ends in .txt
if file[-4:] != ".txt":
file = file + ".txt"
global application_Settings
file = open(os.path.expanduser(file), "w", encoding='utf-8-sig')
# box 1
file.write("# box 1\n")
combo_Name = self.builder.get_object("combo_Name")
combo_Name_Entry = self.builder.get_object("combo_Name_Entry")
file.write("combo_Name=" + combo_Name_Entry.get_text() + "\n")
entry_Name_Fixed = self.builder.get_object("entry_Name_Fixed")
file.write("entry_Name_Fixed=" + entry_Name_Fixed.get_text() + "\n")
# box 2
file.write("# box 2\n")
entry_Replace_Search = self.builder.get_object("entry_Replace_Search")
file.write("entry_Replace_Search=" + entry_Replace_Search.get_text() + "\n")
checkbox_Replace_Case = self.builder.get_object("checkbox_Replace_Case")
file.write("checkbox_Replace_Case=" + str(checkbox_Replace_Case.get_active()) + "\n")
entry_Replace_With = self.builder.get_object("entry_Replace_With")
file.write("entry_Replace_With=" + entry_Replace_With.get_text() + "\n")
# box 3
file.write("# box 3\n")
combo_Case = self.builder.get_object("combo_Case")
combo_Case_Entry = self.builder.get_object("combo_Case_Entry")
file.write("combo_Case=" + combo_Case_Entry.get_text() + "\n")
# box 4
file.write("# box 4\n")
spin_Remove_First = self.builder.get_object("spin_Remove_First")
file.write("spin_Remove_First=" + str(int(spin_Remove_First.get_value())) + "\n")
spin_Remove_Last = self.builder.get_object("spin_Remove_Last")
file.write("spin_Remove_Last=" + str(int(spin_Remove_Last.get_value())) + "\n")
spin_Remove_From = self.builder.get_object("spin_Remove_From")
file.write("spin_Remove_From=" + str(int(spin_Remove_From.get_value())) + "\n")
spin_Remove_To = self.builder.get_object("spin_Remove_To")
file.write("spin_Remove_To=" + str(int(spin_Remove_To.get_value())) + "\n")
combo_Remove_Crop = self.builder.get_object("combo_Remove_Crop")
combo_Remove_Crop_Entry = self.builder.get_object("combo_Remove_Crop_Entry")
file.write("combo_Remove_Crop=" + combo_Remove_Crop_Entry.get_text() + "\n")
entry_Remove_Crop = self.builder.get_object("entry_Remove_Crop")
file.write("entry_Remove_Crop=" + entry_Remove_Crop.get_text() + "\n")
# box 5
file.write("# box 5\n")
entry_Add_Insert = self.builder.get_object("entry_Add_Insert")
file.write("entry_Add_Insert=" + entry_Add_Insert.get_text() + "\n")
entry_Add_Suffix = self.builder.get_object("entry_Add_Suffix")
file.write("entry_Add_Suffix=" + entry_Add_Suffix.get_text() + "\n")
entry_Add_Prefix = self.builder.get_object("entry_Add_Prefix")
file.write("entry_Add_Prefix=" + entry_Add_Prefix.get_text() + "\n")
spin_Add_Insert = self.builder.get_object("spin_Add_Insert")
file.write("spin_Add_Insert=" + str(int(spin_Add_Insert.get_value())) + "\n")
# box 6
file.write("# box 6\n")
combo_Append_Folder_Name = self.builder.get_object("combo_Append_Folder_Name")
combo_Append_Folder_Name_Entry = self.builder.get_object("combo_Append_Folder_Name_Entry")
file.write("combo_Append_Folder_Name=" + combo_Append_Folder_Name_Entry.get_text() + "\n")
entry_Append_Folder_Name_Separator = self.builder.get_object("entry_Append_Folder_Name_Separator")
file.write("entry_Append_Folder_Name_Separator=" + entry_Append_Folder_Name_Separator.get_text() + "\n")
# box 7
file.write("# box 7\n")
combo_Numbering = self.builder.get_object("combo_Numbering")
combo_Numbering_Entry = self.builder.get_object("combo_Numbering_Entry")
file.write("combo_Numbering=" + combo_Numbering_Entry.get_text() + "\n")
spin_Numbering_At = self.builder.get_object("spin_Numbering_At")
file.write("spin_Numbering_At=" + str(int(spin_Numbering_At.get_value())) + "\n")
spin_Numbering_Increment = self.builder.get_object("spin_Numbering_Increment")
file.write("spin_Numbering_Increment=" + str(int(spin_Numbering_Increment.get_value())) + "\n")
spin_Numbering_Padding = self.builder.get_object("spin_Numbering_Padding")
file.write("spin_Numbering_Padding=" + str(int(spin_Numbering_Padding.get_value())) + "\n")
spin_Numbering_Start = self.builder.get_object("spin_Numbering_Start")
file.write("spin_Numbering_Start=" + str(int(spin_Numbering_Start.get_value())) + "\n")
checkbox_Numbering_Per_Folder = self.builder.get_object("checkbox_Numbering_Per_Folder")
file.write("checkbox_Numbering_Per_Folder=" + str(checkbox_Numbering_Per_Folder.get_active()) + "\n")
entry_Numbering_Separator = self.builder.get_object("entry_Numbering_Separator")
file.write("entry_Numbering_Separator=" + entry_Numbering_Separator.get_text() + "\n")
# box 8
file.write("# box 8\n")
combo_Extension = self.builder.get_object("combo_Extension")
combo_Extension_entry = self.builder.get_object("combo_Extension_entry")
file.write("combo_Extension=" + combo_Extension_entry.get_text() + "\n")
entry_Extension = self.builder.get_object("entry_Extension")
file.write("entry_Extension=" + entry_Extension.get_text() + "\n")
# box 9
file.write("# box 9\n")
checkbox_Folders = self.builder.get_object("checkbox_Folders")
file.write("checkbox_Folders=" + str(checkbox_Folders.get_active()) + "\n")
checkbox_Subfolders = self.builder.get_object("checkbox_Subfolders")
file.write("checkbox_Subfolders=" + str(checkbox_Subfolders.get_active()) + "\n")
checkbox_Files = self.builder.get_object("checkbox_Files")
file.write("checkbox_Files=" + str(checkbox_Files.get_active()) + "\n")
checkbox_Hidden = self.builder.get_object("checkbox_Hidden")
file.write("checkbox_Hidden=" + str(checkbox_Hidden.get_active()) + "\n")
radio_Use_RegEx = self.builder.get_object("radio_Use_RegEx")
file.write("radio_Use_RegEx=" + str(radio_Use_RegEx.get_active()) + "\n")
radio_Use_Wildcards = self.builder.get_object("radio_Use_Wildcards")
file.write("radio_Use_Wildcards=" + str(radio_Use_Wildcards.get_active()) + "\n")
entry_Mask = self.builder.get_object("entry_Mask")
file.write("entry_Mask=" + entry_Mask.get_text() + "\n")
spin_File_Name_Min = self.builder.get_object("spin_File_Name_Min")
file.write("spin_File_Name_Min=" + str(int(spin_File_Name_Min.get_value())) + "\n")
spin_File_Name_Max = self.builder.get_object("spin_File_Name_Max")
file.write("spin_File_Name_Max=" + str(int(spin_File_Name_Max.get_value())) + "\n")
# Save History
file.write("# Save History\n")
checkbox_Save_History = self.builder.get_object("checkbox_Save_History")
file.write("checkbox_Save_History=" + str(checkbox_Save_History.get_active()) + "\n")
# Data Grid