showProgress does eight iterations before showing the progress dialog

This commit is contained in:
David Vierra 2015-02-08 09:23:34 -10:00
parent c8c577f63f
commit 97d4cb0e6a
3 changed files with 44 additions and 34 deletions

View File

@ -140,11 +140,7 @@ class Fill(BrushMode):
:type command: BrushCommand
"""
fill = command.editorSession.currentDimension.fillBlocksIter(selections[0], command.blockInfo)
if selections[0].chunkCount > 32:
showProgress("Applying brush...", fill)
else:
for _ in fill:
pass
showProgress("Applying brush...", fill)
class BrushModes(object):

View File

@ -9,6 +9,7 @@ from mcedit2.util.worldloader import LoaderTimer
log = logging.getLogger(__name__)
itersBeforeDialog = 8
def showProgress(text, iter, cancel=False):
"""
@ -23,38 +24,43 @@ def showProgress(text, iter, cancel=False):
:return:
:rtype:
"""
from mcedit2 import editorapp
dialog = QtGui.QProgressDialog(editorapp.MCEditApp.app.mainWindow)
dialog.setWindowTitle(text)
dialog.setWindowModality(Qt.WindowModal)
dialog.show()
progress = None
LoaderTimer.stopAll()
for progress in iter:
if isinstance(progress, basestring):
max = current = 0
status = progress
elif isinstance(progress, (tuple, list)):
if len(progress) > 2:
current, max, status = progress[:3]
else:
current, max = progress
status = ""
i = 0
with LoaderTimer.stopCtx():
for progress in iter:
i += 1
if i > itersBeforeDialog:
break
else:
current = max = 1
status = ""
return progress
dialog.setValue(current)
dialog.setMaximum(max)
dialog.setLabelText(status)
QtGui.QApplication.processEvents()
if dialog.wasCanceled():
return False
dialog = QtGui.QProgressDialog(QtGui.qApp.mainWindow)
dialog.setWindowTitle(text)
dialog.setWindowModality(Qt.WindowModal)
dialog.show()
LoaderTimer.startAll()
dialog.close()
return progress
for progress in iter:
if isinstance(progress, basestring):
max = current = 0
status = progress
elif isinstance(progress, (tuple, list)):
if len(progress) > 2:
current, max, status = progress[:3]
else:
current, max = progress
status = ""
else:
current = max = 1
status = ""
dialog.setValue(current)
dialog.setMaximum(max)
dialog.setLabelText(status)
QtGui.QApplication.processEvents()
if dialog.wasCanceled():
return False
dialog.close()
return progress

View File

@ -2,6 +2,7 @@
${NAME}
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import contextlib
import logging
import weakref
from PySide import QtCore
@ -16,6 +17,13 @@ class LoaderTimer(QtCore.QTimer):
super(LoaderTimer, self).__init__(*args, **kwargs)
_loaderTimers.append(weakref.ref(self))
@classmethod
@contextlib.contextmanager
def stopCtx(cls):
cls.stopAll()
yield
cls.startAll()
@staticmethod
def stopAll():
for ref in _loaderTimers: