-
Notifications
You must be signed in to change notification settings - Fork 3
/
FF_Main_UI.py
1329 lines (1134 loc) · 58.1 KB
/
FF_Main_UI.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
# This source file is a part of File Find made by Pixel-Master
#
# Copyright 2022-2024 Pixel-Master
#
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
# which should be included with this package. The terms are also available at
# http://www.gnu.org/licenses/gpl-3.0.html
# This file contains the code for the main window
# Imports
import logging
import os
from unicodedata import normalize
from json import dump, load
from sys import platform
import sys
# PySide6 Gui Imports
from PySide6.QtCore import QSize, Qt, QDate
from PySide6.QtGui import QFont, QDoubleValidator, QAction, QIcon, QClipboard
from PySide6.QtWidgets import QWidget, QLabel, QPushButton, QRadioButton, QFileDialog, \
QLineEdit, QButtonGroup, QDateEdit, QComboBox, QSystemTrayIcon, QMenu, QCompleter, QTabWidget, \
QMainWindow, QGridLayout, QSpacerItem, QSizePolicy
# Projects Libraries
import FF_Additional_UI
import FF_Files
import FF_About_UI
import FF_Search
import FF_Settings
# The class for the main window where filters can be selected
class MainWindow:
def __init__(self):
# Debug
logging.info("Launching UI...")
logging.debug("Setting up self.Root_Window...")
# Main Window
# Create the window
self.Root_Window = QMainWindow()
# Set the Title of the Window
self.Root_Window.setWindowTitle("File Find")
# Set the start size
self.BASE_WIDTH = 800
self.BASE_HEIGHT = 370
self.Root_Window.setBaseSize(self.BASE_WIDTH, self.BASE_HEIGHT)
self.Root_Window.resize(self.Root_Window.baseSize())
# Display the Window
self.Root_Window.show()
# Adding Layouts
# Main Layout
# Create a central widget
self.Central_Widget = QWidget(self.Root_Window)
self.Root_Window.setCentralWidget(self.Central_Widget)
# Create the main Layout
self.Main_Layout = QGridLayout(self.Central_Widget)
self.Central_Widget.setLayout(self.Main_Layout)
self.Main_Layout.setContentsMargins(20, 20, 20, 20)
self.Main_Layout.setVerticalSpacing(20)
# Tab widget, switch between Basic, Advanced and Sorting
self.tabbed_widget = QTabWidget(self.Root_Window)
# Display at the correct position
self.Main_Layout.addWidget(self.tabbed_widget, 1, 0, 10, 13)
# Labels
logging.debug("Setting up Labels...")
# Create a Label for every Filter with the Function, defined above
# -----Basic Search-----
# Tabs and Label
# Creating a new QWidget for the Basic tab
self.basic_search_widget = QWidget(self.Root_Window)
# Layout
self.basic_search_widget_layout = QGridLayout(self.basic_search_widget)
self.basic_search_widget.setLayout(self.basic_search_widget_layout)
self.basic_search_widget_layout.addItem(QSpacerItem(600, 0, hData=QSizePolicy.Policy.Maximum), 0, 0)
self.basic_search_widget_layout.addItem(QSpacerItem(600, 0, hData=QSizePolicy.Policy.Maximum), 0, 5)
# Add Tab
self.tabbed_widget.addTab(self.basic_search_widget, "Basic")
# Creating the Labels with tooltips
label_name = self.generate_large_filter_label(
"Name:",
self.basic_search_widget,
self.generic_tooltip("Name",
"Input needs to match the name of a file exactly, \nignoring case.\n\n"
"Also supports unix shell-style wildcards,\n"
"which are not the same as regular expressions. (also ignoring case)\n\nUsage:\n"
"Pattern Meaning\n"
" * matches everything\n"
" ? matches any single character\n"
" [seq] matches any character in seq\n"
" [!seq] matches any character not in seq\n\n"
"For further documentation: http://docs.python.org/library/fnmatch",
"Example.txt",
os.path.join(FF_Files.USER_FOLDER, "example.txt")))
self.basic_search_widget_layout.addWidget(label_name, 0, 1)
label_name_contains = self.generate_large_filter_label(
"Name contains:",
self.basic_search_widget,
self.generic_tooltip("Name contains",
"The name of a file must contain input,\nignoring case.",
"file",
os.path.join(FF_Files.USER_FOLDER, "my-file.pdf")))
self.basic_search_widget_layout.addWidget(label_name_contains, 1, 1)
label_file_group = self.generate_large_filter_label(
"File Types:",
self.basic_search_widget,
self.generic_tooltip("File Types",
"Select groups of files that should be included in search results",
"Music",
os.path.join(FF_Files.USER_FOLDER, "song.mp3")))
self.basic_search_widget_layout.addWidget(label_file_group, 2, 1)
label_directory = self.generate_large_filter_label(
"Directory:",
self.basic_search_widget,
self.generic_tooltip("Directory",
"The Directory to search in.",
os.path.join(
FF_Files.USER_FOLDER,
"Downloads"),
os.path.join(
FF_Files.USER_FOLDER,
"Downloads",
"example.pdf")))
self.basic_search_widget_layout.addWidget(label_directory, 3, 1)
# -----File Content-----
# Tab and Label
# Creating a new QWidget for the file content tab
self.properties_widget = QWidget(self.Root_Window)
# Layout
self.properties_widget_layout = QGridLayout(self.properties_widget)
self.properties_widget.setLayout(self.properties_widget_layout)
# Adding space
self.properties_widget_layout.addItem(QSpacerItem(600, 0, hData=QSizePolicy.Policy.Maximum), 0, 0)
self.properties_widget_layout.addItem(QSpacerItem(600, 0, hData=QSizePolicy.Policy.Maximum), 0, 6)
# Add Tab
self.tabbed_widget.addTab(self.properties_widget, "Properties")
# Search for file content
label_file_contains = self.generate_large_filter_label(
"File contains:",
self.properties_widget,
self.generic_tooltip("File contains:",
"Allows you to search in files. Input must be in the file content.\n"
"This option can take really long.\nInput is case-sensitive.",
"This is an example file!",
os.path.join(
FF_Files.USER_FOLDER, "example.txt (which contains: This is an example file!)")))
self.properties_widget_layout.addWidget(label_file_contains, 0, 1)
# Creation date
label_c_date = self.generate_large_filter_label(
"Date created:",
self.properties_widget,
self.generic_tooltip("Date created",
"Specify a date range for the date the file has been created,\n"
"leave at default to ignore.",
"5.Jul.2020 - 10.Aug.2020",
os.path.join(FF_Files.USER_FOLDER, "example.txt (created at 1.Aug.2020)")))
self.properties_widget_layout.addWidget(label_c_date, 1, 1)
label_c_date_2 = self.generate_large_filter_label("-", self.properties_widget)
self.properties_widget_layout.addWidget(label_c_date_2, 1, 4)
# Date modified
label_m_date = self.generate_large_filter_label(
"Date modified:",
self.properties_widget,
self.generic_tooltip("Date modified",
"Specify a date range for the date the file has been modified,\n "
"leave at default to ignore.",
"5.Jul.2020 - 10.Aug.2020",
os.path.join(FF_Files.USER_FOLDER, "example.txt (modified at 1.Aug.2020)")))
self.properties_widget_layout.addWidget(label_m_date, 2, 1)
label_m_date_2 = self.generate_large_filter_label("-", self.properties_widget)
self.properties_widget_layout.addWidget(label_m_date_2, 2, 4)
label_file_size = self.generate_large_filter_label(
"File size min:",
self.properties_widget,
self.generic_tooltip(
"File size",
"Input specifies file size in a range from min to max.\n"
"Select the unit (Byte, Megabyte, Gigabyte...) on the left.\n"
"Select \"No Limit\" to only set a minimum or maximum value.",
"min: 1 GB max: No Limit",
os.path.join(FF_Files.USER_FOLDER, "Applications",
"Microsoft Word.app (with a size of 2 GB)")))
self.properties_widget_layout.addWidget(label_file_size, 3, 1)
label_file_size_max = self.generate_large_filter_label("max:", self.properties_widget)
self.properties_widget_layout.addWidget(label_file_size_max, 3, 4)
# -----Advanced Search-----
# Tab and Label
# Creating a new QWidget for the file content tab
self.advanced_search_widget = QWidget(self.Root_Window)
# Layout
self.advanced_search_widget_layout = QGridLayout(self.advanced_search_widget)
self.advanced_search_widget.setLayout(self.advanced_search_widget_layout)
# Adding a spacer
self.advanced_search_widget_layout.addItem(QSpacerItem(600, 0, hData=QSizePolicy.Policy.Maximum), 0, 0)
self.advanced_search_widget_layout.addItem(QSpacerItem(600, 0, hData=QSizePolicy.Policy.Maximum), 0, 6)
# Add Tab
self.tabbed_widget.addTab(self.advanced_search_widget, "Advanced")
label_extension = self.generate_large_filter_label(
"File ending:",
self.advanced_search_widget,
self.generic_tooltip("File ending",
"Input needs to match the file ending (file type)\nwithout the \".\","
" ignoring case.",
"txt",
os.path.join(
FF_Files.USER_FOLDER,
"example.txt")))
self.advanced_search_widget_layout.addWidget(label_extension, 0, 1)
label_system_files = self.generate_large_filter_label(
"Search in system files:",
self.advanced_search_widget,
self.generic_tooltip("Search in system files",
"Toggle to include files in the system and library folders.",
"Yes",
os.path.join(FF_Files.USER_FOLDER, "Library", "Caches", "example.txt")))
self.advanced_search_widget_layout.addWidget(label_system_files, 1, 1)
label_files_folders = self.generate_large_filter_label(
"Search for:",
self.advanced_search_widget,
self.generic_tooltip("Search for",
"Toggle to only include folders or files in the search results",
"only Folders",
os.path.join(FF_Files.USER_FOLDER, "Downloads")))
self.advanced_search_widget_layout.addWidget(label_files_folders, 2, 1)
# -----Sorting-----
# Tab and Label
# Creating a new QWidget for the Sorting tab
self.sorting_widget = QWidget(self.Root_Window)
# Layout
self.sorting_widget_layout = QGridLayout(self.sorting_widget)
self.sorting_widget.setLayout(self.sorting_widget_layout)
# Adding a spacer
self.sorting_widget_layout.addItem(QSpacerItem(600, 0, hData=QSizePolicy.Policy.Maximum), 0, 0)
self.sorting_widget_layout.addItem(QSpacerItem(600, 0, hData=QSizePolicy.Policy.Maximum), 0, 6)
# Add Tab
self.tabbed_widget.addTab(self.sorting_widget, "Sorting")
label_sort_by = self.generate_large_filter_label(
"Sort by:",
self.sorting_widget,
self.generic_tooltip("Sort by",
"Select a sorting method to sort the results.",
"File Size",
"Results sorted by file size"))
self.sorting_widget_layout.addWidget(label_sort_by, 0, 1)
label_reverse_sort = self.generate_large_filter_label(
"Reverse results:",
self.sorting_widget,
self.generic_tooltip("Reverse Results",
"Reverse the sorted search results.",
"Yes",
"Reversed search results"))
self.sorting_widget_layout.addWidget(label_reverse_sort, 1, 1)
# -----Terminal Command-----
# Label, saying command
label_command_title = QLabel(self.Root_Window)
label_command_title.setText("Command:")
label_command_title.setToolTip(
"Terminal command:\nYou can paste this command into the Terminal app to search with the \"find\" tool")
label_command_title.setFont(QFont(FF_Files.DEFAULT_FONT, FF_Files.NORMAL_FONT_SIZE))
self.Main_Layout.addWidget(label_command_title, 11, 0)
label_command_title.hide()
# Label, displaying the command, using a read only line edit
label_command = QLineEdit(self.Root_Window)
label_command.setReadOnly(True)
label_command.setFixedWidth(300)
self.Main_Layout.addWidget(label_command, 11, 1)
label_command.hide()
# Copy Command Button
button_command_copy = QPushButton(self.Root_Window)
# Change the Text
button_command_copy.setText("Copy")
# When resizing, it shouldn't change size
button_command_copy.setFixedWidth(60)
# Display the Button at the correct position
self.Main_Layout.addWidget(button_command_copy, 11, 2)
button_command_copy.hide()
# ----- Search Indicator-----
# Title of searching indicator
search_status_title_label = QLabel(self.Root_Window)
search_status_title_label.setText("Status:")
search_status_title_label.setFont(QFont(FF_Files.DEFAULT_FONT, FF_Files.NORMAL_FONT_SIZE))
search_status_title_label.setToolTip(
"Search Indicator:\n"
"Indicates if searching and shows the numbers of active searches.\n"
"For more precise information click on the File Find logo in the menu-bar.")
search_status_title_label.show()
self.Main_Layout.addWidget(search_status_title_label, 12, 0)
# Label to indicate if searching
global search_status_label
search_status_label = QLabel(self.Root_Window)
search_status_label.setText("Inactive")
search_status_label.setFont(QFont(FF_Files.DEFAULT_FONT, FF_Files.NORMAL_FONT_SIZE))
search_status_label.setStyleSheet(f"color: {FF_Files.GREEN_COLOR};")
search_status_label.show()
self.Main_Layout.addWidget(search_status_label, 12, 1)
self.Main_Layout.addItem(QSpacerItem(600, 0, hData=QSizePolicy.Policy.Maximum), 12, 2)
# Entries
logging.debug("Setting up Entries...")
# Create an Entry for every Filter with the function self.generate_filter_entry()
# Name
self.edit_name = self.generate_filter_entry(self.basic_search_widget)
# Place
self.basic_search_widget_layout.addWidget(self.edit_name, 0, 2)
# Name contains
self.edit_name_contains = self.generate_filter_entry(self.basic_search_widget)
# Place
self.basic_search_widget_layout.addWidget(self.edit_name_contains, 1, 2)
# File extension
self.edit_file_extension = self.generate_filter_entry(self.properties_widget)
# Place
self.advanced_search_widget_layout.addWidget(self.edit_file_extension, 0, 2, 1, 5)
# Edit for displaying the Path
self.edit_directory = self.generate_filter_entry(self.basic_search_widget)
# Set text and tooltip to display the directory
self.edit_directory.setText(FF_Files.SELECTED_DIR)
# Execute the validate_dir function if text is changed
self.edit_directory.textChanged.connect(self.validate_dir)
# Loading Completions
self.complete_path(FF_Files.SELECTED_DIR, check=False)
# Resize and place on screen
self.basic_search_widget_layout.addWidget(self.edit_directory, 3, 2)
# File contains
self.edit_file_contains = self.generate_filter_entry(self.properties_widget)
self.edit_file_contains.resize(230, 25)
self.properties_widget_layout.addWidget(self.edit_file_contains, 0, 2, 1, 7)
# File size
# File size min
self.edit_size_min = self.generate_filter_entry(self.properties_widget, True)
self.edit_size_min.setFixedWidth(60)
self.properties_widget_layout.addWidget(self.edit_size_min, 3, 2)
# File size max
self.edit_size_max = self.generate_filter_entry(self.properties_widget, True)
self.edit_size_max.setFixedWidth(60)
self.properties_widget_layout.addWidget(self.edit_size_max, 3, 5)
# Unit selectors for selecting Byte, KiloByte, Megabyte...
def create_unit_selector(corresponding_edit):
# Create a QComboBox
unit_selector = QComboBox(self.advanced_search_widget)
unit_selector.addItems(["No Limit", "Bytes", "KB", "MB", "GB"])
# Set a fixed width
unit_selector.setFixedWidth(100)
def selection_changed():
if unit_selector.currentText() == "No Limit":
corresponding_edit.setEnabled(False)
corresponding_edit.setToolTip("No Limit is selected")
corresponding_edit.setStyleSheet(f"background-color: {FF_Files.GREY_DISABLED_COLOR};")
else:
corresponding_edit.setEnabled(True)
corresponding_edit.setToolTip("")
corresponding_edit.setStyleSheet(";")
# Connect to change event
unit_selector.currentTextChanged.connect(selection_changed)
# Set value to "No Limit"
unit_selector.setCurrentText("No Limit")
# Deactivate Edit
selection_changed()
return unit_selector
# Unit selector min
self.unit_selector_min = create_unit_selector(self.edit_size_min)
self.properties_widget_layout.addWidget(self.unit_selector_min, 3, 3)
# Unit selector max
self.unit_selector_max = create_unit_selector(self.edit_size_max)
self.properties_widget_layout.addWidget(self.unit_selector_max, 3, 6)
# Radio Button
logging.debug("Setting up Radio Buttons...")
# Search for Library Files
# Group for Radio Buttons
self.library_group = QButtonGroup(self.Root_Window)
# Radio Button 1
self.rb_library_yes = self.create_radio_button(self.library_group, "Yes", self.advanced_search_widget)
# Add the button to the layout
self.advanced_search_widget_layout.addWidget(self.rb_library_yes, 1, 2)
# Radio Button 2
self.rb_library_no = self.create_radio_button(self.library_group, "No", self.advanced_search_widget)
# Add the button to the layout
self.advanced_search_widget_layout.addWidget(self.rb_library_no, 1, 2, 1, 4, Qt.AlignmentFlag.AlignCenter)
# Select the Button 2
self.rb_library_no.setChecked(True)
# Reverse Sort
# Group for Radio Buttons
reverse_sort_group = QButtonGroup(self.Root_Window)
# Radio Button 1
rb_reverse_sort_yes = self.create_radio_button(reverse_sort_group, "Yes", self.sorting_widget)
# Add the button to the layout
self.sorting_widget_layout.addWidget(rb_reverse_sort_yes, 1, 2)
# Radio Button 2
rb_reverse_sort_no = self.create_radio_button(reverse_sort_group, "No", self.sorting_widget)
# Add the button to the layout
self.sorting_widget_layout.addWidget(rb_reverse_sort_no, 1, 3)
# Select the Button
rb_reverse_sort_no.setChecked(True)
# Drop Down Menus
logging.debug("Setting up Combo Boxes...")
# Sorting Menu
# Defining
self.combobox_sorting = QComboBox(self.sorting_widget)
# Adding Options
self.combobox_sorting.addItems(
["None (fastest)",
"File Size",
"File Name",
"Date Modified",
"Date Created",
"Path"])
# Set a fixed width
self.combobox_sorting.setFixedWidth(150)
# Display
self.combobox_sorting.show()
self.sorting_widget_layout.addWidget(self.combobox_sorting, 0, 2, 1, 4)
# Search for Files or Folders Menu
# Defining
self.combobox_search_for = QComboBox(self.advanced_search_widget)
# Adding Options
self.combobox_search_for.addItems(
["Files and Folders",
"only Files",
"only Folders"])
# Display
self.combobox_search_for.setFixedWidth(200)
self.advanced_search_widget_layout.addWidget(self.combobox_search_for, 2, 2)
# Search for file types: all, images, movies, music, etc...
self.combobox_file_types = FF_Additional_UI.CheckableComboBox(self.advanced_search_widget)
self.combobox_file_types.addItems(FF_Files.FILE_FORMATS.keys())
self.combobox_file_types.setFixedWidth(230)
# Display
self.combobox_file_types.show()
self.basic_search_widget_layout.addWidget(self.combobox_file_types, 2, 2)
# The combobox for file types and the file ending line edit can not be used together,
# as there will be no files found
def block_file_types():
# Block / Unblock File ending edit
if self.combobox_file_types.all_checked_items() != list(FF_Files.FILE_FORMATS.keys()):
# Disable File ending edit
# Debug
logging.debug("Disabled file ending edit")
# Block the file ending edit
self.edit_file_extension.setDisabled(True)
self.edit_file_extension.setToolTip("File types can't be used together with file extension")
self.edit_file_extension.setStyleSheet(f"background-color: {FF_Files.GREY_DISABLED_COLOR};")
else:
# Debug
logging.debug("Enabled file ending edit")
# Enable the file ending edit
self.edit_file_extension.setDisabled(False)
self.edit_file_extension.setToolTip("")
self.edit_file_extension.setStyleSheet(";")
# Block/ Unblock FIle groups combobox
if self.edit_file_extension.text() == "":
# Debug
logging.debug("Enabled combobox file groups")
# Enable Combobox
# Set the displayed text to the original
self.combobox_file_types.setPlaceholderText(self.combobox_file_types.determine_text())
self.combobox_file_types.setDisabled(False)
self.combobox_file_types.setToolTip("")
# Enabling "select all" and "Deselect all" buttons
self.combobox_file_types.data_changed()
# If something is written in the file ending edit
else:
# Enable Combobox
# Debug
logging.debug("Disabled combobox file groups")
# Set the displayed text to the text of the line edit
self.combobox_file_types.setPlaceholderText(self.edit_file_extension.text())
self.combobox_file_types.setDisabled(True)
self.combobox_file_types.setToolTip("File types can't be used together with file extension")
# Disabling "select all" and "Deselect all" buttons
deselect_all_button.setDisabled(True)
select_all_button.setDisabled(True)
# Connecting change signals to the function defined above
self.edit_file_extension.textChanged.connect(block_file_types)
self.combobox_file_types.model().dataChanged.connect(block_file_types)
# Date-Time Entries
logging.debug("Setting up Day Entries...")
# Date Created
self.c_date_from_drop_down = self.generate_day_entry(self.advanced_search_widget)
self.properties_widget_layout.addWidget(self.c_date_from_drop_down, 1, 2, 1, 4)
self.c_date_to_drop_down = self.generate_day_entry(self.advanced_search_widget)
self.c_date_to_drop_down.setDate(QDate.currentDate())
self.properties_widget_layout.addWidget(self.c_date_to_drop_down, 1, 5, 1, 7)
# Date Modified
self.m_date_from_drop_down = self.generate_day_entry(self.advanced_search_widget)
self.properties_widget_layout.addWidget(self.m_date_from_drop_down, 2, 2, 1, 4)
self.m_date_to_drop_down = self.generate_day_entry(self.advanced_search_widget)
self.m_date_to_drop_down.setDate(QDate.currentDate())
self.properties_widget_layout.addWidget(self.m_date_to_drop_down, 2, 5, 1, 7)
# Push Buttons
logging.debug("Setting up Push Buttons...")
# Buttons
# Search from Button
# Opens the File dialogue and changes the current working dir into the returned value
def open_dialog():
search_from = QFileDialog.getExistingDirectory(dir=FF_Files.SELECTED_DIR)
# If a dir was selected
if search_from != "":
try:
FF_Files.SELECTED_DIR = search_from
self.edit_directory.setText(search_from)
except OSError:
pass
browse_path_button = self.generate_edit_button(open_dialog, self.basic_search_widget, text="Browse")
browse_path_button.setFixedWidth(80)
self.basic_search_widget_layout.addWidget(browse_path_button, 3, 3)
# Select and deselect all options in the check able file group combobox
select_all_button = self.generate_edit_button(
self.combobox_file_types.select_all, self.basic_search_widget, text="Select all")
select_all_button.setFixedWidth(80)
self.basic_search_widget_layout.addWidget(select_all_button, 2, 3)
select_all_button.setEnabled(False)
deselect_all_button = self.generate_edit_button(
self.combobox_file_types.deselected_all, self.basic_search_widget, text="Deselect all")
# Place on the layout
deselect_all_button.setFixedWidth(90)
self.basic_search_widget_layout.addWidget(deselect_all_button, 2, 4)
# Activate/Deactivate buttons if necessary
self.combobox_file_types.button_signals.all_selected.connect(lambda: deselect_all_button.setDisabled(False))
self.combobox_file_types.button_signals.all_selected.connect(lambda: select_all_button.setDisabled(True))
# If only some options are enabled
self.combobox_file_types.button_signals.some_selected.connect(lambda: deselect_all_button.setDisabled(False))
self.combobox_file_types.button_signals.some_selected.connect(lambda: select_all_button.setDisabled(False))
# If all files are deselected
self.combobox_file_types.button_signals.all_deselected.connect(lambda: deselect_all_button.setDisabled(True))
self.combobox_file_types.button_signals.all_deselected.connect(lambda: select_all_button.setDisabled(False))
# Print the given data
def print_data():
logging.info(
f"\nFilters:\n"
f"Name: {self.edit_name.text()}\n"
f"Name contains: {self.edit_name_contains.text()}\n"
f"File Ending: {self.edit_file_extension.text()}\n"
f"Search from: {os.path.abspath(FF_Files.SELECTED_DIR)}\n\n"
f"File size: min: {self.edit_size_min.text()} ({self.unit_selector_min.currentText()})"
f" max: {self.edit_size_max.text()} ({self.unit_selector_min.currentText()})\n"
f"Date modified from: {self.m_date_from_drop_down.text()} to: {self.m_date_to_drop_down.text()}\n"
f"Date created from: {self.c_date_from_drop_down.text()} to: {self.c_date_to_drop_down.text()}\n"
f"Content: {self.edit_file_contains.text()}\n\n"
f"Search for system files: {self.rb_library_yes.isChecked()}\n"
f"Search for: {self.combobox_search_for.currentText()}\n"
f"File Groups: {self.combobox_file_types.all_checked_items()}\n\n"
f"Sort results by: {self.combobox_sorting.currentText()}\n"
f"Reverse results: {rb_reverse_sort_yes.isChecked()}\n")
# Start Search with args locally
def search_entry():
# Debug
logging.debug("User clicked Find")
# Print Input
print_data()
# Start Searching
FF_Search.Search(
data_name=self.edit_name.text(),
data_in_name=self.edit_name_contains.text(),
data_filetype=self.edit_file_extension.text(),
data_file_size_min=self.edit_size_min.text(), data_file_size_max=self.edit_size_max.text(),
data_file_size_min_unit=self.unit_selector_min.currentText(),
data_file_size_max_unit=self.unit_selector_max.currentText(),
data_library=self.rb_library_yes.isChecked(),
data_search_from_valid=os.path.abspath(FF_Files.SELECTED_DIR),
data_search_from_unchecked=self.edit_directory.text(),
data_content=self.edit_file_contains.text(),
data_search_for=self.combobox_search_for.currentText(),
data_date_edits={"c_date_from": self.c_date_from_drop_down,
"c_date_to": self.c_date_to_drop_down,
"m_date_from": self.m_date_from_drop_down,
"m_date_to": self.m_date_to_drop_down},
data_sort_by=self.combobox_sorting.currentText(),
data_reverse_sort=rb_reverse_sort_yes.isChecked(),
data_file_group=self.combobox_file_types.all_checked_items(),
parent=self.Root_Window)
# Saves the function in a different var
self.search_entry = search_entry
# Generate a shell command, that displays in the UI
def generate_terminal_command():
# Debug
logging.debug("User clicked Generate Terminal Command")
# Print the data
print_data()
def copy_command():
# Copying the command
clipboard = QClipboard()
clipboard.setText(shell_command)
# Feedback to the User
logging.info(f"Copied Command: {shell_command}")
# Messagebox
FF_Additional_UI.PopUps.show_info_messagebox("Successful copied!",
f"Successful copied Command:\n{shell_command} !",
self.Root_Window)
# Calling the function, which generate a shell command
shell_command = str(
FF_Search.GenerateTerminalCommand(self.edit_name.text(), self.edit_name_contains.text(),
self.edit_file_extension.text(), self.edit_size_max.text()))
# Showing the label that says "Command:"
label_command_title.show()
# Displaying the command label
label_command.setText(shell_command)
label_command.setToolTip(shell_command)
label_command.show()
# Copy Command Button
# Disconnect the button set a new click event
try:
button_command_copy.clicked.disconnect()
except (TypeError, RuntimeError, RuntimeWarning):
# If this fails, that means that there is now connected signal
pass
button_command_copy.clicked.connect(copy_command)
# Display the Button at the correct position
button_command_copy.show()
# Large Buttons
# Search button with image, to start searching
# Menu when Right-clicking
context_menu = QMenu(self.Root_Window)
# Search and delete cache for selected folder action
action_search_without_cache = QAction("Search and delete cache for selected folder", self.Root_Window)
action_search_without_cache.triggered.connect(self.delete_cache_and_search)
context_menu.addAction(action_search_without_cache)
# Separator
context_menu.addSeparator()
# Load Search Action
action_open_search = QAction("&Open Search / Filter Preset", self.Root_Window)
action_open_search.triggered.connect(lambda: self.import_filters())
context_menu.addAction(action_open_search)
# Shell Command Action
action_terminal = QAction("Generate Terminal Command", self.Root_Window)
action_terminal.triggered.connect(generate_terminal_command)
context_menu.addAction(action_terminal)
# Separator
context_menu.addSeparator()
# Reset Action
reset_action = QAction("Reset filters", self.Root_Window)
reset_action.triggered.connect(self.reset_filters)
context_menu.addAction(reset_action)
# Defining Button
search_button = self.generate_large_button("Find", search_entry, 25)
# Context Menu
search_button.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
search_button.customContextMenuRequested.connect(
lambda point: context_menu.exec(search_button.mapToGlobal(point)))
# Icon
FF_Additional_UI.UIIcon(
os.path.join(FF_Files.ASSETS_FOLDER, "Find_button_img_small.png"), search_button.setIcon)
search_button.setIconSize(QSize(25, 25))
# Place
search_button.setFixedWidth(120)
self.Main_Layout.addWidget(search_button, 12, 12, Qt.AlignmentFlag.AlignLeft)
# Set up the menu bar
logging.info("Setting up Menu Bar...")
self.menu_bar(generate_terminal_command)
# Setting filters to default
self.reset_filters()
# Showing PopUps
FF_Additional_UI.welcome_popups(parent=self.Root_Window)
# Debug
logging.info("Finished Setting up Main UI\n")
# Functions to automate Labels
@staticmethod
def generate_large_filter_label(name: str, tab: QWidget, tooltip: str = ""):
# Define the Label
label = QLabel(name, parent=tab)
# Change Font
label.setFont(QFont(FF_Files.DEFAULT_FONT, FF_Files.NORMAL_FONT_SIZE))
# Hover tool tip
label.setToolTip(f"{tooltip}")
label.setToolTipDuration(-1)
# Display the Label
label.show()
# Return the label to place it in the layout
return label
# Function to automate entry creation
def generate_filter_entry(self, tab: QWidget, only_int: bool = False):
# Define the Entry
entry = QLineEdit(tab)
# Set the Length
entry.resize(230, 20)
entry.setFixedHeight(25)
entry.setFixedWidth(230)
# If only_int true, configure the label
if only_int:
validator = QDoubleValidator(self.Root_Window)
validator.setBottom(0)
entry.setValidator(validator)
# Display the Entry
entry.show()
# Return the Label to place it
return entry
# Function for automating radio buttons
@staticmethod
def create_radio_button(group, text, tab: QWidget):
# Create Radio Button
rb = QRadioButton(tab)
# Set the Text
rb.setText(text)
# Add the Button to the Group
group.addButton(rb)
# Display the Button
rb.show()
# Return the Button
return rb
# Function for automating day edits
@staticmethod
def generate_day_entry(tab: QWidget):
# Define dt_entry
dt_entry = QDateEdit(tab)
# Change dd.mm.yy to dd.MM.yyyy (e.g. 13.1.01 = 13.Jan.2001)
dt_entry.setDisplayFormat("dd.MMM.yyyy")
# Set a fixed width
dt_entry.setFixedWidth(120)
# Display
dt_entry.show()
# Return day time entry to place it in the layout
return dt_entry
# Functions to automate Buttons
@staticmethod
def generate_edit_button(command, tab: QWidget, text):
# Generate the Button
button = QPushButton(tab)
# Change the Text
button.setText(text)
# Set the command
button.clicked.connect(command)
# Display the Button
button.show()
# Return the value of the Button, to place the button in the layout
return button
def generate_large_button(self, text, command, font_size):
# Define the Button
button = QPushButton(self.Root_Window)
# Set the Text
button.setText(text)
# Set the font
font = QFont(FF_Files.DEFAULT_FONT, font_size)
font.setBold(True)
button.setFont(font)
# Set the Command
button.clicked.connect(command)
# Display the Button
button.show()
# Return the Button
return button
# Auto complete paths
def complete_path(self, path, check=True):
# Adds all folders in path into paths
def get_paths():
paths = []
for list_folder in os.listdir(path):
if os.path.isdir(os.path.join(FF_Files.SELECTED_DIR, list_folder)):
# Normalising the unicode form to deal with special characters (e.g. ä, ö, ü) on macOS
normalised_path = normalize("NFC", os.path.join(FF_Files.SELECTED_DIR, list_folder))
paths.append(normalised_path)
# Returns the list
return paths
# Check if "/" is at end of inputted path
if check:
# Going through all paths to look if auto-completion should be loaded
if path.endswith("/") and (platform == "darwin" or platform == "linux"):
completer_paths = get_paths()
logging.debug("Changed QCompleter")
# On Windows paths and with "\"
elif path.endswith("\\") and (platform == "win32" or platform == "cygwin"):
completer_paths = get_paths()
logging.debug("Changed QCompleter")
else:
return
# If executed at launch skip check because home path doesn't end with a "/"
else:
completer_paths = get_paths()
logging.debug("Changed QCompleter")
# Set the saved list as Completer
directory_line_edit_completer = QCompleter(completer_paths, parent=self.Root_Window)
self.edit_directory.setCompleter(directory_line_edit_completer)
# Validate Paths in the directory box
def validate_dir(self):
# Debug
logging.debug(f"Directory Path changed to: {self.edit_directory.text()}")
# Get the text
check_path = self.edit_directory.text()
# If User pressed "Cancel"
if check_path == "":
return
# Changing Tool-Tip
self.edit_directory.setToolTip(self.edit_directory.text())
# Testing if path is folder
if os.path.isdir(check_path):
# Changing Path
logging.debug(f"Path: {check_path} valid")
FF_Files.SELECTED_DIR = check_path
# Change color
self.edit_directory.setStyleSheet("")
# Updating Completions
self.complete_path(check_path)
else:
# Debug
logging.debug(f"Path: {check_path} invalid")
# Change color
self.edit_directory.setStyleSheet(f"color: {FF_Files.RED_COLOR};")
# Resetting all filters
def reset_filters(self):
if os.path.exists(os.path.join(FF_Files.FF_LIB_FOLDER, "Default.FFFilter")):
# Debug
logging.info("Resetting all filters to user set default...")
self.import_filters(os.path.join(FF_Files.FF_LIB_FOLDER, "Default.FFFilter"))
else:
# Debug
logging.info("Resetting all filters to standard default...")
# Resetting basic window
self.edit_name.setText("")
self.edit_name_contains.setText("")
self.combobox_file_types.select_all()
self.edit_directory.setText(FF_Files.USER_FOLDER)
# Resetting Properties
self.edit_file_contains.setText("")
self.m_date_from_drop_down.setDate(QDate(2000, 1, 1))
self.c_date_from_drop_down.setDate(QDate(2000, 1, 1))
self.m_date_to_drop_down.setDate(QDate.currentDate())
self.c_date_to_drop_down.setDate(QDate.currentDate())
self.edit_size_max.setText("")
self.edit_size_min.setText("")
self.unit_selector_min.setCurrentText("No Limit")
self.unit_selector_max.setCurrentText("No Limit")
# Resetting Advanced
self.edit_file_extension.setText("")
self.rb_library_yes.setChecked(False)
self.combobox_search_for.setCurrentIndex(0)
# Resetting Sorting
self.combobox_sorting.setCurrentIndex(0)
self.rb_library_yes.setChecked(False)
# Debug
logging.info("Set all filters to default")
# Importing all filters from a FFFilter file
def import_filters(self, import_path=None):
if import_path is None:
# Debug
logging.info("Asking for location for export")
import_path = QFileDialog.getOpenFileName(parent=self.Root_Window,
dir=FF_Files.USER_FOLDER,
caption="Export File Find Search",
filter="*.FFFilter;*.FFSearch")[0]
# If opened file is a search
if import_path.endswith(".FFSearch"):
FF_Search.LoadSearch.open_file(import_path, self.Root_Window)
# Quit function
return
# Opening file, throws error if no files was selected
try:
with open(import_path, "rb") as export_file:
filters = load(fp=export_file)
except FileNotFoundError:
logging.warning(f"File not found: {import_path}")
return
# Debug
logging.info(f"Importing filters with version: {filters['VERSION']},"
f" while local version: {FF_Files.FF_FILTER_VERSION}...")
# Basic
self.edit_name.setText(filters["name"])
self.edit_name_contains.setText(filters["name_contains"])
self.combobox_file_types.check_items(filters["file_types"])
directory = filters["directory"].replace("USER_FOLDER", FF_Files.USER_FOLDER)
self.edit_directory.setText(directory)
# Properties
self.edit_file_contains.setText(filters["file_contains"])
self.m_date_from_drop_down.setDate(QDate.fromString(filters["dates"]["m_date_from"], Qt.DateFormat.ISODate))
self.c_date_from_drop_down.setDate(QDate.fromString(filters["dates"]["c_date_from"], Qt.DateFormat.ISODate))
if filters["dates"]["m_date_to"] == "DEFAULT_DATE":
self.m_date_to_drop_down.setDate(QDate.currentDate())
else:
self.m_date_to_drop_down.setDate(QDate.fromString(filters["dates"]["m_date_to"], Qt.DateFormat.ISODate))
if filters["dates"]["c_date_to"] == "DEFAULT_DATE":
self.c_date_to_drop_down.setDate(QDate.currentDate())
else: