# ---------------------------------------------------------------------------- # Copyright (c) 2019-2020, Diego Garcia Huerta. # # Your use of this software as distributed in this GitHub repository, is # governed by the BSD 3-clause License. # # Your use of the Shotgun Pipeline Toolkit is governed by the applicable license # agreement between you and Autodesk / Shotgun. # # The full license is in the file LICENSE, distributed with this software. # ---------------------------------------------------------------------------- import os from krita import Krita from tank import Hook __author__ = "Diego Garcia Huerta" __contact__ = "https://www.linkedin.com/in/diegogh/" class BreakdownSceneOperations(Hook): """ Breakdown operations for Krita. This implementation handles detection of krita read and write nodes. """ def scan_scene(self): """ The scan scene method is executed once at startup and its purpose is to analyze the current scene and return a list of references that are to be potentially operated on. The return data structure is a list of dictionaries. Each scene reference that is returned should be represented by a dictionary with three keys: - "attr": The filename attribute of the 'node' that is to be operated on. Most DCCs have a concept of a node, attribute, path or some other way to address a particular object in the scene. - "type": The object type that this is. This is later passed to the update method so that it knows how to handle the object. - "path": Path on disk to the referenced object. Toolkit will scan the list of items, see if any of the objects matches any templates and try to determine if there is a more recent version available. Any such versions are then displayed in the UI as out of date. """ # not much to do here for this engine, really. # but it is handy to know what is loaded. # this is a bit dogy, but works, we hide the update # button as it is not needed. app = self.parent engine = app.engine for widget in engine.created_qt_dialogs: if widget._widget._app == app: widget._widget.ui.update.hide() break # Introspect the krita scene for read and write nodes # so we can gather the filenames available. refs = [] krita_app = Krita.instance() documents = krita_app.documents() for doc in documents: ref_path = doc.fileName() if ref_path: refs.append({"node": doc, "type": "file", "path": ref_path}) return refs def update(self, items): """ Perform replacements given a number of scene items passed from the app. Once a selection has been performed in the main UI and the user clicks the update button, this method is called. The items parameter is a list of dictionaries on the same form as was generated by the scan_scene hook above. The path key now holds the that each attribute should be updated *to* rather than the current path. """ pass