Ejemplo n.º 1
0
    def init_qt_app(self):
        """
        Initializes if not done already the QT Application for the engine.
        """
        from sgtk.platform.qt import QtGui

        self.logger.debug("Initializing QT Application for the engine")

        if not QtGui.QApplication.instance():
            self._qt_app = QtGui.QApplication(sys.argv)
        else:
            self._qt_app = QtGui.QApplication.instance()

        # set icon for the engine windows
        self._qt_app.setWindowIcon(QtGui.QIcon(self.icon_256))

        self._qt_app_main_window = QtGui.QMainWindow()
        self._qt_app_central_widget = QtGui.QWidget()
        self._qt_app_main_window.setCentralWidget(self._qt_app_central_widget)
        self._qt_app.setQuitOnLastWindowClosed(False)

        # Make the QApplication use the dark theme. Must be called after the
        # QApplication is instantiated
        self._initialize_dark_look_and_feel()

        self.logger.debug("QT Application: %s" % self._qt_app)
Ejemplo n.º 2
0
    def init_qt_app(self):
        """
        Initialize QT application.
        """
        from sgtk.platform.qt import QtGui

        self.logger.debug("%s: Initializing QtApp", self)

        # Get current instance
        instance = QtGui.QApplication.instance()

        # Create instance
        if not instance:
            self._qt_app = QtGui.QApplication(sys.argv)
            self._qt_app.setQuitOnLastWindowClosed(False)
            self.logger.info("Created QApplication instance: {0}".format(
                self._qt_app))

            def _app_quit():
                QtGui.QApplication.processEvents()

            QtGui.QApplication.instance().aboutToQuit.connect(_app_quit)
        # Use current instance
        else:
            self._qt_app = instance

        # Make the QApplication use the dark theme. Must be called after the QApplication is instantiated
        self._initialize_dark_look_and_feel()
    def setUp(self):
        """
        Fixtures setup
        """
        os.environ["PUBLISH2_API_TEST"] = "1"
        repo_root = os.path.normpath(
            os.path.join(os.path.dirname(__file__), "..", ".."))

        os.environ["REPO_ROOT"] = repo_root

        super(PublishApiTestBase, self).setUp()
        self.setup_fixtures()

        # set up an environment variable that points to the root of the
        # framework so we can specify its location in the environment fixture

        self.framework_root = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "..", "..", ".."))
        os.environ["APP_ROOT"] = self.framework_root

        # Add these to mocked shotgun
        self.add_to_sg_mock_db([self.project])

        # now make a context
        context = self.tk.context_from_entity(self.project["type"],
                                              self.project["id"])

        # and start the engine
        self.engine = sgtk.platform.start_engine("tk-shell", self.tk, context)

        self.app = self.engine.apps["tk-multi-publish2"]

        self.manager = self.app.create_publish_manager()

        self.api = self.app.import_module("tk_multi_publish2").api
        self.PublishData = self.api.PublishData
        self.PublishItem = self.api.PublishItem
        self.PublishTree = self.api.PublishTree
        self.PublishManager = self.api.PublishManager
        self.PublishPluginInstance = self.api.plugins.PublishPluginInstance

        publish_tree_widget = self.app.import_module(
            "tk_multi_publish2").publish_tree_widget
        self.PublishTreeWidget = publish_tree_widget.PublishTreeWidget

        self.image_path = os.path.join(repo_root, "icon_256.png")
        self.dark_image_path = os.path.join(repo_root, "icon_256_dark.png")

        # Local import since the QtGui module is set only after engine startup.
        from sgtk.platform.qt import QtCore, QtGui

        self.QtGui = QtGui
        self.QtCore = QtCore

        # Instantiate the QApplication singleton if missing.
        if QtGui.QApplication.instance() is None:
            QtGui.QApplication([])

        self.image = QtGui.QPixmap(self.image_path)
Ejemplo n.º 4
0
    def pre_app_init(self):
        from sgtk.platform.qt import QtCore, QtGui

        if not QtCore.QCoreApplication.instance():
            # WARNING: need to keep a python reference to
            # the qt app, or python will destroy it and
            # ruin everything
            self._qt_app = QtGui.QApplication([])
            self._initialize_dark_look_and_feel()
            tde4.setTimerCallbackFunction(
                "sgtk.platform.current_engine()._heartbeat",
                HEARTBEAT_INTERVAL_MS,
            )
Ejemplo n.º 5
0
    def _initialise_qapplication(self):
        """
        Ensure the QApplication is initialized
        """
        from sgtk.platform.qt import QtGui

        qt_app = QtGui.QApplication.instance()
        if qt_app is None:
            self.log_debug("Initialising main QApplication...")
            qt_app = QtGui.QApplication([])
            qt_app.setWindowIcon(QtGui.QIcon(self.icon_256))
            qt_app.setQuitOnLastWindowClosed(False)

            # set up the dark style
            self._initialize_dark_look_and_feel()
