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