Ignore accents supported. fix #15
This commit is contained in:
parent
649e081e78
commit
b3c36c4493
@ -105,5 +105,10 @@ class Config(object):
|
|||||||
"""
|
"""
|
||||||
return self.data.get('last_folder', '')
|
return self.data.get('last_folder', '')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ignore_accents(self):
|
||||||
|
'''ignore accents of field in querying'''
|
||||||
|
return self.data.get('ignore_accents', False)
|
||||||
|
|
||||||
|
|
||||||
config = Config(mw)
|
config = Config(mw)
|
||||||
|
|||||||
@ -56,6 +56,7 @@ arr = [
|
|||||||
['NEW_VERSION', u'检查到新版本:', u'New version:'],
|
['NEW_VERSION', u'检查到新版本:', u'New version:'],
|
||||||
['UPDATE', u'更新', u'Update'],
|
['UPDATE', u'更新', u'Update'],
|
||||||
['FORCE_UPDATE', u'强制更新字段', u'Force Update Fields'],
|
['FORCE_UPDATE', u'强制更新字段', u'Force Update Fields'],
|
||||||
|
['IGNORE_ACCENTS', u'忽略声调', u'Ignore Accents'],
|
||||||
['SETTINGS', u'参数', u'Settings'],
|
['SETTINGS', u'参数', u'Settings'],
|
||||||
['THREAD_NUMBER', u'线程数', u'Thread Number'],
|
['THREAD_NUMBER', u'线程数', u'Thread Number'],
|
||||||
['INITLIZING_DICT', u'初始化词典...', u'Initlizing Dictionary...'],
|
['INITLIZING_DICT', u'初始化词典...', u'Initlizing Dictionary...'],
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import re
|
|||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import unicodedata
|
||||||
|
|
||||||
from aqt import mw
|
from aqt import mw
|
||||||
from aqt.qt import QFileDialog, QObject, QThread, pyqtSignal, pyqtSlot, QMutex
|
from aqt.qt import QFileDialog, QObject, QThread, pyqtSignal, pyqtSlot, QMutex
|
||||||
@ -337,6 +338,11 @@ def add_to_tmpl(note, **kwargs):
|
|||||||
class InvalidWordException(Exception):
|
class InvalidWordException(Exception):
|
||||||
"""Invalid word exception"""
|
"""Invalid word exception"""
|
||||||
|
|
||||||
|
def strip_combining(txt):
|
||||||
|
"Return txt with all combining characters removed."
|
||||||
|
norm = unicodedata.normalize('NFKD', txt)
|
||||||
|
return u"".join([c for c in norm if not unicodedata.combining(c)])
|
||||||
|
|
||||||
def query_all_flds(note):
|
def query_all_flds(note):
|
||||||
"""
|
"""
|
||||||
Query all fields of single note
|
Query all fields of single note
|
||||||
@ -346,6 +352,9 @@ def query_all_flds(note):
|
|||||||
if not word:
|
if not word:
|
||||||
raise InvalidWordException
|
raise InvalidWordException
|
||||||
|
|
||||||
|
if config.ignore_accents:
|
||||||
|
word = strip_combining(unicode(word))
|
||||||
|
|
||||||
# progress.update_title(u'Querying [[ %s ]]' % word)
|
# progress.update_title(u'Querying [[ %s ]]' % word)
|
||||||
|
|
||||||
services = {}
|
services = {}
|
||||||
|
|||||||
@ -68,6 +68,11 @@ class ParasDialog(QDialog):
|
|||||||
layout.addWidget(check_force_update)
|
layout.addWidget(check_force_update)
|
||||||
layout.addSpacing(10)
|
layout.addSpacing(10)
|
||||||
|
|
||||||
|
check_ignore_accents = QCheckBox(_("IGNORE_ACCENTS"))
|
||||||
|
check_ignore_accents.setChecked(config.ignore_accents)
|
||||||
|
layout.addWidget(check_ignore_accents)
|
||||||
|
layout.addSpacing(10)
|
||||||
|
|
||||||
hbox = QHBoxLayout()
|
hbox = QHBoxLayout()
|
||||||
input_thread_number = QSpinBox(parent=self)
|
input_thread_number = QSpinBox(parent=self)
|
||||||
input_thread_number.setRange(1, 120)
|
input_thread_number.setRange(1, 120)
|
||||||
@ -87,6 +92,7 @@ class ParasDialog(QDialog):
|
|||||||
layout.addWidget(buttonBox)
|
layout.addWidget(buttonBox)
|
||||||
|
|
||||||
self.check_force_update = check_force_update
|
self.check_force_update = check_force_update
|
||||||
|
self.check_ignore_accents = check_ignore_accents
|
||||||
self.input_thread_number = input_thread_number
|
self.input_thread_number = input_thread_number
|
||||||
|
|
||||||
layout.setAlignment(Qt.AlignTop|Qt.AlignLeft)
|
layout.setAlignment(Qt.AlignTop|Qt.AlignLeft)
|
||||||
@ -97,8 +103,11 @@ class ParasDialog(QDialog):
|
|||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
data = {'force_update': self.check_force_update.isChecked(),
|
data = {
|
||||||
'thread_number': self.input_thread_number.value()}
|
'force_update': self.check_force_update.isChecked(),
|
||||||
|
'ignore_accents': self.check_ignore_accents.isChecked(),
|
||||||
|
'thread_number': self.input_thread_number.value()
|
||||||
|
}
|
||||||
config.update(data)
|
config.update(data)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user