forked from KrisNumber24/KanbanTxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KanbanTxt.py
2509 lines (2146 loc) · 105 KB
/
KanbanTxt.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
# KanbanTxt - A light todo.txt editor that display the to do list as a kanban board.
# Copyright (C) 2022 KrisNumber24
# 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
# 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://github.com/KrisNumber24/KanbanTxt/blob/main/LICENSE.
import os
import pathlib
import re
from datetime import date
import tkinter as tk
from tkinter import filedialog
from tkinter import simpledialog
from tkinter import ttk
import tkinter.font as tkFont
import argparse
from idlelib.tooltip import Hovertip
import ctypes
import json
def f_sort_column_by_prio(d):
return d['priority'] if d['priority'] is not None else 'z'
def f_sort_column_by_order(d):
return d['index']
def f_sort_column_by_txt(d):
return d['raw_txt']
def f_sort_column_by_subject(d):
return d['subject']
def f_sort_column_by_tag(d, tag_name, tag_indicator):
if len(d[tag_name]) < 1:
return chr(ord('z') + 1)
project_tags_copy = []
for p in d[tag_name]:
project_tags_copy.append(p[tag_name].casefold())
project_tags_copy.sort()
s = ' '.join(project_tags_copy)
s = s.replace(tag_indicator, '')
return s
def f_sort_column_by_project(d):
return f_sort_column_by_tag(d, 'project', '+')
def f_sort_column_by_context(d):
return f_sort_column_by_tag(d, 'context', '@')
SORT_METHODS = [
{
'text': "Task priority",
'tooltip': 'Sort by task priority:\n'
'tasks with priority (A) will be put first, then (B)... up to (Z).\n'
'Tasks without set priority will be put last.\n'
'Tasks within the same priority will be put in order of their definition in the txt file.',
'f': f_sort_column_by_prio,
'rev': False
},
{
'text': "Reversed task priority",
'tooltip': 'Sort by task reversed priority:\n'
'tasks with priority (A) will be put last, before (B)... up to (Z).\n'
'Tasks without set priority will be put first.\n'
'Tasks within the same priority will be put in reversed order of their definition in the txt file.',
'f': f_sort_column_by_prio,
'rev': True
},
{
'text': "Order in txt file",
'tooltip': 'Tasks are ordered by their definition in the txt file:\n'
'if a task is defined earlier in txt than the other, it will appear higher.',
'f': f_sort_column_by_order,
'rev': False
},
{
'text': "Reversed order in txt file",
'tooltip': 'Tasks are ordered in reverse by their definition in the txt file:\n'
'if a task is defined later in txt than the other, it will appear higher.',
'f': f_sort_column_by_order,
'rev': True
},
{
'text': "Alphabetically by subject",
'tooltip': "Tasks are ordered lexicographically by their subject.\n"
"It won't include priority or other tags defined at the beginning of line in the todo.txt.",
'f': f_sort_column_by_subject,
'rev': False
},
{
'text': "Alphabetically by text",
'tooltip': "Tasks are ordered lexicographically by their definition in the txt file.\n"
"It WILL include priority or other tags defined at the beginning of line in the todo.txt.\n"
"This is similar to sorting by priority, but the tasks without priority will be sorted alphabetically and not by their order in txt file.",
'f': f_sort_column_by_txt,
'rev': False
},
{
'text': "Alphabetically by project",
'tooltip': "Tasks are ordered lexicographically by their project tags.\n"
"If task has multiple project tags, they will be first sorted alphabetically.",
'f': f_sort_column_by_project,
'rev': False
},
{
'text': "Alphabetically by context",
'tooltip': "Tasks are ordered lexicographically by their context tags.\n"
"If task has multiple context tags, they will be first sorted alphabetically.",
'f': f_sort_column_by_context,
'rev': False
},
]
class CustomizeViewDialog(simpledialog.Dialog):
def __init__(self, parent, title,
out_show_project,
out_show_context,
out_show_special_kv_data,
out_show_index,
out_show_priority,
out_show_date,
out_show_content,
out_sort_method,
out_col0_name,
out_col1_name,
out_col2_name,
out_col3_name,
out_fontsize,
out_ask_for_add,
out_ask_for_delete,
out_hide_memo,
out_hide_button_delete,
out_hide_button_add_date,
out_hide_buttons_assign_priority,
out_hide_buttons_move_to_column,
out_hide_buttons_move_line_up_down,
):
self.show_project = out_show_project
self.show_context = out_show_context
self.show_special_kv_data = out_show_special_kv_data
self.show_index = out_show_index
self.show_priority = out_show_priority
self.show_date = out_show_date
self.show_content = out_show_content
self.sort_method = out_sort_method
self.ask_for_add = out_ask_for_add
self.ask_for_delete = out_ask_for_delete
self.col_names = [
out_col0_name,
out_col1_name,
out_col2_name,
out_col3_name,
]
self.font_size = out_fontsize
self.hide_memo = out_hide_memo
self.hide_button_delete = out_hide_button_delete
self.hide_button_add_date = out_hide_button_add_date
self.hide_buttons_assign_priority = out_hide_buttons_assign_priority
self.hide_buttons_move_to_column = out_hide_buttons_move_to_column
self.hide_buttons_move_line_up_down = out_hide_buttons_move_line_up_down
super().__init__(parent, title)
def create_checkbox(self, text, tooltip, variable, frame):
checkbox = tk.Checkbutton(frame, text=text, variable=variable)
Hovertip(checkbox, tooltip)
checkbox.pack(anchor=tk.W)
def create_radiobuttion(self, text, tooltip, variable, value, frame):
radiobutton = tk.Radiobutton(frame, text=text, variable=variable, value=value)
Hovertip(radiobutton, tooltip)
radiobutton.pack(anchor=tk.W)
def create_text_entry(self, tooltip, variable, frame, col, row):
entry = tk.Entry(frame, textvariable=variable)
Hovertip(entry, tooltip)
entry.grid(row=row, column=col, padx=10, pady=10, sticky=tk.NW)
def body(self, frame):
grid_frame = tk.Frame(frame)
grid_frame.pack(anchor=tk.NW, fill="both")
row = 0
frame_colnames = tk.LabelFrame(grid_frame, text="Column names: ")
frame_colnames.grid(columnspan=3, row=row, column=0, padx=10, pady=10, sticky=tk.NW)
for i, v in enumerate(self.col_names):
self.create_text_entry(f"Name of column {i}.", v, frame_colnames, row=row, col=i)
row = 1
first_column_frame = tk.Frame(grid_frame)
first_column_frame.grid(row=row, column=0, padx=10, pady=10, sticky=tk.NW)
frame_sorting = tk.LabelFrame(first_column_frame, text="Sort tasks in columns by: ")
frame_sorting.pack()
for i in range(len(SORT_METHODS)):
m = SORT_METHODS[i]
self.create_radiobuttion(m['text'], m['tooltip'], self.sort_method, i, frame_sorting)
second_column_frame = tk.Frame(grid_frame)
second_column_frame.grid(row=row, column=1, padx=10, pady=10, sticky=tk.NW)
frame_show_hide = tk.LabelFrame(second_column_frame, text="Show/hide task cards' elements: ")
frame_show_hide.pack()
self.create_checkbox('Priority', 'Show priority of a task on a card', self.show_priority, frame_show_hide)
self.create_checkbox('Date', 'Show date of a task on a card', self.show_date, frame_show_hide)
self.create_checkbox('Project', 'Show project labels of a task on a card', self.show_project, frame_show_hide)
self.create_checkbox('Context', 'Show context labels of a task on a card', self.show_context, frame_show_hide)
self.create_checkbox('Special k-v data', 'Show special k-v data labels of a task on a card', self.show_special_kv_data, frame_show_hide)
self.create_checkbox('Index', 'Show line index of a task on a card', self.show_index, frame_show_hide)
self.create_checkbox('Subject', 'Show the main content of a task on a card', self.show_content, frame_show_hide)
frame_fontsize = tk.LabelFrame(second_column_frame, text="Font size: ")
frame_fontsize.pack(fill='x', pady=10)
fontsize_spinbox = tk.Spinbox(frame_fontsize, from_=4, to=100, textvariable=self.font_size, wrap=True)
fontsize_spinbox.pack(anchor=tk.W, padx=10, pady=10, fill='x')
third_column_frame = tk.Frame(grid_frame)
third_column_frame.grid(row=row, column=2, padx=10, pady=10, sticky=tk.NW)
frame_hide_editor_elements = tk.LabelFrame(third_column_frame, text="Show editor widgets: ")
frame_hide_editor_elements.pack()
self.create_checkbox("Memo", "", self.hide_memo, frame_hide_editor_elements)
self.create_checkbox("Buttons 'Move to column'", "", self.hide_buttons_move_to_column, frame_hide_editor_elements)
self.create_checkbox("Button 'Add date'", "", self.hide_button_add_date, frame_hide_editor_elements)
self.create_checkbox("Button 'Delete'", "", self.hide_button_delete, frame_hide_editor_elements)
self.create_checkbox("Buttons 'Move line up/down'", "", self.hide_buttons_move_line_up_down, frame_hide_editor_elements)
self.create_checkbox("Buttons 'Assign priority'", "", self.hide_buttons_assign_priority, frame_hide_editor_elements)
frame_ask_for = tk.LabelFrame(third_column_frame, text="Ask for confirmation, when: ")
frame_ask_for.pack(fill='x', pady=(10, 0))
self.create_checkbox("Adding new task", "", self.ask_for_add, frame_ask_for)
self.create_checkbox("Removing a task", "", self.ask_for_delete, frame_ask_for)
def exit(self):
string_col_names = [x.get() for x in self.col_names]
are_col_names_unique = len(string_col_names) == len(set(string_col_names))
if not are_col_names_unique:
tk.messagebox.showwarning(title="Error in column names", message=f"You can't set the same name for multiple columns.")
return
self.destroy()
def buttonbox(self):
ok_button = tk.Button(self, text='OK', width=5, command=self.exit)
ok_button.pack(side='right', padx=15, pady=(0, 10))
self.bind("<Escape>", lambda event: self.exit())
self.bind("<Return>", lambda event: self.exit())
class BrowseTagsDialog(simpledialog.Dialog):
def __init__(self, parent, name, tags, out_selected_tag):
self.name = name
self.tags = tags
self.selected_value = out_selected_tag
self.last_entry_value = ""
self.is_choice_confirmed = False
super().__init__(parent, f"Pick a {name} tag to insert")
def set_focus_on_entry_widget(self):
self.entry_widget.focus_set()
self.set_on_zero()
def body(self, frame):
frame_tags = tk.LabelFrame(frame, text=f"Available {self.name} tags: ", width=200)
frame_tags.grid(row=0, column=0, padx=10, pady=10, sticky=tk.EW)
self.entry_widget = tk.Entry(frame_tags, width=100)
self.entry_widget.grid(row=0, column=0, padx=10, pady=10)
self.entry_widget.bind('<KeyRelease>', self.on_key_pressed)
self.entry_widget.bind('<Up>', self.on_key_up)
self.entry_widget.bind('<Down>', self.on_key_down)
self.values = []
for tag in self.tags:
self.values.append(tag)
self.listbox_widget = tk.Listbox(frame_tags)
self.listbox_widget.grid(row=1, column=0, padx=10, pady=10, sticky=tk.NSEW)
self.listbox_widget.bind('<<ListboxSelect>>', self.on_selected)
self.parent.after(100, self.set_focus_on_entry_widget)
self.scrollbar = tk.Scrollbar(frame_tags)
self.scrollbar.grid(row=1, column=1, sticky=tk.NS)
self.listbox_widget.config(yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.listbox_widget.yview)
self.update_data(self.values)
def on_key_up(self, event):
curselection = self.listbox_widget.curselection()
selected_index = 0
if len(curselection) > 0:
selected_index = int(self.listbox_widget.curselection()[0])
index = selected_index - 1
size = self.listbox_widget.size()
if size > 0:
if index < 0:
index = size - 1
self.listbox_widget.select_clear(0, "end")
self.listbox_widget.select_set(index)
self.listbox_widget.event_generate("<<ListboxSelect>>")
self.listbox_widget.see(index)
self.listbox_widget.activate(index)
self.scrollbar.update_idletasks()
def on_key_down(self, event):
curselection = self.listbox_widget.curselection()
selected_index = 0
if len(curselection) > 0:
selected_index = int(self.listbox_widget.curselection()[0])
index = selected_index + 1
size = self.listbox_widget.size()
if size > 0:
if index >= size:
index = 0
self.listbox_widget.select_clear(0, "end")
self.listbox_widget.select_set(index)
self.listbox_widget.event_generate("<<ListboxSelect>>")
self.listbox_widget.see(index)
self.listbox_widget.activate(index)
self.scrollbar.update_idletasks()
def set_on_zero(self):
index = 0
size = self.listbox_widget.size()
if size > 0:
self.listbox_widget.select_clear(0, "end")
self.listbox_widget.select_set(index)
self.listbox_widget.event_generate("<<ListboxSelect>>")
self.listbox_widget.see(index)
self.listbox_widget.activate(index)
self.scrollbar.update_idletasks()
def on_selected(self, event):
w = event.widget
index = int(w.curselection()[0])
value = w.get(index)
self.selected_value.set(value)
def on_key_pressed(self, event):
value = event.widget.get()
if value == self.last_entry_value:
return
self.last_entry_value = value
if value == '':
data = self.values
else:
data = []
for item in self.values:
if value.lower() in item.lower():
data.append(item)
self.update_data(data)
self.set_on_zero()
self.scrollbar.update_idletasks()
def update_data(self, data):
self.selected_value.set("")
self.listbox_widget.delete(0, 'end')
for item in data:
self.listbox_widget.insert('end', item)
self.on_key_down(None)
def destroy(self):
if not self.is_choice_confirmed:
self.selected_value.set("")
super().destroy()
def exit(self):
self.is_choice_confirmed = True
self.destroy()
def exit_cancel(self):
self.destroy()
def buttonbox(self):
ok_button = tk.Button(self, text=' Insert ', width=5, command=self.exit)
ok_button.pack(side='right', padx=(0, 15), pady=(0, 10))
cancel_button = tk.Button(self, text=' Cancel ', width=5, command=self.exit_cancel)
cancel_button.pack(side='right', padx=(0, 15), pady=(0, 10))
self.bind("<Escape>", lambda event: self.exit_cancel())
self.bind("<Return>", lambda event: self.exit())
class KanbanTxtViewer:
THEMES = {
'LIGHT_COLORS': {
"column0": '#f27272',
"column1": '#00b6e4',
"column2": '#22b57f',
"column3": "#8BC34A",
"column0-column": '#daecf1',
"column1-column": '#daecf1',
"column2-column": '#daecf1',
"column3-column": "#daecf1",
"important": "#a7083b",
"project": '#00b6e4',
'context': '#1c9c6d',
'main-background': "#C0D6E8",
'card-background': '#ffffff',
'done-card-background': '#edf5f7',
'editor-background': '#cae1e8',
'main-text': '#4c6066',
'editor-text': '#000000',
'button': '#415358',
'kv-data': '#b8becc',
'priority_color_scale': [
"#ec1c24",
"#ff7f27",
"#ffca18",
"#77dd77",
"#aec6cf"
]
},
'DARK_COLORS': {
"column0": '#f27272',
"column1": '#00b6e4',
"column2": '#22b57f',
"column3": "#8BC34A",
"column0-column": '#15151f',
"column1-column": '#15151f',
"column2-column": '#15151f',
"column3-column": "#15151f",
"important": "#e12360",
"project": '#00b6e4',
'context': '#1c9c6d',
'main-background': "#1f1f2b",
'card-background': '#2c2c3a',
'done-card-background': '#1f1f2b',
'editor-background': '#15151f',
'main-text': '#b6cbd1',
'editor-text': '#cee4eb',
'button': '#b6cbd1',
'kv-data': '#43454a',
'priority_color_scale': [
"#ff6961",
"#ffb347",
"#fdfd96",
"#77dd77",
"#aec6cf"
]
},
}
FONTS = []
KANBAN_KEY = "knbn"
KANBAN_VAL_IN_PROGRESS = "in_progress"
KANBAN_VAL_VALIDATION = "validation"
CONFIG_PATH = 'config.json'
CONFIG_KEY_FONT_SIZE = 'card_font_size'
CONFIG_KEY_HIDE_PROJECT = 'card_hide_project'
CONFIG_KEY_HIDE_CONTEXT = 'card_hide_context'
CONFIG_KEY_HIDE_SPECIAL_KV_DATA = 'card_hide_special_kv_data'
CONFIG_KEY_HIDE_INDEX = 'card_hide_index'
CONFIG_KEY_HIDE_PRIORITY = 'card_hide_priority'
CONFIG_KEY_HIDE_DATE = 'card_hide_date'
CONFIG_KEY_HIDE_SUBJECT = 'card_hide_subject'
CONFIG_KEY_SORT_METHOD = 'sort_method'
CONFIG_KEY_ASK_FOR_ADD = 'ask_for_new_task'
CONFIG_KEY_ASK_FOR_DELETE = 'ask_for_delete'
CONFIG_KEY_HIDE_MEMO = 'hide_memo'
CONFIG_KEY_HIDE_BUTTONS_MOVE_TO_COLUMN = 'hide_buttons_move_to_column'
CONFIG_KEY_HIDE_BUTTONS_ASSIGN_PRIORITY = 'hide_buttons_assign_priority'
CONFIG_KEY_HIDE_BUTTONS_MOVE_LINE_UP_DOWN = 'hide_buttons_move_line_up_down'
CONFIG_KEY_HIDE_BUTTON_ADD_DATE = 'hide_button_add_date'
CONFIG_KEY_HIDE_BUTTON_DELETE = 'hide_button_delete'
CONFIG_KEY_DARKMODE = 'darkmode'
CONFIG_KEY_COL_0_NAME = 'column_0'
CONFIG_KEY_COL_1_NAME = 'column_1'
CONFIG_KEY_COL_2_NAME = 'column_2'
CONFIG_KEY_COL_3_NAME = 'column_3'
CONFIG_DEFAULTS = {
CONFIG_KEY_ASK_FOR_ADD: True,
CONFIG_KEY_ASK_FOR_DELETE: True,
CONFIG_KEY_FONT_SIZE: 10,
CONFIG_KEY_HIDE_PROJECT: False,
CONFIG_KEY_HIDE_CONTEXT: False,
CONFIG_KEY_HIDE_SPECIAL_KV_DATA: False,
CONFIG_KEY_HIDE_INDEX: False,
CONFIG_KEY_HIDE_PRIORITY: False,
CONFIG_KEY_HIDE_DATE: False,
CONFIG_KEY_HIDE_SUBJECT: False,
CONFIG_KEY_SORT_METHOD: 0,
CONFIG_KEY_DARKMODE: False,
CONFIG_KEY_HIDE_BUTTON_ADD_DATE: False,
CONFIG_KEY_HIDE_BUTTON_DELETE: False,
CONFIG_KEY_HIDE_BUTTONS_ASSIGN_PRIORITY: False,
CONFIG_KEY_HIDE_BUTTONS_MOVE_TO_COLUMN: False,
CONFIG_KEY_HIDE_BUTTONS_MOVE_LINE_UP_DOWN: False,
CONFIG_KEY_HIDE_MEMO: False,
CONFIG_KEY_COL_0_NAME: "To Do",
CONFIG_KEY_COL_1_NAME: "In progress",
CONFIG_KEY_COL_2_NAME: "Validation",
CONFIG_KEY_COL_3_NAME: "Done",
}
def __init__(self, file='', darkmode=None) -> None:
self.config = None
if os.path.exists(self.CONFIG_PATH):
with open(self.CONFIG_PATH, "r") as config_file:
self.config = json.load(config_file)
self.COLUMN_0_NAME = self.get_value_from_config_or_default(self.CONFIG_KEY_COL_0_NAME)
self.COLUMN_1_NAME = self.get_value_from_config_or_default(self.CONFIG_KEY_COL_1_NAME)
self.COLUMN_2_NAME = self.get_value_from_config_or_default(self.CONFIG_KEY_COL_2_NAME)
self.COLUMN_3_NAME = self.get_value_from_config_or_default(self.CONFIG_KEY_COL_3_NAME)
self.COLUMNS_NAMES = [
self.COLUMN_0_NAME,
self.COLUMN_1_NAME,
self.COLUMN_2_NAME,
self.COLUMN_3_NAME
]
self.card_font_size = self.get_value_from_config_or_default(self.CONFIG_KEY_FONT_SIZE)
self.show_project = not self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_PROJECT)
self.show_context = not self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_CONTEXT)
self.show_special_kv_data = not self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_SPECIAL_KV_DATA)
self.show_index = not self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_INDEX)
self.show_priority = not self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_PRIORITY)
self.show_date = not self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_DATE)
self.show_content = not self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_SUBJECT)
self.hide_memo = self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_MEMO)
self.hide_button_delete = self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_BUTTON_DELETE)
self.hide_button_add_date = self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_BUTTON_ADD_DATE)
self.hide_buttons_assign_priority = self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_BUTTONS_ASSIGN_PRIORITY)
self.hide_buttons_move_to_column = self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_BUTTONS_MOVE_TO_COLUMN)
self.hide_buttons_move_line_up_down = self.get_value_from_config_or_default(self.CONFIG_KEY_HIDE_BUTTONS_MOVE_LINE_UP_DOWN)
self.ask_for_add = self.get_value_from_config_or_default(self.CONFIG_KEY_ASK_FOR_ADD)
self.ask_for_delete = self.get_value_from_config_or_default(self.CONFIG_KEY_ASK_FOR_DELETE)
self.sort_method_idx = self.get_value_from_config_or_default(self.CONFIG_KEY_SORT_METHOD)
self.filter_view_message = None
self.editor_warning_tooltip = None
self.widgets_for_disable_in_filter_mode = []
self.non_filtered_content_line_mapping = None
self.non_filtered_content = None
self.filter = None
self.drag_begin_cursor_pos = (0, 0)
self.dragged_widgets = []
self.drop_areas = []
self.drop_areas_frame = None
self.drop_area_highlight = None
if darkmode is None:
darkmode = self.get_value_from_config_or_default(self.CONFIG_KEY_DARKMODE)
self.darkmode = darkmode
self.file = file
self.current_date = date.today()
self.ui_columns = {}
for col in self.COLUMNS_NAMES:
self.ui_columns[col] = []
self._after_id = -1
self.selected_task_card = None
self.draw_ui(1000, 700, 0, 0)
def draw_ui(self, window_width, window_height, window_x, window_y):
# Define theme
dark_option = 'LIGHT_COLORS'
if self.darkmode:
dark_option = 'DARK_COLORS'
default_scheme = list(self.THEMES.keys())[0]
color_scheme = self.THEMES.get(dark_option, default_scheme)
self.COLORS = color_scheme
# Create main window
self.main_window = tk.Tk()
self.main_window.bind('<Button-1>', self.clear_drop_areas_frame)
self.main_window.bind('<Motion>', self.highlight_drop_area)
self.main_window.bind('<Control-f>', self.activate_search_input)
self.main_window.bind('<Escape>', self.deactivate_search_input)
self.main_window.bind('<Control-MouseWheel>', self.on_control_scroll)
self.main_window.bind('<Alt-v>', self.on_customize_view_button)
self.main_window.bind('<Control-plus>', self.on_browse_project_tags)
self.main_window.bind('<Control-at>', self.on_browse_context_tags)
self.main_window.title('KanbanTxt')
icon_path = pathlib.Path('icons8-kanban-64.png')
if icon_path.exists():
self.main_window.iconphoto(False, tk.PhotoImage(file=icon_path))
self.main_window['background'] = self.COLORS['main-background']
self.main_window['relief'] = 'flat'
self.main_window.geometry("%dx%d+%d+%d" % (window_width, window_height, window_x, window_y))
self.FONTS.append(tkFont.Font(name='main', family='arial', size=10, weight=tkFont.NORMAL))
self.FONTS.append(tkFont.Font(name='h2', family='arial', size=14, weight=tkFont.NORMAL))
self.FONTS.append(tkFont.Font(name='done-task', family='arial', size='10', overstrike=1))
# Bind shortkey to open or save a new file
self.main_window.bind('<Control-s>', self.reload_and_create_file)
self.main_window.bind('<Control-o>', self.open_file_dialog)
self.draw_editor_panel()
self.draw_content_frame()
# Load the file provided in arguments if there is one
if os.path.isfile(self.file):
self.load_txt_file()
def activate_search_input(self, event):
if self.filter is not None:
self.clear_filter()
self.filter_entry_box.focus()
def deactivate_search_input(self, event):
if self.filter is not None:
self.clear_filter()
self.text_editor.focus()
def get_cursor_pos(self):
return self.main_window.winfo_pointerx(), self.main_window.winfo_pointery()
def clear_drop_areas_frame(self, event=None):
if self.drop_areas_frame is not None:
self.drop_areas_frame.destroy()
self.drop_areas_frame = None
def on_click(self, event):
self.drag_begin_cursor_pos = self.get_cursor_pos()
self.highlight_task(event)
def on_drag_init(self, event):
dragged_widget_name = event.widget.winfo_name()
if dragged_widget_name in self.dragged_widgets:
return
self.clear_drop_areas_frame()
self.dragged_widgets.append(dragged_widget_name)
self.main_window.after(50, self.on_drag, event) # a little delay to give the UI time to refresh highlighted task card
def highlight_drop_area(self, event):
if self.drop_areas_frame is None:
return
if len(self.drop_areas) == 0:
return
drop_canvas = self.drop_areas_frame.winfo_children()[0]
if self.drop_area_highlight is not None:
drop_canvas.delete(self.drop_area_highlight)
self.drop_area_highlight = None
drop_area = self.get_drop_area_from_cursor()
if drop_area is not None:
self.drop_area_highlight = drop_canvas.create_rectangle(drop_area['x1'], drop_area['y1'], drop_area['x2'], drop_area['y2'], fill="", outline='red', width=3)
def on_drag(self, event):
event.widget.config(cursor="fleur")
# properties of a single drop area
drop_area_width = 100
drop_area_height = 100
drop_area_spacing = 25
# properties of the parent window for drop areas
# should appear above currently dragged task card, and it should not protrude beyond
# the border of the main window
drop_areas_frame_border = 4
drop_areas_title_text_pos_y = 10
drop_areas_pos_x = drop_area_spacing
drop_areas_pos_y = 2 * drop_areas_title_text_pos_y
self.drop_areas.clear()
# determine whether user dragged vertically (to change priority) or horizontally (to change column)
cursor_x_pos, cursor_y_pos = self.get_cursor_pos()
distance_x = abs(cursor_x_pos - self.drag_begin_cursor_pos[0])
distance_y = abs(cursor_y_pos - self.drag_begin_cursor_pos[1])
if distance_x >= distance_y:
drop_areas_title = "Move this task to:"
move_functors = {
self.COLUMN_0_NAME: self.move_to_todo,
self.COLUMN_1_NAME: self.move_to_in_progress,
self.COLUMN_2_NAME: self.move_to_validation,
self.COLUMN_3_NAME: self.move_to_done,
}
for idx, column_name in enumerate(self.COLUMNS_NAMES):
self.drop_areas.append({
'name': column_name,
'color': self.COLORS[f"column{idx}"],
'functor': move_functors[column_name],
'x1': drop_areas_pos_x,
'y1': drop_areas_pos_y,
'x2': drop_areas_pos_x + drop_area_width,
'y2': drop_areas_pos_y + drop_area_height
})
drop_areas_pos_x += drop_area_spacing + drop_area_width
else:
drop_areas_title = "Change priority to:"
priority_functors = {
"A": self.change_priority_to_A,
"B": self.change_priority_to_B,
"C": self.change_priority_to_C,
"D": self.change_priority_to_D,
"E": self.change_priority_to_E,
"(none)": lambda: self.change_priority(None, "")
}
i = 0
for priority in priority_functors.keys():
color = 'white'
if i < len(self.COLORS['priority_color_scale']):
color = self.COLORS['priority_color_scale'][i]
i += 1
self.drop_areas.append({
'name': priority,
'color': color,
'functor': priority_functors[priority],
'x1': drop_areas_pos_x,
'y1': drop_areas_pos_y,
'x2': drop_areas_pos_x + drop_area_width,
'y2': drop_areas_pos_y + drop_area_height
})
drop_areas_pos_x += drop_area_spacing + drop_area_width
task_card_frame_widget = self.get_task_card_frame_widget(event.widget)
drop_areas_frame_width = (drop_area_width + drop_area_spacing) * (len(self.drop_areas) + 1)
drop_areas_frame_pos_x = cursor_x_pos - int(drop_areas_frame_width / 2)
drop_areas_frame_pos_y = task_card_frame_widget.winfo_rooty() - drop_area_height - drop_area_spacing
main_window_geometry = [int(a) for a in re.split('[+x]', self.main_window.geometry())]
main_window_end_pos_x = main_window_geometry[0] + main_window_geometry[2]
drop_areas_frame_pos_x_offset = drop_areas_frame_pos_x + drop_areas_frame_width - main_window_end_pos_x
if drop_areas_frame_pos_x_offset >= 0:
drop_areas_frame_pos_x -= drop_areas_frame_pos_x_offset + drop_area_spacing
# use a Toplevel window, overridedirect and "-topmost" attribute to trick tkinter into
# displaying this window on top in a desired position
self.drop_areas_frame = tk.Toplevel(self.main_window, padx=0, pady=0, background=self.COLORS['button'], borderwidth=drop_areas_frame_border)
self.drop_areas_frame.geometry(f"{drop_areas_frame_width}x{drop_area_height + drop_area_spacing + drop_areas_title_text_pos_y}+{drop_areas_frame_pos_x}+{drop_areas_frame_pos_y}")
self.drop_areas_frame.overrideredirect(True)
self.drop_areas_frame.wm_attributes("-topmost", True)
# canvas to paint drop areas onto
canvas_width = (drop_area_width + drop_area_spacing) * (len(self.drop_areas)) + drop_area_spacing
canvas = tk.Canvas(self.drop_areas_frame,
borderwidth=0,
bg="white",
width=canvas_width)
canvas.pack()
for drop_area in self.drop_areas:
canvas.create_rectangle(drop_area['x1'], drop_area['y1'], drop_area['x2'], drop_area['y2'], fill=drop_area['color'])
canvas.create_text(drop_area['x1'] + drop_area_width / 2, drop_area['y1'] + drop_area_height / 2, text=drop_area['name'], fill='black')
canvas.create_text(canvas_width / 2, drop_areas_title_text_pos_y, text=drop_areas_title, fill='black')
def is_cursor_in_box(self, box_x1, box_y1, box_x2, box_y2):
cursor_pos_x, cursor_pos_y = self.get_cursor_pos()
return box_x1 < cursor_pos_x < box_x2 and box_y1 < cursor_pos_y < box_y2
def get_drop_area_from_cursor(self):
if self.drop_areas_frame is not None and len(self.drop_areas) > 0:
drop_canvas = self.drop_areas_frame.winfo_children()[0]
for i in range(len(self.drop_areas)):
canvas_offset_x = drop_canvas.winfo_rootx()
canvas_offset_y = drop_canvas.winfo_rooty()
drop_top_left_x = self.drop_areas[i]['x1'] + canvas_offset_x
drop_top_left_y = self.drop_areas[i]['y1'] + canvas_offset_y
drop_bottom_right_x = self.drop_areas[i]['x2'] + canvas_offset_x
drop_bottom_right_y = self.drop_areas[i]['y2'] + canvas_offset_y
if self.is_cursor_in_box(drop_top_left_x, drop_top_left_y, drop_bottom_right_x, drop_bottom_right_y):
return self.drop_areas[i]
return None
def on_drop(self, event):
dragged_widget_name = event.widget.winfo_name()
if dragged_widget_name not in self.dragged_widgets:
return
self.dragged_widgets.remove(dragged_widget_name)
event.widget.config(cursor="hand2")
if self.drop_areas_frame is None:
return
drop_area = self.get_drop_area_from_cursor()
if drop_area is not None:
drop_area['functor']()
self.drop_areas.clear()
self.clear_drop_areas_frame()
def on_browse_tags(self, tagname):
tags = {}
for task_data in self.cards_data:
temp_list = task_data[tagname]
for elem in temp_list:
tag = elem[tagname]
if tag not in tags:
tags[tag] = 1
else:
tags[tag] += 1
selected_tag = tk.StringVar(value="")
BrowseTagsDialog(self.main_window, tagname, tags, selected_tag)
if len(selected_tag.get()) > 0:
index = self.text_editor.index(tk.INSERT)
self.text_editor.insert(index, f" {selected_tag.get()} ")
def on_browse_project_tags(self, event=None):
self.on_browse_tags("project")
def on_browse_context_tags(self, event=None):
self.on_browse_tags("context")
def on_customize_view_button(self, event=None):
show_project_var = tk.IntVar(value=self.show_project)
show_context_var = tk.IntVar(value=self.show_context)
show_special_kv_data_var = tk.IntVar(value=self.show_special_kv_data)
show_index = tk.IntVar(value=self.show_index)
show_priority_var = tk.IntVar(value=self.show_priority)
show_date_var = tk.IntVar(value=self.show_date)
show_content_var = tk.IntVar(value=self.show_content)
ask_for_add_var = tk.IntVar(value=self.ask_for_add)
ask_for_delete_var = tk.IntVar(value=self.ask_for_delete)
out_sort_method = tk.StringVar(value=self.sort_method_idx)
out_fontsize = tk.StringVar(value=self.card_font_size)
out_col0_name = tk.StringVar(value=self.COLUMN_0_NAME)
out_col1_name = tk.StringVar(value=self.COLUMN_1_NAME)
out_col2_name = tk.StringVar(value=self.COLUMN_2_NAME)
out_col3_name = tk.StringVar(value=self.COLUMN_3_NAME)
hide_memo = tk.IntVar(value=not self.hide_memo)
hide_button_delete = tk.IntVar(value=not self.hide_button_delete)
hide_button_add_date = tk.IntVar(value=not self.hide_button_add_date)
hide_buttons_assign_priority = tk.IntVar(value=not self.hide_buttons_assign_priority)
hide_buttons_move_to_column = tk.IntVar(value=not self.hide_buttons_move_to_column)
hide_buttons_move_line_up_down = tk.IntVar(value=not self.hide_buttons_move_line_up_down)
CustomizeViewDialog(title="Customize view",
parent=self.main_window,
out_show_date=show_date_var,
out_show_priority=show_priority_var,
out_show_content=show_content_var,
out_show_context=show_context_var,
out_show_project=show_project_var,
out_show_special_kv_data=show_special_kv_data_var,
out_show_index=show_index,
out_sort_method=out_sort_method,
out_fontsize=out_fontsize,
out_col0_name=out_col0_name,
out_col1_name=out_col1_name,
out_col2_name=out_col2_name,
out_col3_name=out_col3_name,
out_ask_for_add=ask_for_add_var,
out_ask_for_delete=ask_for_delete_var,
out_hide_memo=hide_memo,
out_hide_button_delete=hide_button_delete,
out_hide_button_add_date=hide_button_add_date,
out_hide_buttons_assign_priority=hide_buttons_assign_priority,
out_hide_buttons_move_to_column=hide_buttons_move_to_column,
out_hide_buttons_move_line_up_down=hide_buttons_move_line_up_down,
)
self.show_date = show_date_var.get()
self.show_priority = show_priority_var.get()
self.show_content = show_content_var.get()
self.show_context = show_context_var.get()
self.show_project = show_project_var.get()
self.show_special_kv_data = show_special_kv_data_var.get()
self.show_index = show_index.get()
self.ask_for_delete = ask_for_delete_var.get()
self.ask_for_add = ask_for_add_var.get()
self.sort_method_idx = int(out_sort_method.get())
self.card_font_size = int(out_fontsize.get())
self.hide_memo = not hide_memo.get()
self.hide_button_add_date = not hide_button_add_date.get()
self.hide_button_delete = not hide_button_delete.get()
self.hide_buttons_move_line_up_down = not hide_buttons_move_line_up_down.get()
self.hide_buttons_move_to_column = not hide_buttons_move_to_column.get()
self.hide_buttons_assign_priority = not hide_buttons_assign_priority.get()
new_column_names = [
out_col0_name.get(),
out_col1_name.get(),
out_col2_name.get(),
out_col3_name.get(),
]
are_new_column_names_unique = len(new_column_names) == len(set(new_column_names))
has_any_column_changed = False
if are_new_column_names_unique:
for i, new_name in enumerate(new_column_names):
old_name = self.COLUMNS_NAMES[i]
if old_name != new_name:
self.ui_columns[new_name] = self.ui_columns[old_name]
del self.ui_columns[old_name]
self.progress_bars[new_name] = self.progress_bars[old_name]
del self.progress_bars[old_name]
has_any_column_changed = True
if has_any_column_changed:
self.COLUMNS_NAMES = new_column_names
self.COLUMN_0_NAME = new_column_names[0]
self.COLUMN_1_NAME = new_column_names[1]
self.COLUMN_2_NAME = new_column_names[2]
self.COLUMN_3_NAME = new_column_names[3]
self.store_in_config(self.CONFIG_KEY_COL_0_NAME, self.COLUMN_0_NAME)
self.store_in_config(self.CONFIG_KEY_COL_1_NAME, self.COLUMN_1_NAME)
self.store_in_config(self.CONFIG_KEY_COL_2_NAME, self.COLUMN_2_NAME)
self.store_in_config(self.CONFIG_KEY_COL_3_NAME, self.COLUMN_3_NAME)
self.store_in_config(self.CONFIG_KEY_HIDE_DATE, not self.show_date)
self.store_in_config(self.CONFIG_KEY_HIDE_PRIORITY, not self.show_priority)
self.store_in_config(self.CONFIG_KEY_HIDE_SUBJECT, not self.show_content)
self.store_in_config(self.CONFIG_KEY_HIDE_CONTEXT, not self.show_context)
self.store_in_config(self.CONFIG_KEY_HIDE_PROJECT, not self.show_project)
self.store_in_config(self.CONFIG_KEY_HIDE_SPECIAL_KV_DATA, not self.show_special_kv_data)
self.store_in_config(self.CONFIG_KEY_HIDE_INDEX, not self.show_index)
self.store_in_config(self.CONFIG_KEY_ASK_FOR_ADD, self.ask_for_add)
self.store_in_config(self.CONFIG_KEY_ASK_FOR_DELETE, self.ask_for_delete)
self.store_in_config(self.CONFIG_KEY_SORT_METHOD, self.sort_method_idx)
self.store_in_config(self.CONFIG_KEY_FONT_SIZE, self.card_font_size)
editor_widget_change_state = [
self.store_in_config(self.CONFIG_KEY_HIDE_MEMO, self.hide_memo),
self.store_in_config(self.CONFIG_KEY_HIDE_BUTTON_ADD_DATE, self.hide_button_add_date),
self.store_in_config(self.CONFIG_KEY_HIDE_BUTTON_DELETE, self.hide_button_delete),
self.store_in_config(self.CONFIG_KEY_HIDE_BUTTONS_ASSIGN_PRIORITY, self.hide_buttons_assign_priority),
self.store_in_config(self.CONFIG_KEY_HIDE_BUTTONS_MOVE_LINE_UP_DOWN, self.hide_buttons_move_line_up_down),
self.store_in_config(self.CONFIG_KEY_HIDE_BUTTONS_MOVE_TO_COLUMN, self.hide_buttons_move_to_column)
]
has_any_editor_widget_changed = any(editor_widget_change_state)
if has_any_column_changed or has_any_editor_widget_changed:
self.recreate_main_window()
self.save_config_file()
self.reload_ui_from_text()
def get_value_from_config_or_default(self, key):
value = None
if self.config is not None:
value = self.config.get(key)
if value is None:
value = self.CONFIG_DEFAULTS[key]
return value
def store_in_config(self, key, value):
value_changed = True
if self.config is None:
self.config = {}
if self.config.get(key, None) == value:
value_changed = False
self.config[key] = value
return value_changed
def save_config_file(self):
if self.config is None:
return
try:
with open(self.CONFIG_PATH, "w") as f:
json.dump(self.config, f, sort_keys=True, indent=4)
except Exception as error:
tk.messagebox.showwarning(title="Error writing config file", message=f"Can't save the file '{self.CONFIG_PATH}', make sure you have the right to write here!")
def draw_editor_panel(self):
self.widgets_for_disable_in_filter_mode.clear()
# EDITION FRAME
edition_frame = tk.Frame(self.main_window, bg=self.COLORS['editor-background'], width=20)
edition_frame.grid(row=0, column=0, sticky=tk.NSEW)