diff --git a/engine.py b/engine.py index c53d340..d189cd7 100644 --- a/engine.py +++ b/engine.py @@ -185,6 +185,7 @@ def __init__(self, *args, **kwargs): self._qt_app = None self._dcc_app = None self._menu_generator = None + self._event_callbacks = {} Engine.__init__(self, *args, **kwargs) @@ -383,6 +384,23 @@ def process_request(self, method, **kwargs): self.destroy_engine() self. _qt_app.quit() + if method in self._event_callbacks: + self.logger.info("About to run callbacks for %s" % method) + for fn in self._event_callbacks[method]: + self.logger.info(" callback: %s" % fn) + fn(**kwargs) + + def register_event_callback(self, event_type, callback_fn): + if event_type not in self._event_callbacks: + self._event_callbacks[event_type] = [] + self._event_callbacks[event_type].append(callback_fn) + + def unregister_event_callback(self, event_type, callback_fn): + if event_type not in self._event_callbacks: + return + + if callback_fn in self._event_callbacks[event_type]: + self._event_callbacks[event_type].remove(callback_fn) def pre_app_init(self): """ diff --git a/python/tk_substancepainter/application.py b/python/tk_substancepainter/application.py index b265712..4e88c90 100644 --- a/python/tk_substancepainter/application.py +++ b/python/tk_substancepainter/application.py @@ -286,9 +286,37 @@ def get_map_export_information(self): return result def export_document_maps(self, destination): + # This is a trick to wait until the async process of + # exporting textures finishes. + self.__export_results = None + + def run_once_finished_exporting_maps(**kwargs): + self.__export_results = kwargs.get("map_infos", {}) + + self.engine.register_event_callback( + "EXPORT_FINISHED", run_once_finished_exporting_maps + ) + + self.log_debug("Starting map export...") result = self.send_and_receive( "EXPORT_DOCUMENT_MAPS", destination=destination ) + + while self.__export_results is None: + self.log_debug("Waiting for maps to be exported ...") + QCoreApplication.processEvents() + time.sleep(self.wait_period) + + self.engine.unregister_event_callback( + "EXPORT_FINISHED", run_once_finished_exporting_maps + ) + + result = self.__export_results + + # no need for this variable anymore + del self.__export_results + + self.log_debug("Map export ended.") return result def update_document_resources(self, old_url, new_url): diff --git a/resources/plugins/shotgun_bridge/main.qml b/resources/plugins/shotgun_bridge/main.qml index 4282a2e..da0577d 100644 --- a/resources/plugins/shotgun_bridge/main.qml +++ b/resources/plugins/shotgun_bridge/main.qml @@ -467,7 +467,10 @@ PainterPlugin var export_preset = alg.mapexport.getProjectExportPreset(); var export_options = alg.mapexport.getProjectExportOptions(); var export_path = data.destination; - return alg.mapexport.exportDocumentMaps(export_preset, export_path, export_options.fileFormat) + server.sendCommand("EXPORT_STARTED", {}); + var result = alg.mapexport.exportDocumentMaps(export_preset, export_path, export_options.fileFormat) + server.sendCommand("EXPORT_FINISHED", {map_infos:result}); + return true; } function updateDocumentResources(data)