Ejemplo n.º 6
0
    def _initialise_qapplication(self):
        """
        Ensure the QApplication is initialized
        """
        from sgtk.platform.qt import QtGui

        self._qt_app = QtGui.QApplication.instance()
        if self._qt_app is None:
            self.log_debug("Initialising main QApplication...")
            self._qt_app = QtGui.QApplication(sys.argv)
            self._qt_app.setWindowIcon(QtGui.QIcon(self.icon_256))
            self._qt_app.setQuitOnLastWindowClosed(True)

            # set up the dark style
            self._initialize_dark_look_and_feel()
            self._qt_app.aboutToQuit.connect(self._qt_app.deleteLater)
Ejemplo n.º 7
0
def bootstrap(root_path, port, engine_name, app_id):
    """
    Main entry point for adobe rpc python process.

    Blocking method. Launches a QT Application event loop.

    :param root_path: The path to the plugin on disk
    :param port: The communication port to use
    :param engine_name: The engine instance name <--- @todo - not needed?
    :param app_id: The application id
    """
    # first add our plugin python logic sys.path
    sys.path.insert(0, os.path.join(get_extension_install_directory(), "python"))
    sys.path.insert(0, root_path)
    import tk_framework_adobe

    # set the port in the env so that the engine can pick it up. this also
    # allows engine restarts to find the proper port.
    os.environ["SHOTGUN_ADOBE_PORT"] = port

    # set the application id in the environment. This will allow the engine
    # to know what host runtime it's in -- Photoshop, AE, etc.
    os.environ["SHOTGUN_ADOBE_APPID"] = app_id

    # do the toolkit bootstrapping. this will replace the core imported via the
    # sys path with the one specified via the resolved config. it will startup
    # the engine and make Qt available to us.
    if os.environ.get("TANK_CONTEXT") and os.environ.get("TANK_ENGINE"):
        tk_framework_adobe.toolkit_classic_bootstrap()

    else:
        tk_framework_adobe.toolkit_plugin_bootstrap(root_path)

    # core may have been swapped. import sgtk
    import sgtk

    # get a handle on the newly bootstrapped engine
    engine = sgtk.platform.current_engine()

    from sgtk.platform.qt import QtGui
    from sgtk.platform.engine_logging import ToolkitEngineHandler

    app_name = "ShotGrid Framework for Adobe CC"

    # create and set up the Qt app. we don't want the app to close when the
    # last window is shut down since it's running in parallel to the CC product.
    # We'll manage shutdown
    app = QtGui.QApplication([app_name])

    # the icon that will display for the python process in the dock/task bar
    app_icon = QtGui.QIcon(os.path.join(root_path, "icon_256.png"))

    # set up the QApplication
    app.setApplicationName(app_name)
    app.setWindowIcon(app_icon)
    app.setQuitOnLastWindowClosed(False)

    # some operations can't be done until a qapplication exists.
    engine.post_qt_init()

    # log metrics for the app name and version
    host_info = engine.host_info
    engine.log_user_attribute_metric(
        "%s Version" % host_info["name"], host_info["version"]
    )

    # debug logging for the app name/version as well
    engine.logger.debug("Adobe CC Product: %s" % host_info["name"])
    engine.logger.debug("Adobe CC Version: %s" % host_info["version"])

    # once the event loop starts, the bootstrap process is complete and
    # everything should be connected. this is a blocking call, so nothing else
    # can happen afterward.
    engine.logger.debug("Starting Qt event loop...")

    # Note: Qt exits the event loop when the process receives a TERM signal which
    # is sent by the parent process when leaving Photoshop or restarting the
    # integration.
    ret = app.exec_()
    # We need to remove the engine log handler which tries to send back messages
    # to Photoshop either through a socket or stdout: we have no guarantee that
    # any of those is still open when Photoshop is quitting and any message send
    # through those will make our Python process hang.
    root_logger = sgtk.LogManager().root_logger
    handlers = list(root_logger.handlers)
    while handlers:
        handler = handlers.pop()
        if isinstance(handler, ToolkitEngineHandler):
            root_logger.removeHandler(handler)
    # Destroy the engine which will stop any background thread that was started.
    engine.logger.debug("Shutting down engine")
    engine.destroy_engine()
    engine.logger.debug("Exiting process...")
    # FiXME: Temp workaround for Shotgun-utils BackgroundTaskManager thread not
    # being joined on shutdown: if we exit immediately we will get some
    # "QThread: Destroyed while thread is still running" errors which can lead to
    # crashes. Until this problem is fixed (#46207) we give the thread a chance
    # to exit its exec loop by sleeping a couple of seconds.
    import time

    time.sleep(2)
    sys.exit(ret)
