@@ -730,6 +730,8 @@ def help_cascade_post():
730
730
gc_collect ()
731
731
gc_enable ()
732
732
733
+ self .search_results_reset = True
734
+
733
735
self_main .mainloop ()
734
736
735
737
@@ -1509,12 +1511,12 @@ def ver_number(var):
1509
1511
(fuzzy_radio_name := Radiobutton (find_filename_frame ,text = "by fuzzy match" ,variable = self .find_filename_search_kind_var ,value = 'fuzzy' ,command = self .find_mod )).grid (row = 4 , column = 0 , sticky = 'news' ,padx = 4 ,pady = 4 )
1510
1512
1511
1513
regexp_tooltip = "Regular expression\n "
1512
- regexp_tooltip_name = "checked on the file\n or folder name."
1513
- regexp_tooltip_cd = "checked on the entire\n Custom Data of a file."
1514
+ regexp_tooltip_name = "Checked on the file\n or folder name."
1515
+ regexp_tooltip_cd = "Checked on the entire\n Custom Data of a file."
1514
1516
1515
- glob_tooltip = "An expression containing wildcard characters\n such as '*','?' or character range '[a-c]'.\n "
1516
- glob_tooltip_name = 'checked on the file or folder name.'
1517
- glob_tooltip_cd = 'checked on the entire Custom Data of a file.'
1517
+ glob_tooltip = "An expression containing wildcard characters\n such as '*','?' or character range '[a-c]'.\n \n Place '*' at the beginning and end of an expression \n unless you want the expression to be found exactly \n at the beginning or end of a path element \n \n "
1518
+ glob_tooltip_name = 'Checked on the file or folder name.'
1519
+ glob_tooltip_cd = 'Checked on the entire Custom Data of a file.'
1518
1520
1519
1521
fuzzy_tooltip = 'Fuzzy matching is implemented using SequenceMatcher\n from the difflib module. Any file whose similarity\n score exceeds the threshold will be classified as found.\n The similarity score is calculated\n '
1520
1522
fuzzy_tooltip_name = 'based on the file or folder name.'
@@ -1643,9 +1645,9 @@ def validate_size_str(val):
1643
1645
1644
1646
self .search_butt = Button (self .find_dialog .area_buttons , text = 'Search' , width = 14 , command = self .find_items )
1645
1647
self .search_butt .pack (side = 'left' , anchor = 'n' ,padx = 5 ,pady = 5 )
1646
- self .search_show_butt = Button (self .find_dialog .area_buttons , text = 'Show results' , width = 14 , command = self .find_show_results )
1648
+ self .search_show_butt = Button (self .find_dialog .area_buttons , text = 'Show results' , width = 14 , command = self .find_show_results , state = 'disabled' )
1647
1649
self .search_show_butt .pack (side = 'left' , anchor = 'n' ,padx = 5 ,pady = 5 )
1648
- self .search_save_butt = Button (self .find_dialog .area_buttons , text = 'Save results' , width = 14 , command = self .find_save_results )
1650
+ self .search_save_butt = Button (self .find_dialog .area_buttons , text = 'Save results' , width = 14 , command = self .find_save_results , state = 'disabled' )
1649
1651
self .search_save_butt .pack (side = 'left' , anchor = 'n' ,padx = 5 ,pady = 5 )
1650
1652
1651
1653
Button (self .find_dialog .area_buttons , text = 'Close' , width = 14 , command = self .find_close ).pack (side = 'right' , anchor = 'n' ,padx = 5 ,pady = 5 )
@@ -1660,7 +1662,7 @@ def validate_size_str(val):
1660
1662
1661
1663
self .results_on_find = LabelDialogQuestion (self .find_dialog .widget ,(self .ico_librer ,self .ico_librer_small ),self .bg_color ,pre_show = lambda new_widget : self .pre_show (on_main_window_dialog = False ,new_widget = new_widget ),post_close = lambda : self .post_close (on_main_window_dialog = False ))
1662
1664
1663
- self .results_on_find .cancel_button .configure (text = 'Continue search. ' ,width = 20 )
1665
+ self .results_on_find .cancel_button .configure (text = 'Continue search' ,width = 20 )
1664
1666
self .results_on_find .ok_button .configure (text = 'Close Search dialog' ,width = 20 )
1665
1667
1666
1668
self .find_dialog_created = True
@@ -2104,15 +2106,13 @@ def find_next(self):
2104
2106
self .select_find_result (1 )
2105
2107
2106
2108
def find_save_results (self ):
2107
- self .find_items ()
2108
-
2109
2109
if report_file_name := asksaveasfilename (parent = self .find_dialog .widget , initialfile = 'librer_search_report.txt' ,defaultextension = ".txt" ,filetypes = [("All Files" ,"*.*" ),("Text Files" ,"*.txt" )]):
2110
2110
self .status ('saving file "%s" ...' % str (report_file_name ))
2111
2111
2112
2112
with open (report_file_name ,'w' ) as report_file :
2113
2113
report_file_write = report_file .write
2114
- #report_file_write('criteria: \n')
2115
2114
2115
+ report_file_write ('# ' + ('\n # ' ).join (self .search_info_lines ) + '\n \n ' )
2116
2116
for record in librer_core .records :
2117
2117
if record .find_results :
2118
2118
report_file_write (f'record:{ record .header .label } \n ' )
@@ -2124,9 +2124,9 @@ def find_save_results(self):
2124
2124
self .status ('file saved: "%s"' % str (report_file_name ))
2125
2125
2126
2126
def find_show_results (self ):
2127
- self .find_items ()
2127
+ rest_txt_list = ['# ' + line for line in self .search_info_lines ]
2128
+ rest_txt_list .append ('' )
2128
2129
2129
- rest_txt_list = []
2130
2130
for record in librer_core .records :
2131
2131
if record .find_results :
2132
2132
rest_txt_list .append (f'record:{ record .header .label } ' )
@@ -2248,13 +2248,14 @@ def find_mod(self):
2248
2248
self .search_show_butt .configure (state = 'disabled' )
2249
2249
self .search_save_butt .configure (state = 'disabled' )
2250
2250
else :
2251
- if self .searching_aborted :
2251
+ if self .searching_aborted or self . search_results_reset :
2252
2252
self .search_butt .configure (state = 'normal' )
2253
2253
else :
2254
2254
self .search_butt .configure (state = 'disabled' )
2255
2255
2256
- self .search_show_butt .configure (state = 'normal' )
2257
- self .search_save_butt .configure (state = 'normal' )
2256
+ if self .any_find_result :
2257
+ self .search_show_butt .configure (state = 'normal' )
2258
+ self .search_save_butt .configure (state = 'normal' )
2258
2259
2259
2260
self .find_dialog .widget .update ()
2260
2261
@@ -2269,6 +2270,7 @@ def find_mod(self):
2269
2270
#@restore_status_line
2270
2271
def find_items (self ):
2271
2272
if self .find_params_changed :
2273
+ self .search_results_reset = False
2272
2274
2273
2275
self .find_clear ()
2274
2276
@@ -2302,11 +2304,96 @@ def find_items(self):
2302
2304
filename_fuzzy_threshold = self .find_name_fuzzy_threshold .get ()
2303
2305
cd_fuzzy_threshold = self .find_cd_fuzzy_threshold .get ()
2304
2306
2307
+ self .search_info_lines = []
2308
+ search_info_lines_append = self .search_info_lines .append
2309
+ if find_range_all :
2310
+ search_info_lines_append ('Search in all records' )
2311
+ else :
2312
+ search_info_lines_append (f'Search in record:{ self .current_record .header .label } ' )
2313
+
2314
+ range_par = self .current_record if not find_range_all else None
2315
+
2316
+ sel_range = [range_par ] if range_par else librer_core .records
2317
+ files_search_quant = sum ([record .header .quant_files + record .header .quant_folders for record in sel_range ])
2318
+
2319
+ if files_search_quant == 0 :
2320
+ return 1
2321
+
2322
+ if find_filename_search_kind == 'regexp' :
2323
+ if find_name_regexp :
2324
+ if res := test_regexp (find_name_regexp ):
2325
+ self .info_dialog_on_find .show ('regular expression error' ,res )
2326
+ return
2327
+ search_info_lines_append (f'Regular expression on path element:"{ find_name_regexp } "' )
2328
+ else :
2329
+ self .info_dialog_on_find .show ('regular expression empty' ,'(for path element)' )
2330
+ return
2331
+ elif find_filename_search_kind == 'glob' :
2332
+ if find_name_glob :
2333
+ info_str = f'Glob expression on path element:"{ find_name_glob } "'
2334
+ if find_name_case_sens :
2335
+ search_info_lines_append (info_str + ' (Case sensitive)' )
2336
+ else :
2337
+ search_info_lines_append (info_str )
2338
+ else :
2339
+ self .info_dialog_on_find .show ('empty glob expression' ,'(for path element)' )
2340
+ return
2341
+ elif find_filename_search_kind == 'fuzzy' :
2342
+ if find_name_fuzz :
2343
+ try :
2344
+ float (filename_fuzzy_threshold )
2345
+ except ValueError :
2346
+ self .info_dialog_on_find .show ('fuzzy threshold error' ,f"wrong threshold value:{ filename_fuzzy_threshold } " )
2347
+ return
2348
+ search_info_lines_append (f'Fuzzy match on path element:"{ find_name_fuzz } " (...>{ filename_fuzzy_threshold } )' )
2349
+ else :
2350
+ self .info_dialog_on_find .show ('fuzzy expression error' ,'empty expression' )
2351
+ return
2352
+
2353
+ if find_cd_search_kind == 'without' :
2354
+ search_info_lines_append (f'Files without Custom Data' )
2355
+ elif find_cd_search_kind == 'any' :
2356
+ search_info_lines_append (f'Files with any correct Custom Data' )
2357
+ elif find_cd_search_kind == 'error' :
2358
+ search_info_lines_append ('Files with error on CD extraction' )
2359
+ elif find_cd_search_kind == 'regexp' :
2360
+ if find_cd_regexp :
2361
+ if res := test_regexp (find_cd_regexp ):
2362
+ self .info_dialog_on_find .show ('regular expression error' ,res )
2363
+ return
2364
+ search_info_lines_append (f'Regular expression on Custom Data:"{ find_cd_regexp } "' )
2365
+ else :
2366
+ self .info_dialog_on_find .show ('regular expression empty' ,'(for Custom Data)' )
2367
+ return
2368
+ elif find_cd_search_kind == 'glob' :
2369
+ if find_cd_glob :
2370
+ info_str = f'Glob expression on Custom Data:"{ find_cd_glob } "'
2371
+ if find_cd_case_sens :
2372
+ search_info_lines_append (info_str + ' (Case sensitive)' )
2373
+ else :
2374
+ search_info_lines_append (info_str )
2375
+ else :
2376
+ self .info_dialog_on_find .show ('empty glob expression' ,'(for Custom Data)' )
2377
+ return
2378
+ elif find_cd_search_kind == 'fuzzy' :
2379
+ if find_cd_fuzz :
2380
+ try :
2381
+ float (cd_fuzzy_threshold )
2382
+ except ValueError :
2383
+ self .info_dialog_on_find .show ('fuzzy threshold error' ,f"wrong threshold value:{ cd_fuzzy_threshold } " )
2384
+ return
2385
+ search_info_lines_append (f'Fuzzy match on Custom Data:"{ find_cd_fuzz } " (...>{ cd_fuzzy_threshold } )' )
2386
+
2387
+ else :
2388
+ self .info_dialog_on_find .show ('fuzzy expression error' ,'empty expression' )
2389
+ return
2390
+
2305
2391
if find_size_min :
2306
2392
min_num = str_to_bytes (find_size_min )
2307
2393
if min_num == - 1 :
2308
2394
self .info_dialog_on_find .show ('min size value error' ,f'fix "{ find_size_min } "' )
2309
2395
return
2396
+ search_info_lines_append (f'Min size:{ find_size_min } ' )
2310
2397
else :
2311
2398
min_num = ''
2312
2399
@@ -2315,6 +2402,7 @@ def find_items(self):
2315
2402
if max_num == - 1 :
2316
2403
self .info_dialog_on_find .show ('max size value error' ,f'fix "{ find_size_max } "' )
2317
2404
return
2405
+ search_info_lines_append (f'Max size:{ find_size_max } ' )
2318
2406
else :
2319
2407
max_num = ''
2320
2408
@@ -2330,25 +2418,15 @@ def find_items(self):
2330
2418
except Exception as te :
2331
2419
self .info_dialog_on_find .show ('file modification time min error ' ,f'{ find_modtime_min } \n { te } ' )
2332
2420
return
2333
-
2421
+ search_info_lines_append ( f'Min modtime: { find_modtime_min } ' )
2334
2422
t_max = None
2335
2423
if find_modtime_max :
2336
2424
try :
2337
2425
t_max = int (mktime (parse_datetime (find_modtime_max ).timetuple ()))
2338
2426
except Exception as te :
2339
2427
self .info_dialog_on_find .show ('file modification time max error ' ,f'{ find_modtime_max } \n { te } ' )
2340
2428
return
2341
-
2342
- range_par = self .current_record if not find_range_all else None
2343
-
2344
- if check_res := librer_core .find_items_in_records_check (
2345
- range_par ,
2346
- min_num ,max_num ,
2347
- find_filename_search_kind ,find_name ,find_name_case_sens ,
2348
- find_cd_search_kind ,find_cd ,find_cd_case_sens ,
2349
- filename_fuzzy_threshold ,cd_fuzzy_threshold ):
2350
- self .info_dialog_on_find .show ('regular expression error' ,check_res )
2351
- return
2429
+ search_info_lines_append (f'Max modtime:{ find_modtime_max } ' )
2352
2430
2353
2431
self .cfg .set (CFG_KEY_find_range_all ,find_range_all )
2354
2432
self .cfg .set (CFG_KEY_find_cd_search_kind ,find_cd_search_kind )
@@ -2424,8 +2502,8 @@ def find_items(self):
2424
2502
self_progress_dialog_on_find_update_lab_image = self_progress_dialog_on_find .update_lab_image
2425
2503
self_get_hg_ico = self .get_hg_ico
2426
2504
2427
- librer_core_files_search_quant = librer_core .files_search_quant
2428
- fnumber_librer_core_files_search_quant = fnumber (librer_core_files_search_quant )
2505
+ # librer_core_files_search_quant = librer_core.files_search_quant
2506
+ fnumber_files_search_quant = fnumber (files_search_quant )
2429
2507
fnumber_records_len = fnumber (records_len )
2430
2508
2431
2509
time_without_busy_sign = 0
@@ -2438,13 +2516,13 @@ def find_items(self):
2438
2516
2439
2517
curr_files = librer_core .total_search_progress
2440
2518
2441
- files_perc = curr_files * 100.0 / librer_core_files_search_quant
2519
+ files_perc = curr_files * 100.0 / files_search_quant
2442
2520
2443
2521
self_progress_dialog_on_find_progr1var_set (librer_core .records_perc_info )
2444
2522
self_progress_dialog_on_find_progr2var_set (files_perc )
2445
2523
2446
2524
self_progress_dialog_on_find_lab_r1_config (text = fnumber (librer_core .search_record_nr ) + '/' + fnumber_records_len )
2447
- self_progress_dialog_on_find_lab_r2_config (text = fnumber (curr_files ) + '/' + fnumber_librer_core_files_search_quant )
2525
+ self_progress_dialog_on_find_lab_r2_config (text = fnumber (curr_files ) + '/' + fnumber_files_search_quant )
2448
2526
2449
2527
if self .action_abort :
2450
2528
librer_core .abort ()
@@ -2501,7 +2579,8 @@ def find_items(self):
2501
2579
2502
2580
self .find_mod ()
2503
2581
2504
- self .results_on_find .show ('Search results' ,f"found: { find_results_quant_sum_format } items.\n \n Navigate search results by\n \' Find next (F3)\' & 'Find prev (Shift+F3)'\n actions." + abort_info )
2582
+ search_info = '\n ' .join (self .search_info_lines )
2583
+ self .results_on_find .show ('Search results' ,f"{ search_info } \n \n found: { find_results_quant_sum_format } items.\n \n Navigate search results by\n \' Find next (F3)\' & 'Find prev (Shift+F3)'\n actions." + abort_info )
2505
2584
self .status_find_tooltip (f"available search results: { find_results_quant_sum_format } " )
2506
2585
2507
2586
if not self .searching_aborted and self .any_find_result :
0 commit comments