Skip to content

Commit

Permalink
v2.1.4_71
Browse files Browse the repository at this point in the history
*src/libstudy.py 修复了学习完成之后课程进度仍未完成的bug
*src/init.py,src/libfile.py 修复了Windows端读取课程进度时由于换行符问题引起的bug
*src/libfile.py 修复了Windows端因文件编码方式不同引起的bug
*src/bss.py 优化了加载模块前的处理并增加了提示
-src/libstudy.py 去除了开始学习前对“列表为空”的判断,合并到“已学完”的提示
  • Loading branch information
BailPlus committed Jul 3, 2024
1 parent 1158be4 commit 87ad797
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 79 deletions.
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
白杉树背单词训练软件 更新日志
2024.7.3:v2.1.4_71
*src/libstudy.py 修复了学习完成之后课程进度仍未完成的bug
*src/init.py,src/libfile.py 修复了Windows端读取课程进度时由于换行符问题引起的bug
*src/libfile.py 修复了Windows端因文件编码方式不同引起的bug
*src/bss.py 优化了加载模块前的处理并增加了提示
-src/libstudy.py 去除了开始学习前对“列表为空”的判断,合并到“已学完”的提示
2024.6.30:v2.1.3_70
*src/libaudio.py,src/libnetwork.py 换用了新的tts引擎
*src/libgui.py 修复了下载音频时进度条不走,结束时直接从0走到100%的问题
Expand Down
9 changes: 5 additions & 4 deletions src/bss.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/python3
#coding:utf-8
#Copyright Bail 2021-2024
#bssenglish 白杉树背单词训练软件 v2.1.3_70
#2021.7.11-2024.6.30
#bssenglish 白杉树背单词训练软件 v2.1.4_71
#2021.7.11-2024.7.3

