This repository has been archived by the owner on Oct 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixer.py
81 lines (67 loc) · 2.28 KB
/
fixer.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
from tkinter import *
from wframe import WFrame, StartPosition
from vscrollwidget import VScrollWidget
import pickle
class Typo:
context = None
expected = -1
ch = None
def __init__(self, context, expected, ch):
self.context = context
self.expected = expected
self.ch = ch
def toString(self, suggest):
return '\n'.join([
self.context,
' ' * self.expected + '¯',
'입력: %s; 개선 조언: %s' % (self.ch, suggest)
])
class TypoList(list):
def append(self, context, expected, ch):
super().append(Typo(context, expected, ch))
## 오타 알리미
class Fixer(WFrame):
typos = None
def __init__(self, master=None, **kw):
self.typos = Fixer.load()
super().__init__(master, **kw)
def initializeWidget(self):
self.scrollFrame = VScrollWidget(self)
self.scrollFrame.pack(fill=BOTH, expand=TRUE)
for typo in self.typos:
label = Label(self.scrollFrame.frame)
label['justify'] = LEFT
label['font'] = 'Consolas'
label['padx'] = 0
label['pady'] = 0
label['text'] = typo.toString(Fixer.suggest(typo))
label.pack(padx=(40, 0), pady=(20, 0), anchor=NW)
self.text = '오타 알리미'
self.width = 640
self.height = 480
self.startPosition = StartPosition.centerParent
## 오타에 대한 조언을하는 메서드
#
# 매우 중요!
# @return string
@staticmethod
def suggest(typo):
if ' ' in typo.context[typo.expected - 2:][:4]:
return '차분한 마음으로 타자해보세요.'
elif typo.ch in typo.context[typo.expected - 2:][:4]:
return '타속은 너무 신경쓰지 말고,\n연습하는 느낌으로 타자해보세요.'
return '좀 더 연습하세요.'
@staticmethod
def load():
typos = None
try:
with open('data/typos.pkl', 'rb') as data:
typos = pickle.load(data)
except:
pass
return TypoList() if typos == None else typos
@staticmethod
def save(typoList):
typoBak = Fixer.load()
with open('data/typos.pkl', 'wb') as typos:
pickle.dump(typoBak + typoList, typos)