I'm building a relatively simple UI using PyQt5. There are a few points in the application that run a process that takes some time, so I have used QApplication.setOverrideCursor to indicate that a process is running.
This is done through this decorator (taken from this question):
def waiting_effects(function):
def new_function(self):
QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
function(self)
QtWidgets.QApplication.restoreOverrideCursor()
return new_function
This works for most of the methods in the UI class except for one:
@waiting_effects
def load_data_folder(self):
folder = QtWidgets.QFileDialog.getExistingDirectory(self)
if folder:
self.clear_plot(name="All")
self.vr_headers = []
self.ls_headers = []
self.df = pvi.import_folder(folder)
if self.df['voltage recording'] is not None:
self.vr_headers = self.df['voltage recording'].columns[1:].tolist()
self.sweeps = self.df['voltage recording'].index.levels[0]
if self.df['linescan'] is not None:
self.ls_headers = self.df['linescan'].columns[1::2].tolist()
if self.df['voltage recording'] is None:
self.sweeps = self.df['linescan'].index.levels[0]
self.ratio_dropdown1.clear()
self.ratio_dropdown2.clear()
for profile in self.ls_headers:
self.ratio_dropdown1.addItem(profile)
self.ratio_dropdown2.addItem(profile)
self.tabWidget.setTabEnabled(2, True)
elif self.tabWidget.isTabEnabled(2):
self.tabWidget.setTabEnabled(2, False)
self.update_treeWidget()
The @waiting_effects decorator in this case does not produce any change in the cursor.
Rather than using the decorator I have tried wrapping the block of code after the QFileDialog with the QApplication.setOverrideCursor, but this has not worked. I.e.:
def load_data_folder(self):
folder = QtWidgets.QFileDialog.getExistingDirectory(self)
QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
if folder:
self.clear_plot(name="All")
self.vr_headers = []
self.ls_headers = []
self.df = pvi.import_folder(folder)
if self.df['voltage recording'] is not None:
self.vr_headers = self.df['voltage recording'].columns[1:].tolist()
self.sweeps = self.df['voltage recording'].index.levels[0]
if self.df['linescan'] is not None:
self.ls_headers = self.df['linescan'].columns[1::2].tolist()
if self.df['voltage recording'] is None:
self.sweeps = self.df['linescan'].index.levels[0]
self.ratio_dropdown1.clear()
self.ratio_dropdown2.clear()
for profile in self.ls_headers:
self.ratio_dropdown1.addItem(profile)
self.ratio_dropdown2.addItem(profile)
self.tabWidget.setTabEnabled(2, True)
elif self.tabWidget.isTabEnabled(2):
self.tabWidget.setTabEnabled(2, False)
self.update_treeWidget()
QtWidgets.QApplication.restoreOverrideCursor()
The slow part of this function is the line:
self.df = pvi.import_folder(folder)
This import_folder is a function from another module I have written that loads the data folders that our acquisition software generates. I have tried wrapping just this line with QApplication.setOverrideCursor, but again that has not produced any effect.
Any thoughts / suggestions on what might be going on here?
Thanks