Пример #1
0
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
# Source Code License included in this distribution package. See LICENSE.
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

import tempfile
import sys
import os

from sgtk.platform.qt import QtCore, QtGui
import sgtk

QT_MAJOR = int(QtCore.qVersion().split(".")[0])  # Works for PySide* and PyQt*


class ScreenGrabber(QtGui.QDialog):
    """
    A transparent tool dialog for selecting an area (QRect) on the screen.

    This tool does not by itself perform a screen capture. The resulting
    capture rect can be used (e.g. with the get_desktop_pixmap function) to
    blit the selected portion of the screen into a pixmap.
    """

    # If set to a callable, it will be used when performing a
    # screen grab in place of the default behavior defined in
    # this module.
    SCREEN_GRAB_CALLBACK = None
Пример #2
0
    def execute_command(self, cmd_key, args):
        """
        Executes a given command.
        """
        cb = self.commands[cmd_key]["callback"]

        getargspec = inspect.getargspec if six.PY2 else inspect.getfullargspec

        # make sure the number of parameters to the command are correct
        cb_arg_spec = getargspec(cb)
        cb_arg_list = cb_arg_spec[0]
        cb_var_args = cb_arg_spec[1]

        if hasattr(cb, "__self__"):
            # first argument to cb will be class instance:
            cb_arg_list = cb_arg_list[1:]

        # ensure the correct/minimum number of arguments have been passed:
        have_expected_args = False
        if cb_var_args:
            have_expected_args = len(args) >= len(cb_arg_list)
        else:
            have_expected_args = len(args) == len(cb_arg_list)

        if not have_expected_args:
            expected_args = list(cb_arg_list)
            if cb_var_args:
                expected_args.append("*%s" % cb_var_args)
            raise TankError(
                "Cannot run command! Expected command arguments (%s)"
                % ", ".join(expected_args)
            )

        if not self._has_qt:
            # QT not available - just run the command straight
            return cb(*args)
        else:
            from sgtk.platform.qt import QtCore, QtGui

            # we got QT capabilities. Start a QT app and fire the command into the app
            tk_shell = self.import_module("tk_shell")
            t = tk_shell.Task(self, cb, args)

            # start up our QApp now, if none is already running
            qt_application = None
            if not QtGui.QApplication.instance():
                # We need to clear Qt library paths on Linux if KDE is the active environment.
                # This resolves issues with mismatched Qt libraries between the OS and the
                # application being launched if it is a DCC that comes with a bundled Qt.
                # It appears to only need to be fixed in PySide (1), PySide2 is fine.
                if (
                    tank.util.is_linux()
                    and os.environ.get("KDE_FULL_SESSION") is not None
                    and QtCore.qVersion()[0] == "4"
                ):

                    QtGui.QApplication.setLibraryPaths([])

                qt_application = QtGui.QApplication([])
                qt_application.setWindowIcon(QtGui.QIcon(self.icon_256))
                self._initialize_dark_look_and_feel()

            # if we didn't start the QApplication here, leave the responsibility
            # to run the exec loop and quit to the initial creator of the QApplication
            if qt_application:
                # when the QApp starts, initialize our task code
                QtCore.QTimer.singleShot(0, t.run_command)
                # and ask the main app to exit when the task emits its finished signal
                t.finished.connect(qt_application.quit)

                # start the application loop. This will block the process until the task
                # has completed - this is either triggered by a main window closing or
                # byt the finished signal being called from the task class above.
                qt_application.exec_()
            else:
                # we can run the command now, as the QApp is already started
                t.run_command()
Пример #3
0
        """
        Paints the line plain text editor and adds a placeholder on bottom right corner when multiple values are detected.
        """
        super(PublishDescriptionEditQt4, self).paintEvent(paint_event)

        if self.placeholderVisible():
            painter = QtGui.QPainter(self.viewport())
            colour = self.palette().text().color()
            colour.setAlpha(128)
            painter.setPen(colour)
            painter.setClipRect(self.rect())
            margin = self.document().documentMargin()
            textRect = self.viewport().rect().adjusted(margin, margin, 0, 0)
            painter.drawText(
                textRect,
                QtCore.Qt.AlignTop | QtCore.Qt.TextWordWrap,
                self.placeholderText(),
            )


# Qt 5 implements a QTextEdit with a placeholder feature built in.
# However for Qt 4 we've had to implement one.
if QtCore.qVersion()[0] == "4":
    base = PublishDescriptionEditQt4
else:
    base = PublishDescriptionEditBase


class PublishDescriptionEdit(base):
    pass