Ejemplo n.º 8
0
def bootstrap(root_path, port, engine_name, app_id):
    """
    Main entry point for photoshop python process.

    Blocking method. Launches a QT Application event loop.

    :param root_path: The path to the plugin on disk
    :param port: The communication port to use
    :param engine_name: The engine instance name <--- @todo - not needed?
    :param app_id: The application id
    """
    # first add our plugin python logic sys.path
    plugin_python_path = os.path.join(root_path, "python")
    sys.path.insert(0, plugin_python_path)
    import tk_photoshopcc_basic

    # set the port in the env so that the engine can pick it up. this also
    # allows engine restarts to find the proper port.
    os.environ["SHOTGUN_ADOBE_PORT"] = port

    # set the application id in the environment. This will allow the engine
    # to know what host runtime it's in -- Photoshop, AE, etc.
    os.environ["SHOTGUN_ADOBE_APPID"] = app_id

    # do the toolkit bootstrapping. this will replace the core imported via the
    # sys path with the one specified via the resolved config. it will startup
    # the engine and make Qt available to us.
    if os.environ.get("TANK_CONTEXT") and os.environ.get("TANK_ENGINE"):
        tk_photoshopcc_basic.toolkit_classic_bootstrap()

    else:
        tk_photoshopcc_basic.toolkit_plugin_bootstrap(root_path)

    # core may have been swapped. import sgtk
    import sgtk

    # get a handle on the newly bootstrapped engine
    engine = sgtk.platform.current_engine()

    from sgtk.platform.qt import QtGui

    app_name = "Shotgun Engine for Photoshop CC"

    # create and set up the Qt app. we don't want the app to close when the
    # last window is shut down since it's running in parallel to the CC product.
    # We'll manage shutdown
    app = QtGui.QApplication([app_name])

    # the icon that will display for the python process in the dock/task bar
    app_icon = QtGui.QIcon(os.path.join(root_path, "icon_256.png"))

    # set up the QApplication
    app.setApplicationName(app_name)
    app.setWindowIcon(app_icon)
    app.setQuitOnLastWindowClosed(False)

    # some operations can't be done until a qapplication exists.
    engine.post_qt_init()

    # log metrics for the app name and version
    engine.log_user_attribute_metric("%s Version" % engine.adobe.app.name,
                                     engine.adobe.app.version)

    # debug logging for the app name/version as well
    engine.logger.debug("Adobe CC Product: %s" % engine.adobe.app.name)
    engine.logger.debug("Adobe CC Version: %s" % engine.adobe.app.version)

    # once the event loop starts, the bootstrap process is complete and
    # everything should be connected. this is a blocking call, so nothing else
    # can happen afterward.
    print "Starting Qt event loop..."
    sys.exit(app.exec_())
def main():
    
    app = QtGui.QApplication(sys.argv)
    ex = MyWidgetHolder()
    sys.exit(app.exec_())
Ejemplo n.º 10
0
    global g_current_file
    cur_file = tde4.getProjectPath()
    if g_current_file != cur_file:
        if cur_file:
            engine = sgtk.platform.current_engine()
            context = engine.context
            new_context = engine.sgtk.context_from_path(cur_file, context)
            if new_context != context:
                sgtk.platform.change_context(new_context)
        g_current_file = cur_file


if __name__ == '__main__':
    engine = sgtk.platform.current_engine()
    if not engine:
        from tank_vendor.shotgun_authentication import ShotgunAuthenticator
        user = ShotgunAuthenticator(sgtk.util.CoreDefaultsManager()).get_user()
        sgtk.set_authenticated_user(user)
        context = sgtk.context.deserialize(os.environ.get("TANK_CONTEXT"))
        engine = sgtk.platform.start_engine('tk-3de4', context.sgtk, context)

    from sgtk.platform.qt import QtCore, QtGui

    # Qt
    if not QtCore.QCoreApplication.instance():
        QtGui.QApplication([])
        global g_current_file
        g_current_file = tde4.getProjectPath()
        tde4.setTimerCallbackFunction("_timer", 50)
        engine.post_qt_init()
Ejemplo n.º 11
0
    def sendCommand(self):
        data = self.paramsLineEdit.text()
        command = self.methodCombo.currentText()
        data = eval(data)

        if command == "SHOW_MENU" or command == "ENGINE_READY":
            self.client.send_command(command, **data)
        else:
            result = self.client.send_and_receive_command(command, **data)
            if result:
                self.resultsTextEdit.setText("%s" % result)

    def enablesendCommandButton(self):
        self.sendCommandButton.setEnabled(
            bool(self.hostLineEdit.text() and self.portLineEdit.text())
        )


if __name__ == "__main__":

    import sys

    logger.info("-" * 80)
    logger.info("--- external client ---")
    logger.info("-" * 80)
    app = QtGui.QApplication(sys.argv)
    client = Client()
    client.show()
    sys.exit(client.exec_())