Niels
(nLs)
October 10, 2018, 12:39pm
1
The python code in my logic class can take some time to finish its calculations. I would like to add a progress bar in the UI. Is there any way to work with a progressbar info from python?
cpinter
(Csaba Pinter)
October 10, 2018, 1:37pm
2
You can use this convenience function for that
setattr(mbox, key, value)
# Windows 10 peek feature in taskbar shows all hidden but not destroyed windows
# (after creating and closing a messagebox, hovering over the mouse on Slicer icon, moving up the
# mouse to the peek thumbnail would show it again).
# Popup windows in other Qt applications often show closed popups (such as
# Paraview's Edit / Find data dialog, MeshMixer's File/Preferences dialog).
# By calling deleteLater, the messagebox is permanently deleted when the current call is completed.
mbox.deleteLater()
return mbox.exec_()
def createProgressDialog(parent=None, value=0, maximum=100, labelText="", windowTitle="Processing...", **kwargs):
"""Display a modal QProgressDialog. Go to QProgressDialog documentation
http://pyqt.sourceforge.net/Docs/PyQt4/qprogressdialog.html for more keyword arguments, that could be used.
E.g. progressbar = createProgressIndicator(autoClose=False) if you don't want the progress dialog to automatically
close.
Updating progress value with progressbar.value = 50
Updating label text with progressbar.labelText = "processing XYZ"
"""
import qt
progressIndicator = qt.QProgressDialog(parent if parent else mainWindow())
progressIndicator.minimumDuration = 0
See example of usage here
if missingFileCount > 0:
slicer.util.warningDisplay("Warning: %d of %d selected files listed in the database cannot be found on disk."
% (missingFileCount, allFileCount), windowTitle="DICOM")
if missingFileCount == allFileCount:
return loadablesByPlugin, loadEnabled
plugins = self.pluginSelector.selectedPlugins()
progress = slicer.util.createProgressDialog(parent=self, value=0, maximum=len(plugins))
for step, pluginClass in enumerate(plugins):
if not self.pluginInstances.has_key(pluginClass):
self.pluginInstances[pluginClass] = slicer.modules.dicomPlugins[pluginClass]()
plugin = self.pluginInstances[pluginClass]
if progress.wasCanceled:
break
progress.labelText = '\nChecking %s' % pluginClass
slicer.app.processEvents()
progress.setValue(step)
1 Like
Niels
(nLs)
October 11, 2018, 7:39am
3
Thanks! My guess is that updating the progress object from inside the python logic is not good practice right. Do I have stick to widget space for this?
lassoan
(Andras Lasso)
October 11, 2018, 12:27pm
4
In Python scripted modules, we typically add callback functions in the logic class to provide real-time feedback to widget (or any other component that uses the logic class). See for example how it is done in DICOM Patcher module .