Adapt to anki 2.1
This commit is contained in:
parent
0e0cc52f0c
commit
fd2d1b3d39
@ -1,43 +0,0 @@
|
||||
#-*- coding:utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2018 sthoo <sth201807@gmail.com>
|
||||
#
|
||||
# Support: Report an issue at https://github.com/sth2018/FastWordQuery/issues
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# any later version; http://www.gnu.org/copyleft/gpl.html.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from anki.hooks import addHook
|
||||
|
||||
############## other config here ##################
|
||||
shortcut = 'Ctrl+Q'
|
||||
LDOCE6_PATH = u'D:\\mdx_server\\mdx\\LDOCE6.mdx'
|
||||
###################################################
|
||||
|
||||
def start_here():
|
||||
|
||||
"""
|
||||
Copyright (C) 2018 sthoo <sth201807@gmail.com>
|
||||
Support: Report an issue at https://github.com/sth2018/FastWordQuery/issues
|
||||
"""
|
||||
|
||||
import fastwq
|
||||
|
||||
fastwq.config.read()
|
||||
if not fastwq.have_setup:
|
||||
fastwq.config_menu()
|
||||
fastwq.browser_menu()
|
||||
fastwq.customize_addcards()
|
||||
fastwq.window_shortcut(shortcut)
|
||||
|
||||
addHook("profileLoaded", start_here)
|
||||
@ -17,109 +17,24 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from aqt import mw
|
||||
from aqt.qt import *
|
||||
from anki.hooks import addHook, wrap
|
||||
from aqt.addcards import AddCards
|
||||
from aqt.utils import showInfo, shortcut
|
||||
from .gui import show_options, show_about_dialog
|
||||
from .query import query_from_browser, query_from_editor_all_fields
|
||||
from .context import config, APP_ICON
|
||||
from .lang import _
|
||||
from anki.hooks import addHook
|
||||
from . import common as fastwq
|
||||
from .context import config
|
||||
|
||||
|
||||
__all__ = [
|
||||
'add_query_button', 'browser_menu',
|
||||
'customize_addcards', 'config_menu',
|
||||
'window_shortcut'
|
||||
]
|
||||
############## other config here ##################
|
||||
shortcut = 'Ctrl+Q'
|
||||
LDOCE6_PATH = u'D:\\mdx_server\\mdx\\LDOCE6.mdx'
|
||||
###################################################
|
||||
|
||||
|
||||
have_setup = False
|
||||
my_shortcut = ''
|
||||
def start_here():
|
||||
config.read()
|
||||
config.LDOCE6_PATH = LDOCE6_PATH
|
||||
if not fastwq.have_setup:
|
||||
fastwq.config_menu()
|
||||
fastwq.browser_menu()
|
||||
fastwq.customize_addcards()
|
||||
fastwq.window_shortcut(shortcut)
|
||||
|
||||
|
||||
def wrap_method(func, *args, **kwargs):
|
||||
'''
|
||||
wrap a function with params when it's called
|
||||
'''
|
||||
def callback():
|
||||
return func(*args, **kwargs)
|
||||
return callback
|
||||
|
||||
|
||||
def add_query_button(self):
|
||||
'''
|
||||
add a button in add card window
|
||||
'''
|
||||
bb = self.form.buttonBox
|
||||
ar = QDialogButtonBox.ActionRole
|
||||
self.queryButton = bb.addButton(_(u"Query"), ar)
|
||||
self.queryButton.clicked.connect(wrap_method(
|
||||
query_from_editor_all_fields, self.editor))
|
||||
self.queryButton.setShortcut(QKeySequence(my_shortcut))
|
||||
self.queryButton.setToolTip(
|
||||
shortcut(_(u"Query (shortcut: %s)" % my_shortcut)))
|
||||
|
||||
|
||||
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(wrap_method(query_from_browser, browser))
|
||||
action.setShortcut(QKeySequence(my_shortcut))
|
||||
menu.addAction(action)
|
||||
# Options
|
||||
action = QAction("Options", browser)
|
||||
def _show_options():
|
||||
model_id = -1
|
||||
for note_id in browser.selectedNotes():
|
||||
note = browser.mw.col.getNote(note_id)
|
||||
model_id = note.model()['id']
|
||||
break
|
||||
show_options(browser, model_id)
|
||||
action.triggered.connect(_show_options)
|
||||
menu.addAction(action)
|
||||
# About
|
||||
action = QAction("About", browser)
|
||||
action.triggered.connect(wrap_method(show_about_dialog, browser))
|
||||
menu.addAction(action)
|
||||
|
||||
addHook('browser.setupMenus', on_setup_menus)
|
||||
|
||||
|
||||
def customize_addcards():
|
||||
"""
|
||||
add button to addcards window
|
||||
"""
|
||||
AddCards.setupButtons = wrap(
|
||||
AddCards.setupButtons, add_query_button, "before")
|
||||
|
||||
|
||||
def config_menu():
|
||||
"""
|
||||
add menu to anki window menebar
|
||||
"""
|
||||
action = QAction(APP_ICON, "FastWQ...", mw)
|
||||
action.triggered.connect(wrap_method(show_options))
|
||||
mw.form.menuTools.addAction(action)
|
||||
global have_setup
|
||||
have_setup = True
|
||||
|
||||
|
||||
def window_shortcut(key_sequence):
|
||||
"""
|
||||
setup shortcut
|
||||
"""
|
||||
global my_shortcut
|
||||
my_shortcut = key_sequence
|
||||
|
||||
addHook("profileLoaded", start_here)
|
||||
125
addons21/fastwq/common.py
Normal file
125
addons21/fastwq/common.py
Normal file
@ -0,0 +1,125 @@
|
||||
#-*- coding:utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2018 sthoo <sth201807@gmail.com>
|
||||
#
|
||||
# Support: Report an issue at https://github.com/sth2018/FastWordQuery/issues
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# any later version; http://www.gnu.org/copyleft/gpl.html.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from aqt import mw
|
||||
from aqt.qt import *
|
||||
from anki.hooks import addHook, wrap
|
||||
from aqt.addcards import AddCards
|
||||
from aqt.utils import showInfo, shortcut
|
||||
from .gui import show_options, show_about_dialog
|
||||
from .query import query_from_browser, query_from_editor_all_fields
|
||||
from .context import config, APP_ICON
|
||||
from .lang import _
|
||||
|
||||
|
||||
__all__ = [
|
||||
'add_query_button', 'browser_menu',
|
||||
'customize_addcards', 'config_menu',
|
||||
'window_shortcut'
|
||||
]
|
||||
|
||||
|
||||
have_setup = False
|
||||
my_shortcut = ''
|
||||
|
||||
|
||||
def wrap_method(func, *args, **kwargs):
|
||||
'''
|
||||
wrap a function with params when it's called
|
||||
'''
|
||||
def callback():
|
||||
return func(*args, **kwargs)
|
||||
return callback
|
||||
|
||||
|
||||
def add_query_button(self):
|
||||
'''
|
||||
add a button in add card window
|
||||
'''
|
||||
bb = self.form.buttonBox
|
||||
ar = QDialogButtonBox.ActionRole
|
||||
self.queryButton = bb.addButton(_(u"Query"), ar)
|
||||
self.queryButton.clicked.connect(wrap_method(
|
||||
query_from_editor_all_fields, self.editor))
|
||||
self.queryButton.setShortcut(QKeySequence(my_shortcut))
|
||||
self.queryButton.setToolTip(
|
||||
shortcut(_(u"Query (shortcut: %s)" % my_shortcut)))
|
||||
|
||||
|
||||
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(wrap_method(query_from_browser, browser))
|
||||
action.setShortcut(QKeySequence(my_shortcut))
|
||||
menu.addAction(action)
|
||||
# Options
|
||||
action = QAction("Options", browser)
|
||||
def _show_options():
|
||||
model_id = -1
|
||||
for note_id in browser.selectedNotes():
|
||||
note = browser.mw.col.getNote(note_id)
|
||||
model_id = note.model()['id']
|
||||
break
|
||||
show_options(browser, model_id)
|
||||
action.triggered.connect(_show_options)
|
||||
menu.addAction(action)
|
||||
# About
|
||||
action = QAction("About", browser)
|
||||
action.triggered.connect(wrap_method(show_about_dialog, browser))
|
||||
menu.addAction(action)
|
||||
|
||||
addHook('browser.setupMenus', on_setup_menus)
|
||||
|
||||
|
||||
def customize_addcards():
|
||||
"""
|
||||
add button to addcards window
|
||||
"""
|
||||
AddCards.setupButtons = wrap(
|
||||
AddCards.setupButtons, add_query_button, "before")
|
||||
|
||||
|
||||
def config_menu():
|
||||
"""
|
||||
add menu to anki window menebar
|
||||
"""
|
||||
action = QAction(APP_ICON, "FastWQ...", mw)
|
||||
action.triggered.connect(wrap_method(show_options))
|
||||
mw.form.menuTools.addAction(action)
|
||||
global have_setup
|
||||
have_setup = True
|
||||
|
||||
|
||||
def window_shortcut(key_sequence):
|
||||
"""
|
||||
setup shortcut
|
||||
"""
|
||||
global my_shortcut
|
||||
my_shortcut = key_sequence
|
||||
|
||||
@ -36,6 +36,7 @@ class Config(object):
|
||||
"""
|
||||
|
||||
_CONFIG_FILENAME = '.fastwqcfg.json' #Config File Path
|
||||
LDOCE6_PATH = ''
|
||||
|
||||
def __init__(self, window):
|
||||
self.path = self._CONFIG_FILENAME
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
#-*- coding:utf-8 -*-
|
||||
import re
|
||||
import FastWQ
|
||||
from ..base import *
|
||||
from ...context import config
|
||||
|
||||
PATH = FastWQ.LDOCE6_PATH
|
||||
|
||||
VOICE_PATTERN = r'<a href="sound://([\w/]+\w*\.mp3)"><img src="img/spkr_%s.png"></a>'
|
||||
MAPPINGS = [
|
||||
@ -17,7 +16,7 @@ LANG_TO_REGEXPS = {lang: regexps for lang, regexps in MAPPINGS}
|
||||
class Ldoce6(MdxService):
|
||||
|
||||
def __init__(self):
|
||||
super(Ldoce6, self).__init__(PATH)
|
||||
super(Ldoce6, self).__init__(config.LDOCE6_PATH)
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user