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