forked from Procrat/eva-deprecated
/
actions.py
127 lines (97 loc) · 2.99 KB
/
actions.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
from exceptions import QuitException
from pony import orm
import db
import ui
def Action(mnemonic: str, name: str):
return lambda run: ui.Choice(mnemonic, name, run)
@Action('q', 'Quit')
def quit():
raise QuitException()
@Action('i', 'New long-term idea')
@orm.db_session
def new_idea():
content = ui.ask('Tell me all about it.')
db.Idea(content=content)
@Action('p', 'New project')
@orm.db_session
def new_project():
name = ui.ask('What project are you planning on taking on?')
project = db.Project(name=name)
# Ask for tasks in this project
while True:
task = ui.ask('What does this project consist of?')
if not task:
break
db.Task(content=task, project=project)
@Action('t', 'New task')
@orm.db_session
def new_task():
content = ui.ask('What do you want to have done?')
if ui.ask_polar_question('Does it take less than two minutes?'):
print("Do it now! I'll wait.")
input('> ')
return
task = db.Task(content=content)
project_choices = list(_generate_project_choices())
task.project = ui.let_choose('Is it part of a project?', project_choices,
none_option='No')
if ui.ask_polar_question('Can it be devided in smaller chunks?'):
while True:
subtask_content = ui.ask('Like what?')
if not subtask_content:
break
subtask = db.Task(content=subtask_content, project=task.project)
task.subtasks.add(subtask)
@Action('s', 'Open scratchpad')
@orm.db_session
def open_scratchpad():
scratchpad = db.get_scratchpad()
new_content = ui.ask_from_editor(scratchpad.content)
scratchpad.content = new_content
@Action('l', 'List everything')
@orm.db_session
def list_all():
for project in db.Project.select():
print(project.name.upper())
print('-' * len(project.name))
for task in project.tasks:
print(task)
print()
# List tasks that aren't part of a project
tasks = orm.select(task for task in db.Task if task.project is None)
if tasks:
print('TASKS')
print('-----')
for task in tasks:
print(task)
print()
ideas = db.Idea.select()
if ideas:
print('IDEAS')
print('-----')
for idea in ideas:
print(idea)
scratchpad = db.get_scratchpad()
if scratchpad.content:
print('SCRATCHPAD')
print('----------')
print(scratchpad.content)
def _generate_project_choices():
mnemonics = {}
no_mnemonic_possible_counter = 0
for project in db.Project.select():
for letter in project.name.lower():
if letter not in mnemonics:
break
else:
letter = str(no_mnemonic_possible_counter)
no_mnemonic_possible_counter += 1
yield ui.Choice(letter, project.name, project)
MAIN_ACTIONS = [
new_task,
new_project,
new_idea,
open_scratchpad,
list_all,
quit,
]