Ejemplo n.º 1
0
    def destroy_menu(self):
        """"
        Clears sgtk menu.
        """

        sgtk_menu = [("", [("_", None)])]
        commands.defineModeMenu(self._toolkit_rv_mode_name, sgtk_menu)
Ejemplo n.º 2
0
    def license_state_transition(self, event):
        event.reject()

        if rvc.licensingState() == 2 and self.licensing_style == "shotgun":
            # If we can't reach Shotgun server, don't bother trying to initialize toolkit.
            if self.event_queue:
                if "Offline usage" in event.contents():
                    sys.stderr.write(
                        "INFO: Offline, so not initilizing Shotgun Toolkit\n")
                    msg = "Shotgun Offline ..."
                    rve.displayFeedback2(msg, 2.0)
                if not self.toolkit_initialized:
                    self.init_and_process_events()

            elif not "RV_SHOTGUN_NO_SG_REVIEW_MENU" in os.environ:
                # No events queued, so build Stand-in menu (IE don't initialize toolkit until we must)
                modeMenu = [("SG Review", [
                    ("_", None),
                    ("Get Help ...", self.get_help, None,
                     lambda: rvc.UncheckedMenuState),
                    ("_", None),
                    ("Launch Media App", self.launch_media_app, None,
                     lambda: rvc.UncheckedMenuState),
                    ("_", None),
                    ("Submit Tool", self.queue_launch_submit_tool, None,
                     lambda: rvc.UncheckedMenuState),
                    ("_", None),
                    ("Import Cut", self.queue_launch_import_cut_app, None,
                     lambda: rvc.UncheckedMenuState),
                    ("_", None),
                    ("Initialize Shotgun", self.initialize_shotgun, None,
                     lambda: rvc.UncheckedMenuState),
                    ("_", None),
                ])]
                rvc.defineModeMenu(self._modeName, modeMenu)

                # We need url for some of these menu items
                (url, login, token) = self.get_default_rv_auth_session()
                self.server_url = url.encode("utf-8")
Ejemplo n.º 3
0
    def create_menu(self, *args):
        """
        Render the entire SGTK menu.
        """

        # handle used to hold list of menu items
        self._menu_handle = []

        # clear sgtk menu
        sgtk_menu = [(self._menu_name, [("_", None)])]
        commands.defineModeMenu(self._toolkit_rv_mode_name, sgtk_menu)

        # add context submenu
        self._context_menu = self._add_context_menu()
        self._menu_handle.append(self._context_menu)

        # add separator
        separator_item = ("_", None)
        self._menu_handle.append(separator_item)

        # create menu item for each command
        menu_items = []
        for (cmd_name, cmd_details) in self._engine.commands.items():
            menu_items.append(AppCommand(cmd_name, cmd_details))

        # sort list of commands in name order
        menu_items.sort(key=lambda x: x.name)

        # add favourites to the menu
        for fav in self._engine.get_setting("menu_favourites", []):
            app_instance_name = fav["app_instance"]
            menu_name = fav["name"]
            for cmd in menu_items:
                if cmd.get_app_instance_name() == app_instance_name and cmd.name == menu_name:
                    menu_item = cmd.define_menu_item()
                    self._menu_handle.append(menu_item)
                    cmd.favourite = True

        # add separator
        self._menu_handle.append(separator_item)

        # separate menu items out into various sections
        commands_by_app = {}
        for cmd in menu_items:
            if cmd.get_type() == "context_menu":
                menu_item = cmd.define_menu_item()
                self._context_menu[1].append(menu_item)
            else:
                app_name = cmd.get_app_name()
                if app_name is None:
                    app_name = "Other Items"
                if not app_name in commands_by_app:
                    commands_by_app[app_name] = []
                menu_item = cmd.define_menu_item()
                commands_by_app[app_name].append(menu_item)

        # add app-specific menus to the menu handle
        for menu_name, menu_items in commands_by_app.iteritems():
            self._menu_handle.append((menu_name, menu_items))

        # update sgtk menu
        sgtk_menu = [(self._menu_name, self._menu_handle)]
        commands.defineModeMenu(self._toolkit_rv_mode_name, sgtk_menu)
Ejemplo n.º 4
0
    def initialize_toolkit(self):
        try:
            # Clear the "stand-in" mode menu, and let the apps rebuild it
            modeMenu = [("SG Review", None)]
            rvc.defineModeMenu(self._modeName, modeMenu)

            startTime = rvc.theTime()
            bundle_cache_dir = os.path.join(sgtk_dist_dir(), "bundle_cache")

            core = os.path.join(bundle_cache_dir, "manual", "tk-core",
                                "v1.0.43")
            core = os.environ.get("RV_TK_CORE") or core

            # append python path to get to the actual code
            core = os.path.join(core, "python")

            log.info("Looking for tk-core here: %s" % str(core))

            # now we can kick off sgtk
            sys.path.insert(0, core)
            sys.stderr.write(
                "INFO: Toolkit initialization: ready to import sgtk at %g sec.\n"
                % (rvc.theTime() - startTime))

            # import bootstrapper
            import sgtk
            sys.stderr.write(
                "INFO: Toolkit initialization: sgtk import complete at %g sec.\n"
                % (rvc.theTime() - startTime))

            # begin logging the toolkit log tree file
            sgtk.LogManager().initialize_base_file_handler("tk-rv")

            # import authentication code
            from sgtk_auth import get_toolkit_user

            # allow dev to override log level
            log_level = logging.WARNING
            if (os.environ.has_key("RV_TK_LOG_DEBUG")):
                log_level = logging.DEBUG

            # bind toolkit logging to our logger
            sgtk.LogManager().initialize_custom_handler(log_handler)
            # and set the level
            log_handler.setLevel(log_level)

            # Get an authenticated user object from rv's security architecture
            (user, url) = get_toolkit_user()
            self.server_url = url
            log.info("Will connect using %r" % user)

            # Now do the bootstrap!
            log.debug("Ready for bootstrap!")
            mgr = sgtk.bootstrap.ToolkitManager(user)
            sys.stderr.write(
                "INFO: Toolkit initialization: ToolkitManager complete at %g sec.\n"
                % (rvc.theTime() - startTime))

            # In disted code, by default, all TK code is read from the
            # 'bundle_cache' baked during the build process.
            mgr.bundle_cache_fallback_paths = [bundle_cache_dir]

            dev_config = os.environ.get("RV_TK_DEV_CONFIG")

            if (dev_config):
                # Use designated developer's tk-config-rv instead of disted one.
                mgr.base_configuration = dict(
                    type="dev",
                    path=dev_config,
                )
            else:
                mgr.base_configuration = dict(
                    type="manual",
                    name="tk-config-rv",
                    version="v1.0.43",
                )

            # tell the bootstrap API that we don't want to
            # allow for overrides from Shotgun
            mgr.do_shotgun_config_lookup = False

            # define the entry point for this plugin in
            # order to sandbox it relative to other plugins
            mgr.entry_point = "rv_review"

            # Bootstrap the tk-rv engine into an empty context!
            mgr.bootstrap_engine("tk-rv")
            log.debug("Bootstrapping process complete!")

            self.toolkit_initialized = True
            sys.stderr.write("INFO: Toolkit initialization took %g sec.\n" %
                             (rvc.theTime() - startTime))

        except Exception, e:
            sys.stderr.write(
                "ERROR: Toolkit initialization failed.  Please authenticate RV with your Shotgun server and restart.\n"
                + "**********************************\n")
            traceback.print_exc(None, sys.stderr)
            sys.stderr.write("**********************************\n")
            rve.displayFeedback2("", 0.1)