Add cloze formatter in Setting dialog fix #76
This commit is contained in:
parent
b165b2d30d
commit
7d12e7857a
@ -136,5 +136,10 @@ class Config(object):
|
|||||||
'''auto check new version'''
|
'''auto check new version'''
|
||||||
return self.data.get('auto_update', True)
|
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)
|
config = Config(mw)
|
||||||
|
|||||||
@ -74,6 +74,16 @@ class SettingDialog(Dialog):
|
|||||||
hbox.setStretchFactor(input_thread_number, 2)
|
hbox.setStretchFactor(input_thread_number, 2)
|
||||||
layout.addLayout(hbox)
|
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 = QDialogButtonBox(parent=self)
|
||||||
buttonBox.setStandardButtons(QDialogButtonBox.Ok)
|
buttonBox.setStandardButtons(QDialogButtonBox.Ok)
|
||||||
buttonBox.accepted.connect(self.accept) # 确定
|
buttonBox.accepted.connect(self.accept) # 确定
|
||||||
@ -86,6 +96,7 @@ class SettingDialog(Dialog):
|
|||||||
self.check_auto_update = check_auto_update
|
self.check_auto_update = check_auto_update
|
||||||
self.check_ighore_mdx_wordcase = check_ighore_mdx_wordcase
|
self.check_ighore_mdx_wordcase = check_ighore_mdx_wordcase
|
||||||
self.input_thread_number = input_thread_number
|
self.input_thread_number = input_thread_number
|
||||||
|
self.input_cloze_str = input_cloze_str
|
||||||
|
|
||||||
layout.setAlignment(Qt.AlignTop|Qt.AlignLeft)
|
layout.setAlignment(Qt.AlignTop|Qt.AlignLeft)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
@ -101,6 +112,7 @@ class SettingDialog(Dialog):
|
|||||||
'auto_update': self.check_auto_update.isChecked(),
|
'auto_update': self.check_auto_update.isChecked(),
|
||||||
'ignore_mdx_wordcase': self.check_ighore_mdx_wordcase.isChecked(),
|
'ignore_mdx_wordcase': self.check_ighore_mdx_wordcase.isChecked(),
|
||||||
'thread_number': self.input_thread_number.value(),
|
'thread_number': self.input_thread_number.value(),
|
||||||
|
'cloze_str': self.input_cloze_str.text()
|
||||||
}
|
}
|
||||||
config.update(data)
|
config.update(data)
|
||||||
|
|
||||||
@ -79,6 +79,7 @@ _arr = [
|
|||||||
['CURRENT_FIELDS', u'当前字段', u'Current Fields'],
|
['CURRENT_FIELDS', u'当前字段', u'Current Fields'],
|
||||||
['OPTIONS', u'选项', u'Options'],
|
['OPTIONS', u'选项', u'Options'],
|
||||||
['CLOZE_WORD', u'单词填空', u'Cloze word'],
|
['CLOZE_WORD', u'单词填空', u'Cloze word'],
|
||||||
|
['CLOZE_WORD_FORMAT', '单词填空格式', 'Cloze word formater'],
|
||||||
|
|
||||||
['BRE_PRON', u'英式发音', u'British Pronunciation'],
|
['BRE_PRON', u'英式发音', u'British Pronunciation'],
|
||||||
['AME_PRON', u'美式发音', u'American Pronunciation'],
|
['AME_PRON', u'美式发音', u'American Pronunciation'],
|
||||||
|
|||||||
@ -288,7 +288,7 @@ def cloze_deletion(text, cloze):
|
|||||||
if w[:l].lower() == cloze.lower():
|
if w[:l].lower() == cloze.lower():
|
||||||
e = s + l
|
e = s + l
|
||||||
w = word[: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
|
offset += 8
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
@ -136,4 +136,10 @@ class Config(object):
|
|||||||
'''auto check new version'''
|
'''auto check new version'''
|
||||||
return self.data.get('auto_update', True)
|
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)
|
config = Config(mw)
|
||||||
|
|||||||
@ -74,6 +74,16 @@ class SettingDialog(Dialog):
|
|||||||
hbox.setStretchFactor(input_thread_number, 2)
|
hbox.setStretchFactor(input_thread_number, 2)
|
||||||
layout.addLayout(hbox)
|
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 = QDialogButtonBox(parent=self)
|
||||||
buttonBox.setStandardButtons(QDialogButtonBox.Ok)
|
buttonBox.setStandardButtons(QDialogButtonBox.Ok)
|
||||||
buttonBox.accepted.connect(self.accept) # 确定
|
buttonBox.accepted.connect(self.accept) # 确定
|
||||||
@ -86,6 +96,7 @@ class SettingDialog(Dialog):
|
|||||||
self.check_auto_update = check_auto_update
|
self.check_auto_update = check_auto_update
|
||||||
self.check_ighore_mdx_wordcase = check_ighore_mdx_wordcase
|
self.check_ighore_mdx_wordcase = check_ighore_mdx_wordcase
|
||||||
self.input_thread_number = input_thread_number
|
self.input_thread_number = input_thread_number
|
||||||
|
self.input_cloze_str = input_cloze_str
|
||||||
|
|
||||||
layout.setAlignment(Qt.AlignTop|Qt.AlignLeft)
|
layout.setAlignment(Qt.AlignTop|Qt.AlignLeft)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
@ -101,6 +112,7 @@ class SettingDialog(Dialog):
|
|||||||
'auto_update': self.check_auto_update.isChecked(),
|
'auto_update': self.check_auto_update.isChecked(),
|
||||||
'ignore_mdx_wordcase': self.check_ighore_mdx_wordcase.isChecked(),
|
'ignore_mdx_wordcase': self.check_ighore_mdx_wordcase.isChecked(),
|
||||||
'thread_number': self.input_thread_number.value(),
|
'thread_number': self.input_thread_number.value(),
|
||||||
|
'cloze_str': self.input_cloze_str.text()
|
||||||
}
|
}
|
||||||
config.update(data)
|
config.update(data)
|
||||||
|
|
||||||
@ -79,6 +79,7 @@ _arr = [
|
|||||||
['CURRENT_FIELDS', u'当前字段', u'Current Fields'],
|
['CURRENT_FIELDS', u'当前字段', u'Current Fields'],
|
||||||
['OPTIONS', u'选项', u'Options'],
|
['OPTIONS', u'选项', u'Options'],
|
||||||
['CLOZE_WORD', u'单词填空', u'Cloze word'],
|
['CLOZE_WORD', u'单词填空', u'Cloze word'],
|
||||||
|
['CLOZE_WORD_FORMAT', '单词填空格式', 'Cloze word formater'],
|
||||||
|
|
||||||
['BRE_PRON', u'英式发音', u'British Pronunciation'],
|
['BRE_PRON', u'英式发音', u'British Pronunciation'],
|
||||||
['AME_PRON', u'美式发音', u'American Pronunciation'],
|
['AME_PRON', u'美式发音', u'American Pronunciation'],
|
||||||
|
|||||||
@ -289,7 +289,7 @@ def cloze_deletion(text, cloze):
|
|||||||
if w[:l].lower() == cloze.lower():
|
if w[:l].lower() == cloze.lower():
|
||||||
e = s + l
|
e = s + l
|
||||||
w = word[: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
|
offset += 8
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user