def __init__(self, application): # We need the application to send posted events. We hold a reference # to any dialogs to ensure that they don't get garbage collected # (and thus close in the process). The reference count for this object # will go to zero when it removes itself from Houdini's event loop. self.application = application self.event_loop = QtCore.QEventLoop()
def render_and_submit(self, template, fields, first_frame, last_frame, sg_publishes, sg_task, comment, thumbnail_path, progress_cb): """ Main application entry point to be called by other applications / hooks. :template: SGTK Template object. The template defining the path where frames should be found. :fields: Fields to be used to fill out the template with. :first_frame: int. The first frame of the sequence of frames. :last_frame: int. The last frame of the sequence of frames. :sg_publishes: A list of shotgun published file objects to link the publish against. :sg_task: A Shotgun task object to link against. Can be None. :comment: str. A description to add to the Version in Shotgun. Returns the Version that was created in Shotgun. """ # Is the app configured to do anything? upload_to_shotgun = self.get_setting("upload_to_shotgun") store_on_disk = self.get_setting("store_on_disk") if not upload_to_shotgun and not store_on_disk: self.log_warning( "App is not configured to store images on disk nor upload to shotgun!" ) return None progress_cb(10, "Preparing") # Make sure we don't overwrite the caller's fields fields = copy.copy(fields) # Tweak fields so that we'll be getting nuke formated sequence markers (%03d, %04d etc): for key_name in [ key.name for key in template.keys.values() if isinstance(key, tank.templatekey.SequenceKey) ]: fields[key_name] = "FORMAT: %d" # Get our input path for frames to convert to movie path = template.apply_fields(fields) # Movie output width and height width = self.get_setting("movie_width") height = self.get_setting("movie_height") fields["width"] = width fields["height"] = height # Get an output path for the movie. output_path_template = self.get_template("movie_path_template") output_path = output_path_template.apply_fields(fields) # Render and Submit progress_cb(20, "Rendering movie") self._render_movie_in_nuke(fields, path, output_path, width, height, first_frame, last_frame) progress_cb(50, "Creating Shotgun Version") sg_version = self._submit_version(path, output_path, sg_publishes, sg_task, comment, store_on_disk, first_frame, last_frame) # Upload in a new thread and make our own event loop to wait for the # thread to finish. progress_cb(60, "Uploading to Shotgun") event_loop = QtCore.QEventLoop() thread = UploaderThread(self, sg_version, output_path, thumbnail_path, upload_to_shotgun) thread.finished.connect(event_loop.quit) thread.start() event_loop.exec_() # log any errors generated in the thread for e in thread.get_errors(): self.log_error(e) # Remove from filesystem if required if not store_on_disk and os.path.exists(output_path): os.unlink(output_path) return sg_version