Skip to content

Commit

Permalink
Add cloze formatter in Setting dialog fix #76
Browse files Browse the repository at this point in the history
  • Loading branch information
sthoo authored and sthoo committed Nov 5, 2018
1 parent b165b2d commit 7d12e78
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 2 deletions.
5 changes: 5 additions & 0 deletions addons/fastwq/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,10 @@ def auto_update(self):
'''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)
12 changes: 12 additions & 0 deletions addons/fastwq/gui/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ def build(self):
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) # 确定
Expand All @@ -86,6 +96,7 @@ def build(self):
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)
Expand All @@ -101,6 +112,7 @@ def save(self):
'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)

1 change: 1 addition & 0 deletions addons/fastwq/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
['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'],
Expand Down
2 changes: 1 addition & 1 deletion addons/fastwq/query/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions addons21/fastwq/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,10 @@ def auto_update(self):
'''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)
12 changes: 12 additions & 0 deletions addons21/fastwq/gui/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ def build(self):
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) # 确定
Expand All @@ -86,6 +96,7 @@ def build(self):
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)
Expand All @@ -101,6 +112,7 @@ def save(self):
'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)

1 change: 1 addition & 0 deletions addons21/fastwq/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
['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'],
Expand Down
2 changes: 1 addition & 1 deletion addons21/fastwq/query/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7d12e78

Please sign in to comment.