'''
灵感来源:红杉树智能英语(http://www.hssenglish.com)
Expand All @@ -26,11 +26,12 @@

def loadplugins():
'''加载模块'''
sys.path.append('.',) #这是什么鬼东西?
sys.path.append(libfile.getpath('plugins'))
os.chdir(libfile.getpath('plugins'))
for i in os.listdir('.'):
pkgname = i.split('.')[0] #去掉后缀名
pkgname = os.path.splitext(i)[0] #去掉后缀名
__import__(pkgname)
print(f'I: 已加载模块: {pkgname}')
def printe(*args,**kw):
'''从stderr通道输出内容
与内置函数print用法相同'''
Expand Down
2 changes: 1 addition & 1 deletion src/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def makeprogress():
path = os.path.join(libfile.path['progress'],md5)
if not os.path.exists(path):
with open(path,'w') as file:
file.write(os.linesep.join(('0','0','0')))
file.write('0\n0\n0')
def main():
print('开始初始化')
makedir()
Expand Down
10 changes: 5 additions & 5 deletions src/libfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def islessonfile(fn:str)->bool:
'''判断是否为课程文件(通过比对文件头)
fn(str):文件名
返回值:为课程文件性(bool)'''
with open(fn) as file:
with open(fn,encoding='utf-8') as file:
if file.readline() == LESSON_FILE_HEADER:
return True
else:
Expand All @@ -70,14 +70,14 @@ def readfile(fn:str)->libclass.Lesson:
fn(str):文件名
返回值:课程对象(libclass.Lesson)'''
#读取课程信息
with open(fn) as file:
with open(fn,encoding='utf-8') as file:
file.readline()
lesson_info = json.loads(file.readline())
#读取课程内容
words = tuple(libclass.Word(*i) for i in readfromcsv(fn,2))
md5 = get_file_md5(fn)
progress_file_name = os.path.join(path['progress'],md5)
with open(progress_file_name) as progress_file:
with open(progress_file_name,encoding='utf-8') as progress_file:
progress = list(map(int,progress_file.readlines()))
lesson = libclass.Lesson(**lesson_info,words=words,md5=md5,progress=progress) #使用`words=words`是为了避免参数传乱出现bug
return lesson
Expand Down Expand Up @@ -139,5 +139,5 @@ def saveprogress(lessonlst:list):
lessonlst(list[libclass.Lesson]):课程对象列表'''
for i in lessonlst:
progress_file_name = os.path.join(path['progress'],i.md5)
with open(progress_file_name,'w') as progress_file:
progress_file.write(os.linesep.join(map(str,i.progress)))
with open(progress_file_name,'w',encoding='utf-8') as progress_file:
progress_file.write('\n'.join(map(str,i.progress)))
118 changes: 49 additions & 69 deletions src/libstudy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def hui4(): #会,进入看对错
duibtn.grid(row=1,column=0)
buduibtn.grid(row=1,column=1)
def dui4(): #对,标为熟词并进入下一个单词
## nonlocal current_word
nonlocal index
huilst.append(current_word)
index += 1
nextword()
def bu4(): #不会/不对,进入复习
sclst.append(current_word)
Expand All @@ -37,7 +38,7 @@ def recite(ci4:int): #下一次复习
recitebtn.config(text=f'复习(剩余{ci4}次)',command=lambda:recite(ci4-1))
def nextword():
nonlocal index #防止下一行的判断出现bug
if index+1 == len(wlst): #如果是最后一个单词
if index == len(wlst): #如果是最后一个单词
libgui.showinfo('恭喜你学完本课',parent=win)
close()
else:
Expand All @@ -49,7 +50,6 @@ def nextword():

#初始化变量
nonlocal current_word #index上面已经声明
index += 1
current_word = wlst[index]

#播放等
Expand All @@ -71,11 +71,6 @@ def close():
huilst = [] #熟词列表
current_word:libclass.Word = None #当前学习的单词

#排除空列表
if len(wlst) == 0:
libgui.showinfo('列表为空,无可学习') #由于没有弹出窗口,所以不设置parent参数
return

#初始化界面
win = libgui.remember(root)
win.protocol('WM_DELETE_WINDOW',close)
Expand All @@ -87,21 +82,15 @@ def close():
#recitebtn的command在recite函数里指定

#显示第一个单词
win.title(f'记忆 {index+1}/{len(wlst)}')
current_word = wlst[index]
current_word.play()
wordlab.config(text=current_word.word)
pronlab.config(text=current_word.pronounce)
huibtn.grid(row=0,column=0)
buhuibtn.grid(row=0,column=1)
nextword()
def listen(root:libgui.Tk,lesson:libclass.Lesson):
'''听写模块
root(tkinter.Tk):根窗口
wlst(list):包含要学习的单词对象的列表'''
def enter():
nonlocal current_word,status,index,sclst

if status == None: #未判:判
if status == None: #未判:判,并加入生词熟词列表
entry.config(state=libgui.DISABLED)
wordlab.config(text=current_word.word)
myinput = entry.get()
Expand All @@ -113,24 +102,9 @@ def enter():
judgelab['text'] = '(x)'
sclst.append(current_word)
status = False
elif status == True: #已判,正确:加入熟词,下一个
if index+1 == len(wlst): #如果是最后一个单词
libgui.showinfo('恭喜你学完本课',parent=win)
close()
else:
#初始化变量
index += 1
current_word = wlst[index]

#显示下一个单词
win.title(f'听写 {index+1}/{len(wlst)}')
judgelab.config(text='')
entry.config(state=libgui.NORMAL)
entry.delete(0,libgui.END)
current_word.play()
pronlab.config(text=current_word.pronounce)
wordlab.config(text='')
status = None
elif status == True: #已判,正确:下一个
index += 1
nextword()
elif status == False: #已判,错误:进入抄写
judgelab.config(text='')
entry.config(state=libgui.NORMAL)
Expand All @@ -149,6 +123,24 @@ def enter():
status = False
else:
raise ValueError(f'错误的状态: {status}')
def nextword():
if index == len(wlst): #如果是最后一个单词
libgui.showinfo('恭喜你学完本课',parent=win)
close()
else:
#初始化变量
nonlocal current_word,status
current_word = wlst[index]
status = None

#显示下一个单词
win.title(f'听写 {index+1}/{len(wlst)}')
judgelab.config(text='')
entry.config(state=libgui.NORMAL)
entry.delete(0,libgui.END)
current_word.play()
pronlab.config(text=current_word.pronounce)
wordlab.config(text='')
def close():
libsc.mark('listen',sclst,huilst)
lesson.progress[1] = index
Expand All @@ -163,11 +155,6 @@ def close():
huilst = [] #熟词列表
current_word:libclass.Word = None #当前学习的单词

#排除空列表
if len(wlst) == 0:
libgui.showinfo('列表为空,无可学习')
return

#初始化界面
win = libgui.listen(root)
win.protocol('WM_DELETE_WINDOW',close)
Expand All @@ -176,18 +163,15 @@ def close():
entry.bind('<Control_L>',lambda event:current_word.play())

#显示第一个单词
win.title(f'听写 {index+1}/{len(wlst)}')
current_word = wlst[index]
current_word.play()
pronlab.config(text=current_word.pronounce)
nextword()
def write(root:libgui.Tk,lesson:libclass.Lesson):
'''默写模块
root(tkinter.Tk):根窗口
wlst(list):包含要学习的单词对象的列表'''
def enter():
nonlocal current_word,status,index,sclst

if status == None: #未判:判
if status == None: #未判:判,并加入生词熟词列表
entry.config(state=libgui.DISABLED)
wordlab.config(text=current_word.word)
myinput = entry.get()
Expand All @@ -199,23 +183,9 @@ def enter():
judgelab['text'] = '(x)'
sclst.append(current_word)
status = False
elif status == True: #已判,正确:加入熟词,下一个
if index+1 == len(wlst): #如果是最后一个单词
libgui.showinfo('恭喜你学完本课',parent=win)
close()
else:
#初始化变量
index += 1
current_word = wlst[index]

#显示下一个单词
win.title(f'默写 {index+1}/{len(wlst)}')
judgelab.config(text='')
entry.config(state=libgui.NORMAL)
entry.delete(0,libgui.END)
translab.config(text=current_word.trans)
wordlab.config(text='')
status = None
elif status == True: #已判,正确:,下一个
index += 1
nextword()
elif status == False: #已判,错误:进入抄写
judgelab.config(text='')
entry.config(state=libgui.NORMAL)
Expand All @@ -233,6 +203,23 @@ def enter():
status = False
else:
raise ValueError(f'错误的状态: {status}')
def nextword():
if index == len(wlst): #如果是最后一个单词
libgui.showinfo('恭喜你学完本课',parent=win)
close()
else:
#初始化变量
nonlocal current_word,status
current_word = wlst[index]
status = None

#显示下一个单词
win.title(f'默写 {index+1}/{len(wlst)}')
judgelab.config(text='')
entry.config(state=libgui.NORMAL)
entry.delete(0,libgui.END)
translab.config(text=current_word.trans)
wordlab.config(text='')
def close():
libsc.mark('write',sclst,huilst)
lesson.progress[2] = index
Expand All @@ -247,18 +234,11 @@ def close():
huilst = [] #熟词列表
current_word:libclass.Word = None #当前学习的单词

#排除空列表
if len(wlst) == 0:
libgui.showinfo('列表为空,无可学习')
return

#初始化界面
win = libgui.write(root)
win.protocol('WM_DELETE_WINDOW',close)
translab,entry,judgelab,wordlab = win.translab,win.entry,win.judgelab,win.wordlab
entry.bind('<Return>',lambda event:enter())

#显示第一个单词
win.title(f'默写 {index+1}/{len(wlst)}')
current_word = wlst[index]
translab.config(text=current_word.trans)
nextword()

0 comments on commit 87ad797

Please sign in to comment.