add skip info into progress window.

This commit is contained in:
St.Huang 2018-07-13 11:19:29 +08:00
parent e576d248d6
commit b6b26108c7
3 changed files with 36 additions and 24 deletions

View File

@ -58,6 +58,7 @@ arr = [
['FORCE_UPDATE', u'强制更新字段', u'Force Update Fields'], ['FORCE_UPDATE', u'强制更新字段', u'Force Update Fields'],
['IGNORE_ACCENTS', u'忽略声调', u'Ignore Accents'], ['IGNORE_ACCENTS', u'忽略声调', u'Ignore Accents'],
['SKIP_VALUED', u'跳过有值项', u'Skip Valued'], ['SKIP_VALUED', u'跳过有值项', u'Skip Valued'],
['SKIPED', u'略过', 'Skip'],
['SETTINGS', u'参数', u'Settings'], ['SETTINGS', u'参数', u'Settings'],
['THREAD_NUMBER', u'线程数', u'Thread Number'], ['THREAD_NUMBER', u'线程数', u'Thread Number'],
['INITLIZING_DICT', u'初始化词典...', u'Initlizing Dictionary...'], ['INITLIZING_DICT', u'初始化词典...', u'Initlizing Dictionary...'],

View File

@ -21,10 +21,19 @@
import time import time
from collections import defaultdict from collections import defaultdict
from aqt.qt import * from PyQt4 import QtCore, QtGui
from .lang import _ from .lang import _
INFO_TEMPLATE = u''.join([
_('QUERIED') + u'<br>' + 45 * u'-' + u'<br>',
_('SUCCESS') + u' {} ' + _('WORDS') + u'<br>',
_('SKIPED') + u' {} ' + _('WORDS') + u'<br>',
_('UPDATE') + u' {} ' + _('FIELDS') + u'<br>',
_('FAILURE') + u' {} ' + _('WORDS') + u'<br>'
])
class ProgressWindow(object): class ProgressWindow(object):
""" """
Query progress window Query progress window
@ -32,7 +41,7 @@ class ProgressWindow(object):
def __init__(self, mw): def __init__(self, mw):
self.mw = mw self.mw = mw
self.app = QApplication.instance() self.app = QtGui.QApplication.instance()
self._win = None self._win = None
self._msg_count = defaultdict(int) self._msg_count = defaultdict(int)
@ -45,22 +54,20 @@ class ProgressWindow(object):
else: else:
return return
number_info = '' words_number, fields_number, fails_number, skips_number = (
words_number, fields_number, fails_number = ( self._msg_count.get('words_number', 0),
self._msg_count['words_number'], self._msg_count.get('fields_number', 0),
self._msg_count['fields_number'], self._msg_count.get('fails_number', 0),
self._msg_count['fails_number'] self._msg_count.get('skips_number', 0)
)
number_info = INFO_TEMPLATE.format(
words_number,
skips_number,
fields_number,
fails_number
) )
if words_number or fields_number:
number_info += _('QUERIED') + u'<br>' + 45 * u'-'
number_info += u'<br>{0}: {1} {2}'.format(
_('SUCCESS'), words_number, _('WORDS'))
number_info += u'<br>{0}: {1} {2}'.format(
_('UPDATE'), fields_number, _('FIELDS'))
number_info += u'<br>{0}: {1} {2}'.format(
_('FAILURE'), fails_number, _('WORDS'))
self._update(label=number_info, value=words_number) self._update(label=number_info, value=words_number+skips_number+fails_number)
self._win.adjustSize() self._win.adjustSize()
def update_title(self, title): def update_title(self, title):
@ -73,8 +80,8 @@ class ProgressWindow(object):
# setup window # setup window
label = label or _("Processing...") label = label or _("Processing...")
parent = parent or self.app.activeWindow() or self.mw parent = parent or self.app.activeWindow() or self.mw
self._win = QProgressDialog(label, '', min, max, parent) self._win = QtGui.QProgressDialog(label, '', min, max, parent)
self._win.setWindowModality(Qt.ApplicationModal) self._win.setWindowModality(QtCore.Qt.ApplicationModal)
self._win.setCancelButton(None) self._win.setCancelButton(None)
self._win.canceled.connect(self.finish) self._win.canceled.connect(self.finish)
self._win.setWindowTitle("Querying...") self._win.setWindowTitle("Querying...")
@ -107,12 +114,12 @@ class ProgressWindow(object):
self._counter = value or (self._counter + 1) self._counter = value or (self._counter + 1)
self._win.setValue(self._counter) self._win.setValue(self._counter)
if process and elapsed >= 0.2: if process and elapsed >= 0.2:
self.app.processEvents(QEventLoop.ExcludeUserInputEvents) self.app.processEvents(QtCore.QEventLoop.ExcludeUserInputEvents)
self._lastUpdate = time.time() self._lastUpdate = time.time()
def _setBusy(self): def _setBusy(self):
self._disabled = True self._disabled = True
self.mw.app.setOverrideCursor(QCursor(Qt.WaitCursor)) self.mw.app.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
def _unsetBusy(self): def _unsetBusy(self):
self._disabled = False self._disabled = False

View File

@ -118,6 +118,7 @@ class QueryWorkerManager(object):
self.counter = 0 self.counter = 0
self.fails = 0 self.fails = 0
self.fields = 0 self.fields = 0
self.skips = 0
self.missed_css = list() self.missed_css = list()
def get_worker(self): def get_worker(self):
@ -143,8 +144,10 @@ class QueryWorkerManager(object):
self.mutex.lock() self.mutex.lock()
if success_num > 0: if success_num > 0:
self.counter += 1 self.counter += 1
else: elif success_num == 0:
self.fails += 1 self.fails += 1
else:
self.skips += 1
val = update_note_fields(note, results) val = update_note_fields(note, results)
self.fields += val self.fields += val
self.missed_css += missed_css self.missed_css += missed_css
@ -165,6 +168,7 @@ class QueryWorkerManager(object):
self.progress.update_labels(MapDict( self.progress.update_labels(MapDict(
type='count', type='count',
words_number = self.counter, words_number = self.counter,
skips_number = self.skips,
fails_number = self.fails, fails_number = self.fails,
fields_number = self.fields)) fields_number = self.fields))
mw.app.processEvents() mw.app.processEvents()
@ -370,7 +374,7 @@ def query_all_flds(note):
continue continue
#skip valued #skip valued
skip = each.get('skip_valued', False) skip = each.get('skip_valued', False)
if skip and not note.fields[i]: if skip and len(note.fields[i]) != 0:
continue continue
#normal #normal
dict_name = each.get('dict', '').strip() dict_name = each.get('dict', '').strip()
@ -397,7 +401,7 @@ def query_all_flds(note):
#except: #except:
# showInfo(_("NO_QUERY_WORD")) # showInfo(_("NO_QUERY_WORD"))
# pass # pass
missed_css = list() missed_css = list()
for service in services.values(): for service in services.values():
if isinstance(service, LocalService): if isinstance(service, LocalService):
@ -409,4 +413,4 @@ def query_all_flds(note):
}) })
service_pool.put(service) service_pool.put(service)
return result, success_num, missed_css return result, -1 if len(tasks) == 0 else success_num, missed_css