From 2d09d13d809ac1af7fd72091bbd2d5063e8de5ac Mon Sep 17 00:00:00 2001 From: "St.Huang" Date: Wed, 12 Sep 2018 12:28:50 +0800 Subject: [PATCH] Add check update to FastWQ menu --- addons/fastwq/__init__.py | 5 +++++ addons/fastwq/gui/common.py | 5 +++-- addons/fastwq/gui/options.py | 2 +- addons/fastwq/lang.py | 1 + addons/fastwq/libs/ankihub.py | 7 ++++--- addons21/fastwq/common.py | 5 +++++ addons21/fastwq/gui/common.py | 5 +++-- addons21/fastwq/gui/options.py | 2 +- addons21/fastwq/lang.py | 1 + addons21/fastwq/libs/ankihub.py | 7 ++++--- 10 files changed, 28 insertions(+), 12 deletions(-) diff --git a/addons/fastwq/__init__.py b/addons/fastwq/__init__.py index 7c2df4a..79c4f9c 100644 --- a/addons/fastwq/__init__.py +++ b/addons/fastwq/__init__.py @@ -106,6 +106,11 @@ def _show_options(): if b: menu.addSeparator() + # check update + action = QAction(_('CHECK_UPDATE'), browser) + action.triggered.connect(lambda: check_updates(background=False, parent=browser)) + menu.addAction(action) + # About action = QAction(_('ABOUT'), browser) action.triggered.connect(lambda: show_about_dialog(browser)) diff --git a/addons/fastwq/gui/common.py b/addons/fastwq/gui/common.py index 239946f..5684bfe 100644 --- a/addons/fastwq/gui/common.py +++ b/addons/fastwq/gui/common.py @@ -34,10 +34,11 @@ __all__ = ['show_options', 'check_updates', 'show_fm_dialog', 'show_about_dialog'] -def check_updates(background=False): +def check_updates(background=False, parent=None): '''check add-on last version''' try: - state = ankihub.update([Endpoint.check_version], Endpoint.version, background) + parent = mw if parent is None else parent + state = ankihub.update([Endpoint.check_version], Endpoint.version, background, parent) if not background: if state == 0: showInfo(_('LATEST_VERSION')) diff --git a/addons/fastwq/gui/options.py b/addons/fastwq/gui/options.py index 17bf793..7fcab17 100644 --- a/addons/fastwq/gui/options.py +++ b/addons/fastwq/gui/options.py @@ -192,7 +192,7 @@ def show_paras(self): def check_updates(self): '''check addon version''' from .common import check_updates - check_updates() + check_updates(parent=self) def show_fm_dialog(self): '''open folder manager dialog''' diff --git a/addons/fastwq/lang.py b/addons/fastwq/lang.py index 49bf1d4..821fc60 100644 --- a/addons/fastwq/lang.py +++ b/addons/fastwq/lang.py @@ -59,6 +59,7 @@ ['NEW_VERSION', u'检查到新版本:', u'New version available:'], ['UPDATE', u'更新', u'Update'], ['AUTO_UPDATE', u'自动检测新版本', u'Auto check new version'], + ['CHECK_UPDATE', u'检测更新', u'Check Update'], ['IGNORE_MDX_WORDCASE', u'忽略本地词典单词大小写', u'Ignore MDX dictionary word case'], ['FORCE_UPDATE', u'强制更新字段', u'Forced Updates of all fields'], ['IGNORE_ACCENTS', u'忽略声调', u'Ignore Accents'], diff --git a/addons/fastwq/libs/ankihub.py b/addons/fastwq/libs/ankihub.py index f34977f..d94bd9b 100644 --- a/addons/fastwq/libs/ankihub.py +++ b/addons/fastwq/libs/ankihub.py @@ -159,10 +159,11 @@ def callback(appendHtml, onReady): return callback -def update(add=[], VERSION='v0.0.0', background=False): +def update(add=[], VERSION='v0.0.0', background=False, parent=None): + parent = parent if parent else mw # progress win if not background: - progresswin = QProgressDialog('Update Checking...', '', 0, 0, mw) + progresswin = QProgressDialog('Update Checking...', '', 0, 0, parent) progresswin.setWindowModality(Qt.ApplicationModal) progresswin.setCancelButton(None) progresswin.setWindowFlags( @@ -264,7 +265,7 @@ def update(add=[], VERSION='v0.0.0', background=False): if progresswin: progresswin.hide() progresswin.destroy() - dialog = DialogUpdates(None, data, repository, updateSingle(repositories, path, data)) + dialog = DialogUpdates(parent, data, repository, updateSingle(repositories, path, data)) dialog.exec_() dialog.destroy() else: diff --git a/addons21/fastwq/common.py b/addons21/fastwq/common.py index 7c2df4a..79c4f9c 100644 --- a/addons21/fastwq/common.py +++ b/addons21/fastwq/common.py @@ -106,6 +106,11 @@ def _show_options(): if b: menu.addSeparator() + # check update + action = QAction(_('CHECK_UPDATE'), browser) + action.triggered.connect(lambda: check_updates(background=False, parent=browser)) + menu.addAction(action) + # About action = QAction(_('ABOUT'), browser) action.triggered.connect(lambda: show_about_dialog(browser)) diff --git a/addons21/fastwq/gui/common.py b/addons21/fastwq/gui/common.py index 239946f..5684bfe 100644 --- a/addons21/fastwq/gui/common.py +++ b/addons21/fastwq/gui/common.py @@ -34,10 +34,11 @@ __all__ = ['show_options', 'check_updates', 'show_fm_dialog', 'show_about_dialog'] -def check_updates(background=False): +def check_updates(background=False, parent=None): '''check add-on last version''' try: - state = ankihub.update([Endpoint.check_version], Endpoint.version, background) + parent = mw if parent is None else parent + state = ankihub.update([Endpoint.check_version], Endpoint.version, background, parent) if not background: if state == 0: showInfo(_('LATEST_VERSION')) diff --git a/addons21/fastwq/gui/options.py b/addons21/fastwq/gui/options.py index 17bf793..7fcab17 100644 --- a/addons21/fastwq/gui/options.py +++ b/addons21/fastwq/gui/options.py @@ -192,7 +192,7 @@ def show_paras(self): def check_updates(self): '''check addon version''' from .common import check_updates - check_updates() + check_updates(parent=self) def show_fm_dialog(self): '''open folder manager dialog''' diff --git a/addons21/fastwq/lang.py b/addons21/fastwq/lang.py index 49bf1d4..821fc60 100644 --- a/addons21/fastwq/lang.py +++ b/addons21/fastwq/lang.py @@ -59,6 +59,7 @@ ['NEW_VERSION', u'检查到新版本:', u'New version available:'], ['UPDATE', u'更新', u'Update'], ['AUTO_UPDATE', u'自动检测新版本', u'Auto check new version'], + ['CHECK_UPDATE', u'检测更新', u'Check Update'], ['IGNORE_MDX_WORDCASE', u'忽略本地词典单词大小写', u'Ignore MDX dictionary word case'], ['FORCE_UPDATE', u'强制更新字段', u'Forced Updates of all fields'], ['IGNORE_ACCENTS', u'忽略声调', u'Ignore Accents'], diff --git a/addons21/fastwq/libs/ankihub.py b/addons21/fastwq/libs/ankihub.py index 4c9b3a7..b009b84 100644 --- a/addons21/fastwq/libs/ankihub.py +++ b/addons21/fastwq/libs/ankihub.py @@ -160,10 +160,11 @@ def callback(appendHtml, onReady): return callback -def update(add=[], VERSION='v0.0.0', background=False): +def update(add=[], VERSION='v0.0.0', background=False, parent=None): + parent = parent if parent else mw # progress win if not background: - progresswin = QProgressDialog('Update Checking...', '', 0, 0, mw) + progresswin = QProgressDialog('Update Checking...', '', 0, 0, parent) progresswin.setWindowModality(Qt.ApplicationModal) progresswin.setCancelButton(None) progresswin.setWindowFlags( @@ -265,7 +266,7 @@ def update(add=[], VERSION='v0.0.0', background=False): if progresswin: progresswin.hide() progresswin.destroy() - dialog = DialogUpdates(None, data, repository, updateSingle(repositories, path, data)) + dialog = DialogUpdates(parent, data, repository, updateSingle(repositories, path, data)) dialog.exec_() dialog.destroy() else: