Skip to content

Commit

Permalink
Merge branch 'engine_event_callbacks'
Browse files Browse the repository at this point in the history
  • Loading branch information
diegogarciahuerta committed May 13, 2020
2 parents a2450a1 + b75d089 commit 44f2e20
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
18 changes: 18 additions & 0 deletions engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
"""
Expand Down
28 changes: 28 additions & 0 deletions python/tk_substancepainter/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion resources/plugins/shotgun_bridge/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 44f2e20

Please sign in to comment.