fix #45
This commit is contained in:
parent
92040c4531
commit
d03b48f3f9
@ -38,6 +38,7 @@ def start_here():
|
||||
fastwq.have_setup = True
|
||||
fastwq.config_menu()
|
||||
fastwq.browser_menu()
|
||||
fastwq.context_menu()
|
||||
fastwq.customize_addcards()
|
||||
if fastwq.config.auto_update:
|
||||
fastwq.check_updates(True)
|
||||
|
||||
@ -23,15 +23,14 @@ from anki.hooks import addHook, wrap
|
||||
from aqt.addcards import AddCards
|
||||
from aqt.utils import showInfo, shortcut, downArrow
|
||||
from .gui import show_options, show_about_dialog, check_updates
|
||||
from .query import query_from_browser, query_from_editor_all_fields
|
||||
from .query import query_from_browser, query_from_editor_fields
|
||||
from .context import config, APP_ICON
|
||||
from .lang import _
|
||||
|
||||
|
||||
__all__ = [
|
||||
'add_query_button', 'browser_menu',
|
||||
'customize_addcards', 'config_menu',
|
||||
'check_updates'
|
||||
'browser_menu', 'customize_addcards',
|
||||
'config_menu', 'check_updates', 'context_menu'
|
||||
]
|
||||
|
||||
|
||||
@ -51,12 +50,12 @@ def browser_menu():
|
||||
menu = QMenu("FastWQ", browser.form.menubar)
|
||||
browser.form.menubar.addMenu(menu)
|
||||
# Query Selected
|
||||
action = QAction("Query Selected", browser)
|
||||
action = QAction(_('QUERY_SELECTED'), browser)
|
||||
action.triggered.connect(lambda: query_from_browser(browser))
|
||||
action.setShortcut(QKeySequence(my_shortcut))
|
||||
menu.addAction(action)
|
||||
# Options
|
||||
action = QAction("Options", browser)
|
||||
action = QAction(_('OPTIONS'), browser)
|
||||
def _show_options():
|
||||
model_id = -1
|
||||
for note_id in browser.selectedNotes():
|
||||
@ -67,7 +66,7 @@ def browser_menu():
|
||||
action.triggered.connect(_show_options)
|
||||
menu.addAction(action)
|
||||
# About
|
||||
action = QAction("About", browser)
|
||||
action = QAction(_('ABOUT'), browser)
|
||||
action.triggered.connect(lambda: show_about_dialog(browser))
|
||||
menu.addAction(action)
|
||||
|
||||
@ -85,7 +84,7 @@ def customize_addcards():
|
||||
bb = self.form.buttonBox
|
||||
ar = QDialogButtonBox.ActionRole
|
||||
# button
|
||||
fastwqBtn = QPushButton(_("Query") + u" " + downArrow())
|
||||
fastwqBtn = QPushButton(_("QUERY") + u" " + downArrow())
|
||||
fastwqBtn.setShortcut(QKeySequence(my_shortcut))
|
||||
fastwqBtn.setToolTip(
|
||||
_(u"Shortcut: %s") % shortcut(my_shortcut)
|
||||
@ -96,11 +95,11 @@ def customize_addcards():
|
||||
if isinstance(e, QMouseEvent):
|
||||
if e.buttons() & Qt.LeftButton:
|
||||
menu = QMenu(self)
|
||||
menu.addAction(_("Query"), lambda: query_from_editor_all_fields(self.editor, False), QKeySequence(my_shortcut))
|
||||
menu.addAction(_("Options"), lambda: show_options(self, self.editor.note.model()['id']))
|
||||
menu.addAction(_("QUERY"), lambda: query_from_editor_fields(self.editor), QKeySequence(my_shortcut))
|
||||
menu.addAction(_("OPTIONS"), lambda: show_options(self, self.editor.note.model()['id']))
|
||||
menu.exec_(fastwqBtn.mapToGlobal(QPoint(0, fastwqBtn.height())))
|
||||
else:
|
||||
query_from_editor_all_fields(self.editor, False)
|
||||
query_from_editor_fields(self.editor)
|
||||
|
||||
fastwqBtn.mousePressEvent = onQuery
|
||||
fastwqBtn.clicked.connect(onQuery)
|
||||
@ -119,3 +118,22 @@ def config_menu():
|
||||
action = QAction(APP_ICON, "FastWQ...", mw)
|
||||
action.triggered.connect(lambda: show_options())
|
||||
mw.form.menuTools.addAction(action)
|
||||
|
||||
|
||||
def context_menu():
|
||||
'''mouse right click menu'''
|
||||
def on_setup_menus(web_view, menu):
|
||||
"""
|
||||
add context menu to webview
|
||||
"""
|
||||
submenu = menu.addMenu('FastWQ')
|
||||
submenu.addAction(_('ALL_FIELDS'), lambda: query_from_editor_fields(web_view.editor), QKeySequence(my_shortcut))
|
||||
submenu.addAction(_('CURRENT_FIELDS'),
|
||||
lambda: query_from_editor_fields(
|
||||
web_view.editor,
|
||||
fields=[web_view.editor.currentField]
|
||||
)
|
||||
)
|
||||
submenu.addAction(_("OPTIONS"), lambda: show_options(web_view, web_view.editor.note.model()['id']))
|
||||
|
||||
addHook('EditorWebView.contextMenuEvent', on_setup_menus)
|
||||
|
||||
@ -72,6 +72,11 @@ _arr = [
|
||||
['SELECT_ALL', u'全选', u'All'],
|
||||
['DICTS_NAME', u'字典名称', u'Dictionary Name'],
|
||||
['EDIT', u'编辑', u'Edit'],
|
||||
['QUERY', u'查询', u'Query'],
|
||||
['QUERY_SELECTED', u'查询选中项', u'Query Selected'],
|
||||
['ALL_FIELDS', u'所有字段', u'All Fields'],
|
||||
['CURRENT_FIELDS', u'当前字段', u'Current Fields'],
|
||||
['OPTIONS', u'选项', u'Options'],
|
||||
|
||||
['BRE_PRON', u'英式发音', u'British Pronunciation'],
|
||||
['AME_PRON', u'美式发音', u'American Pronunciation'],
|
||||
|
||||
@ -37,7 +37,7 @@ from ..service.base import LocalService
|
||||
from ..utils import Empty, MapDict, Queue, wrap_css
|
||||
|
||||
|
||||
__all__ = ['query_from_browser', 'query_from_editor_all_fields']
|
||||
__all__ = ['query_from_browser', 'query_from_editor_fields']
|
||||
|
||||
|
||||
def query_from_browser(browser):
|
||||
@ -52,13 +52,13 @@ def query_from_browser(browser):
|
||||
for note_id in browser.selectedNotes()]
|
||||
|
||||
if len(notes) == 1:
|
||||
query_from_editor_all_fields(browser.editor)
|
||||
query_from_editor_fields(browser.editor)
|
||||
else:
|
||||
query_all(notes)
|
||||
# browser.model.reset()
|
||||
|
||||
|
||||
def query_from_editor_all_fields(editor, flush=True):
|
||||
def query_from_editor_fields(editor, fields=None):
|
||||
"""
|
||||
Query word fileds from Editor
|
||||
"""
|
||||
@ -67,6 +67,7 @@ def query_from_editor_all_fields(editor, flush=True):
|
||||
return
|
||||
|
||||
word_ord, word, maps = inspect_note(editor.note)
|
||||
flush = not editor.addMode
|
||||
nomaps = True
|
||||
for each in maps:
|
||||
dict_unique = each.get('dict_unique', '').strip()
|
||||
@ -80,16 +81,17 @@ def query_from_editor_all_fields(editor, flush=True):
|
||||
show_options(
|
||||
editor.parentWindow,
|
||||
editor.note.model()['id'],
|
||||
query_from_editor_all_fields,
|
||||
editor
|
||||
query_from_editor_fields,
|
||||
editor,
|
||||
fields
|
||||
)
|
||||
else:
|
||||
query_all([editor.note], flush)
|
||||
query_all([editor.note], flush, fields)
|
||||
editor.setNote(editor.note, focus=True)
|
||||
editor.saveNow()
|
||||
|
||||
|
||||
def query_all(notes, flush=True):
|
||||
def query_all(notes, flush=True, fields=None):
|
||||
"""
|
||||
Query maps word fileds
|
||||
"""
|
||||
@ -101,6 +103,7 @@ def query_all(notes, flush=True):
|
||||
#work_manager.reset()
|
||||
#progress.start(max=len(notes), min=0, immediate=True)
|
||||
work_manager.flush = flush
|
||||
work_manager.query_fields = fields
|
||||
queue = work_manager.queue
|
||||
|
||||
for note in notes:
|
||||
|
||||
@ -35,7 +35,7 @@ from ..utils import wrap_css
|
||||
__all__ = [
|
||||
'InvalidWordException', 'update_note_fields',
|
||||
'update_note_field', 'promot_choose_css', 'add_to_tmpl',
|
||||
'query_all_flds', 'inspect_note'
|
||||
'query_flds', 'inspect_note'
|
||||
]
|
||||
|
||||
|
||||
@ -178,9 +178,9 @@ def add_to_tmpl(note, **kwargs):
|
||||
note.model()['tmpls'][0]['afmt'] = afmt
|
||||
|
||||
|
||||
def query_all_flds(note):
|
||||
def query_flds(note, fileds=None):
|
||||
"""
|
||||
Query all fields of single note
|
||||
Query fields of single note
|
||||
"""
|
||||
|
||||
word_ord, word, maps = inspect_note(note)
|
||||
@ -212,14 +212,15 @@ def query_all_flds(note):
|
||||
dict_fld_ord = each.get('dict_fld_ord', -1)
|
||||
fld_ord = each.get('fld_ord', -1)
|
||||
if dict_unique and dict_fld_ord != -1 and fld_ord != -1:
|
||||
s = services.get(dict_unique, None)
|
||||
if s is None:
|
||||
s = service_pool.get(dict_unique)
|
||||
if fileds is None or fld_ord in fileds:
|
||||
s = services.get(dict_unique, None)
|
||||
if s is None:
|
||||
s = service_pool.get(dict_unique)
|
||||
if s and s.support:
|
||||
services[dict_unique] = s
|
||||
if s and s.support:
|
||||
services[dict_unique] = s
|
||||
if s and s.support:
|
||||
tasks.append({'k': dict_unique, 'w': word,
|
||||
'f': dict_fld_ord, 'i': fld_ord})
|
||||
tasks.append({'k': dict_unique, 'w': word,
|
||||
'f': dict_fld_ord, 'i': fld_ord})
|
||||
|
||||
success_num = 0
|
||||
result = defaultdict(QueryResult)
|
||||
|
||||
@ -27,7 +27,7 @@ from ..lang import _
|
||||
from ..gui import ProgressWindow
|
||||
from ..utils import Empty, MapDict, Queue
|
||||
|
||||
from .common import InvalidWordException, query_all_flds, update_note_fields
|
||||
from .common import InvalidWordException, query_flds, update_note_fields
|
||||
|
||||
|
||||
__all__ = ['QueryWorkerManager']
|
||||
@ -59,7 +59,7 @@ class QueryThread(QtCore.QThread):
|
||||
continue
|
||||
|
||||
try:
|
||||
results, success_num, missed_css = query_all_flds(note)
|
||||
results, success_num, missed_css = query_flds(note, self.manager.query_fields)
|
||||
if not self.exit and self.manager:
|
||||
if self.manager.update(note, results, success_num, missed_css):
|
||||
self.note_flush.emit(note)
|
||||
@ -92,6 +92,7 @@ class QueryWorkerManager(object):
|
||||
self.skips = 0
|
||||
self.missed_css = list()
|
||||
self.flush = True
|
||||
self.query_fields = None
|
||||
|
||||
def get_worker(self):
|
||||
worker = QueryThread(self)
|
||||
|
||||
@ -34,6 +34,7 @@ def start_here():
|
||||
fastwq.have_setup = True
|
||||
fastwq.config_menu()
|
||||
fastwq.browser_menu()
|
||||
fastwq.context_menu()
|
||||
fastwq.customize_addcards()
|
||||
if fastwq.config.auto_update:
|
||||
fastwq.check_updates(True)
|
||||
|
||||
@ -23,15 +23,14 @@ from anki.hooks import addHook, wrap
|
||||
from aqt.addcards import AddCards
|
||||
from aqt.utils import showInfo, shortcut, downArrow
|
||||
from .gui import show_options, show_about_dialog, check_updates
|
||||
from .query import query_from_browser, query_from_editor_all_fields
|
||||
from .query import query_from_browser, query_from_editor_fields
|
||||
from .context import config, APP_ICON
|
||||
from .lang import _
|
||||
|
||||
|
||||
__all__ = [
|
||||
'add_query_button', 'browser_menu',
|
||||
'customize_addcards', 'config_menu',
|
||||
'check_updates'
|
||||
'browser_menu', 'customize_addcards',
|
||||
'config_menu', 'check_updates', 'context_menu'
|
||||
]
|
||||
|
||||
|
||||
@ -51,12 +50,12 @@ def browser_menu():
|
||||
menu = QMenu("FastWQ", browser.form.menubar)
|
||||
browser.form.menubar.addMenu(menu)
|
||||
# Query Selected
|
||||
action = QAction("Query Selected", browser)
|
||||
action = QAction(_('QUERY_SELECTED'), browser)
|
||||
action.triggered.connect(lambda: query_from_browser(browser))
|
||||
action.setShortcut(QKeySequence(my_shortcut))
|
||||
menu.addAction(action)
|
||||
# Options
|
||||
action = QAction("Options", browser)
|
||||
action = QAction(_('OPTIONS'), browser)
|
||||
def _show_options():
|
||||
model_id = -1
|
||||
for note_id in browser.selectedNotes():
|
||||
@ -67,7 +66,7 @@ def browser_menu():
|
||||
action.triggered.connect(_show_options)
|
||||
menu.addAction(action)
|
||||
# About
|
||||
action = QAction("About", browser)
|
||||
action = QAction(_('ABOUT'), browser)
|
||||
action.triggered.connect(lambda: show_about_dialog(browser))
|
||||
menu.addAction(action)
|
||||
|
||||
@ -85,7 +84,7 @@ def customize_addcards():
|
||||
bb = self.form.buttonBox
|
||||
ar = QDialogButtonBox.ActionRole
|
||||
# button
|
||||
fastwqBtn = QPushButton(_("Query") + u" " + downArrow())
|
||||
fastwqBtn = QPushButton(_("QUERY") + u" " + downArrow())
|
||||
fastwqBtn.setShortcut(QKeySequence(my_shortcut))
|
||||
fastwqBtn.setToolTip(
|
||||
_(u"Shortcut: %s") % shortcut(my_shortcut)
|
||||
@ -96,11 +95,11 @@ def customize_addcards():
|
||||
if isinstance(e, QMouseEvent):
|
||||
if e.buttons() & Qt.LeftButton:
|
||||
menu = QMenu(self)
|
||||
menu.addAction(_("Query"), lambda: query_from_editor_all_fields(self.editor, False), QKeySequence(my_shortcut))
|
||||
menu.addAction(_("Options"), lambda: show_options(self, self.editor.note.model()['id']))
|
||||
menu.addAction(_("QUERY"), lambda: query_from_editor_fields(self.editor), QKeySequence(my_shortcut))
|
||||
menu.addAction(_("OPTIONS"), lambda: show_options(self, self.editor.note.model()['id']))
|
||||
menu.exec_(fastwqBtn.mapToGlobal(QPoint(0, fastwqBtn.height())))
|
||||
else:
|
||||
query_from_editor_all_fields(self.editor, False)
|
||||
query_from_editor_fields(self.editor)
|
||||
|
||||
fastwqBtn.mousePressEvent = onQuery
|
||||
fastwqBtn.clicked.connect(onQuery)
|
||||
@ -119,3 +118,22 @@ def config_menu():
|
||||
action = QAction(APP_ICON, "FastWQ...", mw)
|
||||
action.triggered.connect(lambda: show_options())
|
||||
mw.form.menuTools.addAction(action)
|
||||
|
||||
|
||||
def context_menu():
|
||||
'''mouse right click menu'''
|
||||
def on_setup_menus(web_view, menu):
|
||||
"""
|
||||
add context menu to webview
|
||||
"""
|
||||
submenu = menu.addMenu('FastWQ')
|
||||
submenu.addAction(_('ALL_FIELDS'), lambda: query_from_editor_fields(web_view.editor), QKeySequence(my_shortcut))
|
||||
submenu.addAction(_('CURRENT_FIELDS'),
|
||||
lambda: query_from_editor_fields(
|
||||
web_view.editor,
|
||||
fields=[web_view.editor.currentField]
|
||||
)
|
||||
)
|
||||
submenu.addAction(_("OPTIONS"), lambda: show_options(web_view, web_view.editor.note.model()['id']))
|
||||
|
||||
addHook('EditorWebView.contextMenuEvent', on_setup_menus)
|
||||
|
||||
@ -72,6 +72,11 @@ _arr = [
|
||||
['SELECT_ALL', u'全选', u'All'],
|
||||
['DICTS_NAME', u'字典名称', u'Dictionary Name'],
|
||||
['EDIT', u'编辑', u'Edit'],
|
||||
['QUERY', u'查询', u'Query'],
|
||||
['QUERY_SELECTED', u'查询选中项', u'Query Selected'],
|
||||
['ALL_FIELDS', u'所有字段', u'All Fields'],
|
||||
['CURRENT_FIELDS', u'当前字段', u'Current Fields'],
|
||||
['OPTIONS', u'选项', u'Options'],
|
||||
|
||||
['BRE_PRON', u'英式发音', u'British Pronunciation'],
|
||||
['AME_PRON', u'美式发音', u'American Pronunciation'],
|
||||
|
||||
@ -37,7 +37,7 @@ from ..service.base import LocalService
|
||||
from ..utils import Empty, MapDict, Queue, wrap_css
|
||||
|
||||
|
||||
__all__ = ['query_from_browser', 'query_from_editor_all_fields']
|
||||
__all__ = ['query_from_browser', 'query_from_editor_fields']
|
||||
|
||||
|
||||
def query_from_browser(browser):
|
||||
@ -52,13 +52,13 @@ def query_from_browser(browser):
|
||||
for note_id in browser.selectedNotes()]
|
||||
|
||||
if len(notes) == 1:
|
||||
query_from_editor_all_fields(browser.editor)
|
||||
query_from_editor_fields(browser.editor)
|
||||
else:
|
||||
query_all(notes)
|
||||
# browser.model.reset()
|
||||
|
||||
|
||||
def query_from_editor_all_fields(editor, flush=True):
|
||||
def query_from_editor_fields(editor, fields=None):
|
||||
"""
|
||||
Query word fileds from Editor
|
||||
"""
|
||||
@ -67,6 +67,7 @@ def query_from_editor_all_fields(editor, flush=True):
|
||||
return
|
||||
|
||||
word_ord, word, maps = inspect_note(editor.note)
|
||||
flush = not editor.addMode
|
||||
nomaps = True
|
||||
for each in maps:
|
||||
dict_unique = each.get('dict_unique', '').strip()
|
||||
@ -80,17 +81,18 @@ def query_from_editor_all_fields(editor, flush=True):
|
||||
show_options(
|
||||
editor.parentWindow,
|
||||
editor.note.model()['id'],
|
||||
query_from_editor_all_fields,
|
||||
editor
|
||||
query_from_editor_fields,
|
||||
editor,
|
||||
fields
|
||||
)
|
||||
else:
|
||||
editor.setNote(editor.note)
|
||||
query_all([editor.note], flush)
|
||||
query_all([editor.note], flush, fields)
|
||||
editor.setNote(editor.note, focusTo=0)
|
||||
editor.saveNow(lambda:None)
|
||||
|
||||
|
||||
def query_all(notes, flush=True):
|
||||
def query_all(notes, flush=True, fields=None):
|
||||
"""
|
||||
Query maps word fileds
|
||||
"""
|
||||
@ -102,6 +104,7 @@ def query_all(notes, flush=True):
|
||||
#work_manager.reset()
|
||||
#progress.start(max=len(notes), min=0, immediate=True)
|
||||
work_manager.flush = flush
|
||||
work_manager.query_fields = fields
|
||||
queue = work_manager.queue
|
||||
|
||||
for note in notes:
|
||||
|
||||
@ -34,7 +34,7 @@ from ..utils import wrap_css
|
||||
__all__ = [
|
||||
'InvalidWordException', 'update_note_fields',
|
||||
'update_note_field', 'promot_choose_css', 'add_to_tmpl',
|
||||
'query_all_flds', 'inspect_note'
|
||||
'query_flds', 'inspect_note'
|
||||
]
|
||||
|
||||
|
||||
@ -178,9 +178,9 @@ def add_to_tmpl(note, **kwargs):
|
||||
note.model()['tmpls'][0]['afmt'] = afmt
|
||||
|
||||
|
||||
def query_all_flds(note):
|
||||
def query_flds(note, fileds=None):
|
||||
"""
|
||||
Query all fields of single note
|
||||
Query fields of single note
|
||||
"""
|
||||
|
||||
word_ord, word, maps = inspect_note(note)
|
||||
@ -212,14 +212,15 @@ def query_all_flds(note):
|
||||
dict_fld_ord = each.get('dict_fld_ord', -1)
|
||||
fld_ord = each.get('fld_ord', -1)
|
||||
if dict_unique and dict_fld_ord != -1 and fld_ord != -1:
|
||||
s = services.get(dict_unique, None)
|
||||
if s is None:
|
||||
s = service_pool.get(dict_unique)
|
||||
if fileds is None or fld_ord in fileds:
|
||||
s = services.get(dict_unique, None)
|
||||
if s is None:
|
||||
s = service_pool.get(dict_unique)
|
||||
if s and s.support:
|
||||
services[dict_unique] = s
|
||||
if s and s.support:
|
||||
services[dict_unique] = s
|
||||
if s and s.support:
|
||||
tasks.append({'k': dict_unique, 'w': word,
|
||||
'f': dict_fld_ord, 'i': fld_ord})
|
||||
tasks.append({'k': dict_unique, 'w': word,
|
||||
'f': dict_fld_ord, 'i': fld_ord})
|
||||
|
||||
success_num = 0
|
||||
result = defaultdict(QueryResult)
|
||||
|
||||
@ -28,7 +28,7 @@ from ..lang import _
|
||||
from ..gui import ProgressWindow
|
||||
from ..utils import Empty, MapDict, Queue
|
||||
|
||||
from .common import InvalidWordException, query_all_flds, update_note_fields
|
||||
from .common import InvalidWordException, query_flds, update_note_fields
|
||||
|
||||
|
||||
__all__ = ['QueryWorkerManager']
|
||||
@ -60,7 +60,7 @@ class QueryThread(QThread):
|
||||
continue
|
||||
|
||||
try:
|
||||
results, success_num, missed_css = query_all_flds(note)
|
||||
results, success_num, missed_css = query_flds(note, self.manager.query_fields)
|
||||
if not self.exit and self.manager:
|
||||
if self.manager.update(note, results, success_num, missed_css):
|
||||
self.note_flush.emit(note)
|
||||
@ -93,6 +93,7 @@ class QueryWorkerManager(object):
|
||||
self.skips = 0
|
||||
self.missed_css = list()
|
||||
self.flush = True
|
||||
self.query_fields = None
|
||||
|
||||
def get_worker(self):
|
||||
worker = QueryThread(self)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user