def threadFunctionDialog(worker_fun, worker_fun_args, close_after_finish=True, buttons=None, title='', text=None, center_by_window=None): """ Executes worker_fun function inside a thread. Function provides a dialog for UI feedback (messages and/or progressbar). :param worker_fun: user's method/function to be executed inside a thread :param worker_fun_args: argumets passed to worker_fun :param close_after_finish: True, if a dialog is to be closed after finishing worker_fun :param buttons: list of dialog button definitions; look at doc od whd_thread_fun.Ui_ThreadFunDialog class :return: value returned from worker_fun """ ui = ThreadFunDlg(worker_fun, worker_fun_args, close_after_finish, buttons=buttons, title=title, text=text, center_by_window=center_by_window) ui.exec_() ret = ui.getResult() ret_exception = ui.worker_exception del ui if ret_exception: # if there was an exception in the worker function, pass it to the caller raise ret_exception return ret
def run_thread_dialog(worker_fun: Callable[[CtrlObject, Any], Any], worker_fun_args: Tuple[Any, ...], close_after_finish=True, buttons=None, title='', text=None, center_by_window=None): """ Executes worker_fun function inside a thread. Function provides a dialog for UI feedback (messages and/or progressbar). :param worker_fun: user's method/function to be executed inside a thread :param worker_fun_args: argumets passed to worker_fun :param close_after_finish: True, if a dialog is to be closed after finishing worker_fun :param buttons: list of dialog button definitions; look at doc od whd_thread_fun.Ui_ThreadFunDialog class :return: value returned from worker_fun """ ui = ThreadFunDlg(worker_fun, worker_fun_args, close_after_finish, buttons=buttons, title=title, text=text, center_by_window=center_by_window) ui.exec_() ret = ui.getResult() ret_exception = ui.worker_exception del ui QtWidgets.qApp.processEvents( QEventLoop.ExcludeUserInputEvents) # wait until dialog hides if ret_exception: # if there was an exception in the worker function, pass it to the caller raise ret_exception return ret