def looped(window, *args, **kwargs): if hasattr(linux_native_dialog, 'native_failed'): import importlib m = importlib.import_module('calibre.gui2.qt_file_dialogs') qfunc = getattr(m, 'choose_' + name) return qfunc(window, *args, **kwargs) try: if window is None: return func(window, *args, **kwargs) ret = [None, None] loop = QEventLoop(window) def r(): try: ret[0] = func(window, *args, **kwargs) except: ret[1] = sys.exc_info() while not loop.isRunning(): time.sleep(0.001) # yield so that loop starts loop.quit() t = Thread(name='FileDialogHelper', target=r) t.daemon = True t.start() loop.exec_(QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents) if ret[1] is not None: reraise(*ret[1]) return ret[0] except Exception: linux_native_dialog.native_failed = True import traceback traceback.print_exc() return looped(window, *args, **kwargs)
def __init__(self): QEventLoop.__init__(self) self.dialog_closed.connect(self.exit, type=Qt.ConnectionType.QueuedConnection)