refactoring.
This commit is contained in:
parent
99d6fff58a
commit
4124b30954
@ -17,22 +17,21 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import anki
|
from PyQt4 import QtCore, QtGui
|
||||||
import aqt
|
|
||||||
from aqt import mw
|
from aqt import mw
|
||||||
from aqt.qt import *
|
|
||||||
from anki.hooks import addHook, wrap
|
from anki.hooks import addHook, wrap
|
||||||
from aqt.addcards import AddCards
|
from aqt.addcards import AddCards
|
||||||
from aqt.utils import showInfo, shortcut
|
from aqt.utils import showInfo, shortcut
|
||||||
from .ui import show_options
|
from .gui import show_options, show_about_dialog
|
||||||
from .query import *
|
from .query import query_from_browser, query_from_editor_all_fields
|
||||||
from .context import config, APP_ICON
|
from .context import config, APP_ICON
|
||||||
from .lang import _
|
from .lang import _
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'wrap_method', 'add_query_button', 'browser_menu',
|
'add_query_button', 'browser_menu',
|
||||||
'customize_addcards', 'config_menu', 'window_shortcut'
|
'customize_addcards', 'config_menu',
|
||||||
|
'window_shortcut'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -54,11 +53,11 @@ def add_query_button(self):
|
|||||||
add a button in add card window
|
add a button in add card window
|
||||||
'''
|
'''
|
||||||
bb = self.form.buttonBox
|
bb = self.form.buttonBox
|
||||||
ar = QDialogButtonBox.ActionRole
|
ar = QtGui.QDialogButtonBox.ActionRole
|
||||||
self.queryButton = bb.addButton(_(u"Query"), ar)
|
self.queryButton = bb.addButton(_(u"Query"), ar)
|
||||||
self.queryButton.clicked.connect(wrap_method(
|
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(QtGui.QKeySequence(my_shortcut))
|
||||||
self.queryButton.setToolTip(
|
self.queryButton.setToolTip(
|
||||||
shortcut(_(u"Query (shortcut: %s)" % my_shortcut)))
|
shortcut(_(u"Query (shortcut: %s)" % my_shortcut)))
|
||||||
|
|
||||||
@ -72,15 +71,15 @@ def browser_menu():
|
|||||||
on browser setupMenus was called
|
on browser setupMenus was called
|
||||||
"""
|
"""
|
||||||
# main menu
|
# main menu
|
||||||
menu = QMenu("FastWQ", browser.form.menubar)
|
menu = QtGui.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 = QtGui.QAction("Query Selected", browser)
|
||||||
action.triggered.connect(wrap_method(query_from_browser, browser))
|
action.triggered.connect(wrap_method(query_from_browser, browser))
|
||||||
action.setShortcut(QKeySequence(my_shortcut))
|
action.setShortcut(QtGui.QKeySequence(my_shortcut))
|
||||||
menu.addAction(action)
|
menu.addAction(action)
|
||||||
#Options
|
# Options
|
||||||
action = QAction("Options", browser)
|
action = QtGui.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():
|
||||||
@ -90,8 +89,12 @@ def browser_menu():
|
|||||||
show_options(browser, model_id)
|
show_options(browser, model_id)
|
||||||
action.triggered.connect(_show_options)
|
action.triggered.connect(_show_options)
|
||||||
menu.addAction(action)
|
menu.addAction(action)
|
||||||
|
# About
|
||||||
|
action = QtGui.QAction("About", browser)
|
||||||
|
action.triggered.connect(wrap_method(show_about_dialog, browser))
|
||||||
|
menu.addAction(action)
|
||||||
|
|
||||||
anki.hooks.addHook('browser.setupMenus', on_setup_menus)
|
addHook('browser.setupMenus', on_setup_menus)
|
||||||
|
|
||||||
|
|
||||||
def customize_addcards():
|
def customize_addcards():
|
||||||
@ -106,7 +109,7 @@ def config_menu():
|
|||||||
"""
|
"""
|
||||||
add menu to anki window menebar
|
add menu to anki window menebar
|
||||||
"""
|
"""
|
||||||
action = QAction(APP_ICON, "FastWQ...", mw)
|
action = QtGui.QAction(APP_ICON, "FastWQ...", mw)
|
||||||
action.triggered.connect(wrap_method(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
|
||||||
|
|||||||
@ -21,8 +21,9 @@
|
|||||||
from .lang import _
|
from .lang import _
|
||||||
|
|
||||||
|
|
||||||
VERSION = 'v1.1.4'
|
__all__ = ['VERSION', 'Endpoint', 'Template']
|
||||||
|
|
||||||
|
VERSION = 'v1.1.4'
|
||||||
|
|
||||||
class Endpoint:
|
class Endpoint:
|
||||||
repository = u'https://github.com/sth2018/FastWordQuery'
|
repository = u'https://github.com/sth2018/FastWordQuery'
|
||||||
|
|||||||
@ -23,7 +23,9 @@ from .constants import VERSION
|
|||||||
from .utils import get_icon
|
from .utils import get_icon
|
||||||
|
|
||||||
|
|
||||||
CONFIG_FILENAME = '.fastwqcfg.json' #Config File Path
|
__all__ = ['APP_ICON', 'config']
|
||||||
|
|
||||||
|
|
||||||
APP_ICON = get_icon('wqicon.png') #Addon Icon
|
APP_ICON = get_icon('wqicon.png') #Addon Icon
|
||||||
|
|
||||||
|
|
||||||
@ -33,8 +35,10 @@ class Config(object):
|
|||||||
Addon Config
|
Addon Config
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
_CONFIG_FILENAME = '.fastwqcfg.json' #Config File Path
|
||||||
|
|
||||||
def __init__(self, window):
|
def __init__(self, window):
|
||||||
self.path = CONFIG_FILENAME
|
self.path = self._CONFIG_FILENAME
|
||||||
self.window = window
|
self.window = window
|
||||||
self.version = '0'
|
self.version = '0'
|
||||||
self.read()
|
self.read()
|
||||||
|
|||||||
4
src/fastwq/gui/__init__.py
Normal file
4
src/fastwq/gui/__init__.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#-*- coding:utf-8 -*-
|
||||||
|
|
||||||
|
from .common import *
|
||||||
|
from .progress import *
|
||||||
67
src/fastwq/gui/base.py
Normal file
67
src/fastwq/gui/base.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#-*- coding:utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright © 2016–2017 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 PyQt4 import QtCore, QtGui
|
||||||
|
from ..context import APP_ICON
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['Dialog', 'WIDGET_SIZE']
|
||||||
|
|
||||||
|
|
||||||
|
class Dialog(QtGui.QDialog):
|
||||||
|
'''
|
||||||
|
Base used for all dialog windows.
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __init__(self, parent, title):
|
||||||
|
'''
|
||||||
|
Set the modal status for the dialog, sets its layout to the
|
||||||
|
return value of the _ui() method, and sets a default title.
|
||||||
|
'''
|
||||||
|
|
||||||
|
self._title = title
|
||||||
|
self._parent = parent
|
||||||
|
super(Dialog, self).__init__(parent)
|
||||||
|
|
||||||
|
self.setModal(True)
|
||||||
|
self.setWindowFlags(
|
||||||
|
self.windowFlags() &
|
||||||
|
~QtCore.Qt.WindowContextHelpButtonHint
|
||||||
|
)
|
||||||
|
self.setWindowIcon(APP_ICON)
|
||||||
|
self.setWindowTitle(
|
||||||
|
title if "FastWQ" in title
|
||||||
|
else "FastWQ - " + title
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class WidgetSize(object):
|
||||||
|
'''
|
||||||
|
constant values
|
||||||
|
'''
|
||||||
|
dialog_width = 700
|
||||||
|
dialog_height_margin = 120
|
||||||
|
map_min_height = 0
|
||||||
|
map_max_height = 31
|
||||||
|
map_fld_width = 100
|
||||||
|
map_dictname_width = 150
|
||||||
|
map_dictfield_width = 160
|
||||||
|
|
||||||
|
|
||||||
|
WIDGET_SIZE = WidgetSize()
|
||||||
72
src/fastwq/gui/common.py
Normal file
72
src/fastwq/gui/common.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#-*- coding:utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright © 2016–2017 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/>.
|
||||||
|
|
||||||
|
import types
|
||||||
|
from PyQt4 import QtGui
|
||||||
|
from aqt import mw
|
||||||
|
from aqt.utils import showInfo
|
||||||
|
from .options import OptionsDialog
|
||||||
|
from .foldermanager import FoldersManageDialog
|
||||||
|
from ..libs import ankihub
|
||||||
|
from ..context import config
|
||||||
|
from ..lang import _
|
||||||
|
from ..constants import Endpoint, Template
|
||||||
|
from ..service import service_manager
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['show_options', 'check_updates', 'show_fm_dialog', 'show_about_dialog']
|
||||||
|
|
||||||
|
|
||||||
|
def check_updates():
|
||||||
|
'''check add-on last version'''
|
||||||
|
try:
|
||||||
|
if not ankihub.update([Endpoint.check_version], False, Endpoint.version):
|
||||||
|
showInfo(_('LATEST_VERSION'))
|
||||||
|
except:
|
||||||
|
showInfo(_('CHECK_FAILURE'))
|
||||||
|
|
||||||
|
|
||||||
|
def show_fm_dialog(browser = None):
|
||||||
|
'''open dictionary folder manager window'''
|
||||||
|
parent = mw if browser is None else browser
|
||||||
|
fm_dialog = FoldersManageDialog(parent, u'Dictionary Folder Manager')
|
||||||
|
fm_dialog.activateWindow()
|
||||||
|
fm_dialog.raise_()
|
||||||
|
if fm_dialog.exec_() == QtGui.QDialog.Accepted:
|
||||||
|
# update local services
|
||||||
|
service_manager.update_services()
|
||||||
|
# reshow options window
|
||||||
|
show_options(browser)
|
||||||
|
|
||||||
|
|
||||||
|
def show_options(browser = None, model_id = -1, callback = None, *args, **kwargs):
|
||||||
|
'''open options window'''
|
||||||
|
parent = mw if browser is None else browser
|
||||||
|
config.read()
|
||||||
|
opt_dialog = OptionsDialog(parent, u'Options', model_id)
|
||||||
|
opt_dialog.activateWindow()
|
||||||
|
opt_dialog.raise_()
|
||||||
|
if opt_dialog.exec_() == QtGui.QDialog.Accepted:
|
||||||
|
if isinstance(callback, types.FunctionType):
|
||||||
|
callback(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def show_about_dialog(parent):
|
||||||
|
'''open about dialog'''
|
||||||
|
QtGui.QMessageBox.about(parent, _('ABOUT'), Template.tmpl_about)
|
||||||
98
src/fastwq/gui/foldermanager.py
Normal file
98
src/fastwq/gui/foldermanager.py
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#-*- coding:utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright © 2016–2017 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 PyQt4 import QtCore, QtGui
|
||||||
|
from .base import Dialog, WIDGET_SIZE
|
||||||
|
from ..context import config
|
||||||
|
from ..lang import _, _sl
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['FoldersManageDialog']
|
||||||
|
|
||||||
|
|
||||||
|
class FoldersManageDialog(Dialog):
|
||||||
|
'''
|
||||||
|
Dictionary folder manager window. add or remove dictionary folders.
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __init__(self, parent, title=u'Dictionary Folder Manager'):
|
||||||
|
super(FoldersManageDialog, self).__init__(parent, title)
|
||||||
|
#self._dict_paths = []
|
||||||
|
self.build()
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
layout = QtGui.QVBoxLayout()
|
||||||
|
btn_layout = QtGui.QHBoxLayout()
|
||||||
|
add_btn = QtGui.QPushButton("+")
|
||||||
|
remove_btn = QtGui.QPushButton("-")
|
||||||
|
btn_layout.addWidget(add_btn)
|
||||||
|
btn_layout.addWidget(remove_btn)
|
||||||
|
add_btn.clicked.connect(self.add_folder)
|
||||||
|
remove_btn.clicked.connect(self.remove_folder)
|
||||||
|
self.folders_lst = QtGui.QListWidget()
|
||||||
|
self.folders_lst.addItems(config.dirs)
|
||||||
|
self.chk_use_filename = QtGui.QCheckBox(_('CHECK_FILENAME_LABEL'))
|
||||||
|
self.chk_export_media = QtGui.QCheckBox(_('EXPORT_MEDIA'))
|
||||||
|
self.chk_use_filename.setChecked(config.use_filename)
|
||||||
|
self.chk_export_media.setChecked(config.export_media)
|
||||||
|
chk_layout = QtGui.QHBoxLayout()
|
||||||
|
chk_layout.addWidget(self.chk_use_filename)
|
||||||
|
chk_layout.addWidget(self.chk_export_media)
|
||||||
|
btnbox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok, QtCore.Qt.Horizontal, self)
|
||||||
|
btnbox.accepted.connect(self.accept)
|
||||||
|
layout.addLayout(btn_layout)
|
||||||
|
layout.addWidget(self.folders_lst)
|
||||||
|
layout.addLayout(chk_layout)
|
||||||
|
layout.addWidget(btnbox)
|
||||||
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
def add_folder(self):
|
||||||
|
dir_ = QtGui.QFileDialog.getExistingDirectory(
|
||||||
|
self,
|
||||||
|
caption=u"Select Folder",
|
||||||
|
directory=config.last_folder,
|
||||||
|
options=QtGui.QFileDialog.ShowDirsOnly | QtGui.QFileDialog.DontResolveSymlinks
|
||||||
|
)
|
||||||
|
if dir_:
|
||||||
|
self.folders_lst.addItem(dir_)
|
||||||
|
config.update({'last_folder': dir_})
|
||||||
|
|
||||||
|
def remove_folder(self):
|
||||||
|
item = self.folders_lst.takeItem(self.folders_lst.currentRow())
|
||||||
|
del item
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dirs(self):
|
||||||
|
'''dictionary folders list'''
|
||||||
|
return [self.folders_lst.item(i).text()
|
||||||
|
for i in range(self.folders_lst.count())]
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
'''ok button clicked'''
|
||||||
|
self.save()
|
||||||
|
super(FoldersManageDialog, self).accept()
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
'''save config to file'''
|
||||||
|
data = {
|
||||||
|
'dirs': self.dirs,
|
||||||
|
'use_filename': self.chk_use_filename.isChecked(),
|
||||||
|
'export_media': self.chk_export_media.isChecked()
|
||||||
|
}
|
||||||
|
config.update(data)
|
||||||
@ -17,212 +17,22 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
from PyQt4 import QtCore, QtGui
|
||||||
import sys
|
|
||||||
import json
|
|
||||||
import types
|
|
||||||
from collections import namedtuple
|
|
||||||
|
|
||||||
import anki
|
import anki
|
||||||
import aqt
|
import aqt
|
||||||
import aqt.models
|
import aqt.models
|
||||||
from aqt import mw
|
from aqt import mw
|
||||||
from PyQt4 import QtCore, QtGui
|
|
||||||
from aqt.studydeck import StudyDeck
|
from aqt.studydeck import StudyDeck
|
||||||
from aqt.utils import shortcut, showInfo
|
from .base import Dialog, WIDGET_SIZE
|
||||||
from .constants import VERSION, Endpoint, Template
|
from .setting import SettingDialog
|
||||||
from .context import APP_ICON, config
|
from ..context import config
|
||||||
from .lang import _, _sl
|
from ..lang import _, _sl
|
||||||
from .service import service_manager, service_pool
|
from ..service import service_manager, service_pool
|
||||||
from .utils import MapDict, get_icon, get_model_byId, get_ord_from_fldname
|
from ..utils import get_model_byId
|
||||||
|
from ..constants import Endpoint
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['WIDGET_SIZE', 'Dialog', 'ParasDialog',
|
__all__ = ['OptionsDialog']
|
||||||
'FoldersManageDialog', 'OptionsDialog', 'check_updates',
|
|
||||||
'show_options', 'show_fm_dialog'
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class WIDGET_SIZE:
|
|
||||||
dialog_width = 700
|
|
||||||
dialog_height_margin = 120
|
|
||||||
map_min_height = 0
|
|
||||||
map_max_height = 31
|
|
||||||
map_fld_width = 100
|
|
||||||
map_dictname_width = 150
|
|
||||||
map_dictfield_width = 160
|
|
||||||
|
|
||||||
|
|
||||||
class Dialog(QtGui.QDialog):
|
|
||||||
'''
|
|
||||||
Base used for all dialog windows.
|
|
||||||
'''
|
|
||||||
|
|
||||||
def __init__(self, parent, title):
|
|
||||||
'''
|
|
||||||
Set the modal status for the dialog, sets its layout to the
|
|
||||||
return value of the _ui() method, and sets a default title.
|
|
||||||
'''
|
|
||||||
|
|
||||||
self._title = title
|
|
||||||
self._parent = parent
|
|
||||||
super(Dialog, self).__init__(parent)
|
|
||||||
|
|
||||||
self.setModal(True)
|
|
||||||
self.setWindowFlags(
|
|
||||||
self.windowFlags() &
|
|
||||||
~QtCore.Qt.WindowContextHelpButtonHint
|
|
||||||
)
|
|
||||||
self.setWindowIcon(APP_ICON)
|
|
||||||
self.setWindowTitle(
|
|
||||||
title if "FastWQ" in title
|
|
||||||
else "FastWQ - " + title
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ParasDialog(Dialog):
|
|
||||||
'''
|
|
||||||
Setting window, some golbal params for query function.
|
|
||||||
'''
|
|
||||||
|
|
||||||
def __init__(self, parent, title=u'Setting'):
|
|
||||||
super(ParasDialog, self).__init__(parent, title)
|
|
||||||
self.setFixedWidth(400)
|
|
||||||
self.check_force_update = None
|
|
||||||
self.input_thread_number = None
|
|
||||||
self.build()
|
|
||||||
|
|
||||||
def build(self):
|
|
||||||
layout = QtGui.QVBoxLayout()
|
|
||||||
|
|
||||||
check_force_update = QtGui.QCheckBox(_("FORCE_UPDATE"))
|
|
||||||
check_force_update.setChecked(config.force_update)
|
|
||||||
layout.addWidget(check_force_update)
|
|
||||||
layout.addSpacing(10)
|
|
||||||
|
|
||||||
check_ignore_accents = QtGui.QCheckBox(_("IGNORE_ACCENTS"))
|
|
||||||
check_ignore_accents.setChecked(config.ignore_accents)
|
|
||||||
layout.addWidget(check_ignore_accents)
|
|
||||||
layout.addSpacing(10)
|
|
||||||
|
|
||||||
hbox = QtGui.QHBoxLayout()
|
|
||||||
input_thread_number = QtGui.QSpinBox(parent=self)
|
|
||||||
input_thread_number.setRange(1, 120)
|
|
||||||
input_thread_number.setValue(config.thread_number)
|
|
||||||
input_label = QtGui.QLabel(_("THREAD_NUMBER") + ":", parent=self)
|
|
||||||
hbox.addWidget(input_label)
|
|
||||||
hbox.setStretchFactor(input_label, 1)
|
|
||||||
hbox.addWidget(input_thread_number)
|
|
||||||
hbox.setStretchFactor(input_thread_number, 2)
|
|
||||||
layout.addLayout(hbox)
|
|
||||||
|
|
||||||
buttonBox = QtGui.QDialogButtonBox(parent=self)
|
|
||||||
buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
|
|
||||||
buttonBox.accepted.connect(self.accept) # 确定
|
|
||||||
|
|
||||||
layout.addSpacing(48)
|
|
||||||
layout.addWidget(buttonBox)
|
|
||||||
|
|
||||||
self.check_force_update = check_force_update
|
|
||||||
self.check_ignore_accents = check_ignore_accents
|
|
||||||
self.input_thread_number = input_thread_number
|
|
||||||
|
|
||||||
layout.setAlignment(QtCore.Qt.AlignTop|QtCore.Qt.AlignLeft)
|
|
||||||
self.setLayout(layout)
|
|
||||||
|
|
||||||
def accept(self):
|
|
||||||
self.save()
|
|
||||||
super(ParasDialog, self).accept()
|
|
||||||
|
|
||||||
def save(self):
|
|
||||||
data = {
|
|
||||||
'force_update': self.check_force_update.isChecked(),
|
|
||||||
'ignore_accents': self.check_ignore_accents.isChecked(),
|
|
||||||
'thread_number': self.input_thread_number.value()
|
|
||||||
}
|
|
||||||
config.update(data)
|
|
||||||
|
|
||||||
|
|
||||||
class FoldersManageDialog(Dialog):
|
|
||||||
'''
|
|
||||||
Dictionary folder manager window. add or remove dictionary folders.
|
|
||||||
'''
|
|
||||||
|
|
||||||
def __init__(self, parent, title=u'Dictionary Folder Manager'):
|
|
||||||
super(FoldersManageDialog, self).__init__(parent, title)
|
|
||||||
#self._dict_paths = []
|
|
||||||
self.build()
|
|
||||||
|
|
||||||
def build(self):
|
|
||||||
layout = QtGui.QVBoxLayout()
|
|
||||||
btn_layout = QtGui.QHBoxLayout()
|
|
||||||
add_btn = QtGui.QPushButton("+")
|
|
||||||
remove_btn = QtGui.QPushButton("-")
|
|
||||||
btn_layout.addWidget(add_btn)
|
|
||||||
btn_layout.addWidget(remove_btn)
|
|
||||||
add_btn.clicked.connect(self.add_folder)
|
|
||||||
remove_btn.clicked.connect(self.remove_folder)
|
|
||||||
self.folders_lst = QtGui.QListWidget()
|
|
||||||
self.folders_lst.addItems(config.dirs)
|
|
||||||
self.chk_use_filename = QtGui.QCheckBox(_('CHECK_FILENAME_LABEL'))
|
|
||||||
self.chk_export_media = QtGui.QCheckBox(_('EXPORT_MEDIA'))
|
|
||||||
self.chk_use_filename.setChecked(config.use_filename)
|
|
||||||
self.chk_export_media.setChecked(config.export_media)
|
|
||||||
chk_layout = QtGui.QHBoxLayout()
|
|
||||||
chk_layout.addWidget(self.chk_use_filename)
|
|
||||||
chk_layout.addWidget(self.chk_export_media)
|
|
||||||
btnbox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok, QtCore.Qt.Horizontal, self)
|
|
||||||
btnbox.accepted.connect(self.accept)
|
|
||||||
layout.addLayout(btn_layout)
|
|
||||||
layout.addWidget(self.folders_lst)
|
|
||||||
layout.addLayout(chk_layout)
|
|
||||||
layout.addWidget(btnbox)
|
|
||||||
self.setLayout(layout)
|
|
||||||
|
|
||||||
def add_folder(self):
|
|
||||||
dir_ = QtGui.QFileDialog.getExistingDirectory(
|
|
||||||
self,
|
|
||||||
caption=u"Select Folder",
|
|
||||||
directory=config.last_folder,
|
|
||||||
options=QtGui.QFileDialog.ShowDirsOnly | QtGui.QFileDialog.DontResolveSymlinks
|
|
||||||
)
|
|
||||||
if dir_:
|
|
||||||
self.folders_lst.addItem(dir_)
|
|
||||||
config.update({'last_folder': dir_})
|
|
||||||
|
|
||||||
def remove_folder(self):
|
|
||||||
item = self.folders_lst.takeItem(self.folders_lst.currentRow())
|
|
||||||
del item
|
|
||||||
|
|
||||||
'''
|
|
||||||
def find_mdxes(self):
|
|
||||||
for each in self.dirs:
|
|
||||||
for dirpath, dirnames, filenames in os.walk(each):
|
|
||||||
self._dict_paths.extend([os.path.join(dirpath, filename)
|
|
||||||
for filename in filenames if filename.lower().endswith(u'.mdx')])
|
|
||||||
return list(set(self._dict_paths))
|
|
||||||
|
|
||||||
@property
|
|
||||||
def dict_paths(self):
|
|
||||||
return self.find_mdxes()
|
|
||||||
'''
|
|
||||||
|
|
||||||
@property
|
|
||||||
def dirs(self):
|
|
||||||
return [self.folders_lst.item(i).text()
|
|
||||||
for i in range(self.folders_lst.count())]
|
|
||||||
|
|
||||||
def accept(self):
|
|
||||||
self.save()
|
|
||||||
super(FoldersManageDialog, self).accept()
|
|
||||||
|
|
||||||
def save(self):
|
|
||||||
data = {
|
|
||||||
'dirs': self.dirs,
|
|
||||||
'use_filename': self.chk_use_filename.isChecked(),
|
|
||||||
'export_media': self.chk_export_media.isChecked()
|
|
||||||
}
|
|
||||||
config.update(data)
|
|
||||||
|
|
||||||
|
|
||||||
class OptionsDialog(Dialog):
|
class OptionsDialog(Dialog):
|
||||||
@ -250,6 +60,7 @@ class OptionsDialog(Dialog):
|
|||||||
self.___last_checkeds___ = None
|
self.___last_checkeds___ = None
|
||||||
self.___options___ = list()
|
self.___options___ = list()
|
||||||
self.model_id = model_id if model_id != -1 else config.last_model_id
|
self.model_id = model_id if model_id != -1 else config.last_model_id
|
||||||
|
self.current_model = None
|
||||||
# size and signal
|
# size and signal
|
||||||
self.resize(WIDGET_SIZE.dialog_width, 4 * WIDGET_SIZE.map_max_height + WIDGET_SIZE.dialog_height_margin)
|
self.resize(WIDGET_SIZE.dialog_width, 4 * WIDGET_SIZE.map_max_height + WIDGET_SIZE.dialog_height_margin)
|
||||||
self.emit(QtCore.SIGNAL('before_build'))
|
self.emit(QtCore.SIGNAL('before_build'))
|
||||||
@ -257,6 +68,8 @@ class OptionsDialog(Dialog):
|
|||||||
def _before_build(self):
|
def _before_build(self):
|
||||||
for cls in service_manager.services:
|
for cls in service_manager.services:
|
||||||
service = service_pool.get(cls.__unique__)
|
service = service_pool.get(cls.__unique__)
|
||||||
|
if service:
|
||||||
|
service_pool.put(service)
|
||||||
self.emit(QtCore.SIGNAL('after_build'))
|
self.emit(QtCore.SIGNAL('after_build'))
|
||||||
|
|
||||||
def _after_build(self):
|
def _after_build(self):
|
||||||
@ -289,7 +102,7 @@ class OptionsDialog(Dialog):
|
|||||||
about_btn.clicked.connect(self.show_about)
|
about_btn.clicked.connect(self.show_about)
|
||||||
# about_btn.clicked.connect(self.show_paras)
|
# about_btn.clicked.connect(self.show_paras)
|
||||||
chk_update_btn = QtGui.QPushButton(_('UPDATE'))
|
chk_update_btn = QtGui.QPushButton(_('UPDATE'))
|
||||||
chk_update_btn.clicked.connect(check_updates)
|
chk_update_btn.clicked.connect(self.check_updates)
|
||||||
home_label = QtGui.QLabel(
|
home_label = QtGui.QLabel(
|
||||||
'<a href="{url}">User Guide</a>'.format(url=Endpoint.user_guide))
|
'<a href="{url}">User Guide</a>'.format(url=Endpoint.user_guide))
|
||||||
home_label.setOpenExternalLinks(True)
|
home_label.setOpenExternalLinks(True)
|
||||||
@ -317,22 +130,34 @@ class OptionsDialog(Dialog):
|
|||||||
self.build_mappings_layout(self.current_model)
|
self.build_mappings_layout(self.current_model)
|
||||||
|
|
||||||
def show_paras(self):
|
def show_paras(self):
|
||||||
dialog = ParasDialog(self, u'Setting')
|
'''open setting dialog'''
|
||||||
|
dialog = SettingDialog(self, u'Setting')
|
||||||
dialog.exec_()
|
dialog.exec_()
|
||||||
|
|
||||||
|
def check_updates(self):
|
||||||
|
'''check addon version'''
|
||||||
|
from .common import check_updates
|
||||||
|
check_updates()
|
||||||
|
|
||||||
def show_fm_dialog(self):
|
def show_fm_dialog(self):
|
||||||
|
'''open folder manager dialog'''
|
||||||
|
from .common import show_fm_dialog
|
||||||
self.save()
|
self.save()
|
||||||
self.close()
|
self.close()
|
||||||
show_fm_dialog(self._parent)
|
show_fm_dialog(self._parent)
|
||||||
|
|
||||||
def show_about(self):
|
def show_about(self):
|
||||||
QtGui.QMessageBox.about(self, _('ABOUT'), Template.tmpl_about)
|
'''open about dialog'''
|
||||||
|
from .common import show_about_dialog
|
||||||
|
show_about_dialog(self)
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
|
'''on button was clicked'''
|
||||||
self.save()
|
self.save()
|
||||||
super(OptionsDialog, self).accept()
|
super(OptionsDialog, self).accept()
|
||||||
|
|
||||||
def btn_models_pressed(self):
|
def btn_models_pressed(self):
|
||||||
|
'''on choose model button was clicker'''
|
||||||
self.save()
|
self.save()
|
||||||
self.current_model = self.show_models()
|
self.current_model = self.show_models()
|
||||||
if self.current_model:
|
if self.current_model:
|
||||||
@ -602,39 +427,3 @@ class OptionsDialog(Dialog):
|
|||||||
data[current_model_id] = maps
|
data[current_model_id] = maps
|
||||||
data['last_model'] = self.current_model['id']
|
data['last_model'] = self.current_model['id']
|
||||||
config.update(data)
|
config.update(data)
|
||||||
|
|
||||||
|
|
||||||
def check_updates():
|
|
||||||
'''check add-on last version'''
|
|
||||||
try:
|
|
||||||
import libs.ankihub
|
|
||||||
if not libs.ankihub.update([Endpoint.check_version], False, Endpoint.version):
|
|
||||||
showInfo(_('LATEST_VERSION'))
|
|
||||||
except:
|
|
||||||
showInfo(_('CHECK_FAILURE'))
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def show_options(browser = None, model_id = -1, callback = None, *args, **kwargs):
|
|
||||||
'''open options window'''
|
|
||||||
parent = mw if browser is None else browser
|
|
||||||
config.read()
|
|
||||||
opt_dialog = OptionsDialog(parent, u'Options', model_id)
|
|
||||||
opt_dialog.activateWindow()
|
|
||||||
opt_dialog.raise_()
|
|
||||||
if opt_dialog.exec_() == QtGui.QDialog.Accepted:
|
|
||||||
if isinstance(callback, types.FunctionType):
|
|
||||||
callback(*args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def show_fm_dialog(browser = None):
|
|
||||||
'''open dictionary folder manager window'''
|
|
||||||
parent = mw if browser is None else browser
|
|
||||||
fm_dialog = FoldersManageDialog(parent, u'Dictionary Folder Manager')
|
|
||||||
fm_dialog.activateWindow()
|
|
||||||
fm_dialog.raise_()
|
|
||||||
if fm_dialog.exec_() == QtGui.QDialog.Accepted:
|
|
||||||
# update local services
|
|
||||||
service_manager.update_services()
|
|
||||||
# reshow options window
|
|
||||||
show_options(browser)
|
|
||||||
@ -22,18 +22,18 @@ import time
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from .lang import _
|
from ..lang import _
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['INFO_TEMPLATE', 'ProgressWindow']
|
__all__ = ['ProgressWindow']
|
||||||
|
|
||||||
|
|
||||||
INFO_TEMPLATE = u''.join([
|
_INFO_TEMPLATE = u''.join([
|
||||||
_('QUERIED') + u'<br>' + 45 * u'-' + u'<br>',
|
_('QUERIED') + u'<br>' + 45 * u'-' + u'<br>',
|
||||||
_('SUCCESS') + u' {} ' + _('WORDS') + u'<br>',
|
_('SUCCESS') + u' {} ' + _('WORDS') + u'<br>',
|
||||||
_('SKIPED') + u' {} ' + _('WORDS') + u'<br>',
|
_('SKIPED') + u' {} ' + _('WORDS') + u'<br>',
|
||||||
_('UPDATE') + u' {} ' + _('FIELDS') + u'<br>',
|
_('UPDATE') + u' {} ' + _('FIELDS') + u'<br>',
|
||||||
_('FAILURE') + u' {} ' + _('WORDS') + u'<br>'
|
_('FAILURE') + u' {} ' + _('WORDS') + u''
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ class ProgressWindow(object):
|
|||||||
self._msg_count.get('fails_number', 0),
|
self._msg_count.get('fails_number', 0),
|
||||||
self._msg_count.get('skips_number', 0)
|
self._msg_count.get('skips_number', 0)
|
||||||
)
|
)
|
||||||
number_info = INFO_TEMPLATE.format(
|
number_info = _INFO_TEMPLATE.format(
|
||||||
words_number,
|
words_number,
|
||||||
skips_number,
|
skips_number,
|
||||||
fields_number,
|
fields_number,
|
||||||
90
src/fastwq/gui/setting.py
Normal file
90
src/fastwq/gui/setting.py
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#-*- coding:utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright © 2016–2017 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 PyQt4 import QtCore, QtGui
|
||||||
|
from .base import Dialog, WIDGET_SIZE
|
||||||
|
from ..context import config
|
||||||
|
from ..lang import _
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['SettingDialog']
|
||||||
|
|
||||||
|
|
||||||
|
class SettingDialog(Dialog):
|
||||||
|
'''
|
||||||
|
Setting window, some golbal params for query function.
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __init__(self, parent, title=u'Setting'):
|
||||||
|
super(SettingDialog, self).__init__(parent, title)
|
||||||
|
self.setFixedWidth(400)
|
||||||
|
self.check_force_update = None
|
||||||
|
self.input_thread_number = None
|
||||||
|
self.build()
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
layout = QtGui.QVBoxLayout()
|
||||||
|
|
||||||
|
check_force_update = QtGui.QCheckBox(_("FORCE_UPDATE"))
|
||||||
|
check_force_update.setChecked(config.force_update)
|
||||||
|
layout.addWidget(check_force_update)
|
||||||
|
layout.addSpacing(10)
|
||||||
|
|
||||||
|
check_ignore_accents = QtGui.QCheckBox(_("IGNORE_ACCENTS"))
|
||||||
|
check_ignore_accents.setChecked(config.ignore_accents)
|
||||||
|
layout.addWidget(check_ignore_accents)
|
||||||
|
layout.addSpacing(10)
|
||||||
|
|
||||||
|
hbox = QtGui.QHBoxLayout()
|
||||||
|
input_thread_number = QtGui.QSpinBox(parent=self)
|
||||||
|
input_thread_number.setRange(1, 120)
|
||||||
|
input_thread_number.setValue(config.thread_number)
|
||||||
|
input_label = QtGui.QLabel(_("THREAD_NUMBER") + ":", parent=self)
|
||||||
|
hbox.addWidget(input_label)
|
||||||
|
hbox.setStretchFactor(input_label, 1)
|
||||||
|
hbox.addWidget(input_thread_number)
|
||||||
|
hbox.setStretchFactor(input_thread_number, 2)
|
||||||
|
layout.addLayout(hbox)
|
||||||
|
|
||||||
|
buttonBox = QtGui.QDialogButtonBox(parent=self)
|
||||||
|
buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
|
||||||
|
buttonBox.accepted.connect(self.accept) # 确定
|
||||||
|
|
||||||
|
layout.addSpacing(48)
|
||||||
|
layout.addWidget(buttonBox)
|
||||||
|
|
||||||
|
self.check_force_update = check_force_update
|
||||||
|
self.check_ignore_accents = check_ignore_accents
|
||||||
|
self.input_thread_number = input_thread_number
|
||||||
|
|
||||||
|
layout.setAlignment(QtCore.Qt.AlignTop|QtCore.Qt.AlignLeft)
|
||||||
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
self.save()
|
||||||
|
super(SettingDialog, self).accept()
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
data = {
|
||||||
|
'force_update': self.check_force_update.isChecked(),
|
||||||
|
'ignore_accents': self.check_ignore_accents.isChecked(),
|
||||||
|
'thread_number': self.input_thread_number.value()
|
||||||
|
}
|
||||||
|
config.update(data)
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ __all__ = ['_', '_cl', '_sl']
|
|||||||
|
|
||||||
|
|
||||||
#Language Define, [Key, zh_CN, en]
|
#Language Define, [Key, zh_CN, en]
|
||||||
arr = [
|
_arr = [
|
||||||
['CHECK_FILENAME_LABEL', u'使用文件名作为标签', u'Use Filename As Label'],
|
['CHECK_FILENAME_LABEL', u'使用文件名作为标签', u'Use Filename As Label'],
|
||||||
['EXPORT_MEDIA', u'导出媒体文件', u'Export Media Files'],
|
['EXPORT_MEDIA', u'导出媒体文件', u'Export Media Files'],
|
||||||
['DICTS_FOLDERS', u'字典文件夹', u'Dictionary Folder'],
|
['DICTS_FOLDERS', u'字典文件夹', u'Dictionary Folder'],
|
||||||
@ -76,21 +76,24 @@ arr = [
|
|||||||
['IMAGE', u'图片', u'Image'],
|
['IMAGE', u'图片', u'Image'],
|
||||||
]
|
]
|
||||||
|
|
||||||
trans = {item[0]: {'zh_CN': item[1], 'en': item[2]} for item in arr}
|
_trans = {item[0]: {'zh_CN': item[1], 'en': item[2]} for item in _arr}
|
||||||
|
|
||||||
|
|
||||||
def _(key, lang=currentLang):
|
def _(key, lang=currentLang):
|
||||||
|
'''get local language string'''
|
||||||
if lang != 'zh_CN' and lang != 'en':
|
if lang != 'zh_CN' and lang != 'en':
|
||||||
lang = 'en'
|
lang = 'en'
|
||||||
|
|
||||||
def disp(s):
|
def disp(s):
|
||||||
return s.lower().capitalize()
|
return s.lower().capitalize()
|
||||||
|
|
||||||
if key not in trans or lang not in trans[key]:
|
if key not in _trans or lang not in _trans[key]:
|
||||||
return disp(key)
|
return disp(key)
|
||||||
return trans[key][lang]
|
return _trans[key][lang]
|
||||||
|
|
||||||
|
|
||||||
def _cl(labels, lang=currentLang):
|
def _cl(labels, lang=currentLang):
|
||||||
|
'''get local language string from labels'''
|
||||||
if isinstance(labels, basestring):
|
if isinstance(labels, basestring):
|
||||||
return _(labels)
|
return _(labels)
|
||||||
if lang != 'zh_CN' and lang != 'en':
|
if lang != 'zh_CN' and lang != 'en':
|
||||||
@ -99,4 +102,4 @@ def _cl(labels, lang=currentLang):
|
|||||||
|
|
||||||
|
|
||||||
def _sl(key):
|
def _sl(key):
|
||||||
return trans[key].values()
|
return _trans[key].values()
|
||||||
|
|||||||
@ -28,19 +28,14 @@ from aqt.utils import showInfo, showText, tooltip
|
|||||||
|
|
||||||
from .constants import Endpoint, Template
|
from .constants import Endpoint, Template
|
||||||
from .context import config
|
from .context import config
|
||||||
from .lang import _, _sl
|
from .lang import _
|
||||||
from .progress import ProgressWindow
|
from .gui import ProgressWindow
|
||||||
from .service import service_manager, service_pool, QueryResult, copy_static_file
|
from .service import service_manager, service_pool, QueryResult, copy_static_file
|
||||||
from .service.base import LocalService
|
from .service.base import LocalService
|
||||||
from .utils import Empty, MapDict, Queue, wrap_css
|
from .utils import Empty, MapDict, Queue, wrap_css
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['QueryThread', 'QueryWorkerManager', 'InvalidWordException',
|
__all__ = ['query_from_browser', 'query_from_editor_all_fields']
|
||||||
'query_from_browser', 'query_from_editor_all_fields',
|
|
||||||
'query_all', 'update_note_fields', 'update_note_field',
|
|
||||||
'promot_choose_css', 'add_to_tmpl', 'strip_combining',
|
|
||||||
'query_all_flds', 'inspect_note'
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def inspect_note(note):
|
def inspect_note(note):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user