Exemplo n.º 1
0
    def execute(self, operation, file_path, **kwargs):
        """
        Main hook entry point

        :operation: String
                    Scene operation to perform

        :file_path: String
                    File path to use if the operation
                    requires it (e.g. open)

        :returns:   Depends on operation:
                    'current_path' - Return the current scene
                                     file path as a String
                    all others     - None
        """
        active_doc = rumba.active_document()

        if operation == "current_path":
            current_project_filename = rumba.active_document_filename()
            return current_project_filename

        elif operation == "open":
            rumba.load_document(file_path)

        elif operation == "save":
            if active_doc:
                current_project_filename = rumba.active_document_filename()
                if current_project_filename != "untitled":
                    active_doc.write(current_project_filename)
Exemplo n.º 2
0
def _session_path():
    """
    Return the path to the current session
    :return:
    """
    path = rumba.active_document_filename()
    if path == "untitled":
        path = None

    return path
Exemplo n.º 3
0
    def _on_active_doc_timer(self):
        """
        Refresh the engine if the current document has changed since the last
        time we checked.
        """
        active_document_filename = rumba.active_document_filename()
        if not os.path.exists(active_document_filename):
            return

        if os.path.abspath(self.active_document_filename) != active_document_filename:
            self.logger.debug(
                "Active document changed from: %s to: %s"
                % (self.active_document_filename, active_document_filename)
            )
            self.active_document_filename = os.path.abspath(active_document_filename)
            refresh_engine()
Exemplo n.º 4
0
def refresh_engine():
    """
    refresh the current engine
    """

    logger.debug("Refreshing the engine")

    engine = tank.platform.current_engine()

    if not engine:
        # If we don't have an engine for some reason then we don't have
        # anything to do.
        logger.debug(
            "%s Refresh_engine | No currently initialized engine found; aborting the refresh of the engine\n"
            % APPLICATION_NAME
        )
        return

    active_doc_path = None
    active_doc = rumba.active_document()
    if active_doc:
        # determine the tk instance and context to use:
        active_doc_path = rumba.active_document_filename()

    if not active_doc_path:
        logger.debug("File has not been saved yet, aborting the refresh of the engine.")
        return

    # make sure path is normalized
    active_doc_path = os.path.abspath(active_doc_path)

    # we are going to try to figure out the context based on the
    # active document
    current_context = tank.platform.current_engine().context

    ctx = current_context

    # this file could be in another project altogether, so create a new
    # API instance.
    try:
        # and construct the new context for this path:
        tk = tank.sgtk_from_path(active_doc_path)
        logger.debug(
            "Extracted sgtk instance: '%r' from path: '%r'", tk, active_doc_path
        )

    except tank.TankError:
        # could not detect context from path, will use the project context
        # for menus if it exists
        message = (
            "Shotgun %s Engine could not detect the context\n"
            "from the active document. Shotgun menus will be  \n"
            "stay in the current context '%s' "
            "\n" % (APPLICATION_NAME, ctx)
        )
        display_warning(message)
        return

    ctx = tk.context_from_path(active_doc_path, current_context)
    logger.debug(
        "Given the path: '%s' the following context was extracted: '%r'",
        active_doc_path,
        ctx,
    )

    # default to project context in worse case scenario
    if not ctx:
        project_name = engine.context.project.get("name")
        ctx = tk.context_from_entity_dictionary(engine.context.project)
        logger.debug(
            (
                "Could not extract a context from the current active project "
                "path, so we revert to the current project '%r' context: '%r'"
            ),
            project_name,
            ctx,
        )

    # Only change if the context is different
    if ctx != current_context:
        try:
            engine.change_context(ctx)
        except tank.TankError:
            message = (
                "Shotgun %s Engine could not change context\n"
                "to '%r'. Shotgun menu will be disabled!.\n"
                "\n" % (APPLICATION_NAME, ctx)
            )
            display_warning(message)
            engine.create_shotgun_menu(disabled=True)
Exemplo n.º 5
0
    def execute(self, operation, file_path, context, parent_action,
                file_version, read_only, **kwargs):
        """
        Main hook entry point

        :param operation:       String
                                Scene operation to perform

        :param file_path:       String
                                File path to use if the operation
                                requires it (e.g. open)

        :param context:         Context
                                The context the file operation is being
                                performed in.

        :param parent_action:   This is the action that this scene operation is
                                being executed for.  This can be one of:
                                - open_file
                                - new_file
                                - save_file_as
                                - version_up

        :param file_version:    The version/revision of the file to be opened.  If this is 'None'
                                then the latest version should be opened.

        :param read_only:       Specifies if the file should be opened read-only or not

        :returns:               Depends on operation:
                                'current_path' - Return the current scene
                                                 file path as a String
                                'reset'        - True if scene was reset to an empty
                                                 state, otherwise False
                                all others     - None
        """
        active_doc = rumba.active_document()

        if operation == "current_path":
            current_project_filename = rumba.active_document_filename()
            return current_project_filename

        elif operation == "open":
            rumba.load_document(file_path)

        elif operation == "save":
            if active_doc:
                current_project_filename = rumba.active_document_filename()
                if current_project_filename != "untitled":
                    active_doc.write(current_project_filename)

        elif operation == "save_as":
            if active_doc:
                main_window = rumbapy.widget("MainWindow")
                main_window.save_at(file_path)

        elif operation == "reset":
            if active_doc:
                rumba.new_document()
            return True

        elif operation == "prepare_new":
            rumba.new_document()
            return True