show options window when single query and no field was selected.
This commit is contained in:
parent
fa147a59a8
commit
31872e5646
@ -27,22 +27,26 @@ from aqt.utils import showInfo, shortcut
|
|||||||
from .ui import show_options
|
from .ui import show_options
|
||||||
from .query import *
|
from .query import *
|
||||||
from .context import config, APP_ICON
|
from .context import config, APP_ICON
|
||||||
|
from .lang import _
|
||||||
|
|
||||||
|
|
||||||
have_setup = False
|
have_setup = False
|
||||||
my_shortcut = ''
|
my_shortcut = ''
|
||||||
|
|
||||||
|
|
||||||
def query_decor(func, obj):
|
def wrap_method(func, *args, **kwargs):
|
||||||
|
'''
|
||||||
|
wrap a function with params when it's called
|
||||||
|
'''
|
||||||
def callback():
|
def callback():
|
||||||
return func(obj)
|
return func(*args, **kwargs)
|
||||||
return callback
|
return callback
|
||||||
|
|
||||||
def add_query_button(self):
|
def add_query_button(self):
|
||||||
bb = self.form.buttonBox
|
bb = self.form.buttonBox
|
||||||
ar = QDialogButtonBox.ActionRole
|
ar = QDialogButtonBox.ActionRole
|
||||||
self.queryButton = bb.addButton(_(u"Query"), ar)
|
self.queryButton = bb.addButton(_(u"Query"), ar)
|
||||||
self.queryButton.clicked.connect(query_decor(
|
self.queryButton.clicked.connect(wrap_method(
|
||||||
query_from_editor_all_fields, self.editor))
|
query_from_editor_all_fields, self.editor))
|
||||||
self.queryButton.setShortcut(QKeySequence(my_shortcut))
|
self.queryButton.setShortcut(QKeySequence(my_shortcut))
|
||||||
self.queryButton.setToolTip(
|
self.queryButton.setToolTip(
|
||||||
@ -51,23 +55,23 @@ def add_query_button(self):
|
|||||||
|
|
||||||
def browser_menu():
|
def browser_menu():
|
||||||
"""
|
"""
|
||||||
添加插件菜单至浏览窗口菜单栏
|
add add-on's menu to browser window
|
||||||
"""
|
"""
|
||||||
def on_setup_menus(browser):
|
def on_setup_menus(browser):
|
||||||
"""
|
"""
|
||||||
浏览窗口菜单钩子
|
on browser setupMenus was called
|
||||||
"""
|
"""
|
||||||
# main menu
|
# main 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(query_decor(query_from_browser, (browser)))
|
action.triggered.connect(wrap_method(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)
|
||||||
action.triggered.connect(show_options)
|
action.triggered.connect(wrap_method(show_options, browser))
|
||||||
menu.addAction(action)
|
menu.addAction(action)
|
||||||
|
|
||||||
anki.hooks.addHook('browser.setupMenus', on_setup_menus)
|
anki.hooks.addHook('browser.setupMenus', on_setup_menus)
|
||||||
@ -75,7 +79,7 @@ def browser_menu():
|
|||||||
|
|
||||||
def customize_addcards():
|
def customize_addcards():
|
||||||
"""
|
"""
|
||||||
定制添加卡片界面
|
add button to addcards window
|
||||||
"""
|
"""
|
||||||
AddCards.setupButtons = wrap(
|
AddCards.setupButtons = wrap(
|
||||||
AddCards.setupButtons, add_query_button, "before")
|
AddCards.setupButtons, add_query_button, "before")
|
||||||
@ -83,10 +87,10 @@ def customize_addcards():
|
|||||||
|
|
||||||
def config_menu():
|
def config_menu():
|
||||||
"""
|
"""
|
||||||
添加菜单项至工具下拉菜单中
|
add menu to anki window menebar
|
||||||
"""
|
"""
|
||||||
action = QAction(APP_ICON, "FastWQ...", mw)
|
action = QAction(APP_ICON, "FastWQ...", mw)
|
||||||
action.triggered.connect(show_options)
|
action.triggered.connect(wrap_method(show_options))
|
||||||
mw.form.menuTools.addAction(action)
|
mw.form.menuTools.addAction(action)
|
||||||
global have_setup
|
global have_setup
|
||||||
have_setup = True
|
have_setup = True
|
||||||
@ -94,8 +98,8 @@ def config_menu():
|
|||||||
|
|
||||||
def window_shortcut(key_sequence):
|
def window_shortcut(key_sequence):
|
||||||
"""
|
"""
|
||||||
设置快捷键
|
setup shortcut
|
||||||
"""
|
"""
|
||||||
global my_shortcut
|
global my_shortcut
|
||||||
my_shortcut = key_sequence
|
my_shortcut = key_sequence
|
||||||
|
|
||||||
|
|||||||
@ -186,11 +186,21 @@ 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)
|
maps = config.get_maps(browser.editor.note.model()['id'])
|
||||||
return
|
nomaps = True
|
||||||
|
for each in maps:
|
||||||
query_all(notes)
|
dict_unique = each.get('dict_unique', '').strip()
|
||||||
# browser.model.reset()
|
if dict_unique:
|
||||||
|
nomaps = False
|
||||||
|
break
|
||||||
|
if nomaps:
|
||||||
|
from .ui import show_options
|
||||||
|
show_options(browser)
|
||||||
|
else:
|
||||||
|
query_from_editor_all_fields(browser.editor)
|
||||||
|
else:
|
||||||
|
query_all(notes)
|
||||||
|
# browser.model.reset()
|
||||||
|
|
||||||
|
|
||||||
def query_from_editor_all_fields(editor):
|
def query_from_editor_all_fields(editor):
|
||||||
@ -204,7 +214,7 @@ def query_from_editor_all_fields(editor):
|
|||||||
query_all([editor.note])
|
query_all([editor.note])
|
||||||
editor.setNote(editor.note, focus=True)
|
editor.setNote(editor.note, focus=True)
|
||||||
editor.saveNow()
|
editor.saveNow()
|
||||||
|
|
||||||
|
|
||||||
def query_all(notes):
|
def query_all(notes):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -167,7 +167,7 @@ class FoldersManageDialog(QDialog):
|
|||||||
|
|
||||||
class OptionsDialog(QDialog):
|
class OptionsDialog(QDialog):
|
||||||
|
|
||||||
def __init__(self, parent=0):
|
def __init__(self, parent=0, browser=None):
|
||||||
super(OptionsDialog, self).__init__()
|
super(OptionsDialog, self).__init__()
|
||||||
self.setWindowFlags(Qt.CustomizeWindowHint |
|
self.setWindowFlags(Qt.CustomizeWindowHint |
|
||||||
Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.WindowMinMaxButtonsHint)
|
Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.WindowMinMaxButtonsHint)
|
||||||
@ -175,9 +175,9 @@ class OptionsDialog(QDialog):
|
|||||||
# from PyQt4 import QtCore, QtGui
|
# from PyQt4 import QtCore, QtGui
|
||||||
self.setWindowIcon(APP_ICON)
|
self.setWindowIcon(APP_ICON)
|
||||||
self.setWindowTitle(u"Options")
|
self.setWindowTitle(u"Options")
|
||||||
self.build()
|
self.build(browser)
|
||||||
|
|
||||||
def build(self):
|
def build(self, browser=None):
|
||||||
self.main_layout = QVBoxLayout()
|
self.main_layout = QVBoxLayout()
|
||||||
models_layout = QHBoxLayout()
|
models_layout = QHBoxLayout()
|
||||||
# add buttons
|
# add buttons
|
||||||
@ -226,9 +226,14 @@ class OptionsDialog(QDialog):
|
|||||||
self.setLayout(self.main_layout)
|
self.setLayout(self.main_layout)
|
||||||
# init from saved data
|
# init from saved data
|
||||||
self.current_model = None
|
self.current_model = None
|
||||||
if config.last_model_id:
|
model_id = config.last_model_id
|
||||||
self.current_model = get_model_byId(
|
if browser:
|
||||||
mw.col.models, config.last_model_id)
|
for note_id in browser.selectedNotes():
|
||||||
|
note = browser.mw.col.getNote(note_id)
|
||||||
|
model_id = note.model()['id']
|
||||||
|
break
|
||||||
|
if model_id:
|
||||||
|
self.current_model = get_model_byId(mw.col.models, model_id)
|
||||||
if self.current_model:
|
if self.current_model:
|
||||||
self.models_button.setText(
|
self.models_button.setText(
|
||||||
u'%s [%s]' % (_('CHOOSE_NOTE_TYPES'), self.current_model['name']))
|
u'%s [%s]' % (_('CHOOSE_NOTE_TYPES'), self.current_model['name']))
|
||||||
@ -485,9 +490,9 @@ def check_updates():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def show_options():
|
def show_options(browser = None):
|
||||||
config.read()
|
config.read()
|
||||||
opt_dialog = OptionsDialog(mw)
|
opt_dialog = OptionsDialog(mw, browser)
|
||||||
opt_dialog.exec_()
|
opt_dialog.exec_()
|
||||||
opt_dialog.activateWindow()
|
opt_dialog.activateWindow()
|
||||||
opt_dialog.raise_()
|
opt_dialog.raise_()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user