-
Notifications
You must be signed in to change notification settings - Fork 2
/
cd_opts_dlg.py
2328 lines (2156 loc) · 111 KB
/
cd_opts_dlg.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:
'2.3.15 2021-04-02'
ToDo: (see end of file)
'''
import re, os, sys, json, collections, itertools, webbrowser, tempfile, html, pickle, time, datetime
from itertools import *
from pathlib import PurePath as PPath
from pathlib import Path as Path
def first_true(iterable, default=False, pred=None):return next(filter(pred, iterable), default) # 10.1.2. Itertools Recipes
import cudatext as app
import cudatext_cmd as cmds
import cudax_lib as apx
from .cd_plug_lib import *
d = dict
odict = collections.OrderedDict
#class odict(collections.OrderedDict): #py3.9 conflict
# def __init__(self, *args, **kwargs):
# if args:super().__init__(*args)
# elif kwargs:super().__init__(kwargs.items())
# def __repr__(self):
# return '{%s}' % (', '.join("'%s':%r" % (k,v) for k,v in self.items()))
pass; LOG = (-1== 1) or apx.get_opt('_opts_dlg_log',False) # Do or dont logging.
pass; from pprint import pformat
pass; pf=lambda d:pformat(d,width=150)
pass; pf80=lambda d:pformat(d,width=80)
pass; pf60=lambda d:pformat(d,width=60)
pass; ##!! waits correction
_ = get_translation(__file__) # I18N
MIN_API_VER = '1.0.168'
MIN_API_VER_4WR = '1.0.175' # vis
MIN_API_VER = '1.0.231' # listview has prop columns
MIN_API_VER = '1.0.236' # p, panel
MIN_API_VER = '1.0.237' # STATUSBAR_SET_CELL_HINT
VERSION = re.split('Version:', __doc__)[1].split("'")[1]
VERSION_V, \
VERSION_D = VERSION.split(' ')
MAX_HIST = apx.get_opt('ui_max_history_edits', 20)
CFG_JSON = app.app_path(app.APP_DIR_SETTINGS)+os.sep+'cuda_options_editor.json'
HTM_RPT_FILE= str(Path(tempfile.gettempdir()) / 'CudaText_option_report.html')
FONT_LST = ['default'] \
+ [font
for font in app.app_proc(app.PROC_ENUM_FONTS, '')
if not font.startswith('@')]
pass; #FONT_LST=FONT_LST[:3]
def load_definitions(defn_path_or_json)->list:
""" Return
[{ opt:'opt name'
, def:<def val>
, cmt:'full comment'
, frm:'bool'|'float'|'int'|'str'| # simple
'int2s'|'strs'|'str2s'| # list/dict
'font'|'font-e'| # font non-empty/can-empty
'#rgb'|'#rgb-e'| # color non-empty/can-empty
'hotk'|'file'|'json'|
'unk'
, lst:[str] for frm==ints
, dct:[(num,str)] for frm==int2s
, [(str,str)] for frm==str2s
, chp:'chapter/chapter'
, tgs:['tag',]
}]
"""
pass; #LOG and log('defn_path_or_json={}',(defn_path_or_json))
kinfs = []
lines = defn_path_or_json \
if str==type(defn_path_or_json) else \
defn_path_or_json.open(encoding='utf8').readlines()
if lines[0][0]=='[':
# Data is ready - SKIP parsing
json_bd = defn_path_or_json \
if str==type(defn_path_or_json) else \
defn_path_or_json.open(encoding='utf8').read()
kinfs = json.loads(json_bd, object_pairs_hook=odict)
for kinf in kinfs:
pass; #LOG and log('opt in kinf={}',('opt' in kinf))
if isinstance(kinf['cmt'], list):
kinf['cmt'] = '\n'.join(kinf['cmt'])
upd_cald_vals(kinfs, '+def')
for kinf in kinfs:
kinf['jdc'] = kinf.get('jdc', kinf.get('dct', []))
kinf['jdf'] = kinf.get('jdf', kinf.get('def', ''))
return kinfs
l = '\n'
#NOTE: parse_raw
reTags = re.compile(r' *\((#\w+,?)+\)')
reN2S = re.compile(r'^\s*(\d+): *(.+)' , re.M)
reS2S = re.compile(r'^\s*"(\w*)": *(.+)' , re.M)
# reLike = re.compile(r' *\(like (\w+)\)') ##??
reFldFr = re.compile(r'\s*Folders from: (.+)')
def parse_cmnt(cmnt, frm):#, kinfs):
tags= set()
mt = reTags.search(cmnt)
while mt:
tags_s = mt.group(0)
tags |= set(tags_s.strip(' ()').replace('#', '').split(','))
cmnt = cmnt.replace(tags_s, '')
mt = reTags.search(cmnt)
dctN= [[int(m.group(1)), m.group(2).rstrip(', ')] for m in reN2S.finditer(cmnt+l)]
dctS= [[ m.group(1) , m.group(2).rstrip(', ')] for m in reS2S.finditer(cmnt+l)]
lstF= None
mt = reFldFr.search(cmnt)
if mt:
from_short = mt.group(1)
from_dir = from_short if os.path.isabs(from_short) else os.path.join(app.app_path(app.APP_DIR_DATA), from_short)
pass; #LOG and log('from_dir={}',(from_dir))
if not os.path.isdir(from_dir):
log(_('No folder "{}" from\n{}'), from_short, cmnt)
else:
lstF = [d for d in os.listdir(from_dir)
if os.path.isdir(from_dir+os.sep+d) and d.upper()!='README' and d.strip()]
lstF = sorted(lstF)
pass; #LOG and log('lstF={}',(lstF))
frm,\
lst = ('strs' , lstF) if lstF else \
(frm , [] )
frm,\
dct = ('int2s', dctN) if dctN else \
('str2s', dctS) if dctS else \
(frm , [] )
return cmnt, frm, dct, lst, list(tags)
#def parse_cmnt
def jsstr(s):
return s[1:-1].replace(r'\"','"').replace(r'\\','\\')
reChap1 = re.compile(r' *//\[Section: +(.+)\]')
reChap2 = re.compile(r' *//\[(.+)\]')
reCmnt = re.compile(r' *//(.+)')
reKeyDV = re.compile(r' *"(\w+)" *: *(.+)')
reInt = re.compile(r' *(-?\d+)')
reFloat = re.compile(r' *(-?\d+\.\d+)')
reFontNm= re.compile(r'font\w*_name')
reHotkey= re.compile(r'_hotkey_')
reColor = re.compile(r'_color$')
chap = ''
pre_cmnt= ''
pre_kinf= None
cmnt = ''
for line in lines:
if False:pass
elif reChap1.match(line):
mt= reChap1.match(line)
chap = mt.group(1)
cmnt = ''
elif reChap2.match(line):
mt= reChap2.match(line)
chap = mt.group(1)
cmnt = ''
elif reCmnt.match(line):
mt= reCmnt.match(line)
cmnt += l+mt.group(1)
elif reKeyDV.match(line):
mt= reKeyDV.match(line)
key = mt.group(1)
dval_s = mt.group(2).rstrip(', ')
dfrm,dval= \
('bool', True ) if dval_s=='true' else \
('bool', False ) if dval_s=='false' else \
('float',float(dval_s)) if reFloat.match(dval_s) else \
('int', int( dval_s)) if reInt.match(dval_s) else \
('font', dval_s[1:-1] ) if reFontNm.search(key) else \
('hotk', dval_s[1:-1] ) if reHotkey.search(key) else \
('#rgb', dval_s[1:-1] ) if reColor.search(key) else \
('str', jsstr(dval_s)) if dval_s[0]=='"' and dval_s[-1]=='"' else \
('unk', dval_s )
dfrm,dval=('#rgb-e','' ) if dfrm=='#rgb' and dval=='' else \
(dfrm, dval )
pass; #LOG and log('key,dval_s,dfrm,dval={}',(key,dval_s,dfrm,dval))
cmnt = cmnt.strip(l) if cmnt else pre_cmnt
ref_frm = cmnt[:3]=='...'
pre_cmnt= cmnt if cmnt else pre_cmnt
pass; #LOG and log('ref_frm,pre_cmnt,cmnt={}',(ref_frm,pre_cmnt,cmnt))
cmnt = cmnt.lstrip('.'+l)
dfrm = 'font-e' if dfrm=='font' and _('Empty string is allowed') in cmnt else dfrm
kinf = odict()
kinfs += [kinf]
kinf['opt'] = key
kinf['def'] = dval
kinf['cmt'] = cmnt.strip()
kinf['frm'] = dfrm
if dfrm in ('int','str'):
cmnt,frm,\
dct,lst,tags = parse_cmnt(cmnt, dfrm)#, kinfs)
kinf['cmt'] = cmnt.strip()
if frm!=dfrm:
kinf['frm'] = frm
if dct:
kinf['dct'] = dct
if lst:
kinf['lst'] = lst
if tags:
kinf['tgs'] = tags
if dfrm=='font':
kinf['lst'] = FONT_LST
if dfrm=='font-e':
kinf['lst'] = [''] + FONT_LST
if chap:
kinf['chp'] = chap
if ref_frm and pre_kinf:
# Copy frm data from prev oi
pass; #LOG and log('Copy frm pre_kinf={}',(pre_kinf))
kinf[ 'frm'] = pre_kinf['frm']
if 'dct' in pre_kinf:
kinf['dct'] = pre_kinf['dct']
if 'lst' in pre_kinf:
kinf['lst'] = pre_kinf['lst']
pre_kinf= kinf.copy()
cmnt = ''
#for line
pass; #open(str(defn_path_or_json)+'.p.json', 'w').write(json.dumps(kinfs,indent=2))
upd_cald_vals(kinfs, '+def')
for kinf in kinfs:
kinf['jdc'] = kinf.get('jdc', kinf.get('dct', []))
kinf['jdf'] = kinf.get('jdf', kinf.get('def', ''))
return kinfs
#def load_definitions
def load_vals(opt_dfns:list, lexr_json='', ed_=None, full=False, user_json='user.json')->odict:
""" Create reformated copy (as odict) of
definitions data opt_dfns (see load_definitions)
If ed_ then add
'fval'
for some options
If full==True then append optitions without definition
but only with
{ opt:'opt name'
, frm:'int'|'float'|'str'
, uval:<value from user.json>
, lval:<value from lexer*.json>
}}
Return
{'opt name':{ opt:'opt name', frm:
? , def:, cmt:, dct:, chp:, tgs:
? , uval:<value from user.json>
? , lval:<value from lexer*.json>
? , fval:<value from ed>
}}
"""
user_json = app.app_path(app.APP_DIR_SETTINGS)+os.sep+user_json
lexr_def_json = apx.get_def_setting_dir() +os.sep+lexr_json
lexr_json = app.app_path(app.APP_DIR_SETTINGS)+os.sep+lexr_json
user_vals = apx._json_loads(open(user_json , encoding='utf8').read(), object_pairs_hook=odict) \
if os.path.isfile(user_json) else {}
lexr_def_vals = apx._json_loads(open(lexr_def_json, encoding='utf8').read(), object_pairs_hook=odict) \
if os.path.isfile(lexr_def_json) else {}
lexr_vals = apx._json_loads(open(lexr_json , encoding='utf8').read(), object_pairs_hook=odict) \
if os.path.isfile(lexr_json) else {}
pass; #LOG and log('lexr_vals={}',(lexr_vals))
pass; #LOG and log('lexr_def_vals={}',(lexr_def_vals))
# Fill vals for defined opt
pass; #LOG and log('no opt={}',([oi for oi in opt_dfns if 'opt' not in oi]))
oinf_valed = odict([(oi['opt'], oi) for oi in opt_dfns])
for opt, oinf in oinf_valed.items():
if opt in lexr_def_vals: # Correct def-vals for lexer
oinf['dlx'] = True
oinf['def'] = lexr_def_vals[opt]
oinf['jdf'] = oinf['def']
if opt in user_vals: # Found user-val for defined opt
oinf['uval'] = user_vals[opt]
if opt in lexr_vals: # Found lexer-val for defined opt
oinf['lval'] = lexr_vals[opt]
if ed_ and opt in apx.OPT2PROP: # Found file-val for defined opt
fval = ed_.get_prop(apx.OPT2PROP[opt])
oinf['fval'] =fval
if full:
# Append item for non-defined opt
reFontNm = re.compile(r'font\w*_name')
def val2frm(val, opt=''):
pass; #LOG and log('opt,val={}',(opt,val))
return ('bool' if isinstance(val, bool) else
'int' if isinstance(val, int) else
'float' if isinstance(val, float) else
'json' if isinstance(val, (list, dict)) else
'hotk' if '_hotkey_' in val else
'font' if isinstance(val, str) and
reFontNm.search(val) else
'str')
for uop,uval in user_vals.items():
if uop in oinf_valed: continue
oinf_valed[uop] = odict(
[ ('opt' ,uop)
, ('frm' ,val2frm(uval,uop))
, ('uval' ,uval)
]+([('lval' ,lexr_vals[uop])] if uop in lexr_vals else [])
)
for lop,lval in lexr_vals.items():
if lop in oinf_valed: continue
oinf_valed[lop] = odict(
[ ('opt' ,lop)
, ('frm' ,val2frm(lval,lop))
, ('lval' ,lval)
])
upd_cald_vals(oinf_valed)
upd_cald_vals(oinf_valed, '+def') if lexr_def_vals else None # To update oi['jdf'] by oi['def']
return oinf_valed
#def load_vals
def upd_cald_vals(ois, what=''):
# Fill calculated attrs
if '+def' in what:
for oi in [oi for oi in ois if 'dct' in oi]:
dct = oi['dct']
dval= oi['def']
dc = odict(dct)
pass; #LOG and log('dct={}',(dct))
oi['jdc'] = [f('({}) {}', vl, cm ) for vl,cm in dct]
oi['jdf'] = f('({}) {}', dval, dc[dval])
pass; #LOG and log('oi={}',(oi))
# Fill calculated attrs
if not what or '+clcd' in what:
for op, oi in ois.items():
oi['!'] = ('L' if oi.get('dlx') else '') \
+ ('+!!' if 'def' not in oi and 'lval' in oi else
'+!' if 'def' not in oi and 'uval' in oi else
'!!!' if 'fval' in oi
and oi['fval'] != oi.get('lval'
, oi.get('uval'
, oi.get( 'def'))) else
'!!' if 'lval' in oi else
'!' if 'uval' in oi else
'')
dct = odict(oi.get('dct', []))
oi['juvl'] = oi.get('uval', '') \
if not dct or 'uval' not in oi else \
f('({}) {}', oi['uval'], dct[oi['uval']])
oi['jlvl'] = oi.get('lval', '') \
if not dct or 'lval' not in oi else \
f('({}) {}', oi['lval'], dct[oi['lval']])
oi['jfvl'] = oi.get('fval', '') \
if not dct or 'fval' not in oi else \
f('({}) {}', oi['fval'], dct[oi['fval']])
#def upd_cald_vals
#class OptDt:
# """ Options infos to view/change in dlg.
# Opt getting is direct - by fields.
# Opt setting only by methods.
# """
#
# def __init__(self
# , keys_info=None # Ready data
# , path_raw_keys_info='' # default.json
# , path_svd_keys_info='' # To save parsed default.json
# , bk_sets=False # Create backup of settings before the first change
# ):
# self.defn_path = Path(path_raw_keys_info)
# self.bk_sets = bk_sets # Need to backup
# self.bk_files = {} # Created backup files
#
# self.opts_defn = {} # Meta-info for options: format, comment, dict/list of values, chapter, tags
# self.ul_opts = {} # Total options info for user+cur_lexer
# #def __init__
#
# #class OptDt
_SORT_NO = -1
_SORT_DN = 0
_SORT_UP = 1
_SORT_TSGN = {_SORT_NO:'', _SORT_UP:'↑', _SORT_DN:'↓'}
_SORT_NSGN = {-1:'', 0:'', 1:'²', 2:'³'}
_SORT_NSGN.update({n:str(1+n) for n in range(3,10)})
_sort_pfx = lambda to,num: '' if to==_SORT_NO else _SORT_TSGN[to]+_SORT_NSGN[num]+' '
_next_sort = lambda to: ((1 + 1+to) % 3) - 1
_inve_sort = lambda to: 1 - to
sorts_dflt = lambda cols: [[_SORT_NO, -1] for c in range(cols)]
sorts_sign = lambda sorts, col: _sort_pfx(sorts[col][0], sorts[col][1])
sorts_on = lambda sorts, col: sorts[col][0] != _SORT_NO
def sorts_turn(sorts, col, scam=''):
""" Switch one of sorts """
max_num = max(tn[1] for tn in sorts)
tn_col = sorts[col]
if 0:pass
elif 'c'==scam and tn_col[1]==max_num: # Turn col with max number
tn_col[0] = _next_sort(tn_col[0])
tn_col[1] = -1 if tn_col[0]==_SORT_NO else tn_col[1]
elif 'c'==scam: # Add new or turn other col
tn_col[0] = _next_sort(tn_col[0]) if -1==tn_col[1] else _inve_sort(tn_col[0])
tn_col[1] = max_num+1 if -1==tn_col[1] else tn_col[1]
else:#not scam: # Only col
for cl,tn in enumerate(sorts):
tn[0] = _next_sort(tn_col[0]) if cl==col else _SORT_NO
tn[1] = 0 if cl==col else -1
return sorts
#def sorts_turn
def sorts_sort(sorts, tdata):
""" Sort tdata (must contain only str) by sorts """
pass; #log('tdata={}',(tdata))
pass; #log('sorts={}',(sorts))
max_num = max(tn[1] for tn in sorts)
if -1==max_num: return tdata
def push(lst, v):
lst.append(v)
return lst
prep_str = lambda s,inv: (chr(0x10FFFF) # To move empty to bottom
if not s else
s
if not inv else
''.join(chr(0x10FFFF - ord(c)) for c in s) # 0x10FFFF from chr() doc
)
td_keys = [[r] for r in tdata]
for srt_n in range(1+max_num):
srt_ctn = first_true(((c,tn) for c,tn in enumerate(sorts)), None
,lambda ntn: ntn[1][1]==srt_n)
assert srt_ctn is not None
srt_c = srt_ctn[0]
inv = srt_ctn[1][0]==_SORT_UP
td_keys = [push(r, prep_str(r[0][srt_c], inv)) for r in td_keys]
td_keys.sort(key=lambda r: r[1:])
tdata = [r[0] for r in td_keys] # Remove appended cols
return tdata
#def sorts_sort
class OptEdD:
SCROLL_W= app.app_proc(app.PROC_GET_GUI_HEIGHT, 'scrollbar') if app.app_api_version()>='1.0.233' else 15
COL_SEC = 0
COL_NAM = 1
COL_OVR = 2
COL_DEF = 3
COL_USR = 4
COL_LXR = 5
COL_FIL = 6
COL_LEXR= _('Lexer')
COL_FILE= _('File "{}"')
COL_NMS = (_('Section'), _('Option'), '!', _('Default'), _('User'), COL_LEXR, COL_FILE)
COL_MWS = [ 70, 210, 25, 120, 120, 70, 50] # Min col widths
# COL_MWS = [ 70, 150, 25, 120, 120, 70, 50] # Min col widths
COL_N = len(COL_MWS)
CMNT_MHT= 60 # Min height of Comment
STBR_FLT= 10
STBR_ALL= 11
STBR_MSG= 12
STBR_H = apx.get_opt('ui_statusbar_height',24)
FILTER_C= _('&Filter')
NO_CHAP = _('_no_')
CHPS_H = f(_('Choose section to append in "{}".'
'\rHold Ctrl to add several sections.'
), FILTER_C).replace('&', '')
FLTR_H = _('Suitable options will contain all specified words.'
'\r Tips and tricks:'
'\r • Add "#" to search the words also in comments.'
'\r • Add "@sec" to show options from section with "sec" in name.'
'\r Several sections are allowed.'
'\r Click item in menu "Section..." with Ctrl to add it.'
'\r • To show only overridden options:'
'\r - Add "!" to show only User+Lexer+File.'
'\r - Add "!!" to show only Lexer+File'
'\r - Add "!!!" to show only File.'
'\r • Use "<" or ">" for word boundary.'
'\r Example: '
'\r size> <tab'
'\r selects "tab_size" but not "ui_tab_size" or "tab_size_x".'
'\r • Alt+L - Clear filter')
LOCV_C = _('Go to "{}" in user/lexer config file')
LOCD_C = _('Go to "{}" in default config file')
OPME_H = _('Edit JSON value')
TOOP_H = f(_('Close dialog and open user/lexer settings file'
'\rto edit the current option.'
'\rSee also menu command'
'\r {}'), f(LOCD_C, '<option>'))
LIFL_C = _('Instant filtering')
FULL_C = _('Show &all keys in user/lexer configs')
@staticmethod
def prep_sorts(sorts):
M = OptEdD
if len(sorts)==len(M.COL_NMS):
return sorts
return sorts_dflt(len(M.COL_NMS))
def __init__(self
, path_keys_info ='' # default.json or parsed data (file or list_of_dicts)
, subset ='' # To get/set from/to cuda_options_editor.json
, how ={} # Details to work
):
M,m = self.__class__,self
m.ed = ed
m.how = how
m.defn_path = Path(path_keys_info) if str==type(path_keys_info) else json.dumps(path_keys_info)
m.subset = subset
m.stores = get_hist('dlg'
, json.loads(open(CFG_JSON).read(), object_pairs_hook=odict)
if os.path.exists(CFG_JSON) else odict())
pass; #LOG and log('ok',())
# m.bk_sets = m.stores.get(m.subset+'bk_sets' , False)
m.lexr_l = app.lexer_proc(app.LEXER_GET_LEXERS, False)
m.lexr_w_l = [f('{} {}'
,'!!' if os.path.isfile(app.app_path(app.APP_DIR_SETTINGS)+os.sep+'lexer '+lxr+'.json') else ' '
, lxr)
for lxr in m.lexr_l]
m.cur_op = m.stores.get(m.subset+'cur_op' , '') # Name of current option
m.col_ws = m.stores.get(m.subset+'col_ws' , M.COL_MWS[:])
m.col_ws = m.col_ws if M.COL_N==len(m.col_ws) else M.COL_MWS[:]
m.h_cmnt = m.stores.get(m.subset+'cmnt_heght', M.CMNT_MHT)
m.sorts = m.stores.get(m.subset+'sorts' , [] ) # Def sorts is no sorts
m.live_fltr = m.stores.get(m.subset+'live_fltr' , False) # To filter after each change and no History
m.cond_hl = [s for s in m.stores.get(m.subset+'h.cond', []) if s] if not m.live_fltr else []
m.cond_s = '' if M.restart_cond is None else M.restart_cond # String filter
m.ops_only = [] # Subset to show (future)
m.sorts = M.prep_sorts(m.sorts)
m.lexr = m.ed.get_prop(app.PROP_LEXER_CARET)
m.all_ops = m.stores.get(m.subset+'all_ops' , False) # Show also options without definition
m.opts_defn = {} # Meta-info for options: format, comment, dict of values, chapter, tags
m.opts_full = {} # Show all options
m.chp_tree = {} # {'Ui':{ops:[], 'kids':{...}, 'path':'Ui/Tabs'}
m.pth2chp = {} # path-index for m.chp_tree
# Cache
m.SKWULFs = [] # Last filtered+sorted
m.cols = [] # Last info about listview columns
m.itms = [] # Last info about listview cells
# m.bk_files = {}
# m.do_file('backup-user') if m.bk_sets else 0
m.do_file('load-data')
m.for_ulf = 'u' # 'u' for User, 'l' for Lexer, 'f' for File
m.cur_op = m.cur_op if m.cur_op in m.opts_full else '' # First at start
m.cur_in = 0 if m.cur_op else -1
m.stbr = None # Handle for statusbar_proc
m.locate_on_exit = None
m.chng_rpt = [] # Report of all changes by user
m.apply_one = m.stores.get(m.subset+'apply_one', False) # Do one call OpsReloadAndApply on exit
m.apply_need= False # Need to call OpsReloadAndApply
m.auto4file = m.stores.get(m.subset+'auto4file', True) # Auto reset file value to over value def/user/lex
#def __init__
def stbr_act(self, tag=None, val='', opts={}):
M,m = self.__class__,self
if not m.stbr: return
app.statusbar_proc(m.stbr, app.STATUSBAR_SET_CELL_TEXT, tag=tag, value=str(val))
#def stbr_act
def do_file(self, what, data='', opts={}):
M,m = self.__class__,self
if False:pass
elif what=='load-data':
pass; #LOG and log('',)
m.opts_defn = load_definitions(m.defn_path)
pass; #LOG and log('m.opts_defn={}',pf([o for o in m.opts_defn]))
pass; #LOG and log('m.opts_defn={}',pf([o for o in m.opts_defn if '2s' in o['frm']]))
m.opts_full = load_vals(m.opts_defn
,lexr_json='lexer '+m.lexr+'.json'
,user_json=m.how.get('stor_json', 'user.json')
, ed_=m.ed, full=m.all_ops)
m.cur_op = m.cur_op if m.cur_op in m.opts_full else ''
pass; #LOG and log('m.opts_full={}',pf(m.opts_full))
m.do_file('build-chp-tree')
elif what=='build-chp-tree':
# Build chapter tree
m.chp_tree = odict(ops=list(m.opts_full.keys())
,kids=odict()
,path='') # {chp:{ops:[], kids:{...}, path:'c1/c2'}
m.pth2chp = {} # {path:chp}
for op,oi in m.opts_full.items():
chp_s = oi.get('chp', M.NO_CHAP)
chp_s = chp_s if chp_s else M.NO_CHAP
chp_node= m.chp_tree # Start root to move
kids = chp_node['kids']
path =''
for chp in chp_s.split('/'):
# Move along branch and create nodes if need
chp_node = kids.setdefault(chp, odict())
path += ('/'+chp) if path else chp
chp_node['path']= path
m.pth2chp[path] = chp_node
ops_l = chp_node.setdefault('ops', [])
ops_l += [op]
if not ('/'+chp_s).endswith('/'+chp): # not last
kids = chp_node.setdefault('kids', odict())
pass; #LOG and log('m.chp_tree=¶{}',pf60(m.chp_tree))
pass; #LOG and log('m.pth2chp=¶{}',pf60(m.pth2chp))
elif what == 'locate_to':
to_open = data['path']
find_s = data['find']
app.file_open(to_open) ##!!
pass; #log('to_open={}',(to_open))
pass; #log('ed.get_filename()={}',(ed.get_filename()))
m.ag.opts['on_exit_focus_to_ed'] = ed
# Locate
user_opt= app.app_proc(app.PROC_GET_FINDER_PROP, '') \
if app.app_api_version()>='1.0.248' else \
app.app_proc(app.PROC_GET_FIND_OPTIONS, '') # Deprecated
pass; #log('ed_to_fcs.get_filename()={}',(ed_to_fcs.get_filename()))
pass; #log('ed.get_filename()={}',(ed.get_filename()))
pass; #LOG and log('find_s={!r}',(find_s))
ed.cmd(cmds.cmd_FinderAction, chr(1).join(['findnext', find_s, '', 'fa'])) # f - From-caret, a - Wrap
if app.app_api_version()>='1.0.248':
app.app_proc(app.PROC_SET_FINDER_PROP, user_opt)
else:
app.app_proc(app.PROC_SET_FIND_OPTIONS, user_opt) # Deprecated
elif what in ('locate-def', 'locate-opt', 'goto-def', 'goto-opt', ):
if not m.cur_op:
m.stbr_act(M.STBR_MSG, _('Choose option to find in config file'))
return False
oi = m.opts_full[m.cur_op]
pass; #LOG and log('m.cur_op,oi={}',(m.cur_op,oi))
to_open = ''
if what in ('locate-opt', 'goto-opt'):
if 'uval' not in oi and m.for_ulf=='u':
m.stbr_act(M.STBR_MSG, f(_('No user value for option "{}"'), m.cur_op))
return False
if 'lval' not in oi and m.for_ulf=='l':
m.stbr_act(M.STBR_MSG, f(_('No lexer "{}" value for option "{}"'), m.lexr, m.cur_op))
return False
to_open = 'lexer '+m.lexr+'.json' if m.for_ulf=='l' else 'user.json'
to_open = app.app_path(app.APP_DIR_SETTINGS)+os.sep+to_open
else:
if 'def' not in oi:
m.stbr_act(M.STBR_MSG, f(_('No default for option "{}"'), m.cur_op))
return False
to_open = str(m.defn_path)
if not os.path.exists(to_open):
log('No file={}',(to_open))
return False
find_s = f('"{}"', m.cur_op)
if what in ('goto-def', 'goto-opt'):
m.locate_on_exit = d(path=to_open, find=find_s)
return True #
m.do_file('locate_to', d(path=to_open, find=find_s))
return False
#elif what=='set-dfns':
# m.defn_path = data
# m.do_file('load-data')
# return d(ctrls=odict(m.get_cnts('lvls')))
elif what=='set-lexr':
m.opts_full = load_vals(m.opts_defn
,lexr_json='lexer '+m.lexr+'.json'
,user_json=m.how.get('stor_json', 'user.json')
,ed_=m.ed, full=m.all_ops)
return d(ctrls=odict(m.get_cnts('lvls')))
elif what=='out-rprt':
if do_report(HTM_RPT_FILE, 'lexer '+m.lexr+'.json', m.ed):
webbrowser.open_new_tab('file://' +HTM_RPT_FILE)
app.msg_status(_('Opened browser with file ')+HTM_RPT_FILE)
return []
#def do_file
def _prep_opt(self, opts='', ind=-1, nm=None):
""" Prepare vars to show info about current option by
m.cur_op
m.lexr
Return
{} vi-attrs
{} en-attrs
{} val-attrs
{} items-attrs
"""
M,m = self.__class__,self
if opts=='key2ind':
opt_nm = nm if nm else m.cur_op
m.cur_in= index_1([m.SKWULFs[row][1] for row in range(len(m.SKWULFs))], opt_nm, -1)
return m.cur_in
if opts=='ind2key':
opt_in = ind if -1!=ind else m.ag.cval('lvls')
m.cur_op= m.SKWULFs[opt_in][1] if -1<opt_in<len(m.SKWULFs) else ''
return m.cur_op
if opts=='fid4ed':
if not m.cur_op: return 'lvls'
frm = m.opts_full[m.cur_op]['frm']
fid = 'eded' if frm in ('str', 'int', 'float') else \
'edcb' if frm in ('int2s', 'str2s', 'strs', 'font', 'font-e') else \
'edrf' if frm in ('bool',) else \
'brow' if frm in ('hotk', 'file', '#rgb', '#rgb-e') else \
'opjs' if frm in ('json') else \
'lvls'
pass; #LOG and log('m.cur_op,frm,fid={}',(m.cur_op,frm,fid))
return fid
pass; #LOG and log('m.cur_op, m.lexr={}',(m.cur_op, m.lexr))
vis,ens,vas,its,bcl = {},{},{},{},{}
vis['edcl'] = vis['dfcl'] = False
bcl['edcl'] = bcl['dfcl'] = 0x20000000
# bcl['eded'] = bcl['dfvl'] = 0x20000000
ens['eded'] = ens['setd'] = False # All un=F
vis['eded'] = vis['edcb']=vis['edrf']=vis['edrt']=vis['brow']=vis['toop']=vis['opjs'] = False # All vi=F
vas['eded'] = vas['dfvl']=vas['cmnt']= '' # All ed empty
vas['edcb'] = -1
vas['edrf'] = vas['edrt'] = False
its['edcb'] = []
ens['dfvl'] = True
ens['tofi'] = m.cur_op in apx.OPT2PROP
if m.for_ulf=='l' and m.lexr not in m.lexr_l:
# Not selected lexer
vis['eded'] = True
ens['dfvl'] = False
return vis,ens,vas,its,bcl
if m.for_ulf=='f' and m.cur_op not in apx.OPT2PROP:
# No the option for File
vis['eded'] = True
ens['dfvl'] = False
return vis,ens,vas,its,bcl
if not m.cur_op:
# No current option
vis['eded'] = True
else:
# Current option
oi = m.opts_full[m.cur_op]
pass; #LOG and log('oi={}',(oi))
vas['dfvl'] = str(oi.get('jdf' , '')).replace('True', 'true').replace('False', 'false')
vas['uval'] = oi.get('uval', '')
vas['lval'] = oi.get('lval', '')
vas['fval'] = oi.get('fval', '')
vas['cmnt'] = oi.get('cmt' , '')
frm = oi['frm']
ulfvl_va = vas['fval'] \
if m.for_ulf=='f' else \
vas['lval'] \
if m.for_ulf=='l' else \
vas['uval'] # Cur val with cur state of "For lexer"
ens['eded'] = frm not in ('json', 'hotk', 'file')#, '#rgb', '#rgb-e')
ens['setd'] = frm not in ('json',) and ulfvl_va is not None
if False:pass
elif frm in ('json'):
# vis['toop'] = True
vis['opjs'] = True
vis['eded'] = True
vas['eded'] = str(ulfvl_va)
elif frm in ('str', 'int', 'float'):
vis['eded'] = True
vas['eded'] = str(ulfvl_va)
elif frm in ('hotk', 'file', '#rgb', '#rgb-e'):
vis['eded'] = True
vis['brow'] = True
vas['eded'] = str(ulfvl_va)
vis['edcl'] = frm in ('#rgb', '#rgb-e')
vis['dfcl'] = frm in ('#rgb', '#rgb-e')
bcl['edcl'] = apx.html_color_to_int(ulfvl_va ) if frm in ('#rgb', '#rgb-e') and ulfvl_va else 0x20000000
bcl['dfcl'] = apx.html_color_to_int(vas['dfvl'] ) if frm in ('#rgb', '#rgb-e') and vas['dfvl'] else 0x20000000
elif frm in ('bool',):
vis['edrf'] = True
vis['edrt'] = True
vas['edrf'] = ulfvl_va is False
vas['edrt'] = ulfvl_va is True
elif frm in ('int2s', 'str2s'):
vis['edcb'] = True
ens['edcb'] = True
its['edcb'] = oi['jdc']
vas['edcb'] = index_1([k for (k,v) in oi['dct']], ulfvl_va, -1)
pass; #LOG and log('ulfvl_va, vas[edcb]={}',(ulfvl_va,vas['edcb']))
elif frm in ('strs','font','font-e'):
vis['edcb'] = True
ens['edcb'] = True
its['edcb'] = oi['lst']
vas['edcb'] = index_1(oi['lst'], ulfvl_va, -1)
pass; #LOG and log('ulfvl_va={}',(ulfvl_va))
pass; #LOG and log('vis={}',(vis))
pass; #LOG and log('ens={}',(ens))
pass; #LOG and log('vas={}',(vas))
pass; #LOG and log('its={}',(its))
return vis,ens,vas,its,bcl
#def _prep_opt
def show(self
, title # For cap of dlg
):
M,m = self.__class__,self
def when_exit(ag):
pass; #LOG and log('',())
pass; #pr_ = dlg_proc_wpr(ag.id_dlg, app.DLG_CTL_PROP_GET, name='edch')
pass; #log('exit,pr_={}',('edch', {k:v for k,v in pr_.items() if k in ('x','y')}))
pass; #log('cols={}',(ag.cattr('lvls', 'cols')))
m.col_ws= [ci['wd'] for ci in ag.cattr('lvls', 'cols')]
m.stores[m.subset+'cmnt_heght'] = m.ag.cattr('cmnt', 'h')
if m.apply_one and m.apply_need:
ed.cmd(cmds.cmd_OpsReloadAndApply)
if m.locate_on_exit:
m.do_file('locate_to', m.locate_on_exit)
#def when_exit
repro_py = apx.get_opt('dlg_cuda_options.repro_py') # 'repro_dlg_opted.py'
m.dlg_min_w = 10 + sum(M.COL_MWS) + M.COL_N + M.SCROLL_W
m.dlg_w = 10 + sum(m.col_ws) + M.COL_N + M.SCROLL_W
m.dlg_h = 380 + m.h_cmnt +10 + M.STBR_H
# m.dlg_h = 270 + m.h_cmnt +10 + M.STBR_H
pass; #log('m.dlg_w,m.dlg_h={}',(m.dlg_w,m.dlg_h))
m.ag = DlgAgent(
form =dict(cap = title + f(' ({})', VERSION_V)
,resize = True
,w = m.dlg_w ,w_min=m.dlg_min_w
,h = m.dlg_h
,on_resize=m.do_resize
)
, ctrls=m.get_cnts()
, vals =m.get_vals()
, fid ='cond'
,options = ({
'gen_repro_to_file':repro_py, #NOTE: repro
} if repro_py else {})
)
# Select on pre-show. Reason: linux skip selection event after show
m.ag._update_on_call(m.do_sele('lvls', m.ag))
m.stbr = app.dlg_proc(m.ag.id_dlg, app.DLG_CTL_HANDLE, name='stbr')
app.statusbar_proc(m.stbr, app.STATUSBAR_ADD_CELL , tag=M.STBR_ALL)
app.statusbar_proc(m.stbr, app.STATUSBAR_SET_CELL_SIZE , tag=M.STBR_ALL, value=40)
app.statusbar_proc(m.stbr, app.STATUSBAR_SET_CELL_ALIGN , tag=M.STBR_ALL, value='R')
app.statusbar_proc(m.stbr, app.STATUSBAR_SET_CELL_HINT , tag=M.STBR_ALL, value=_('Number of all options'))
app.statusbar_proc(m.stbr, app.STATUSBAR_ADD_CELL , tag=M.STBR_FLT)
app.statusbar_proc(m.stbr, app.STATUSBAR_SET_CELL_SIZE , tag=M.STBR_FLT, value=40)
app.statusbar_proc(m.stbr, app.STATUSBAR_SET_CELL_ALIGN , tag=M.STBR_FLT, value='R')
app.statusbar_proc(m.stbr, app.STATUSBAR_SET_CELL_HINT , tag=M.STBR_FLT, value=_('Number of shown options'))
app.statusbar_proc(m.stbr, app.STATUSBAR_ADD_CELL , tag=M.STBR_MSG)
app.statusbar_proc(m.stbr, app.STATUSBAR_SET_CELL_AUTOSTRETCH , tag=M.STBR_MSG, value=True)
m.stbr_act(M.STBR_ALL, len(m.opts_full))
m.stbr_act(M.STBR_FLT, len(m.opts_full))
stor_json = app.app_path(app.APP_DIR_SETTINGS)+os.sep+m.how.get('stor_json', 'user.json')
start_mtime = os.path.getmtime(stor_json) if os.path.exists(stor_json) else 0
m.ag.show(when_exit)
m.ag = None
# Save for next using
m.stores[m.subset+'cur_op'] = m.cur_op
m.stores[m.subset+'col_ws'] = m.col_ws
m.stores[m.subset+'sorts'] = m.sorts
if not m.live_fltr:
m.stores[m.subset+'h.cond'] = m.cond_hl
m.stores[m.subset+'all_ops'] = m.all_ops
set_hist('dlg', m.stores)
return start_mtime != (os.path.getmtime(stor_json) if os.path.exists(stor_json) else 0)
#def show
def get_cnts(self, what=''):
M,m = self.__class__,self
reNotWdChar = re.compile(r'\W')
def test_fltr(fltr_s, op, oi):
if not fltr_s: return True
pass; #LOG and log('fltr_s, op, oi[!]={}',(fltr_s, op, oi['!']))
if '!!!' in fltr_s and '!!!' not in oi['!']: return False
if '!!' in fltr_s and '!!' not in oi['!']: return False
pass; #LOG and log('skip !!',())
if '!' in fltr_s and '!' not in oi['!']: return False
pass; #LOG and log('skip !',())
text = op \
+ (' '+oi.get('cmt', '') if '#' in fltr_s else '')
text = text.upper()
fltr_s = fltr_s.replace('!', '').replace('#', '').upper()
if '<' in fltr_s or '>' in fltr_s:
text = '·' + reNotWdChar.sub('·', text) + '·'
fltr_s = ' ' + fltr_s + ' '
fltr_s = fltr_s.replace(' <', ' ·').replace('> ', '· ')
pass; #LOG and log('fltr_s, text={}',(fltr_s, text))
return all(map(lambda c:c in text, fltr_s.split()))
#def test_fltr
def get_tbl_cols(sorts, col_ws):
cnms = list(M.COL_NMS)
cnms[M.COL_FIL] = f(cnms[M.COL_FIL], m.ed.get_prop(app.PROP_TAB_TITLE))
cols = [d(nm=sorts_sign(sorts, c) + cnms[c]
,wd=col_ws[c]
,mi=M.COL_MWS[c]
) for c in range(M.COL_N)]
cols[M.COL_OVR]['al'] = 'C'
if m.how.get('hide_fil', False):
pos_fil = M.COL_NMS.index(M.COL_FILE)
cols[pos_fil]['vi'] = False
if m.how.get('hide_lex_fil', False):
pos_lex = M.COL_NMS.index(M.COL_LEXR)
pos_fil = M.COL_NMS.index(M.COL_FILE)
cols[pos_lex]['vi'] = False
cols[pos_fil]['vi'] = False
return cols
#def get_tbl_cols
def get_tbl_data(opts_full, cond_s, ops_only, sorts, col_ws):
# Filter table data
pass; #LOG and log('cond_s={}',(cond_s))
pass; #log('opts_full/tab_s={}',({o:oi for o,oi in opts_full.items() if o.startswith('tab_s')}))
chp_cond = ''
chp_no_c = False
if '@' in cond_s:
# Prepare to match chapters
chp_cond = ' '.join([mt.group(1) for mt in re.finditer(r'@([\w/]+)' , cond_s)]).upper() # @s+ not empty chp
chp_cond = chp_cond.replace(M.NO_CHAP.upper(), '').strip()
chp_no_c = '@'+M.NO_CHAP in cond_s
cond_s = re.sub( r'@([\w/]*)', '', cond_s) # @s* clear @ and cph
pass; #log('chp_cond, chp_no_c, cond_s={}',(chp_cond, chp_no_c, cond_s))
SKWULFs = [ (oi.get('chp','')
,op
,oi['!']
,str(oi.get('jdf' ,'')).replace('True', 'true').replace('False', 'false')
,str(oi.get('juvl','')).replace('True', 'true').replace('False', 'false')
,str(oi.get('jlvl','')).replace('True', 'true').replace('False', 'false')
,str(oi.get('jfvl','')).replace('True', 'true').replace('False', 'false')
,oi['frm']
)
for op,oi in opts_full.items()
# if (not chp_cond or chp_cond in oi.get('chp', '').upper())
if (not chp_cond or any((chp_cond in oi.get('chp', '').upper()) for chp_cond in chp_cond.split()))
and (not chp_no_c or not oi.get('chp', ''))
and (not cond_s or test_fltr(cond_s, op, oi))
and (not ops_only or op in ops_only)
]
# Sort table data
SKWULFs = sorts_sort(sorts, SKWULFs)
# Fill table
pass; #LOG and log('M.COL_NMS,col_ws,M.COL_MWS={}',(len(M.COL_NMS),len(col_ws),len(M.COL_MWS)))
cols = get_tbl_cols(sorts, col_ws)
itms = (list(zip([_('Section'),_('Option'), '', _('Default'), _('User'), _('Lexer'), _('File')], map(str, col_ws)))
#, [ (str(n)+':'+sc,k ,w ,dv ,uv ,lv ,fv) # for debug
#, [ (sc+' '+fm ,k ,w ,dv ,uv ,lv ,fv) # for debug
, [ (sc ,k ,w ,dv ,uv ,lv ,fv) # for user
for n,( sc ,k ,w ,dv ,uv ,lv ,fv, fm) in enumerate(SKWULFs) ]
)
return SKWULFs, cols, itms
#def get_tbl_data
if not what or '+lvls' in what:
m.SKWULFs,\
m.cols ,\
m.itms = get_tbl_data(m.opts_full, m.cond_s, m.ops_only, m.sorts, m.col_ws)
if 'stbr' in dir(m):
m.stbr_act(M.STBR_FLT, len(m.SKWULFs))
if '+cols' in what:
pass; #LOG and log('m.col_ws={}',(m.col_ws))
m.cols = get_tbl_cols(m.sorts, m.col_ws)
pass; #LOG and log('m.cols={}',(m.cols))
# Prepare [Def]Val data by m.cur_op
vis,ens,vas,its,bcl = m._prep_opt()
ed_s_c = _('>Fil&e:') if m.for_ulf=='f' else \
_('>L&exer:') if m.for_ulf=='l' else \
_('>Us&er:')
cnts = []
if '+cond' in what:
cnts += [0
,('cond',d(items=m.cond_hl))
][1:]
if '+cols' in what or '=cols' in what:
cnts += [0
,('lvls',d(cols=m.cols))
][1:]
if '+lvls' in what or '=lvls' in what:
cnts += [0
,('lvls',d(cols=m.cols, items=m.itms))