Add cloze formatter in Setting dialog fix #76

This commit is contained in:
sthoo 2018-11-05 22:47:30 +08:00
parent b165b2d30d
commit 7d12e7857a
8 changed files with 39 additions and 2 deletions

View File

@ -136,5 +136,10 @@ class Config(object):
'''auto check new version'''
return self.data.get('auto_update', True)
@property
def cloze_str(self):
'''cloze formater string'''
return self.data.get('cloze_str', '{{c1::%s}}')
config = Config(mw)

View File

@ -74,6 +74,16 @@ class SettingDialog(Dialog):
hbox.setStretchFactor(input_thread_number, 2)
layout.addLayout(hbox)
hbox = QHBoxLayout()
input_cloze_str = QLineEdit()
input_cloze_str.setText(config.cloze_str)
input_label = QLabel(_("CLOZE_WORD_FORMAT") + ":", parent=self)
hbox.addWidget(input_label)
hbox.setStretchFactor(input_label, 1)
hbox.addWidget(input_cloze_str)
hbox.setStretchFactor(input_cloze_str, 2)
layout.addLayout(hbox)
buttonBox = QDialogButtonBox(parent=self)
buttonBox.setStandardButtons(QDialogButtonBox.Ok)
buttonBox.accepted.connect(self.accept) # 确定
@ -86,6 +96,7 @@ class SettingDialog(Dialog):
self.check_auto_update = check_auto_update
self.check_ighore_mdx_wordcase = check_ighore_mdx_wordcase
self.input_thread_number = input_thread_number
self.input_cloze_str = input_cloze_str
layout.setAlignment(Qt.AlignTop|Qt.AlignLeft)
self.setLayout(layout)
@ -101,6 +112,7 @@ class SettingDialog(Dialog):
'auto_update': self.check_auto_update.isChecked(),
'ignore_mdx_wordcase': self.check_ighore_mdx_wordcase.isChecked(),
'thread_number': self.input_thread_number.value(),
'cloze_str': self.input_cloze_str.text()
}
config.update(data)

View File

@ -79,6 +79,7 @@ _arr = [
['CURRENT_FIELDS', u'当前字段', u'Current Fields'],
['OPTIONS', u'选项', u'Options'],
['CLOZE_WORD', u'单词填空', u'Cloze word'],
['CLOZE_WORD_FORMAT', '单词填空格式', 'Cloze word formater'],
['BRE_PRON', u'英式发音', u'British Pronunciation'],
['AME_PRON', u'美式发音', u'American Pronunciation'],

View File

@ -288,7 +288,7 @@ def cloze_deletion(text, cloze):
if w[:l].lower() == cloze.lower():
e = s + l
w = word[:l]
result = result[:s+offset] + "{{c1::" + w + "}}" + result[e+offset:]
result = result[:s+offset] + (config.cloze_str % w) + result[e+offset:]
offset += 8
return result

View File

@ -136,4 +136,10 @@ class Config(object):
'''auto check new version'''
return self.data.get('auto_update', True)
@property
def cloze_str(self):
'''cloze formater string'''
return self.data.get('cloze_str', '{{c1::%s}}')
config = Config(mw)

View File

@ -74,6 +74,16 @@ class SettingDialog(Dialog):
hbox.setStretchFactor(input_thread_number, 2)
layout.addLayout(hbox)
hbox = QHBoxLayout()
input_cloze_str = QLineEdit()
input_cloze_str.setText(config.cloze_str)
input_label = QLabel(_("CLOZE_WORD_FORMAT") + ":", parent=self)
hbox.addWidget(input_label)
hbox.setStretchFactor(input_label, 1)
hbox.addWidget(input_cloze_str)
hbox.setStretchFactor(input_cloze_str, 2)
layout.addLayout(hbox)
buttonBox = QDialogButtonBox(parent=self)
buttonBox.setStandardButtons(QDialogButtonBox.Ok)
buttonBox.accepted.connect(self.accept) # 确定
@ -86,6 +96,7 @@ class SettingDialog(Dialog):
self.check_auto_update = check_auto_update
self.check_ighore_mdx_wordcase = check_ighore_mdx_wordcase
self.input_thread_number = input_thread_number
self.input_cloze_str = input_cloze_str
layout.setAlignment(Qt.AlignTop|Qt.AlignLeft)
self.setLayout(layout)
@ -101,6 +112,7 @@ class SettingDialog(Dialog):
'auto_update': self.check_auto_update.isChecked(),
'ignore_mdx_wordcase': self.check_ighore_mdx_wordcase.isChecked(),
'thread_number': self.input_thread_number.value(),
'cloze_str': self.input_cloze_str.text()
}
config.update(data)

View File

@ -79,6 +79,7 @@ _arr = [
['CURRENT_FIELDS', u'当前字段', u'Current Fields'],
['OPTIONS', u'选项', u'Options'],
['CLOZE_WORD', u'单词填空', u'Cloze word'],
['CLOZE_WORD_FORMAT', '单词填空格式', 'Cloze word formater'],
['BRE_PRON', u'英式发音', u'British Pronunciation'],
['AME_PRON', u'美式发音', u'American Pronunciation'],

View File

@ -289,7 +289,7 @@ def cloze_deletion(text, cloze):
if w[:l].lower() == cloze.lower():
e = s + l
w = word[:l]
result = result[:s+offset] + "{{c1::" + w + "}}" + result[e+offset:]
result = result[:s+offset] + (config.cloze_str % w) + result[e+offset:]
offset += 8
return result