fix progress info bugs
This commit is contained in:
parent
774464ca9e
commit
e83be5cde1
@ -25,40 +25,25 @@ class ProgressManager(object):
|
|||||||
self.blockUpdates = False
|
self.blockUpdates = False
|
||||||
self._win = None
|
self._win = None
|
||||||
self._levels = 0
|
self._levels = 0
|
||||||
self.aborted = False
|
|
||||||
self.rows_number = 0
|
|
||||||
self._msg_info = defaultdict(dict)
|
|
||||||
self._msg_count = defaultdict(int)
|
self._msg_count = defaultdict(int)
|
||||||
# Creating progress dialogs
|
# Creating progress dialogs
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
@pyqtSlot(dict)
|
|
||||||
def update_labels(self, data):
|
def update_labels(self, data):
|
||||||
if self.abort():
|
if self.abort():
|
||||||
return
|
return
|
||||||
|
|
||||||
if data.type == 'count':
|
if data.type == 'count':
|
||||||
self._msg_count.update(data)
|
self._msg_count.update(data)
|
||||||
else:
|
else:
|
||||||
self._msg_info[data.index] = data
|
return
|
||||||
|
|
||||||
lst = []
|
|
||||||
for index in range(self.rows_number):
|
|
||||||
info = self._msg_info.get(index, None)
|
|
||||||
if not info:
|
|
||||||
continue
|
|
||||||
if info.type == 'text':
|
|
||||||
lst.append(info.text)
|
|
||||||
else:
|
|
||||||
lst.append(u"{2} [{0}] {1}".format(
|
|
||||||
info.service_name, info.field_name, info.flag))
|
|
||||||
|
|
||||||
number_info = ''
|
number_info = ''
|
||||||
words_number, fields_number, fails_number = (
|
words_number, fields_number, fails_number = (
|
||||||
self._msg_count['words_number'],
|
self._msg_count['words_number'],
|
||||||
self._msg_count['fields_number'],
|
self._msg_count['fields_number'],
|
||||||
self._msg_count['fails_number']
|
self._msg_count['fails_number']
|
||||||
)
|
)
|
||||||
if words_number or fields_number:
|
if words_number or fields_number:
|
||||||
number_info += _('QUERIED') + '<br>' + 45 * '-'
|
number_info += _('QUERIED') + '<br>' + 45 * '-'
|
||||||
number_info += u'<br>{0}: {1}{2}'.format(
|
number_info += u'<br>{0}: {1}{2}'.format(
|
||||||
@ -68,24 +53,17 @@ class ProgressManager(object):
|
|||||||
number_info += u'<br>{0}: {1}{2}'.format(
|
number_info += u'<br>{0}: {1}{2}'.format(
|
||||||
_('FAILURE'), fails_number, _('WORDS'))
|
_('FAILURE'), fails_number, _('WORDS'))
|
||||||
|
|
||||||
self.update('<br>'.join(lst) + number_info, value=words_number)
|
self.update(label=number_info, value=words_number)
|
||||||
self._win.adjustSize()
|
self._win.adjustSize()
|
||||||
|
|
||||||
def update_title(self, title):
|
def update_title(self, title):
|
||||||
self._win.setWindowTitle(title)
|
self._win.setWindowTitle(title)
|
||||||
|
|
||||||
def update_rows(self, number):
|
|
||||||
self.rows_number = number
|
|
||||||
self._msg_info.clear()
|
|
||||||
|
|
||||||
def reset_count(self):
|
def reset_count(self):
|
||||||
self._msg_count.clear()
|
self._msg_count.clear()
|
||||||
|
|
||||||
def start(self, max=0, min=0, label=None, parent=None, immediate=False, rows=0):
|
def start(self, max=0, min=0, label=None, parent=None, immediate=False, rows=0):
|
||||||
self._msg_info.clear()
|
|
||||||
self._msg_count.clear()
|
self._msg_count.clear()
|
||||||
self.rows_number = rows
|
|
||||||
self.aborted = False
|
|
||||||
self._levels += 1
|
self._levels += 1
|
||||||
if self._levels > 1:
|
if self._levels > 1:
|
||||||
return
|
return
|
||||||
|
|||||||
@ -35,13 +35,16 @@ from .progress import ProgressManager
|
|||||||
from .service import service_manager, QueryResult, copy_static_file
|
from .service import service_manager, QueryResult, copy_static_file
|
||||||
from .utils import Empty, MapDict, Queue, wrap_css
|
from .utils import Empty, MapDict, Queue, wrap_css
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def inspect_note(note):
|
def inspect_note(note):
|
||||||
'''
|
"""
|
||||||
inspect the note, and get necessary input parameters
|
inspect the note, and get necessary input parameters
|
||||||
return word_ord: field index of the word in current note
|
return word_ord: field index of the word in current note
|
||||||
return word: the word
|
return word: the word
|
||||||
return maps: dicts map of current note
|
return maps: dicts map of current note
|
||||||
'''
|
"""
|
||||||
|
|
||||||
maps = config.get_maps(note.model()['id'])
|
maps = config.get_maps(note.model()['id'])
|
||||||
for i, m in enumerate(maps):
|
for i, m in enumerate(maps):
|
||||||
if m.get('word_checked', False):
|
if m.get('word_checked', False):
|
||||||
@ -58,8 +61,11 @@ def inspect_note(note):
|
|||||||
word = purify_word(note.fields[word_ord])
|
word = purify_word(note.fields[word_ord])
|
||||||
return word_ord, word, maps
|
return word_ord, word, maps
|
||||||
|
|
||||||
# 工作线程
|
|
||||||
class QueryThread(QThread):
|
class QueryThread(QThread):
|
||||||
|
"""
|
||||||
|
Query Worker Thread
|
||||||
|
"""
|
||||||
|
|
||||||
progress_update = pyqtSignal(dict)
|
progress_update = pyqtSignal(dict)
|
||||||
note_flush = pyqtSignal(object)
|
note_flush = pyqtSignal(object)
|
||||||
@ -87,7 +93,7 @@ class QueryThread(QThread):
|
|||||||
if self.manager:
|
if self.manager:
|
||||||
if self.manager.update(note, results, success_num):
|
if self.manager.update(note, results, success_num):
|
||||||
self.note_flush.emit(note)
|
self.note_flush.emit(note)
|
||||||
# 更新进度
|
# Update progress window infomation
|
||||||
self.progress_update.emit(
|
self.progress_update.emit(
|
||||||
MapDict(
|
MapDict(
|
||||||
type='count',
|
type='count',
|
||||||
@ -99,9 +105,11 @@ class QueryThread(QThread):
|
|||||||
except InvalidWordException:
|
except InvalidWordException:
|
||||||
showInfo(_("NO_QUERY_WORD"))
|
showInfo(_("NO_QUERY_WORD"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class QueryWorkerManager(object):
|
class QueryWorkerManager(object):
|
||||||
|
"""
|
||||||
|
Query Worker Thread Manager
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.workers = []
|
self.workers = []
|
||||||
@ -122,7 +130,6 @@ class QueryWorkerManager(object):
|
|||||||
self.get_worker()
|
self.get_worker()
|
||||||
|
|
||||||
self.total = self.queue.qsize()
|
self.total = self.queue.qsize()
|
||||||
progress.update_rows(len(self.workers))
|
|
||||||
for worker in self.workers:
|
for worker in self.workers:
|
||||||
worker.start()
|
worker.start()
|
||||||
|
|
||||||
@ -169,8 +176,11 @@ def handle_flush(note):
|
|||||||
note.flush()
|
note.flush()
|
||||||
|
|
||||||
|
|
||||||
# 浏览界面查找
|
|
||||||
def query_from_browser(browser):
|
def query_from_browser(browser):
|
||||||
|
"""
|
||||||
|
Query word from Browser
|
||||||
|
"""
|
||||||
|
|
||||||
if not browser:
|
if not browser:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -184,8 +194,12 @@ def query_from_browser(browser):
|
|||||||
query_all(notes)
|
query_all(notes)
|
||||||
browser.model.reset()
|
browser.model.reset()
|
||||||
|
|
||||||
# 编辑界面查找
|
|
||||||
def query_from_editor_all_fields(editor):
|
def query_from_editor_all_fields(editor):
|
||||||
|
"""
|
||||||
|
Query word fileds from Editor
|
||||||
|
"""
|
||||||
|
|
||||||
if not editor or not editor.note:
|
if not editor or not editor.note:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -193,9 +207,12 @@ def query_from_editor_all_fields(editor):
|
|||||||
editor.setNote(editor.note, focus=True)
|
editor.setNote(editor.note, focus=True)
|
||||||
editor.saveNow()
|
editor.saveNow()
|
||||||
|
|
||||||
|
|
||||||
|
def query_all(notes):
|
||||||
|
"""
|
||||||
|
Query maps word fileds
|
||||||
|
"""
|
||||||
|
|
||||||
# 查找所有
|
|
||||||
def query_all(notes):
|
|
||||||
if len(notes) == 0:
|
if len(notes) == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -215,7 +232,12 @@ def query_all(notes):
|
|||||||
work_manager.clean()
|
work_manager.clean()
|
||||||
service_pool.clean();
|
service_pool.clean();
|
||||||
|
|
||||||
|
|
||||||
def update_note_fields(note, results):
|
def update_note_fields(note, results):
|
||||||
|
"""
|
||||||
|
Update query result to note fields, return updated fields count.
|
||||||
|
"""
|
||||||
|
|
||||||
if not results or not note or len(results) == 0:
|
if not results or not note or len(results) == 0:
|
||||||
return
|
return
|
||||||
count = 0
|
count = 0
|
||||||
@ -227,6 +249,10 @@ def update_note_fields(note, results):
|
|||||||
|
|
||||||
|
|
||||||
def update_note_field(note, fld_index, fld_result):
|
def update_note_field(note, fld_index, fld_result):
|
||||||
|
"""
|
||||||
|
Update single field, if result is valid then return 1, else return 0
|
||||||
|
"""
|
||||||
|
|
||||||
result, js, jsfile = fld_result.result, fld_result.js, fld_result.jsfile
|
result, js, jsfile = fld_result.result, fld_result.js, fld_result.jsfile
|
||||||
# js process: add to template of the note model
|
# js process: add to template of the note model
|
||||||
add_to_tmpl(note, js=js, jsfile=jsfile)
|
add_to_tmpl(note, js=js, jsfile=jsfile)
|
||||||
@ -287,7 +313,11 @@ def add_to_tmpl(note, **kwargs):
|
|||||||
class InvalidWordException(Exception):
|
class InvalidWordException(Exception):
|
||||||
"""Invalid word exception"""
|
"""Invalid word exception"""
|
||||||
|
|
||||||
def query_all_flds(note, progress_update=None):
|
def query_all_flds(note):
|
||||||
|
"""
|
||||||
|
Query all fields of single note
|
||||||
|
"""
|
||||||
|
|
||||||
word_ord, word, maps = inspect_note(note)
|
word_ord, word, maps = inspect_note(note)
|
||||||
if not word:
|
if not word:
|
||||||
raise InvalidWordException
|
raise InvalidWordException
|
||||||
@ -315,7 +345,6 @@ def query_all_flds(note, progress_update=None):
|
|||||||
for task in tasks:
|
for task in tasks:
|
||||||
try:
|
try:
|
||||||
service = services.get(task['k'], None)
|
service = services.get(task['k'], None)
|
||||||
service.set_notifier(progress_update, task['i'])
|
|
||||||
qr = service.active(task['f'], task['w'])
|
qr = service.active(task['f'], task['w'])
|
||||||
if qr:
|
if qr:
|
||||||
result.update({task['i']: qr})
|
result.update({task['i']: qr})
|
||||||
@ -329,9 +358,11 @@ def query_all_flds(note, progress_update=None):
|
|||||||
|
|
||||||
return result, success_num
|
return result, success_num
|
||||||
|
|
||||||
# 服务实例对象池
|
|
||||||
class ServicePool(object):
|
class ServicePool(object):
|
||||||
|
"""
|
||||||
|
Service instance pool
|
||||||
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.pools = {}
|
self.pools = {}
|
||||||
|
|
||||||
@ -358,6 +389,6 @@ class ServicePool(object):
|
|||||||
self.pools = {}
|
self.pools = {}
|
||||||
|
|
||||||
|
|
||||||
progress = ProgressManager(mw)
|
progress = ProgressManager(mw) # progress window
|
||||||
work_manager = QueryWorkerManager()
|
work_manager = QueryWorkerManager() # Query Worker Thread Manager
|
||||||
service_pool = ServicePool()
|
service_pool = ServicePool() # Service Instance Pool Manager
|
||||||
|
|||||||
@ -159,33 +159,14 @@ class Service(object):
|
|||||||
# if the service instance is LocalService,
|
# if the service instance is LocalService,
|
||||||
# then have to build then index.
|
# then have to build then index.
|
||||||
if isinstance(self, LocalService):
|
if isinstance(self, LocalService):
|
||||||
self.notify(MapDict(type='text', index=self.work_id,
|
|
||||||
text=u'Building %s...' % self._filename))
|
|
||||||
if isinstance(self, MdxService) or isinstance(self, StardictService):
|
if isinstance(self, MdxService) or isinstance(self, StardictService):
|
||||||
self.builder.check_build()
|
self.builder.check_build()
|
||||||
|
|
||||||
for each in self.exporters:
|
for each in self.exporters:
|
||||||
if action_label == each[0]:
|
if action_label == each[0]:
|
||||||
self.notify(MapDict(type='info', index=self.work_id,
|
return each[1]()
|
||||||
service_name=self.title,
|
|
||||||
field_name=action_label,
|
|
||||||
flag=u'->'))
|
|
||||||
result = each[1]()
|
|
||||||
self.notify(MapDict(type='info', index=self.work_id,
|
|
||||||
service_name=self.title,
|
|
||||||
field_name=action_label,
|
|
||||||
flag=u'√'))
|
|
||||||
return result
|
|
||||||
return QueryResult.default()
|
return QueryResult.default()
|
||||||
|
|
||||||
def set_notifier(self, progress_update, index):
|
|
||||||
self.notify_signal = progress_update
|
|
||||||
self.work_id = index
|
|
||||||
|
|
||||||
def notify(self, data):
|
|
||||||
if self.notify_signal:
|
|
||||||
self.notify_signal.emit(data)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_anki_label(filename, type_):
|
def get_anki_label(filename, type_):
|
||||||
formats = {'audio': u'[sound:{0}]',
|
formats = {'audio': u'[sound:{0}]',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user