From e00a3b2a383935fbde1d44c522ad2ee5be0ce9dd Mon Sep 17 00:00:00 2001 From: David Vierra Date: Mon, 30 May 2016 16:04:19 -1000 Subject: [PATCH] Add progress bar to structure export --- src/mcedit2/editorsession.py | 38 +++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/mcedit2/editorsession.py b/src/mcedit2/editorsession.py index 9ea400e..036a1b9 100644 --- a/src/mcedit2/editorsession.py +++ b/src/mcedit2/editorsession.py @@ -1007,22 +1007,28 @@ class EditorSession(QtCore.QObject): self.tr("Structure Block Files") + " (*.nbt)") if result: - filename = result[0] - if filename: - if sx > 1 or sy > 1 or sz > 1: - dirname = os.path.dirname(filename) - basename = os.path.join(dirname, os.path.splitext(os.path.basename(filename))[0]) - for tx in range(sx): - for ty in range(sy): - for tz in range(sz): - tilename = "%s_%s_%s_%s.nbt" % (basename, tx, ty, tz) - origin = self.currentSelection.origin - origin += (tx * 32, ty * 32, tz * 32) - box = BoundingBox(origin, (32, 32, 32)) - tileSelection = box.intersect(self.currentSelection) - exportStructure(tilename, self.currentDimension, tileSelection, author, excludedBlocks) - else: - exportStructure(filename, self.currentDimension, self.currentSelection, author, excludedBlocks) + def _export(): + filename = result[0] + if filename: + if sx > 1 or sy > 1 or sz > 1: + total = sx * sy * sz + dirname = os.path.dirname(filename) + basename = os.path.join(dirname, os.path.splitext(os.path.basename(filename))[0]) + for tx in range(sx): + for ty in range(sy): + for tz in range(sz): + tilename = "%s_%s_%s_%s.nbt" % (basename, tx, ty, tz) + origin = self.currentSelection.origin + origin += (tx * 32, ty * 32, tz * 32) + box = BoundingBox(origin, (32, 32, 32)) + tileSelection = box.intersect(self.currentSelection) + exportStructure(tilename, self.currentDimension, tileSelection, author, excludedBlocks) + yield tx * sy * sz + ty * sz + tz, total, os.path.basename(tilename) + else: + exportStructure(filename, self.currentDimension, self.currentSelection, author, excludedBlocks) + yield 1, 1, os.path.basename(filename) + + showProgress(self.tr("Exporting structure blocks..."), _export()) # --- Drag-and-drop ---