-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo_io.py
70 lines (54 loc) · 1.84 KB
/
todo_io.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
import os
import subprocess
import colors
import todo_rw
import todo_ui
from todo_config import TAIL_SGL_STR, TAIL_PL_STR, TXT_EDITOR
def tail(length):
"""Depending on length, return singular or plural trailing word."""
if length == 1:
return TAIL_SGL_STR
else:
return TAIL_PL_STR
def critical_str(urgent_int, color):
'''Return a string for critical tasks only if there are any.'''
if urgent_int > 0:
return ' (<span color="{0}">{1!s}</span>) '.format(color, urgent_int)
else:
return ' '
def print_blocklet(task_dict):
'''Print the string that is shown as output in i3blocks.'''
try:
task_int = len(todo_rw.extract_bare_tasks(task_dict))
except KeyError:
task_int = 0
try:
urgent_int = len(task_dict['A'])
except KeyError:
urgent_int = 0
block_out = ('{0!s}'
'<span font_size ="small">'
'{1}'
'{2}</span>').format(task_int,
critical_str(urgent_int, colors.color04),
tail(task_int))
print(block_out)
def run_gui(task_dict):
return_dict = todo_ui.gui_from_tasks(task_dict)
if return_dict['exit_state'] == 0:
todo_rw.apply_gui_changes(return_dict['done_tasks'],
return_dict['rm_tasks'],
task_dict)
task_dict = todo_rw.create_task_dict()
print_blocklet(task_dict)
def open_in_editor(txt_file):
subprocess.run(TXT_EDITOR.format(txt_file), shell=True)
task_dict = todo_rw.create_task_dict()
print_blocklet(task_dict)
task_dict = todo_rw.create_task_dict()
if os.environ['BLOCK_BUTTON'] == '1':
run_gui(task_dict)
elif os.environ['BLOCK_BUTTON'] == '2':
open_in_editor(todo_rw.TODO_TXT)
else:
print_blocklet(task_dict)