-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDesktopNote.py
80 lines (72 loc) · 2.55 KB
/
DesktopNote.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
import pathlib as plb
import pickle as pkl
import easygui as eg
path = plb.Path('note.dat')
if not path.exists():
with open(path, 'wb') as fp:
pkl.dump([], fp)
note: list[list[str, list[str]]] = []
else:
with open('note.dat', 'rb') as fp:
note: list[list[str, list[str]]] = pkl.load(fp)
def choices_from_note() -> list[str]:
return [f'{x[0]}: {x[1][0][:10]}' if len(x[1]) != 0 else f'{x[0]}(empty)' for x in note]
def msg_from_note(idx: int) -> str:
return f'===== {note[idx][0]} =====\n\n' + '\n'.join(note[idx][1])
TITLE = 'DesktopNote'
while True:
opt = eg.buttonbox(
msg='Choose one option:',
title=TITLE,
choices=[
'show all',
'show',
'write',
'revise',
'delete',
'exit'])
if opt is None:
break
match opt:
case 'show all':
eg.msgbox(msg='\n\n'.join([msg_from_note(idx) for idx in range(len(note))]), title=TITLE)
case 'show':
choices = choices_from_note()
opt = eg.choicebox(msg='Choose one note:', title=TITLE, choices=choices)
if opt is None:
continue
idx = choices.index(opt)
eg.msgbox(msg=msg_from_note(idx), title=TITLE)
case 'write':
note_title = eg.enterbox(msg='Please input note title:', title=TITLE)
if not opt:
continue
note_msg = eg.textbox(msg='Text your note:', title=TITLE)
if note_msg is None:
continue
note.append([note_title, note_msg.split('\n')])
with open(path, 'wb') as fp:
pkl.dump(note, fp)
case 'revise':
choices = choices_from_note()
opt = eg.choicebox(msg='Choose one note:', title=TITLE, choices=choices)
if opt is None:
continue
idx = choices.index(opt)
note_msg = eg.textbox(msg='Revise your note:', title=TITLE, text='\n'.join(note[idx][1]))
if note_msg is None:
continue
note[idx][1] = note_msg.split('\n')
with open(path, 'wb') as fp:
pkl.dump(note, fp)
case 'delete':
choices = choices_from_note()
opt = eg.choicebox(msg='Choose one note:', title=TITLE, choices=choices)
if opt is None:
continue
idx = choices.index(opt)
del note[idx]
with open(path, 'wb') as fp:
pkl.dump(note, fp)
case _:
break