forked from kvichans/cuda_find_in_files4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcd_fif4.py
5098 lines (4595 loc) · 253 KB
/
cd_fif4.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
''' Plugin for CudaText editor
Authors:
Andrey Kvichansky (kvichans on github.com)
Version:
'4.8.23 2024-09-22'
'''
# 2023-04-09
# authors: jackusay
from .bottom_panel import *
import re, os, traceback, locale, itertools, codecs, time, collections, datetime as dt #, types, json
from pathlib import Path
from fnmatch import fnmatch
from collections import namedtuple
from collections import defaultdict
from collections import Counter
import cudatext as app
from cudatext import ed
from cudatext_keys import *
import cudatext_cmd as cmds
import cudax_lib as apx
import chardet # Part of Cud/Conda
import logging
logging.getLogger('chardet').setLevel(logging.WARNING)
from .cd_kv_base import * # as part of this plugin
from .cd_kv_dlg import * # as part of this plugin
from .cd_fif4_cs import * # Public strings/struct
from .encodings import * # List of encoding data
VERSION = re.split('Version:', __doc__)[1].split("'")[1]
VERSION_V,VERSION_D = VERSION.split(' ')
# Storing of settings
CFG_FILE = 'cuda_fif4.json'
CFG_PATH = app.app_path(app.APP_DIR_SETTINGS)+os.sep+ CFG_FILE
fget_hist = lambda key, defv=None: \
get_hist(key, defv, module_name=None, to_file= CFG_FILE
,object_pairs_hook=dcta)
fset_hist = lambda key, value: \
set_hist(key, value, module_name=None, to_file= CFG_FILE
,object_pairs_hook=dcta)
get_opt = lambda opt, defv=None: \
apx.get_opt(opt, defv ,user_json=CFG_FILE)
pass; #Debug tools
pass; import cudatext_keys
pass; #import cgitb;cgitb.enable(logdir=os.path.dirname(__file__), display=1, context=7)
pass; #import rpdb;rpdb.Rpdb().set_trace() # telnet 127.0.0.1 4444
pass; from pprint import pformat
pass; pfw=lambda d,w=150:pformat(d,width=w)
pass; pfwg=lambda d,w,g='': re.sub('^', g, pfw(d,w), flags=re.M) if g else pfw(d,w)
pass; # Manage log actions
pass; Tr.sec_digs= 2
pass; #Tr.to_file = str(Path(get_opt('log_file', ''))) #! Need app restart
#NOTE: _log4mod
pass; _log4mod = -1 # 0=False=LOG_FREE, 1=True=LOG_ALLOW, 2=LOG_NEED, -1=LOG_FORBID
pass; _log4mod = get_opt('_log4mod', _log4mod)
pass; _log4cls_Fif4D = -1
pass; _log4fun_fifwork = -1
pass; _log4cls_TabsWalker = -1
pass; _log4cls_FSWalker = -1
pass; _log4fun_FSWalker_walk = -1
pass; _log4cls_Fragmer = -1
pass; _log4cls_Reporter = -1
pass; _dev_kv = get_opt('_dev_kv', False)
pass; log("fif4 start",('')) if _log4mod>=0 or _dev_kv else 0
# i18n
try: _ = get_translation(__file__)
except: _ = lambda p:p
def logx(x):
#print(x)
pass
# Shorter names of usefull tools
odict = collections.OrderedDict # as dict from Py3.7(?)
#d = dict
d = dcta # To use keys as attrs: o=dcta(a=b); x=o.a; o.a=x
defdict = lambda: defaultdict(int)
mtime = lambda f: dt.datetime.fromtimestamp(os.path.getmtime(f)) if os.path.exists(f) else 0
msg_box = lambda txt, flags=app.MB_OK: app.msg_box(txt, flags)
ptime = time.monotonic#time.process_time
USERHOME = os.path.expanduser('~')
# Std tools
def first_true(iterable, default=False, pred=None):return next(filter(pred, iterable), default) # 10.1.2. Itertools Recipes
def quote_if_space(s):
if ' ' in s:
return '"' + s + '"'
else:
return s
def collapse_filename(fn):
if os.name != 'nt':
if (fn+'/').startswith(USERHOME+'/'):
fn = fn.replace(USERHOME, '~', 1)
return fn
_set_text_all_text = ''
def set_text_all(to_ed, text):
global _set_text_all_text
if _set_text_all_text != text:
_set_text_all_text = text
to_ed.set_text_all( text)
logx("set_text_all show all text in file")
_statusbar = None
def use_statusbar(st):
global _statusbar
_statusbar = st
def msg_status(msg, process_messages=True):
pass; #log('###',())
if _statusbar:
app.statusbar_proc(_statusbar, app.STATUSBAR_SET_CELL_TEXT, tag=1, value=msg)
if process_messages:
app.app_idle()
else:
app.msg_status(msg, process_messages)
# OS/Cud properties
#STBR_H = apx.get_opt('ui_statusbar_height', 24) ##??
INDENT_VERT = apx.get_opt('find_indent_vert', -5)
# FIF4_META_OPTS in cd_fif4_cs.py
meta_def = lambda opt: [it['def'] for it in FIF4_META_OPTS if it['opt']==opt][0]
meta_min = lambda opt: [it['min'] for it in FIF4_META_OPTS if it['opt']==opt][0]
def prefix_for_opts(def_prefix=''):
sprd_res = get_opt('separated_histories_for_sess_proj', meta_def('separated_histories_for_sess_proj'))
sess_path = app.app_path(app.APP_FILE_SESSION)
pass; #log('sprd_res={}',(sprd_res))
pass; #log('sess_path={}',(sess_path))
proj_path = ''
try:
import cuda_project_man
proj_vars = cuda_project_man.project_variables()
pass; #log('global_project_info={}',(cuda_project_man.global_project_info))
pass; #log('proj_vars={}',(proj_vars))
proj_path = proj_vars.get('ProjMainFile', '')
except:pass
pass; #log('proj_path={}',(proj_path))
for sprd_re in sprd_res:
if re.search(sprd_re, sess_path) or re.search(sprd_re, proj_path):
pass; #log('prefix={}',(sprd_re+':'))
return sprd_re
pass; #log('prefix={}',(def_prefix))
return def_prefix
#def prefix_for_opts
# Take (cache) some of current settings
WALK_F_PICKING = True
WALK_DOWNTOP = False
ALWAYS_EXCL = ''
RE_VERBOSE = False
PARTS_ORAND = True
BINBLOCKSIZE = 1024
SKIP_FILE_SIZE = 0
ADV_LEXERS = []
FIF_LEXER = []
MARK_FIND_STYLE = {}
MARK_FN2R_STYLE = {}
MARK_REPL_STYLE = {}
LPTH_FIND_STYLE = {}
STATUS_HEIGHT = 21
STBR_H = STATUS_HEIGHT
STATUS_STYLE = {}
COPY_STYLES = False
COPY_STYLES_ROWS= 0
USE_SEL_ON_START= True
VERT_GAP = 0
W_MENU_BTTN = 0
W_WORD_BTTN = 0
W_EXCL_EDIT = 150
DOING_FRAGS = 100
GOTO_FIRST_FR = False
NSHOW_BIGGER = 0
STORE_RESULTS = False
REPL_X_SHIFT = 0
REPL_Y_SHIFT = 0
TITLE_STYLE = DLG_RESIZE
def reload_opts(): #NOTE: reload_opts
global \
WALK_F_PICKING \
,WALK_DOWNTOP \
,ALWAYS_EXCL \
,RE_VERBOSE \
,PARTS_ORAND \
,BINBLOCKSIZE \
,SKIP_FILE_SIZE \
,ADV_LEXERS \
,FIF_LEXER \
,MARK_FIND_STYLE \
,MARK_FN2R_STYLE \
,MARK_REPL_STYLE \
,STBR_H \
,STATUS_HEIGHT \
,STATUS_STYLE \
,COPY_STYLES \
,COPY_STYLES_ROWS\
,USE_SEL_ON_START\
,VERT_GAP \
,W_MENU_BTTN \
,W_WORD_BTTN \
,W_EXCL_EDIT \
,DOING_FRAGS \
,GOTO_FIRST_FR \
,NSHOW_BIGGER \
,STORE_RESULTS \
,REPL_X_SHIFT \
,REPL_Y_SHIFT \
,TITLE_STYLE
WALK_F_PICKING = get_opt('file_picking_stage' , meta_def('file_picking_stage'))
WALK_DOWNTOP = get_opt('from_deepest' , meta_def('from_deepest'))
ALWAYS_EXCL = get_opt('always_not_in_files' , meta_def('always_not_in_files'))
RE_VERBOSE = get_opt('re_verbose' , meta_def('re_verbose'))
PARTS_ORAND = get_opt('any_all_parts' , meta_def('any_all_parts'))
BINBLOCKSIZE = get_opt('is_binary_head_size(bytes)' , meta_def('is_binary_head_size(bytes)'))
SKIP_FILE_SIZE = get_opt('skip_file_size_more(Kb)' , meta_def('skip_file_size_more(Kb)'))
lexers_l = get_opt('lexers_for_results' , meta_def('lexers_for_results'))
FIF_LEXER = apx.choose_avail_lexer(lexers_l)
ADV_LEXERS = get_opt('lexers_to_filter' , meta_def('lexers_to_filter'))
MARK_FIND_STYLE = get_opt('mark_style' , meta_def('mark_style'))
MARK_FN2R_STYLE = get_opt('mark_fnd2rpl_style' , meta_def('mark_fnd2rpl_style'))
MARK_REPL_STYLE = get_opt('mark_replaced_style' , meta_def('mark_replaced_style'))
LPTH_FIND_STYLE = get_opt('lex_path_style' , meta_def('lex_path_style'))
STATUS_HEIGHT = get_opt('statusbar_height' , meta_def('statusbar_height'))
STATUS_HEIGHT = max(STATUS_HEIGHT , meta_min('statusbar_height'))
STBR_H = STATUS_HEIGHT
STATUS_STYLE = get_opt('statusbar_style' , meta_def('statusbar_style'))
COPY_STYLES = get_opt('copy_styles' , meta_def('copy_styles'))
COPY_STYLES_ROWS= get_opt('copy_styles_max_lines' , meta_def('copy_styles_max_lines'))
USE_SEL_ON_START= get_opt('use_selection_on_start' , meta_def('use_selection_on_start'))
VERT_GAP = get_opt('vertical_gap' , meta_def('vertical_gap'))
VERT_GAP = max(VERT_GAP , meta_min('vertical_gap'))
W_MENU_BTTN = get_opt('width_menu_button' , meta_def('width_menu_button'))
W_MENU_BTTN = max(W_MENU_BTTN , meta_min('width_menu_button'))
W_WORD_BTTN = get_opt('width_word_button' , meta_def('width_word_button'))
W_WORD_BTTN = max(W_WORD_BTTN , meta_min('width_word_button'))
W_EXCL_EDIT = get_opt('width_excl_edit' , meta_def('width_excl_edit'))
W_EXCL_EDIT = max(W_EXCL_EDIT , meta_min('width_excl_edit'))
DOING_FRAGS = get_opt('show_progress_fragments' , meta_def('show_progress_fragments'))
DOING_FRAGS = max(DOING_FRAGS , meta_min('show_progress_fragments'))
GOTO_FIRST_FR = get_opt('goto_first_fragment' , meta_def('goto_first_fragment'))
NSHOW_BIGGER = get_opt('dont_show_file_size_more(Kb)', meta_def('dont_show_file_size_more(Kb)'))
STORE_RESULTS = get_opt('store_results' , meta_def('store_results'))
REPL_X_SHIFT = get_opt('replace_x_shift' , meta_def('replace_x_shift'))
REPL_Y_SHIFT = get_opt('replace_y_shift' , meta_def('replace_y_shift'))
TITLE_STYLE = get_opt('title_style' , meta_def('title_style'))
def fit_mark_style_for_attr(js:dict)->dict:
""" Convert
{"color_back":"", "color_font":"", "font_bold":false, "font_italic":false
,"color_border":"", "borders":{"l":"","r":"","b":"","t":""}}
to dict with params for call ed.attr
(color_bg=COLOR_NONE, color_font=COLOR_NONE, font_bold=0, font_italic=0,
color_border=COLOR_NONE, border_left=0, border_right=0, border_down=0, border_up=0)
"""
V_L = ['solid', 'dash', '2px', 'dotted', 'rounded', 'wave']
shex2int= apx.html_color_to_int
kwargs = {}
if js.get('color_back' , ''): kwargs['color_bg'] = shex2int(js['color_back'])
if js.get('color_font' , ''): kwargs['color_font'] = shex2int(js['color_font'])
if js.get('color_border', ''): kwargs['color_border'] = shex2int(js['color_border'])
if js.get('font_bold' , False): kwargs['font_bold'] = 1
if js.get('font_italic' , False): kwargs['font_italic'] = 1
if js.get('font_strikeout',False): kwargs['font_strikeout']=1
jsbr = js.get('borders', {})
if jsbr.get('left' , ''): kwargs['border_left'] = V_L.index(jsbr['left' ])+1
if jsbr.get('right' , ''): kwargs['border_right'] = V_L.index(jsbr['right' ])+1
if jsbr.get('bottom', ''): kwargs['border_down'] = V_L.index(jsbr['bottom'])+1
if jsbr.get('top' , ''): kwargs['border_up'] = V_L.index(jsbr['top' ])+1
pass; #log("kwargs={}",(kwargs))
return kwargs
#def fit_mark_style_for_attr
MARK_FIND_STYLE = fit_mark_style_for_attr(MARK_FIND_STYLE)
MARK_FN2R_STYLE = fit_mark_style_for_attr(MARK_FN2R_STYLE)
MARK_REPL_STYLE = fit_mark_style_for_attr(MARK_REPL_STYLE)
LPTH_FIND_STYLE = fit_mark_style_for_attr(LPTH_FIND_STYLE)
reload_opts()
# How to format Results
TRFM_PLL = 'PLL'
TRFM_P_LL = 'P_LL' #default
TRFM_D_FLL = 'D_FLL'
#TRFM_D_F_LL = 'D_F_LL'
TRFMD2V = dict([
(TRFM_PLL ,_('<path:r>:line') ) # No tree, one row for one output line
,(TRFM_P_LL ,_('<path>#N/<r>:line') ) # Separated rows for full path for diff files
,(TRFM_D_FLL ,_('<dir>#N/<file:r>:line') ) # Separated rows for diff folders
# ,(TRFM_D_F_LL,_('<dir>#N/<dir>#N/<file>#N/<(r)>:line')) # Separated rows for diff folders/files
])
SEP4LEXPATH = ' > '
# Not ASCII chars for code
DDD = '\N{HORIZONTAL ELLIPSIS}'
MDMD = '\N{MIDDLE DOT}'*2
SORT_DN = '\N{DOWNWARDS ARROW}'*2
SORT_UP = '\N{UPWARDS ARROW}'*2
FF_EOL = '\N{SECTION SIGN}'
POS_CHAR = 'XY'
#LF_RT_AR = '\N{LEFT RIGHT ARROW}'
#UP_DN_AR = '\N{UP DOWN ARROW}'
POS_CHAR = '\N{NORTH WEST ARROW TO CORNER}'
SIZE_CHAR = 'HW'
#SIZE_CHAR = UP_DN_AR+LF_RT_AR
#SIZE_CHAR = '\N{DOWNWARDS ARROW LEFTWARDS OF UPWARDS ARROW}'
SIZE_CHAR = '\N{SOUTH EAST ARROW TO CORNER}'
############################################
############################################
#NOTE: GUI main tools
def dlg_fif4_xopts():
try:
import cuda_options_editor as op_ed
except:
return msg_box(_('To view/edit options install plugin "Options Editor"'))
try:
op_ed.OptEdD(
path_keys_info=FIF4_META_OPTS
, subset ='fif-df.'
, how =dict(only_for_ul=True, only_with_def=True, hide_fil=True, stor_json=CFG_FILE)
).show(f(_('[{}] Options'), DLG_CAP_BS))
except Exception as ex:
pass; log('ex={}',(ex))
reload_opts()
#def dlg_fif4_xopts
def dlg_fif4_help(fif):
KEYS_TABLE = DLG_HELP_KEYS
TIPS_FIND = DLG_HELP_FIND
TIPS_RPLS = DLG_HELP_RPLS
TIPS_RSLT = DLG_HELP_RESULTS
TIPS_FAST = DLG_HELP_SPEED
TIPS_TRCK = DLG_HELP_TRICKS
history = open(os.path.dirname(__file__)+os.sep+r'readme'+os.sep+f('history.txt'), encoding='utf-8').read()
c2m = 'mac'==DESKTOP #or True
KEYS_TABLE = KEYS_TABLE.replace('Ctrl+', 'Meta+') if c2m else KEYS_TABLE
TIPS_FIND = TIPS_FIND.replace( 'Ctrl+', 'Meta+') if c2m else TIPS_FIND
TIPS_RPLS = TIPS_RPLS.replace( 'Ctrl+', 'Meta+') if c2m else TIPS_RPLS
TIPS_RSLT = TIPS_RSLT.replace( 'Ctrl+', 'Meta+') if c2m else TIPS_RSLT
TIPS_FAST = TIPS_FAST.replace( 'Ctrl+', 'Meta+') if c2m else TIPS_FAST
TIPS_TRCK = TIPS_TRCK.replace( 'Ctrl+', 'Meta+') if c2m else TIPS_TRCK
page = fget_hist('help.page', 0)
pags_its = [_('Hotkeys'),_('Search'),_('Replace'),_('Results'),_('Speed'),_('Tricks'),_('History')]
res,vals = DlgAg(
form =dict(cap=f(_('[{}] Help'), DLG_CAP_BS), frame ='resize', w=850, h=600)
, ctrls = d(
pags=d(tp='pags',x=5,y=5 ,r=-5,b=-35,a='b.r>' ,val=page ,items=pags_its ),
keys=d(tp='memo',p='pags.0' ,ali=ALI_CL ,val=KEYS_TABLE ,ro_mono_brd='1,1,1'),
tips=d(tp='memo',p='pags.1' ,ali=ALI_CL ,val=TIPS_FIND ,ro_mono_brd='1,1,1'),
tipe=d(tp='memo',p='pags.2' ,ali=ALI_CL ,val=TIPS_RPLS ,ro_mono_brd='1,1,1'),
tipr=d(tp='memo',p='pags.3' ,ali=ALI_CL ,val=TIPS_RSLT ,ro_mono_brd='1,1,1'),
tipo=d(tp='memo',p='pags.4' ,ali=ALI_CL ,val=TIPS_FAST ,ro_mono_brd='1,1,1'),
tipt=d(tp='memo',p='pags.5' ,ali=ALI_CL ,val=TIPS_TRCK ,ro_mono_brd='1,1,1'),
hstt=d(tp='memo',p='pags.6' ,ali=ALI_CL ,val=history ,ro_mono_brd='1,1,1'),
isus=d(tp='lilb',x=5,y=-30 ,r=-5 ,a='..' ,cap=ISUES_C ,url=GH_ISU_URL ),
), fid = 'pags'
, opts = d(negative_coords_reflect=True)
).show() #NOTE: dlg_fif4_help
fset_hist('help.page', vals['pags'])
#def dlg_fif4_help
bpanel = Bpanel() #ok
class Command:
def dlg_fif_opts(self): return dlg_fif4_xopts()
def show_dlg(self): return show_fif4()
def show_dlg_and_find_in_tab(self): return show_fif4(d(work='in_tab'))
def choose_preset_to_run(self): return choose_preset_to_run()
#bpanel = Bpanel() #error; same error as below
# def __init__(self):
# bpanel = Bpanel() #error; to bpanel.open_console(), 'bpanel' is not defined
def open_console(self): return bpanel.open_console()
def close_console(self): return bpanel.close_console()
#def on_exit(self, ed_self): return bpanel.close_console() #useless
#maybe on_exit event is happening too late (after state of bottom panel has been already recorded to session)
#https://github.com/jackusay/cuda_find_in_filesX/issues/13
def on_start2(self, ed_self): return bpanel.close_console()
#problem: if user open normal console, it will be closed.
#def on_start(self, ed_self): return bpanel.close_console()
#too early, PROC_BOTTOMPANEL_GET always empty
#class Command:
the_fif4 = None
def show_fif4(run_opts=None):
""" Parameter run_opts can be dict as this
{'with': { # Default values
'in_reex': False,
'in_case': False,
'in_word': False,
'in_what': '', # What to find
'wk_fold': '', # Start the folder(s)
'wk_incl': '', # Mask(s) for files or subfolders
'wk_excl': '', # Mask(s) to skipped files or subfolders
'wk_dept': 0, # Depth of walk: 0=all, 1=root(s), 2=root(s)+1, ...
'wk_sort': '', # Sort by date before use: new|old
'wk_skip': '', # Skip hidden/binary files: -h|-b|-h-b
'wk_sycm': '', # Only in/out syntax element "comment": in|ot
'wk_syst': '', # Only in/out syntax element "string": in|ot
'rp_cntx': False, # (Report) Catch fragments with extra lines
'rp_cntb': 0, # (Report) Number extra lines before
'rp_cnta': 0, # (Report) Number extra lines after
}}
Values for skipped keys will be set from dialog hystory.
Example
from cuda_find_in_files4 import show_fif4
show_fif4({'with': {
'in_what': 'def',
'wk_fold': '.',
'wk_incl': '*.py'
}})
"""
# lst1 = [1,2]; lst2 = [(*lst1,)] ;print(f'lst2={lst2}') # lst2=[(1, 2)]
# lst1 = [1,2]; lst2 = [*lst1] ;print(f'lst2={lst2}') # lst2=[1, 2]
## lst1 = [1,2]; lst2 = [(*lst1)] ;print(f'lst2={lst2}') # lst2=[1, 2]
# pass; return
global the_fif4
if the_fif4:
del the_fif4
the_fif4 = Fif4D(run_opts)
the_fif4.show(run_opts)
#def show_fif4
def choose_preset_to_run():
global the_fif4
the_fif4 = the_fif4 if the_fif4 else Fif4D()
M,m = the_fif4.__class__,the_fif4
has_sel = USE_SEL_ON_START and ed.get_text_sel()
ps4run = [(nps,ps) for nps,ps in enumerate(m.opts.ps_pset)
if ('in_what' in ps or has_sel)
and 'wk_incl' in ps
and 'wk_fold' in ps
]
if not ps4run: return msg_box(_('No presets to run'))
ps_num = min(fget_hist('ps_to_run', 0), len(ps4run)-1)
ps_num = app.dlg_menu(app.DMENU_LIST, '\n'.join([
ps['nm']+'\t'+M.ZIP_PS4MENU(ps, False)
for nps,ps in ps4run])
, focused=ps_num
, caption=_('Choose preset to run')
)
if ps_num is None: return []
fset_hist('ps_to_run', ps_num)
the_fif4.show(d(work=f'by_ps:{ps4run[ps_num][0]}'))
#def choose_preset_to_run
excl_hi = f(excl_hi_, ALWAYS_EXCL)
DEF_LOC_ENCO= 'cp1252' if sys.platform=='linux' else locale.getpreferredencoding() # cp1251 for ru
DETECT_ENCO = _('detect')
WK_ENCO_DPLN= [DEF_LOC_ENCO, 'utf8', DETECT_ENCO]
dict2hist = lambda dct: ','.join(f'{n}:{v}' for v,n in Counter(v for v in dct.values()).items())
DESKTOP = get_desktop_environment()
cut_amp = lambda cap: cap.replace('&', '') \
if 'win'!=DESKTOP and re.search(r'&\W', cap) else \
cap
class Fif4D:
pass; log4cls=_log4cls_Fif4D
class Dcrs: # Decorators
@staticmethod
def clear_st_msg(argpos, *argvals):
def todecor(mth):
def clear_if(self, *args, **kwargs):
if argpos<len(args) and args[argpos] in argvals:
self.stbr_act('')
return mth(self, *args, **kwargs)
return clear_if
return todecor
#def clear_st_msg
@staticmethod
def timing_to_stbr(argpos, *argvals):
def todecor(mth):
def timing_if(self, *args, **kwargs):
if argpos>=len(args) or args[argpos] not in argvals:
return mth(self, *args, **kwargs)
M,m = type(self),self
self.stbr_act(DDD, M.STBR_TIM)
app.app_idle()
bgn_tm = ptime()
res = mth(self, *args, **kwargs)
end_tm = ptime()
self.stbr_act(M.dur2msg(end_tm-bgn_tm), M.STBR_TIM)
# dur = end_tm-bgn_tm
# pass; #log("dur={}",(dur))
# msg = f'{dur:.2f}"' \
# if dur<60 else \
# f('{}\'{:5.2f}"', int(dur/60), dur-60*int(dur/60))
# self.stbr_act(msg, M.STBR_TIM)
return res
return timing_if
return todecor
#def timing_to_stbr
#class Dcrs
AGEF_CP = _('A&ge of files')
AGEF_L1 = [ 'h', 'd', 'w', 'm', 'y' ]
AGEF_U1 = [_('h'), _('d'), _('w'), _('m'), _('y') ]
AGEF_UL = [_('hour(s)'), _('day(s)'), _('week(s)'), _('month(s)'), _('year(s)') ]
AGEF_MP = lambda:{l1:Fif4D.AGEF_U1[n] for n,l1 in enumerate(Fif4D.AGEF_L1)}
DEPT_UL = [_('+All subfolders'), _('Only start dir'), _('+1 level'), _('+2 levels'), _('+3 levels'), _('+4 levels'), _('+5 levels')]
SORT_CP = _('S&ort collected files')
SORT_UL = [_("Don'&t sort"), _('S&ort, newest first'), _('Sort, o&ldest first')]
SORT_LS = ['' , 'new' , 'old']
SKIP_CP = _('Skip &hidden/binary files')
SKIP_UL = [_("Don'&t skip"), _('Skip &hidden'), _('Skip &binary'), _('Skip hidden &and binary')]
SKIP_LS = ['' , 'h' , 'b' , 'hb']
SYNT_CP = _('S&yntax elements (slowdown)')
INCMM_CP= _('Inside &comment')
OTCMM_CP= _('Outside of c&omment')
INSTR_CP= _('Inside literal &string')
OTSTR_CP= _('Outside of literal s&tring')
# Layout data
MLIN_H = 70 # Min height of m-lines What
RSLT_H = 100 # Min height of Results
SRCF_H = 100 # Min height of Source
# Lambda methods (to simplify CodeTree)
cid_what = lambda self, only=False: \
('in_whaM' if self.opts.vw.mlin else 'in_what') \
if only or not self.last_fid else \
self.last_fid
do_dept = lambda self, ag, aid, data='': \
d(vals=d(wk_dept= (ag.val('wk_dept')+1)%len(Fif4D.DEPT_UL) if aid=='depD' else \
(ag.val('wk_dept')-1)%len(Fif4D.DEPT_UL) ))
CNTX_CA = lambda opts: \
f('&-{}+{}', opts.rp_cntb, opts.rp_cnta) if opts.rp_cntx else \
'&-?+?'
cntx_ca = lambda self: cut_amp(Fif4D.CNTX_CA(self.opts))
SORT_CA = lambda opts: '' if opts.wk_sort is None else \
SORT_DN if opts.wk_sort=='new' else \
SORT_UP if opts.wk_sort=='old' else ''
sort_ca = lambda self: Fif4D.SORT_CA(self.opts)
AGEF_CA = lambda opts: \
f('<{}', opts.wk_agef.split('/')[0]+Fif4D.AGEF_MP().get(opts.wk_agef.split('/')[1], '?')) \
if opts.wk_agef and \
not opts.wk_agef.startswith('0') else ''
agef_ca = lambda self: Fif4D.AGEF_CA(self.opts)
SKIP_CA = lambda opts: '' if opts.wk_skip is None else \
opts.wk_skip.replace('h', '-h').replace('b', '-b')
skip_ca = lambda self: Fif4D.SKIP_CA(self.opts)
SYCM_CA = lambda opts: '' if opts.wk_sycm is None else \
'/*?*/' if opts.wk_sycm=='in' else \
'?/**/?' if opts.wk_sycm=='ot' else ''
sycm_ca = lambda self: Fif4D.SYCM_CA(self.opts)
SYST_CA = lambda opts: '' if opts.wk_syst is None else \
'"?"' if opts.wk_syst=='in' else \
'?""?' if opts.wk_syst=='ot' else ''
syst_ca = lambda self: Fif4D.SYST_CA(self.opts)
LEXA_CA = lambda opts: '' if not opts.rp_lexa else '<>>'
lexa_ca = lambda self: Fif4D.LEXA_CA(self.opts)
ENCO_CA = lambda opts,fsts=False: '' if opts.wk_enco is None else \
('('+dict2hist(opts.wk_enco_ms)+')' if opts.wk_enco_ms else '') \
+((','.join(opts.wk_enco) if fsts else opts.wk_enco[0]) if opts.wk_enco else '')
enco_ca = lambda self,fsts=False: Fif4D.ENCO_CA(self.opts, fsts)
I4OP_CA = lambda opts,wo_enco=False,wo_lexa=False: ' '.join(
[ Fif4D.SORT_CA(opts)
, Fif4D.AGEF_CA(opts)
, Fif4D.SKIP_CA(opts)
, Fif4D.SYCM_CA(opts)
, Fif4D.SYST_CA(opts)
] +
([ Fif4D.LEXA_CA(opts) ] if not wo_lexa else [])
+
([ Fif4D.ENCO_CA(opts) ] if not wo_enco else [])
).replace(' ', ' ').strip()
i4op_ca = lambda self,wo_enco=False,wo_lexa=False: Fif4D.I4OP_CA(self.opts,wo_enco,wo_lexa)
FIT_ML4OPT = lambda s: s.replace(C13+C10, C10)
# FIT_SL4OPT = lambda s: re.sub(r'(?<!\\)'+FF_EOL, C10, s) # negative lookbehind assertion
FIT_SL4OPT = lambda s: s.replace('\\'+FF_EOL, chr(1)).replace(FF_EOL, C10).replace(chr(1), FF_EOL)
FIT_OPT4SL = lambda s: s.replace(FF_EOL , '\\'+FF_EOL ).replace(C10, FF_EOL)
# ZIP_PS4MENU = lambda ps, wnm=True:(( '"'+ps['nm']+'" ' if wnm else '')
ZIP_PS4MENU = lambda ps, wnm=True:((ps['nm']+' [' if wnm else '')
+( '[.*] ' if 'in_reex' in ps else '')
+( '[-+] ' if 'rp_cntx' in ps else '')
+(f(' "{}" ' , ps['in_what'].strip()[:20].strip()) if 'in_what' in ps else '')
+(f(' in "{}" ' , ps['wk_incl'].strip()[:20].strip()) if 'wk_incl' in ps else '')
+(f(' ex "{}" ' , ps['wk_excl'].strip()[:10].strip()) if 'wk_excl' in ps else '')
+(f(' from "{}" ',ps['wk_fold'].strip()[:20].strip()) if 'wk_fold' in ps else '')
+(f(' ({}) ' , Fif4D.DEPT_UL[ps['wk_dept']]) if 'wk_dept' in ps else '')
+( Fif4D.I4OP_CA(ps) )
+(' '+POS_CHAR+' ' if 'la_fmxy' in ps else '')
# +(' XY ' if 'la_fmxy' in ps else '')
+(' '+SIZE_CHAR+' ' if 'la_fmwh' in ps else '')
# +(' HW ' if 'la_fmwh' in ps else '')
+(']' if wnm else '')
).replace(' ',' ').strip()
dur2msg = lambda dur: f'{dur:.2f}"' \
if dur<60 else \
f('{}\'{:02.0f}"', int(dur/60), dur-60*int(dur/60))
TIMER_DELAY = 300 # msec
on_timer = lambda self, tag: self.do_acts(self.ag, tag)
done_finds = [] # Params of executed searches
done_finds_pos = 0 # Pos of last loaded
done_rslts = [] # Results of executed searches
def __init__(self, run_opts=None):
""" Param run_opts - see show_fif4 """
M,m = type(self),self
run_opts= run_opts if run_opts else {}
m.ropts = run_opts
m.opts = dcta( # Default values
in_reex=False,in_case=False,in_word=False
,in_what='' # What to find
# Store multiline value. EOL is '\n' .
# Multiline control shows it "as is".
# Singleline control shows EOL as FF_EOL
,wk_fold='' # Start the folder(s)
,wk_incl='' # See the files/subfolders
,wk_excl='' # Skip the files/subfolders
,wk_dept=0 # Depth of walk (0=all, 1=root(s), 2=+1...)
,wk_sort='' # Sort before use: new|old
,wk_agef='' # Skip files by datetime: \d+(h|d|w|m|y)
,wk_skip='' # Skip hidden/binary files
,wk_enco=WK_ENCO_DPLN # List (3 items) to try reading with the encoding
,wk_enco_ms={} # Map file mask to encoding
,wk_sycm='' # In/Out syntax element "comment"
,wk_syst='' # In/Out syntax element "string"
,rp_cntx=False # Catch frag with extra lines
,rp_cntb=0 # Number extra lines before
,rp_cnta=0 # Number extra lines after
,rp_time=False # Show modification time for files
,rp_lexa=False # Show lexer path for all fragments
,rp_lexp=False # Show lexer path for sel fragment
,rp_trfm=TRFM_P_LL # How to format Results
,rp_relp=True # Show only relative path over root[s]
,rp_shcw=False # Show (r:c:w) or only (r)
,vw=dcta(
mlin=False # Show m-lined control to edit in_what
,mlin_h=M.MLIN_H # Height of m-lined control
,rslt_h=M.RSLT_H # Height of Results
,what_l=[] # History list of 'What to find'
,fold_l=[] # History list of 'Start the folder(s)'
,incl_l=[] # History list of 'See the files/subfolders'
,excl_l=[] # History list of 'Skip the files/subfolders'
,repl_l=[] # History list of 'Replace with'
)
,us_focus='in_what' # Start/Last focused control
,ps_pset=[] # List of presets
,vs_defs=[] # List of cusrom vars [{nm:'N', cm:'cmnt', bd:'str{VV}'}]
,in_repl='' # What to replace
)
pref = prefix_for_opts()
hi_opts = fget_hist([pref, 'opts'] if pref else 'opts', {})
m.opts = update_tree(m.opts, hi_opts)
#logx(f"m.opts: {m.opts}")
pass; #log("run_opts={}",pfw(run_opts))
m.opts = update_tree(m.opts, run_opts.get('with', {}))
pass; #log("m.opts={}",pfw(m.opts))
#logx(f"m.opts2: {m.opts}")
# Upgrade
m.opts.vw.what_l.remove('') if '' in m.opts.vw.what_l else 0
m.opts.vw.fold_l.remove('') if '' in m.opts.vw.fold_l else 0
m.opts.vw.incl_l.remove('') if '' in m.opts.vw.incl_l else 0
m.opts.vw.excl_l.remove('') if '' in m.opts.vw.excl_l else 0
for ps in m.opts.ps_pset:
if 'wk_enco' in ps:
ps.setdefault('wk_enco_ms', {})
# History of singlelined what
m.sl_what_l = [M.FIT_OPT4SL(h) for h in m.opts.vw.what_l]
# Form tools
m.ag = None
m.caps = None
m.rslt = None
m.srcf = None
m.stbr = None
m.last_fid = ''
# Work tools
m.tl_edtr = None # Editor to apply lexer to source
m._locked_cids = [] # To lock while working
m.working = False # Flag to block ESC
m.reporter = None # Keeper/Formater of inner result data
m.observer = None # GUI/workers connector:
# collect and show workers stats,
# wait break and pause/resume/stop workers
m._prev_frgi = () # Last processed fragment in Results
# Fix: Crash if user press Tab on first start
m.opts.us_focus = 'in_whaM' \
if m.opts.vw.mlin else \
'in_what'
m.init_layout()
#def __init__
def vals_opts(self, act, ag=None):
M,m = type(self),self
if False:pass
elif act=='v2o':
# Copy values/positions from form to m.opts
m.opts.in_what = M.FIT_ML4OPT(ag.val('in_whaM')) \
if m.opts.vw.mlin else \
M.FIT_SL4OPT(ag.val('in_what'))
m.opts.update(ag.vals([k for k in self.opts if k[:3] in ('in_', 'wk_')
and k not in ('in_what'
,'wk_sort'
,'wk_agef'
,'wk_skip'
,'wk_enco','wk_enco_ms'
,'wk_sycm','wk_syst'
,'in_repl')]))
m.opts.vw.mlin = ag.val('vw_mlin')
m.opts.rp_cntx = ag.val('rp_cntx')
m.opts.vw.rslt_h = ag.cattr('di_rslt', 'h')
elif act=='o2v':
# Prepare dict of vals by m.opts
res = {**{k:m.opts[k] for k in m.opts if k[:3] in ('in_', 'wk_')
and k not in ('in_what'
,'wk_sort'
,'wk_agef'
,'wk_skip'
,'wk_enco','wk_enco_ms'
,'wk_sycm','wk_syst'
,'in_repl')}
,'rp_cntx':m.opts.rp_cntx
,'in_what':M.FIT_OPT4SL(
m.opts.in_what)
,'in_whaM':m.opts.in_what
,'vw_mlin':m.opts.vw.mlin
}
#if not m.opts.vw.mlin:
# pass; del res['in_whaM'] # Bug #2118
return res
elif act=='as_ps':
# To store as preset
return {k:m.opts[k] for k in m.opts if k[:3] in ('in_', 'wk_') or k[:6]=='rp_cnt'}
#def vals_opts
def dlg_preset(self, ps=None):
pass; #log("ps={}",(ps))
M,m = type(self),self
RAW = '!1'
CNT = '!2'
I4O = '!3'
WHA = '!4'
ENC = '!5'
INC = '!6'
EXC = '!7'
FOL = '!8'
DEP = '!9'
POS = '!0'
FSZ = '!A'
nps = not ps
nm = ps['nm'] if ps else f('#{}', 1+len(m.opts.ps_pset))
chcks = { RAW:'in_reex' in ps,
CNT:'rp_cntx' in ps,
I4O:('wk_sort' in ps or 'wk_agef' in ps or 'wk_skip' in ps or 'wk_sycm' in ps or 'wk_syst' in ps or 'rp_lexa' in ps),
WHA:'in_what' in ps,
ENC:'wk_enco' in ps,
INC:'wk_incl' in ps,
EXC:'wk_excl' in ps,
FOL:'wk_fold' in ps,
DEP:'wk_dept' in ps,
POS:'la_fmxy' in ps,
FSZ:'la_fmwh' in ps,
} if ps else defaultdict(bool, fget_hist(['dlg','preset'], {}))
ivals = dcta(ps) if ps else m.opts
WRDW = W_WORD_BTTN
vgp = VERT_GAP
hfm = 5+vgp*6+30
ok_c = _('Create') if nps else _('Save')
tit_c = _('Create new preset') if nps else _('View preset')
tit_c = '['+DLG_CAP_BS+'] '+tit_c
w_x = m.ag.cattr('in_what', 'x') + 15 # 10 for check
reex_v = ivals.in_reex if nps or chcks[RAW] else False
case_v = ivals.in_case if nps or chcks[RAW] else False
word_v = ivals.in_word if nps or chcks[RAW] else False
cntx_v = M.CNTX_CA(ivals)[1:] if nps or chcks[CNT] else ''
i4op_v = M.I4OP_CA(ivals,True) if nps or chcks[I4O] else ''
what_v = M.FIT_OPT4SL(ivals.in_what) if nps or chcks[WHA] else ''
enco_v = M.ENCO_CA(ivals,True) if nps or chcks[ENC] else ''
incl_v = ivals.wk_incl if nps or chcks[INC] else ''
excl_v = ivals.wk_excl if nps or chcks[EXC] else ''
fold_v = ivals.wk_fold if nps or chcks[FOL] else ''
dept_v = M.DEPT_UL[ivals.wk_dept] if nps or chcks[DEP] else ''
POS_C = _(' Form position')
FSZ_C = _(' Form sizes and Results height')
ag = DlgAg(
ctrls ={
RAW :d(tp='chck' ,y=5 ,x=w_x-35 ,w= 40 ,cap='&1:' ,val=chcks[RAW] ,en=nps ),
'_eex' :d(tp='chbt' ,tid=RAW ,x=w_x+WRDW*0,w=WRDW,cap='.*' ,val=reex_v ,en=nps ),
'_ase' :d(tp='chbt' ,tid=RAW ,x=w_x+WRDW*1,w=WRDW,cap='aA' ,val=case_v ,en=nps ),
'_ord' :d(tp='chbt' ,tid=RAW ,x=w_x+WRDW*2,w=WRDW,cap='"w"' ,val=word_v ,en=nps ),
CNT :d(tp='chck' ,tid=RAW ,x=w_x+115 ,w= 40 ,cap='&2:' ,val=chcks[CNT] ,en=nps ),
'_ntx' :d(tp='edit' ,tid=RAW ,x=w_x+150 ,w= 50 ,en=False ,val=cntx_v ),
I4O :d(tp='chck' ,tid=RAW ,x=w_x+215 ,w= 40 ,cap='&3:' ,val=chcks[I4O] ,en=nps ),
'_4op' :d(tp='edit' ,tid=RAW ,x=w_x+250 ,w= 80 ,en=False ,val=i4op_v ,a='r>' ),
ENC :d(tp='chck' ,tid=RAW ,x=w_x+350 ,w= 40 ,cap='&4:' ,val=chcks[ENC] ,en=nps ,a='>>' ),
'_nco' :d(tp='edit' ,tid=RAW ,x=w_x+385 ,r= -5 ,en=False ,val=enco_v ,a='>>' ),
WHA :d(tp='chck' ,y=5+vgp*1 ,x= 5 ,w= 90 ,cap=WHA__CA[2:],val=chcks[WHA] ,en=nps ),
'_hat' :d(tp='edit' ,tid=WHA ,x=w_x ,r= -5 ,en=False ,val=what_v ,a='r>' ),
INC :d(tp='chck' ,y=5+vgp*2 ,x= 5 ,w= 90 ,cap=INC__CA[2:],val=chcks[INC] ,en=nps ),
'_ncl' :d(tp='edit' ,tid=INC ,x=w_x ,w=330 ,en=False ,val=incl_v ,a='r>' ),
EXC :d(tp='chck' ,tid=INC ,x=w_x+350 ,w= 40 ,cap='&5:' ,val=chcks[EXC] ,en=nps ,a='>>' ),
'_xcl' :d(tp='edit' ,tid=INC ,x=w_x+385 ,r= -5 ,en=False ,val=excl_v ,a='>>' ),
FOL :d(tp='chck' ,y=5+vgp*3 ,x= 5 ,w= 90 ,cap=FOL__CA[2:],val=chcks[FOL] ,en=nps ,a='r>' ),
'_old' :d(tp='edit' ,tid=FOL ,x=w_x ,w=330 ,en=False ,val=fold_v ,a='r>' ),
DEP :d(tp='chck' ,tid=FOL ,x=w_x+350 ,w= 40 ,cap='&6:' ,val=chcks[DEP] ,en=nps ,a='>>' ),
'_ept' :d(tp='edit' ,tid=FOL ,x=w_x+385 ,r= -5 ,en=False ,val=dept_v ,a='>>' ),
POS :d(tp='chck' ,y=5+vgp*4 ,x=w_x ,w=110 ,cap='&7:'+POS_C,val=chcks[POS] ,en=nps ),
FSZ :d(tp='chck' ,y=5+vgp*5 ,x=w_x ,w=310 ,cap='&8:'+FSZ_C,val=chcks[FSZ] ,en=nps ),
'nam_' :d(tp='labl' ,tid='save' ,x=5 ,w=w_x-10,cap=_('>Na&me:') ),
'name' :d(tp='edit' ,tid='save' ,x=w_x ,w=200 ,val=nm ),
'save' :d(tp='bttn' ,y=5+vgp*6 ,x=w_x+385 ,r= -5 ,cap=ok_c ,def_bt=True,on=CB_HIDE ,a='>>' ),
}
,form =d( h=hfm ,h_max=hfm ,w=645 ,cap=tit_c ,frame='resize')
,fid ='name'
,opts =d(negative_coords_reflect=True)
)
ag.update(form=m.ag.fattrs(['x', 'y', 'w']))
ret,vals= ag.show()
if not ps:
pre_chcks = {k:v for k,v in vals.items() if k[0]=='!'}
fset_hist(['dlg','preset'], pre_chcks)
if ret!='save':return None
if not ps:
ps = dcta()
if vals[RAW]:
ps['in_reex'] = m.opts.in_reex
ps['in_case'] = m.opts.in_case
ps['in_word'] = m.opts.in_word
if vals[CNT]:
ps['rp_cntx'] = m.opts.rp_cntx
ps['rp_cntb'] = m.opts.rp_cntb
ps['rp_cnta'] = m.opts.rp_cnta
if vals[I4O]:
ps['wk_sort'] = m.opts.wk_sort
ps['wk_agef'] = m.opts.wk_agef
ps['wk_skip'] = m.opts.wk_skip
ps['wk_sycm'] = m.opts.wk_sycm
ps['wk_syst'] = m.opts.wk_syst
ps['rp_lexa'] = m.opts.rp_lexa
if vals[ENC]:
ps['wk_enco'] = m.opts.wk_enco
if m.opts.wk_enco_ms:
ps['wk_enco_ms']= m.opts.wk_enco_ms
if vals[WHA]:
ps['in_what'] = m.opts.in_what
if vals[INC]:
ps['wk_incl'] = m.opts.wk_incl
if vals[EXC]:
ps['wk_excl'] = m.opts.wk_excl
if vals[FOL]:
ps['wk_fold'] = m.opts.wk_fold
if vals[DEP]:
ps['wk_dept'] = m.opts.wk_dept
if vals[POS]:
ps['la_fmxy'] = m.ag.fattrs(['x', 'y'])
if vals[FSZ]:
ps['la_fmwh'] = m.ag.fattrs(['w', 'h'])
ps['la_rslh'] = m.ag.cattr('di_sptr', 'y')
ps['nm'] = vals['name'] if vals['name'] else nm
return ps
#def dlg_preset
def do_resize(self, ag, aid='', data=''):
pass; #log("### aid={}",(aid))
M,m = type(self),self
return m.do_acts(ag, 'fit-fh')
@Dcrs.clear_st_msg( 1, 'help', 'wk_clea', 'di_menu', 'nf_frag', 'nf_frlp') # aid in the list
@Dcrs.timing_to_stbr(1, 'di_find', 'up_rslt', 'di_rplc', 'di_emul') # aid in the list
def do_acts(self, ag, aid, data='', ops={}): #NOTE: do_acts
logx(f"do_acts begin - aid: {aid}")
# help xopts call-find call-repl
# in_reex in_case in_word
# more-fh less-fh more-fw less-fw more-r less-r more-ml less-ml fit-fh
# addEOL hist vw_mlin wk_agef wk_enco_d rp_cntx
# di_menu ps_prev ps_next ps_prvr ps_nxtr ps_save ps_menu ps_move ps_remv_N ps_load_N
# ac_usec di_brow fold_sh
# nf_frag nf_frlp
# up_rslt di_find vi_fldi
# on_rslt_crt go-next go-prev nav-to
# rplc emul di_rplc di_emul
pass; log4fun= 1
M,m = type(self),self
scam = ag.scam()
pass; #log("aid,scam={}",(aid,scam))
pass; #log__("aid,data,ops={}",(aid,data,ops) ,__=(log4fun,M.log4cls)) if _log4mod>=0 else 0
# Copy values from form to m.opts
m.vals_opts('v2o', ag)
m.stbr_act('') # Clear status
# Save used vals to history lists
def upd_hist(cid_oid, ops_l, unicase, opt_v=None, agupd=True):
opt_v = opt_v if opt_v else m.opts[cid_oid]
if not opt_v: return ops_l
up_ctrl = not ops_l or ops_l[0]!=opt_v
ops_l = add_to_history(opt_v, ops_l, unicase=unicase)
if agupd and up_ctrl:
ag.update(ctrls={cid_oid:d(items=ops_l)})
return ops_l
#def upd_hist
m.sl_what_l = upd_hist('in_what', m.sl_what_l , False, opt_v=M.FIT_OPT4SL(m.opts.in_what))
m.opts.vw.what_l = upd_hist('in_what', m.opts.vw.what_l, False, agupd=False)
m.opts.vw.fold_l = upd_hist('wk_fold', m.opts.vw.fold_l, os.name=='nt')
m.opts.vw.incl_l = upd_hist('wk_incl', m.opts.vw.incl_l, os.name=='nt')
m.opts.vw.excl_l = upd_hist('wk_excl', m.opts.vw.excl_l, os.name=='nt')
# Dispatch act
if aid in ('on_rslt_crt'
,'go-next-fr', 'go-prev-fr', 'go-next-fi', 'go-prev-fi'
,'rslt-to-tab'
,'nav-to'): return m.rslt_srcf_acts(aid, data, ag)
if aid == 'xopts':
fid = ag.focused()
dlg_fif4_xopts()
ag.activate()
return d(fid=fid)
if aid == 'help':
fid = ag.focused()
dlg_fif4_help(self)
ag.activate()
return d(fid=fid)
# if aid=='escape' or
if aid=='in_reex' and scam=='s':
m.opts.in_what = re.escape(m.opts.in_what) \
if m.opts.in_reex else \
re.sub(r'\\(.)', r'\1', m.opts.in_what)
return d(fid='in_what' ,vals=m.vals_opts('o2v'))
if aid in ('in_reex'