-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTODOlist.pyw
1491 lines (1260 loc) · 75.7 KB
/
TODOlist.pyw
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
import PySimpleGUI as sg
from datetime import datetime
from re import match
# TODOlist is a todo list application that features sections that enable the organisation of tasks
# Copyright (C) 2021 Snaiel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# contact: snaiel.email@gmail.com
# /$$ /$$ /$$ /$$ /$$
# | $$ | $$ |__/ | $$ | $$
# | $$ | $$ /$$$$$$ /$$$$$$ /$$ /$$$$$$ | $$$$$$$ | $$ /$$$$$$ /$$$$$$$
# | $$ / $$/ |____ $$ /$$__ $$| $$ |____ $$| $$__ $$| $$ /$$__ $$ /$$_____/
# \ $$ $$/ /$$$$$$$| $$ \__/| $$ /$$$$$$$| $$ \ $$| $$| $$$$$$$$| $$$$$$
# \ $$$/ /$$__ $$| $$ | $$ /$$__ $$| $$ | $$| $$| $$_____/ \____ $$
# \ $/ | $$$$$$$| $$ | $$| $$$$$$$| $$$$$$$/| $$| $$$$$$$ /$$$$$$$/
# \_/ \_______/|__/ |__/ \_______/|_______/ |__/ \_______/|_______/
COLOUR_PICKER_SYMBOL = b'iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAD6UlEQVR4Xu2aSchOURjHfx8ZyrCTqRTKvJCNhYVsLKQIhQxlWBoW7ExlKtkgUUjJTsjGlIVSNiLEhg2RlAULUzL21716v+u+7z3n3HPOe97v+8723jP8f+c5z32e554uennr6uX66QPQZwGdRWAMsACYD0wERgG/gLfAM+AGcB14byqrU47AeGA3sAboXyHuK3ASOAS8qwLRCQDWASeAwVViCs8/AKsyi2jaNWUAWtsxYJOl8MbXdTy2AUeajZEqAK3rFLCxhvi8629gCXClbKwUAfgUn2v+DEwFXhchpAZA6zkNbPCw88UhzpaNmxKAkOIF4ycwAXjVSCYkAH2jDwILMw9+B9gBPC7ZXa3jDLA+wM43DrkZOB4DwAjgPjCuIEjfaDkkBSx565eZfWjxmu9qtiH/Jg9lAUeBLU128xuwOIMg8dp5fetjtOfA5BgW8BSY3kKRIMgSlkUUr+V8BIbHAPAEmBFjSy3n+AQMiwFAkddWy8XFeD3aEZATfAiMjaHKYg5lisomgztBTTAFuJ2lrBZrDPqqrFL5RRQAmkQeVxBGB5VlNrgSI9UQXsYEkFvCI2CQ2TqDvXUeWFscPVQckM8TIrFxIaQAbFpx9zVQSACpiJfO5cCFMnKhAKQkXqW0fc3MJgSAlMTvB3a1OjO+AXSUeN8+wDafvwbMBFTq9t0qd77RS/uY3Fb8ZWAFoHK34gSfEIzF+7IAV/HfM/KTPEKwEu8DQF3xufX5gGAtvi4AX+J9QHASXweAbQ1PZ17ByI8Kh+NiCc7iXQGEEq/1DAFuAnMMPbMqvYuyWp9hl+6v2cYBocWraDnXUonKa0tdIdgASFF8zsoZgikA29L1pew7X3Xmc7N32fmioXzJ6pAvbCzIBIBt6bod4nPNpTl/nVwgJfGq6A6t2N3/ip5V1tDKAlISr0+ddrcqbL4HzK4S3fi8GYDUxOcpbVWcsBM44AOAfleZ/qK+CKw0CHJcHF5ZkCMI+reoRKqx3QXmAXmOYcShzAJUODxn1Btii8+XJV+wPQuY9Am8lf31VWBk1coAPABmGYzSLvEGSzN/pQyAiA6sGKJHiJfGMgC6VNSq9RjxrgAGRHR45rbs+KaLBZhEj8rqbMLbWimto/a/3UIA6BjxIQB0lHjfADpOvCuAbldMsvOni8z6OpgWM9p25ov+wsUH1PE56puMeFcLqAMgKfGxASQnPiaAJMU3A/Cmnf/q6pwvl75lTlCVl9Uug5X0SXbn87WWARgJ6FKTbnvXaXuBPXUGiNG3WVyvi466VqIKi81lR5WmBe9wVqSIoaHWHCaJTa0JUu/cByD1HQq9vl5vAX8A3sTXQVWJ5CgAAAAASUVORK5CYII='
SYMBOL_RIGHT ='►'
SYMBOL_DOWN = '▼'
MENUS = {
'menu_bar': [['&Edit', ['Undo', 'Redo', '---', 'Add', ['Task::ADD', 'Section::ADD', 'List::ADD(MENU)', 'Paste::ADD'], ['Delete', ['List::DELETE', 'Content'], '---', 'Lists', 'Settings', '---', '&Refresh', 'Save']]], ['Help', ['About', 'Wiki']]],
'disabled_menu_bar': [['Edit', ['Undo', 'Redo', '---', '!Add', ['Task'], ['!Delete', ['List'], '---', 'Lists', 'Settings', '---', '!Refresh', 'Save']]], ['Help', ['About', 'Wiki']]],
'task_level_0_and_1': ['Right', ['Move', ['Up::MOVE_ELEMENT', 'Down::MOVE_ELEMENT'], '---', 'Copy::TASK', 'Cut::TASK', '---', 'Insert', ['Task::INSERT', 'Section::INSERT', 'Paste::INSERT'], 'Rename', 'Delete', '---', 'Convert']],
'task_level_2': ['Right', ['Move', ['Up::MOVE_ELEMENT', 'Down::MOVE_ELEMENT'], '---', 'Copy::TASK', 'Cut::TASK', '---', 'Insert', ['Task::INSERT', 'Paste::INSERT'], 'Rename', 'Delete']],
'section_level_0': ['&Right', ['Move', ['Up::MOVE_ELEMENT', 'Down::MOVE_ELEMENT'], '---', 'Copy::SECTION', 'Cut::SECTION', '---', 'Add', ['Task::ADDTO', 'Section::ADDTO', 'Paste::ADDTO'], '&Insert', ['Task::INSERT', 'Section::INSERT', 'Paste::INSERT'], 'Rename', 'Delete', '---', 'Clear', 'Convert', 'Extract']],
'section_level_1': ['Right', ['Move', ['Up::MOVE_ELEMENT', 'Down::MOVE_ELEMENT'], '---', 'Copy::SECTION', 'Cut::SECTION', '---', 'Add', ['Task::ADDTO', 'Paste::ADDTO'], '&Insert', ['Task::INSERT', 'Section::INSERT', 'Paste::INSERT'], 'Rename', 'Delete', '---', 'Clear', 'Convert', 'Extract']]
}
program_values = {
'current_list': '',
'time_to_reset_daily_sections': '',
'undo_limit': 0,
'background_colour': '',
'button_colour': '',
'text_colour_1': '',
'text_colour_2': ''
}
temp_data = {
'list_index': '',
'last_time_closed': '',
'element_keys': [],
'sections_open': {},
'combo': [],
'last_element_right_clicked': '',
'list_selected_to_edit': '',
'last_list_on': '',
'element_copied': None,
'last_action_and_undo_todolists': [[], []], # first list is last action, second list is last undo
'last_action_and_undo_list_editor': [[], []],
'last_action_and_undo_settings': [[], []],
'deleted_todolists': [],
'last_scrollbar_position': (0.0, 1.0),
'previous_settings': {
'time_to_reset_daily_sections': '',
'undo_limit': 0,
'background_colour': '',
'button_colour': '',
'text_colour_1': '',
'text_colour_2': ''
}
}
data = []
# /$$$$$$$$ /$$ /$$
# | $$_____/ | $$ |__/
# | $$ /$$ /$$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
# | $$$$$ | $$ | $$| $$__ $$ /$$_____/|_ $$_/ | $$ /$$__ $$| $$__ $$ /$$_____/
# | $$__/ | $$ | $$| $$ \ $$| $$ | $$ | $$| $$ \ $$| $$ \ $$| $$$$$$
# | $$ | $$ | $$| $$ | $$| $$ | $$ /$$| $$| $$ | $$| $$ | $$ \____ $$
# | $$ | $$$$$$/| $$ | $$| $$$$$$$ | $$$$/| $$| $$$$$$/| $$ | $$ /$$$$$$$/
# |__/ \______/ |__/ |__/ \_______/ \___/ |__/ \______/ |__/ |__/|_______/
def read_data_file():
tasks = ('(T)', '(F)')
booleans = {
'(T)': True,
'(F)': False,
'(O)': True,
'(C)': False
}
with open('data.txt') as f:
file = f.read().splitlines()
settings = file[(file.index('Settings:') + 1):file.index('Data:')]
task_data = file[(file.index('Data:') + 1):]
previous_line = None
todolist_data = []
list_data = []
section = []
subsection = []
for i in settings:
i = i.split(': ')
i[0] = i[0].strip()
program_values[i[0]] = i[1]
for i in task_data:
i = i.split()
if i[0] == 'last_time_closed:':
temp_data['last_time_closed'] = ' '.join(i[1:3])
if previous_line != None and previous_line[0] == '---' and i[0] != '---':
if i[0] == '----':
subsection.append({' '.join(i[1:-1]): booleans[i[-1]]})
elif len(section) != 0:
list_data.append(section.copy())
section.clear()
if previous_line != None and previous_line[0] == '----' and i[0] != '----':
if len(subsection) != 0:
section.append(subsection.copy())
subsection.clear()
if i[0] == '--':
list_data.append(section.copy())
section.clear()
if i[0] == '----' and previous_line[0] == '----':
subsection.append({' '.join(i[1:-1]): booleans[i[-1]]})
if i[0] == '---':
if i[-1] not in tasks and previous_line[0] == '---' and previous_line[-1] not in tasks:
section.append(subsection.copy())
subsection.clear()
if i[-1] in tasks:
section.append({' '.join(i[1:-1]): booleans[i[-1]]})
else:
subsection.append({' '.join(i[1:-1]): booleans[i[-1]]})
if i[0] == '--':
if i[-1] not in tasks and previous_line[0] == '--' and previous_line[-1] not in tasks:
list_data.append(section.copy())
section.clear()
if i[-1] in tasks:
list_data.append({' '.join(i[1:-1]): booleans[i[-1]]})
else:
section.append({' '.join(i[1:-1]): booleans[i[-1]]})
if i[0] == '-':
if len(list_data) != 0:
todolist_data.append(list_data.copy())
list_data.clear()
if i[-1] == '!':
list_data.append(' '.join(i[1:-1]))
program_values['current_list'] = ' '.join(i[1:-1])
else:
list_data.append(' '.join(i[1:]))
previous_line = i
if len(subsection) != 0:
section.append(subsection.copy())
subsection.clear()
if len(section) != 0:
list_data.append(section.copy())
section.clear()
if len(list_data) != 0:
todolist_data.append(list_data.copy())
list_data.clear()
global data
data = todolist_data
def write_data_file():
with open('data.txt', 'w') as f:
lines = ['Settings:' ,'Data:']
file_settings = [
f" time_to_reset_daily_sections: {program_values['time_to_reset_daily_sections']}",
f" undo_limit: {program_values['undo_limit']}",
f" background_colour: {program_values['background_colour']}",
f" button_colour: {program_values['button_colour']}",
f" text_colour_1: {program_values['text_colour_1']}",
f" text_colour_2: {program_values['text_colour_2']}"
]
file_data = [
f" last_time_closed: {temp_data['last_time_closed']}"
]
for todolist in data:
for content in todolist:
if todolist.index(content) == 0:
file_data.append(f"- {content}{' !' if program_values['current_list'] == content else ''}")
if type(content) is dict:
for key, value in content.items():
file_data.append(f"-- {key} {'(T)' if value == True else '(F)'}")
if type(content) is list:
header = None
opened = None
for key, value in content[0].items():
header = key
opened = value
file_data.append(f"-- {header} {'(O)' if opened == True else '(C)'}")
for content_in_section in content:
if type(content_in_section) is dict and content.index(content_in_section) != 0:
for key, value in content_in_section.items():
file_data.append(f"--- {key} {'(T)' if value == True else '(F)'}")
if type(content_in_section) is list:
subheader = None
subheader_opened = None
for key, value in content_in_section[0].items():
subheader = key
subheader_opened = value
file_data.append(f"--- {subheader} {'(O)' if subheader_opened == True else '(C)'}")
for content_in_subsection in content_in_section:
if type(content_in_subsection) is dict and content_in_section.index(content_in_subsection) != 0:
for key, value in content_in_subsection.items():
file_data.append(f"---- {key} {'(T)' if value == True else '(F)'}")
lines[1:1] = file_settings
lines.extend(file_data)
f.write('\n'.join(lines))
def reset_tasks_in_daily_section():
for todolist in data:
for content in todolist:
if type(content) is list and 'Daily' in content[0]:
for content_in_section in content:
if content.index(content_in_section) == 0:
continue
if type(content_in_section) is dict:
for key in content_in_section:
content_in_section[key] = False
if type(content_in_section) is list:
for sub_task in content_in_section:
if content_in_section.index(sub_task) == 0:
continue
if type(sub_task) is dict:
for key in sub_task:
sub_task[key] = False
def colours():
background_colour = program_values['background_colour']
button_colour = program_values['button_colour']
text_colour_1 = program_values['text_colour_1']
text_colour_2 = program_values['text_colour_2']
sg.theme_background_color(background_colour)
sg.theme_element_background_color(background_colour)
sg.theme_text_element_background_color(background_colour)
sg.theme_button_color((text_colour_2, button_colour))
sg.theme_text_color(text_colour_1)
sg.theme_input_text_color(text_colour_2)
def collapse(layout, key, is_visible):
"""
Helper function that creates a Column that can be later made hidden, thus appearing "collapsed"
:param layout: The layout for the section
:param key: Key used to make this seciton visible / invisible
:return: A pinned column that can be placed directly into your layout
:rtype: sg.pin
"""
return sg.pin(sg.Column(layout, key=key, visible=is_visible, pad=(15,0)))
def symbol(opened):
if opened is True:
return SYMBOL_DOWN
else:
return SYMBOL_RIGHT
def create_combo():
temp_data['combo'].clear()
combo = temp_data['combo']
for i in data:
combo.append(i[0])
def create_task(name, checked, list_name, hierarchy_index, section_id):
for i in data:
if i[0] == list_name:
list_index = str(data.index(i)).zfill(2)
hierarchy_index = str(hierarchy_index).zfill(2)
section_id = str(section_id).zfill(2)
element_indexes = f"{list_index} {hierarchy_index} {section_id}"
checkbox_key = f"{element_indexes} TASK CHECKBOX {name}"
checkbox_text_key = f"{element_indexes} TASK TEXT {name}"
right_click_menu = MENUS['task_level_0_and_1']
if hierarchy_index == '02':
right_click_menu = MENUS['task_level_2']
if len(name) > 30:
tooltip = name
else:
tooltip = None
temp_data['element_keys'].append(f"{element_indexes} TASK {name}")
return [sg.Checkbox('', default=checked, enable_events=True, key=checkbox_key, pad=((10, 0),(3,3))), sg.T(name, right_click_menu=right_click_menu, pad=(0,0), key=checkbox_text_key, enable_events=True, tooltip=tooltip)]
def create_section(header, opened, content, list_name, hierarchy_index, section_id):
for i in data:
if i[0] == list_name:
list_index = str(data.index(i)).zfill(2)
hierarchy_index = str(hierarchy_index).zfill(2)
section_id = str(section_id).zfill(2)
element_indexes = f"{list_index} {hierarchy_index} {section_id}"
sectionArrowKey = f'{element_indexes} SECTION ARROW {header}'
sectionTextKey = f'{element_indexes} SECTION TEXT {header}'
section_contentKey = f'{element_indexes} SECTION CONTENT {header}'
right_click_menu = MENUS['section_level_0']
if hierarchy_index == '01':
right_click_menu = MENUS['section_level_1']
if len(header) > 30:
tooltip = header
else:
tooltip = None
temp_data['sections_open'][f"{element_indexes} SECTION {header}"] = opened
temp_data['element_keys'].append(f"{element_indexes} SECTION {header}")
return [[sg.T(symbol(opened), enable_events=True, k=sectionArrowKey, pad=((10, 0),(3,3))), sg.T(header, enable_events=True, k=sectionTextKey, right_click_menu=right_click_menu, tooltip=tooltip)], [collapse(content, section_contentKey, opened)]]
def create_list_layout(list_to_create):
created_list_layout = []
section_id = 0
for i in data:
if i[0] is list_to_create:
contents = i
for content in contents:
if type(content) is dict:
for key, value in content.items():
created_list_layout.append(create_task(key, value, list_to_create, 0, 0))
if type(content) is list:
section_id += 1
id_of_section = section_id
header = None
opened = None
for key, value in content[0].items():
header = key
opened = value
section_content = []
for content_in_section in content:
if type(content_in_section) is dict and content.index(content_in_section) != 0:
for key, value in content_in_section.items():
section_content.append(create_task(key, value, list_to_create, 1, id_of_section))
if type(content_in_section) is list:
section_id += 1
subheader = None
subheader_opened = None
for key, value in content_in_section[0].items():
subheader = key
subheader_opened = value
subsection_content = []
for content_in_subsection in content_in_section:
if type(content_in_subsection) is dict and content_in_section.index(content_in_subsection) != 0:
for key, value in content_in_subsection.items():
subsection_content.append(create_task(key, value, list_to_create, 2, section_id))
for i in create_section(subheader, subheader_opened, subsection_content, list_to_create, 1, id_of_section):
section_content.append(i)
for i in create_section(header, opened, section_content, list_to_create, 0, 0):
created_list_layout.append(i)
return created_list_layout
def create_row_of_columns(list_to_create):
list_of_columns = []
for i in data:
list_layout = create_list_layout(i[0])
list_of_columns.append(sg.Column(layout=list_layout, visible=i[0] == list_to_create, size=(300,390), key=f'COL{data.index(i)}', scrollable=True, vertical_scroll_only=True, pad=((0,5),(10,10))))
list_editor_layout = [
[sg.Listbox(key='LISTS LISTBOX', values=tuple(temp_data['combo']), size=(32,10), pad=(16,10), enable_events=True)],
[sg.B('NONE', focus=True, visible=False)],
[sg.B('Add', k='List::ADD(BUTTON)', size=(28,2), pad=(22, 8), border_width=0)],
[sg.B('Rename', k='List::RENAME', size=(13, 2), pad=((22, 5), (0, 0)), border_width=0), sg.B('Delete', k='List::DELETE', size=(13, 2), border_width=0)],
[sg.B('Move up', k='List::MOVEUP', size=(13, 2), pad=((22, 5), (6, 0)), border_width=0), sg.B('Move down', k='List::MOVEDOWN', size=(13, 2), pad=((5, 0), (6, 0)), border_width=0)],
[sg.B('Undo', k='List::UNDO', size=(13, 2), pad=((22, 5), (8, 0)), border_width=0), sg.B('Redo', k='List::REDO', size=(13, 2), pad=((5, 0), (8, 0)), border_width=0)]
]
frame_layout = [
[sg.CB('', pad=((10, 0),(3,3))), sg.T('Colour ', pad=(0,0))],
[sg.T(symbol(True), pad=((10, 0),(3,3))), sg.T('Settings')], [collapse([[sg.CB('', pad=((10, 0),(3,3))), sg.T('Apply', pad=(0,0))]], None, True)]
]
settings_layout = [
[sg.Text('Reset Daily at', pad=((10,0),(10,0))), sg.Input(default_text=program_values['time_to_reset_daily_sections'], key='-TIME_TO_RESET_DAILY_SECTIONS-', size=(10,1), pad=((53,5),(10,0)))],
[sg.Text('Undo Limit', pad=((10, 0), (5, 15))), sg.Input(default_text=program_values['undo_limit'], key='-UNDO_LIMIT-', size=(10,1), pad=((73,5),(0,10)))],
[sg.Text('Background Colour', pad=(10,0)), sg.Input(default_text=program_values['background_colour'], key='-BACKGROUND_COLOUR-', size=(10,1), pad=((15,5),(0,0))), sg.ColorChooserButton('', image_data=COLOUR_PICKER_SYMBOL, image_size=(20,20), image_subsample=4, target=(sg.ThisRow, -1), border_width=0, key='-BACKGROUND_COLOUR_CHOOSER-')],
[sg.Text('Button Colour', pad=(10,0)), sg.Input(default_text=program_values['button_colour'], key='-BUTTON_COLOUR-', size=(10,1), pad=((46,5),(0,0))), sg.ColorChooserButton('', image_data=COLOUR_PICKER_SYMBOL, image_size=(20,20), image_subsample=4, target=(sg.ThisRow, -1), border_width=0, key='-BUTTON_COLOUR_CHOOSER-')],
[sg.Text('Text Colour 1', pad=(10,0)), sg.Input(default_text=program_values['text_colour_1'], key='-TEXT_COLOUR_1-', size=(10,1), pad=((48,5),(0,0))), sg.ColorChooserButton('', image_data=COLOUR_PICKER_SYMBOL, image_size=(20,20), image_subsample=4, target=(sg.ThisRow, -1), border_width=0, key='-TEXT_COLOUR_1_CHOOSER-')],
[sg.Text('Text Colour 2', pad=(10,0)), sg.Input(default_text=program_values['text_colour_2'], key='-TEXT_COLOUR_2-', size=(10,1), pad=((48,5),(0,0))), sg.ColorChooserButton('', image_data=COLOUR_PICKER_SYMBOL, image_size=(20,20), image_subsample=4, target=(sg.ThisRow, -1), border_width=0, key='-TEXT_COLOUR_2_CHOOSER-')],
[sg.Frame('Result', frame_layout, pad=(25,50), title_color=program_values['text_colour_1'])]
]
list_of_columns.append(sg.Column(layout=list_editor_layout, visible=True if program_values['current_list'] == 'LIST EDITOR' else False, size=(300,400), key='COL LIST EDITOR', scrollable=False, pad=((0,5),(10,10))))
list_of_columns.append(sg.Column(layout=settings_layout, visible=True if program_values['current_list'] == 'SETTINGS' else False, size=(300,390), key='COL SETTINGS', scrollable=False, vertical_scroll_only=True, pad=((0,5),(10,10))))
return(list_of_columns)
def create_layout(list_to_create):
if list_to_create is None:
list_to_create = program_values['current_list']
if list_to_create in ('LIST EDITOR', 'SETTINGS'):
add_buttons_visible = False
if list_to_create == 'LIST EDITOR':
default_value_of_combo_box = 'List Editor'
else:
default_value_of_combo_box = 'Settings'
else:
add_buttons_visible = True
default_value_of_combo_box = temp_data['combo'][temp_data['combo'].index(program_values['current_list'] if program_values['current_list'] != 'LIST EDITOR' else temp_data['combo'][0])]
add_buttons_column = [
[sg.pin(sg.Button('Add Task', size=(15,2), key='Task::ADD', pad=((0,0),(2,0)), border_width=0)), sg.pin(sg.Button('Add Section', size=(15,2), key='Section::ADD', pad=((18,0),(2,0)), border_width=0))]
]
apply_revert_buttons_columns = [
[sg.B('Apply', size=(15,2), border_width=0, pad=((0,0),(2,0))), sg.B('Revert', size=(15, 2), border_width=0, pad=((18,0),(2,0)))]
]
return [
[sg.Menu(MENUS['menu_bar'], key='-MENU BAR-')],
[sg.Combo(temp_data['combo'],default_value=default_value_of_combo_box , size=(100, 1), key='-COMBO-', readonly=True, enable_events=True)],
create_row_of_columns(list_to_create),
[sg.Col(add_buttons_column, k='COL ADD BUTTONS', visible=add_buttons_visible), sg.Col(apply_revert_buttons_columns, k='COL APPLY REVERT BUTTONS', visible=True if program_values['current_list'] == 'SETTINGS' else False)]
]
def add_todolist():
if any(x in event.title() for x in ('Undo', 'Redo')) is False:
current_location = window.current_location()
todolist_name_popup = sg.Window(None, [[sg.Text(f'Todolist name:', justification='c', pad=((100, 0),(200, 5)))], [sg.Input(size=(50, 1), pad=(20,5), key='-INPUT_TODOLIST_NAME-', justification='c')], [sg.Ok(size=(7,1), pad=((70, 10),(5,0))), sg.Cancel(size=(7,1), pad=((0, 5),(5,0)))]], no_titlebar=True, size=(300,550), location=(current_location[0] + 8, current_location[1]), alpha_channel=0.98, keep_on_top=True, finalize=True)
popup_event, popup_values = todolist_name_popup.read(close=True)
list_name = popup_values['-INPUT_TODOLIST_NAME-'] if popup_event == 'Ok' else None
else:
index = 0 if 'Undo' in event.title() else 1
list_name = temp_data['last_action_and_undo_list_editor'][index][-1][1]
if list_name is not None and list_name not in temp_data['combo']:
data.append([list_name])
if 'MENU' in event:
program_values['current_list'] = list_name
add_to_last(('add_todolist', list_name))
create_combo()
temp_data['list_index'] = str(temp_data['combo'].index(list_name)).zfill(2)
create_new_window()
elif list_name in temp_data['combo']:
message_popup('List already exists')
return
def rename_todolist():
if len(values['LISTS LISTBOX']) != 0 or any(x in event.title() for x in ('Undo', 'Redo')):
if any(x in event.title() for x in ('Undo', 'Redo')) is False:
list_to_rename = values['LISTS LISTBOX'][0]
else:
index = 0 if 'Undo' in event.title() else 1
list_to_rename = temp_data['last_action_and_undo_list_editor'][index][-1][1]
if any(x in event.title() for x in ('Undo', 'Redo')) is False:
current_location = window.current_location()
rename_todolist_popup = sg.Window(None, [[sg.Text('Rename todolist to:', justification='c', pad=((80, 0),(200, 5)))], [sg.Input(default_text=list_to_rename, size=(50, 1), pad=(20,5), key='-INPUT_RENAME_TODOLIST-', justification='c')], [sg.Ok(size=(7,1), pad=((70, 10),(5,0))), sg.Cancel(size=(7,1), pad=((0, 5),(5,0)))]], no_titlebar=True, size=(300,550), location=(current_location[0] + 8, current_location[1]), alpha_channel=0.98, keep_on_top=True, finalize=True)
rename_todolist_popup['-INPUT_RENAME_TODOLIST-'].update(select=True)
popup_event, popup_values = rename_todolist_popup.read(close=True)
new_list_name = popup_values['-INPUT_RENAME_TODOLIST-'] if popup_event == 'Ok' else None
else:
index = 0 if 'Undo' in event.title() else 1
new_list_name = temp_data['last_action_and_undo_list_editor'][index][-1][2]
if new_list_name not in temp_data['combo'] and new_list_name not in ('', None):
add_to_last(('rename_todolist', new_list_name, list_to_rename))
for i in data:
if i[0] is list_to_rename:
i[0] = new_list_name
break
for list_name_in_combo in temp_data['combo']:
if list_name_in_combo is list_to_rename:
list_name_in_combo = new_list_name
break
elif new_list_name in temp_data['combo']:
message_popup('List already exists')
return
else:
return
elif len(values['LISTS LISTBOX']) == 0:
message_popup('Select a list first')
create_combo()
window['-COMBO-'].update(values=temp_data['combo'])
window['LISTS LISTBOX'].update(values=tuple(temp_data['combo']))
def delete_todolist():
if any(x in event.title() for x in ('Undo', 'Redo')) is False:
current_location = window.current_location()
element_name_popup = sg.Window(None, [[sg.Text(f"This will delete the list and all of it's contents", justification='c', pad=((10, 0),(200, 5)))], [sg.Ok(size=(7,1), pad=((70, 10),(5,0))), sg.Cancel(size=(7,1), pad=((0, 5),(5,0)))]], no_titlebar=True, size=(300,550), location=(current_location[0] + 8, current_location[1]), alpha_channel=0.98, keep_on_top=True, finalize=True)
popup_event = element_name_popup.read(close=True)[0]
if popup_event == 'Ok':
if window[f'COL LIST EDITOR'].visible == True:
list_to_delete = values['LISTS LISTBOX'][0]
else:
list_to_delete = program_values['current_list']
else:
return
else:
key = 'last_action_and_undo_todolists' if program_values['current_list'] not in ('LIST EDITOR', 'SETTINGS') else ('last_action_and_undo_list_editor' if program_values['current_list'] == 'LIST EDITOR' else 'last_action_and_undo_settings')
index = 0 if 'Undo' in event.title() else 1
list_to_delete = temp_data[key][index][-1][1]
for todolist in data:
if todolist[0] == list_to_delete:
add_to_last(('delete_todolist', list_to_delete, data.index(todolist)))
if len(temp_data['deleted_todolists']) >= int(program_values['undo_limit']):
temp_data['deleted_todolists'].pop(0)
temp_data['deleted_todolists'].append(todolist)
data.remove(todolist)
temp_data['combo'].remove(list_to_delete)
for list_name in temp_data['combo']:
if list_name is not list_to_delete:
if window[f'COL LIST EDITOR'].visible == True:
program_values['current_list'] = 'LIST EDITOR'
else:
program_values['current_list'] = list_name
break
return create_new_window()
def undo_delete_todolist():
print(temp_data['deleted_todolists'])
key = 'last_action_and_undo_todolists' if program_values['current_list'] not in ('LIST EDITOR', 'SETTINGS') else ('last_action_and_undo_list_editor' if program_values['current_list'] == 'LIST EDITOR' else 'last_action_and_undo_settings')
index = 0 if 'Undo' in event.title() else 1
for todolist in temp_data['deleted_todolists']:
if todolist[0] == temp_data[key][index][-1][1]:
data.insert(temp_data[key][index][-1][2], todolist)
add_to_last(('add_todolist', todolist[0]))
create_combo()
return create_new_window()
def move_todolist():
if values['LISTS LISTBOX'] != []:
list_name = values['LISTS LISTBOX'][0]
elif values['LISTS LISTBOX'] == [] and temp_data['list_selected_to_edit'] != '' and any(x in event.title() for x in ('Undo', 'Redo')) is False:
list_name = temp_data['list_selected_to_edit']
elif any(x in event.title() for x in ('Undo', 'Redo')):
index = 0 if 'Undo' in event.title() else 1
list_name = temp_data['last_action_and_undo_list_editor'][index][-1][1]
else:
message_popup('Select a list first')
return
if any(x in event.title() for x in ('Undo', 'Redo')) is False:
direction = 'Up' if 'UP' in event else 'Down'
else:
index = 0 if 'Undo' in event.title() else 1
direction = 'Up' if temp_data['last_action_and_undo_list_editor'][index][-1][2] == 'Down' else 'Down'
for todolist in data:
if todolist[0] is list_name:
if direction == 'Up':
a, b = data.index(todolist), data.index(todolist) - 1
if a == 0:
return
else:
a, b = data.index(todolist), data.index(todolist) + 1
if len(data) == b:
return
data[b], data[a] = data[a], data[b]
break
add_to_last(('move_todolist', list_name, direction))
temp_data['list_selected_to_edit'] = list_name
create_combo()
create_new_window()
def delete_list_contents():
current_location = window.current_location()
element_name_popup = sg.Window(None, [[sg.Text('This will delete the contents of this list\n are you sure?', justification='c', pad=((25, 0),(200, 5)))], [sg.Ok(size=(7,1), pad=((70, 10),(5,0))), sg.Cancel(size=(7,1), pad=((0, 5),(5,0)))]], no_titlebar=True, size=(300,550), location=(current_location[0] + 8, current_location[1]), alpha_channel=0.98, keep_on_top=True, finalize=True)
popup_event = element_name_popup.read(close=True)[0]
if popup_event == 'Ok':
for todolist in data:
if todolist[0] == program_values['current_list']:
todolist[1:] = []
return create_new_window()
def update_data(element_type, event):
element_indexes = event[:8]
if element_type == 'Task':
if 'TEXT' in event:
name = event[19:]
checked = window[f"{element_indexes} TASK CHECKBOX {name}"].Get()
window[f"{element_indexes} TASK CHECKBOX {name}"].update(value=not checked)
else:
name = event[23:]
else:
if 'ARROW' in event:
name = event[23:]
else:
name = event[22:]
temp_data['sections_open'][f"{element_indexes} SECTION {name}"] = not temp_data['sections_open'][f"{element_indexes} SECTION {name}"]
window[f"{element_indexes} SECTION ARROW {name}"].update(SYMBOL_DOWN if temp_data['sections_open'][f"{element_indexes} SECTION {name}"] else SYMBOL_RIGHT)
window[f"{element_indexes} SECTION CONTENT {name}"].update(visible=temp_data['sections_open'][f"{element_indexes} SECTION {name}"])
for todolist in data:
if todolist[0] == program_values['current_list']:
for content in todolist:
if element_type == 'Section':
if type(content) is list:
if name in content[0]:
content[0][name] = temp_data['sections_open'][f"{element_indexes} SECTION {name}"]
return
for content_in_section in content:
if type(content_in_section) is list:
if name in content_in_section[0]:
content_in_section[0][name] = temp_data['sections_open'][f"{element_indexes} SECTION {name}"]
return
if element_type == 'Task':
if type(content) is dict:
if name in content:
content[name] = not content[name]
return
if type(content) is list:
for content_in_section in content:
if type(content_in_section) is dict:
if name in content_in_section:
content_in_section[name] = not content_in_section[name]
return
if type(content_in_section) is list:
for content_in_subsection in content_in_section:
if name in content_in_subsection:
content_in_subsection[name] = not content_in_subsection[name]
return
def get_section_id_for_element_to_append(reference_element, section_id_of_section):
local_section_id = 0
for todolist in data:
if todolist[0] == program_values['current_list']:
for section in [section for section in todolist if type(section) is list]:
local_section_id += 1
if reference_element in section[0]:
return local_section_id
for subsection in [subsection for subsection in section if type(subsection) is list]:
if reference_element in subsection[0] and int(section_id_of_section) == local_section_id:
return local_section_id + [subsection for subsection in section if type(subsection) is list].index(subsection) + 1
else:
for _ in [subsection for subsection in section if type(subsection) is list]:
local_section_id += 1
def add_or_insert_element_calculations():
reference_key = temp_data['last_element_right_clicked'].split()
element_type = event.split('::')[0]
augment_type = event.split('::')[1]
if 'ADD' in event:
if 'ADDTO' in event: # Appending to a list
reference_element = ' '.join(reference_key[5:])
hierarchy_index = reference_key[1]
section_id = str((int(get_section_id_for_element_to_append(reference_element, reference_key[2])))).zfill(2)
else: # Just adding to the end of the todolist
reference_element = None
hierarchy_index = '00'
section_id = '00'
else:
reference_element = ' '.join(reference_key[5:])
' '.join(reference_key[5:])
hierarchy_index = reference_key[1]
section_id = reference_key[2]
if 'Paste' in event and temp_data['element_copied'] is not None:
element_type = 'Task' if type(temp_data['element_copied'][1]) is bool else 'Section'
if element_type == 'Task':
element_name = temp_data['element_copied'][0][19:]
else:
element_name = list(temp_data['element_copied'][0][0].keys())[0]
if element_type == 'Task':
element_to_add = {element_name: temp_data['element_copied'][1]}
else:
if int(hierarchy_index) == 2:
message_popup('Cannot support more subsections\nPasting tasks within copied section...')
element_to_add = tuple(x for x in temp_data['element_copied'][0][1:] if type(x) is dict)
elif int(hierarchy_index) > 0 and temp_data['element_copied'][1] == 2:
element_to_add = [x for x in temp_data['element_copied'][0] if type(x) is dict]
message_popup('Cannot support more subsections\nPasting without subsections...')
else:
element_to_add = temp_data['element_copied'][0]
elif 'Paste' not in event: # Get the name of the new task or section
current_location = window.current_location()
element_name_popup = sg.Window(None, [[sg.Text(f'{element_type} name:', justification='c', pad=((105 if element_type == 'Task' else 95, 0),(200, 5)))], [sg.Input(size=(50, 1), pad=(20,5), key='-INPUT_ELEMENT_NAME-', justification='c')], [sg.Ok(size=(7,1), pad=((70, 10),(5,0))), sg.Cancel(size=(7,1), pad=((0, 5),(5,0)))]], no_titlebar=True, size=(300,550), location=(current_location[0] + 8, current_location[1]), alpha_channel=0.98, keep_on_top=True, finalize=True)
popup_event, popup_values = element_name_popup.read(close=True)
element_name = popup_values['-INPUT_ELEMENT_NAME-'] if popup_event == 'Ok' else None
if element_name in ('', None):
return
if element_type == 'Task':
if ';;' not in element_name:
element_to_add = {element_name: False}
else:
tasks = element_name.split(';;')
element_to_add = [{element_name: True}]
for task in tasks:
element_to_add.append({task: False})
else:
if ';;' not in element_name:
element_to_add = [{element_name: False}]
else:
tasks = element_name.split(';;')
element_to_add = [{element_name: True}]
for task in tasks:
element_to_add.append([{task: False}])
else:
return
# Putting the element into the list
if f"{temp_data['list_index']} {hierarchy_index} {section_id} {element_type.upper()} {element_name}" not in temp_data['element_keys']:
temp_data['last_scrollbar_position'] = window[f"COL{temp_data['combo'].index(program_values['current_list'])}"].Widget.vscrollbar.get()
augment_element_onto_list(element_to_add, augment_type, reference_element, hierarchy_index, section_id)
add_to_last(('add_element', f"{temp_data['list_index']} {hierarchy_index} {section_id} {element_type.upper()} TEXT {element_name}"))
else:
message_popup('Element already exists within\ncurrent area/ section')
def undo_delete_element():
index = 0 if event == 'Undo' else 1
hierarchy_index = temp_data['last_action_and_undo_todolists'][index][-1][1].split()[1]
section_id = temp_data['last_action_and_undo_todolists'][index][-1][1].split()[2]
element = temp_data['last_action_and_undo_todolists'][index][-1][2]
element_index = temp_data['last_action_and_undo_todolists'][index][-1][3]
add_to_last(('add_element', temp_data['last_action_and_undo_todolists'][index][-1][1]))
augment_element_onto_list(element, 'UNDOREDO', None, hierarchy_index, section_id, element_index)
def delete_element():
reference_key = temp_data['last_element_right_clicked'].split()
reference_element = ' '.join(reference_key[5:])
hierarchy_index = reference_key[1]
section_id = reference_key[2]
augment_element_onto_list(None, 'DELETE', reference_element, hierarchy_index, section_id, metadata=' '.join(reference_key))
def augment_element_onto_list(element, augment_type, reference_element, hierarchy_index, section_id, element_index=None, metadata=None):
'''
a workhorse of a function
element: the list or dictionary element that's being put into the data
augment_type: ADD, INSERT, RENAME etc
reference_element: name of the element that you rick clicked to do an action
hierarchy_index: the level of hierarchy within a section
section_id: which section the element is in. The todolist is 0, the first section is 1, then it loops through the subsections
element_index: the index the element is supposed to be at. Used for undo and redo
metadata: custom extra data that is needed for certin operations
'''
print(element, augment_type, reference_element, hierarchy_index, section_id, element_index, metadata)
local_section_id = 0
for todolist in data:
if todolist[0] == program_values['current_list']:
if local_section_id == int(section_id) and augment_type == 'UNDOREDO':
todolist.insert(element_index, element)
return create_new_window()
elif reference_element is None and augment_type != 'UNDOREDO':
todolist.insert(len(todolist), element)
return create_new_window()
for task in [task for task in todolist if type(task) is dict]:
if reference_element in task and hierarchy_index == '00':
if augment_type == 'DELETE':
add_to_last(('delete_element', metadata, task, todolist.index(task)))
todolist.remove(task)
elif augment_type == 'INSERT':
todolist.insert(todolist.index(task), element)
elif augment_type == 'RENAME':
task[metadata] = task.pop(reference_element)
elif augment_type == 'CONVERT' and metadata == 'TASK':
todolist.insert(todolist.index(task), element)
todolist.remove(task)
elif augment_type == 'MOVE':
if metadata == 'Up':
a, b = todolist.index(task), todolist.index(task) - 1
if a == 1:
return
else:
a, b = todolist.index(task), todolist.index(task) + 1
if len(todolist) == b:
return
todolist[b], todolist[a] = todolist[a], todolist[b]
return create_new_window()
for section in [section for section in todolist if type(section) is list]:
if reference_element in section[0] and hierarchy_index == '00':
if augment_type == 'DELETE':
add_to_last(('delete_element', metadata, section, todolist.index(section)))
todolist.remove(section)
elif augment_type == 'INSERT':
todolist.insert(todolist.index(section), element)
elif augment_type == 'ADDTO':
section.insert(len(section), element)
elif augment_type == 'RENAME':
section[0][metadata] = section[0].pop(reference_element)
elif augment_type == 'CONVERT' and metadata == 'SECTION':
todolist.insert(todolist.index(section), element)
todolist.remove(section)
elif augment_type == 'MOVE':
if metadata == 'Up':
a, b = todolist.index(section), todolist.index(section) - 1
if a == 1:
return
else:
a, b = todolist.index(section), todolist.index(section) + 1
if len(todolist) == b:
return
todolist[b], todolist[a] = todolist[a], todolist[b]
return create_new_window()
local_section_id += 1
if local_section_id == int(section_id) and augment_type == 'UNDOREDO':
section.insert(element_index, element)
return create_new_window()
for task in [task for task in section if type(task) is dict]:
if reference_element in task and int(section_id) == local_section_id:
if augment_type == 'DELETE':
add_to_last(('delete_element', metadata, task, section.index(task)))
section.remove(task)
elif augment_type == 'INSERT':
section.insert(section.index(task), element)
elif augment_type == 'RENAME':
task[metadata] = task.pop(reference_element)
elif augment_type == 'CONVERT' and metadata == 'TASK':
section.insert(section.index(task), element)
section.remove(task)
elif augment_type == 'MOVE':
if metadata == 'Up':
a, b = section.index(task), section.index(task) - 1
if a == 1:
return
else:
a, b = section.index(task), section.index(task) + 1
if len(section) == b:
return
section[b], section[a] = section[a], section[b]
return create_new_window()
for subsection in [subsection for subsection in section if type(subsection) is list]:
local_section_id += 1 if augment_type == 'ADDTO' else 0
if local_section_id == int(section_id) and augment_type == 'UNDOREDO':
subsection.insert(element_index, element)
return create_new_window()
if reference_element in subsection[0] and int(section_id) == local_section_id:
if augment_type == 'DELETE':
add_to_last(('delete_element', metadata, subsection, section.index(subsection)))
section.remove(subsection)
elif augment_type == 'INSERT':
section.insert(section.index(subsection), element)
elif augment_type == 'ADDTO':
subsection.insert(len(section), element)
elif augment_type == 'RENAME':
subsection[0][metadata] = subsection[0].pop(reference_element)
elif augment_type == 'CONVERT' and metadata == 'SECTION':
section.insert(section.index(subsection), element)
section.remove(subsection)
elif augment_type == 'MOVE':
if metadata == 'Up':
a, b = section.index(subsection), section.index(subsection) - 1
if a == 1:
return
else:
a, b = section.index(subsection), section.index(subsection) + 1
if len(section) == b:
return
section[b], section[a] = section[a], section[b]
return create_new_window()
else:
for subsection in [subsection for subsection in section if type(subsection) is list]:
local_section_id += 1
if local_section_id == int(section_id) and augment_type == 'UNDOREDO':
subsection.insert(element_index, element)
return create_new_window()
for task in [task for task in subsection if type(task) is dict]:
if reference_element in task and int(section_id) == local_section_id:
if type(element) is tuple:
for taskToInsert in element:
subsection.insert(subsection.index(task), taskToInsert)
else:
if augment_type == 'DELETE':
add_to_last(('delete_element', metadata, task, subsection.index(task)))
subsection.remove(task)
elif augment_type == 'INSERT':
subsection.insert(subsection.index(task), element)
elif augment_type == 'RENAME':
task[metadata] = task.pop(reference_element)
elif augment_type == 'MOVE':
if metadata == 'Up':
a, b = subsection.index(task), subsection.index(task) - 1
if a == 1:
return
else:
a, b = subsection.index(task), subsection.index(task) + 1
if len(subsection) == b:
return
subsection[b], subsection[a] = subsection[a], subsection[b]
return create_new_window()
def rename_element():
if event not in ('Undo', 'Redo'):
element = temp_data['last_element_right_clicked']
current_location = window.current_location()
rename_todolist_popup = sg.Window(None, [[sg.Text(f'Rename {element.split()[3].lower()} to:', justification='c', pad=((90 if element.split()[3].title() == 'Task' else 82, 0),(200, 5)))], [sg.Input(default_text=' '.join(element.split()[5:]), size=(50, 1), pad=(20,5), key='-INPUT_RENAME_ELEMENT-', justification='c')], [sg.Ok(size=(7,1), pad=((70, 10),(5,0))), sg.Cancel(size=(7,1), pad=((0, 5),(5,0)))]], no_titlebar=True, size=(300,550), location=(current_location[0] + 8, current_location[1]), alpha_channel=0.98, keep_on_top=True, finalize=True)
rename_todolist_popup['-INPUT_RENAME_ELEMENT-'].update(select=True)
popup_event, popup_values = rename_todolist_popup.read(close=True)
new_element_name = popup_values['-INPUT_RENAME_ELEMENT-'] if popup_event == 'Ok' else None
else:
index = 0 if event == 'Undo' else 1
element = temp_data['last_action_and_undo_todolists'][index][-1][1]
new_element_name = temp_data['last_action_and_undo_todolists'][index][-1][2]
element = element.split()
hierarchy_index = element[1]
section_id = element[2]
element_type = element[3].title()
old_name = ' '.join(element[5:])
new_key = f"{temp_data['list_index']} {hierarchy_index} {section_id} {element_type.upper()} TEXT {new_element_name}"
if f"{temp_data['list_index']} {hierarchy_index} {section_id} {element_type.upper()} {new_element_name}" not in temp_data['element_keys']:
add_to_last(('rename_element', new_key, old_name))
augment_element_onto_list(None , 'RENAME', old_name, hierarchy_index, section_id, None, new_element_name)
else:
message_popup('Element already exists within\ncurrent area/ section')
def convert_element():
if event not in ('Undo', 'Redo'):
element = temp_data['last_element_right_clicked']
else:
index = 0 if event == 'Undo' else 1
element = temp_data['last_action_and_undo_todolists'][index][-1][1]
element = element.split()
element_name = ' '.join(element[5:])
element_type = element[3].title()
hierarchy_index = element[1]
section_id = element[2]
new_element = [x for x in element if x != element_type.upper()]
new_element.insert(3, 'TASK' if element_type == 'Section' else 'SECTION')