-
Notifications
You must be signed in to change notification settings - Fork 0
/
concept.py
90 lines (75 loc) · 2.41 KB
/
concept.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
import ui
import random
from ui import *
from prompt_toolkit.keys import Keys
label_chain = ['c', 'w', 'b', None]
def label():
return label_chain[0]
def toggle_concept_handle(e):
global label_chain
label_chain = label_chain[1:] + label_chain[:1]
ui.mode_name = fmt_card_mode()
def fmt_card_mode():
return {
'c' : '<c>',
'w' : '<w>',
'b' : '<b>',
None : '<->',
}[label()]
def fmt_label(txt):
return {
'c' : '<b>[concept]</b> ',
'w' : '<b>[word]</b> ',
'b' : '<b>[bio]</b> ',
None : '',
}[label()] + txt
class Concept:
def __init__(self):
self.concept = None
self.desc = None
self.details = None
ui.add_key(Keys.ControlH, toggle_concept_handle)
def cleanup(self):
ui.drop_key(toggle_concept_handle)
def input(self):
self.concept = uinput(text='Concept:', required=True, example='Pigouvian tax')
self.desc = uinput(text='Description:', required=True,
example='A tax on negative externalities')
self.details = uinput(text='Pronunciation/mnemonics?', example='pig-oo-vian',
allow_images=True)
# randomize order (since the concept headline and definition
# are interchangable/makes two cards, shuffling makes learning
# easier)
self.concept, self.desc = random.sample([self.concept, self.desc], 2)
# Add the label
self.concept = fmt_label(self.concept)
self.desc = fmt_label(self.desc)
def output(self):
print_accent('\n*** Card ***')
print(self.concept)
print_hr()
print(self.desc)
if self.details:
print_hr()
print(self.details)
summarize_images()
print()
def save(self, x):
m = x.models.byName('Basic/reversed+details')
x.decks.current()['mid'] = m['id']
n = x.newNote()
n['Front'] = self.concept
n['Back'] = self.desc
combined_details = ''
html = ui.images_save_htmlify(x)
if html:
combined_details += html
if self.details:
combined_details += self.details
if combined_details != '':
n['Details'] = combined_details
x.addNote(n)
x.save()
print_loud('Card saved!', nl=2)
def name(self):
return fmt_card_mode()