block gui updates while painting browser rows

If we processEvents() in the middle of a QItemDelegate, the recursion can
cause a crash on some OSes
This commit is contained in:
Damien Elmes 2013-01-29 06:45:29 +09:00
parent f54c2f7835
commit 0055d31d04
2 changed files with 8 additions and 2 deletions

View file

@ -296,15 +296,19 @@ class StatusDelegate(QItemDelegate):
def __init__(self, browser, model): def __init__(self, browser, model):
QItemDelegate.__init__(self, browser) QItemDelegate.__init__(self, browser)
self.browser = browser
self.model = model self.model = model
def paint(self, painter, option, index): def paint(self, painter, option, index):
self.browser.mw.progress.blockUpdates = True
try: try:
c = self.model.getCard(index) c = self.model.getCard(index)
except: except:
# in the the middle of a reset; return nothing so this row is not # in the the middle of a reset; return nothing so this row is not
# rendered until we have a chance to reset the model # rendered until we have a chance to reset the model
return return
finally:
self.browser.mw.progress.blockUpdates = True
col = None col = None
if c.note().hasTag("Marked"): if c.note().hasTag("Marked"):
col = COLOUR_MARKED col = COLOUR_MARKED

View file

@ -18,6 +18,7 @@ class ProgressManager(object):
self.mw = mw self.mw = mw
self.app = QApplication.instance() self.app = QApplication.instance()
self.inDB = False self.inDB = False
self.blockUpdates = False
self._win = None self._win = None
self._levels = 0 self._levels = 0
@ -49,8 +50,9 @@ Your pysqlite2 is too old. Anki will appear frozen during long operations."""
# ensure timers don't fire # ensure timers don't fire
self.inDB = True self.inDB = True
# handle GUI events # handle GUI events
self._maybeShow() if not self.blockUpdates:
self.app.processEvents(QEventLoop.ExcludeUserInputEvents) self._maybeShow()
self.app.processEvents(QEventLoop.ExcludeUserInputEvents)
self.inDB = False self.inDB = False
# DB-safe timers # DB-safe timers