Skip to content

Commit

Permalink
Add check update to FastWQ menu
Browse files Browse the repository at this point in the history
  • Loading branch information
sth2018 committed Sep 12, 2018
1 parent 6ee8915 commit 2d09d13
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 12 deletions.
5 changes: 5 additions & 0 deletions addons/fastwq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 3 additions & 2 deletions addons/fastwq/gui/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion addons/fastwq/gui/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'''
Expand Down
1 change: 1 addition & 0 deletions addons/fastwq/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
7 changes: 4 additions & 3 deletions addons/fastwq/libs/ankihub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions addons21/fastwq/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 3 additions & 2 deletions addons21/fastwq/gui/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion addons21/fastwq/gui/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'''
Expand Down
1 change: 1 addition & 0 deletions addons21/fastwq/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
7 changes: 4 additions & 3 deletions addons21/fastwq/libs/ankihub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2d09d13

Please sign in to comment.