Ejemplo n.º 1
0
    def __init__(self, title, data, parent=None):
        super(EnvDisplay, self).__init__(parent=parent)
        self.data = data
        self.tree = EnvTree('environ', self.data)
        self.ok_button = QtGui.QPushButton('Ok')
        self.ok_button.setSizePolicy(
            QtGui.QSizePolicy.Maximum,
            QtGui.QSizePolicy.Maximum,
        )
        self.ok_button.clicked.connect(self.accept)
        self.copy_button = QtGui.QPushButton(
            icon=QtGui.QIcon(res.get_path('copy.png')),
            text='Copy to Clipboard',
        )
        self.copy_button.clicked.connect(self.copy_to_clipboard)

        self.button_layout = QtGui.QHBoxLayout()
        self.button_layout.setDirection(self.button_layout.RightToLeft)
        self.button_layout.addWidget(self.ok_button)
        self.button_layout.addWidget(self.copy_button)
        self.button_layout.addStretch()

        self.layout = QtGui.QVBoxLayout()
        self.layout.addWidget(self.tree)
        self.layout.addLayout(self.button_layout)
        self.setLayout(self.layout)
        self.setWindowTitle(title)
        self.setWindowIcon(QtGui.QIcon(res.get_path('icon_dark_256.png')))
Ejemplo n.º 2
0
    def __init__(self, parent):
        """
        :param parent: The model parent.
        :type parent: :class:`~PySide.QtGui.QObject`
        """
        super(WorkAreaButton, self).__init__(parent)

        # an icon to represent all items which
        # aren't the current work area
        self._normal_icon = QtGui.QIcon()
        self._normal_icon.addPixmap(
            QtGui.QPixmap(":/tk_multi_infopanel/pin.png"), QtGui.QIcon.Normal,
            QtGui.QIcon.Off)

        # an icon to represent the current work area
        self._current_work_area_icon = QtGui.QIcon()
        self._current_work_area_icon.addPixmap(
            QtGui.QPixmap(":/tk_multi_infopanel/pin_blue.png"),
            QtGui.QIcon.Disabled, QtGui.QIcon.Off)
        self.setIcon(self._normal_icon)
        self.setIconSize(
            QtCore.QSize(self.WIDGET_WIDTH_COLLAPSED, self.WIDGET_HEIGHT))

        self._bundle = sgtk.platform.current_bundle()

        self._entity_type = None
        self._entity_id = None
        self._is_static = False

        self._caption = "Set Work Area"
        self._width = 120

        self.clicked.connect(self._on_click)

        self.setVisible(False)
Ejemplo n.º 3
0
    def __init__(self, editor_widget, parent=None):
        """
        Initialize the wrapper widget.

        :param editor_widget: The ``EDITOR`` widget instance
        :type editor_widget: :class:`~PySide.QtGui.QWidget`
        :param parent: The parent widget instance or None
        :type parent: :class:`~PySide.QtGui.QWidget`
        :return:
        """
        super(_EditorWidget, self).__init__(parent)
        self._editor_widget = editor_widget
        self._editor_widget.setFocusPolicy(QtCore.Qt.StrongFocus)

        self._done_btn = QtGui.QPushButton()
        self._done_btn.setIcon(QtGui.QIcon(":/qtwidgets-shotgun-fields/edit_close.png"))
        self._done_btn.setFixedSize(QtCore.QSize(16, 16))
        self._done_btn.setFocusPolicy(QtCore.Qt.NoFocus)

        self._apply_btn = QtGui.QPushButton()
        self._apply_btn.setIcon(
            QtGui.QIcon(":/qtwidgets-shotgun-fields/apply_value.png")
        )
        self._apply_btn.setFixedSize(QtCore.QSize(16, 16))
        self._apply_btn.setFocusPolicy(QtCore.Qt.NoFocus)

        # make sure there's never a bg color or border
        self._done_btn.setStyleSheet(BUTTON_STYLE)
        self._apply_btn.setStyleSheet(BUTTON_STYLE)

        if self._editor_widget.sizeHint().height() >= 32:
            btn_layout = QtGui.QVBoxLayout()
            btn_layout.addWidget(self._done_btn)
            btn_layout.addStretch()
            btn_layout.addWidget(self._apply_btn)
        else:
            btn_layout = QtGui.QHBoxLayout()
            btn_layout.addWidget(self._apply_btn)
            btn_layout.addWidget(self._done_btn)
            btn_layout.addStretch()

        if getattr(editor_widget, "_IMMEDIATE_APPLY", None):
            # widget is set to immediately apply value. no need to display the btn
            self._apply_btn.hide()

        layout = QtGui.QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(4)
        layout.addWidget(editor_widget)
        layout.addLayout(btn_layout)
        layout.addStretch()

        layout.setAlignment(self._done_btn, QtCore.Qt.AlignBottom)

        self.installEventFilter(self)

        # ---- connect singals

        self._done_btn.clicked.connect(lambda: self.done_editing.emit())
        self._apply_btn.clicked.connect(self._apply_value)
Ejemplo n.º 4
0
    def _get_default_thumbnail(self, sg_entity):
        """
        Get the default icon for the specified entity.

        :param sg_entity:   A Shotgun entity dictionary for the entity to get the
                            icon for.
        :returns:           A QIcon for the entity if available.  For Step entities, a
                            swatch representing the step colour is returned.  If no
                            icon is available for the entity type then None is returned
        """
        if sg_entity.get("type") == "Step":
            # special case handling for steps to return a colour swatch:
            step_id = sg_entity.get("id")
            if step_id != None:
                # get the colour from the cache:
                if step_id not in ShotgunEntityModel._SG_STEP_COLOURS:
                    ShotgunEntityModel._SG_STEP_COLOURS[step_id] = None
                    # refresh cache:
                    bundle = sgtk.platform.current_bundle()
                    try:
                        sg_steps = bundle.shotgun.find("Step", [], ["color"])
                        for sg_step in sg_steps:
                            colour = None
                            try:
                                colour = tuple([
                                    int(c)
                                    for c in sg_step.get("color").split(",")
                                ])
                            except:
                                pass
                            ShotgunEntityModel._SG_STEP_COLOURS[
                                sg_step["id"]] = colour
                    except:
                        pass
                colour = ShotgunEntityModel._SG_STEP_COLOURS[step_id]

                if colour and isinstance(colour, tuple) and len(colour) == 3:
                    # get the icon for this colour from the cache:
                    if colour not in self._step_swatch_icons:
                        # build icon and add to cache:
                        pm = QtGui.QPixmap(16, 16)
                        pm.fill(QtCore.Qt.transparent)
                        painter = QtGui.QPainter(pm)
                        try:
                            painter.setBrush(
                                QtGui.QBrush(
                                    QtGui.QColor(colour[0], colour[1],
                                                 colour[2])))
                            painter.setPen(QtCore.Qt.black)
                            painter.drawRect(2, 2, 12, 12)
                        finally:
                            painter.end()
                        self._step_swatch_icons[colour] = QtGui.QIcon(pm)

                    # return the icon:
                    return QtGui.QIcon(self._step_swatch_icons[colour])

        # just return the entity icon:
        return self.get_entity_icon(sg_entity.get("type"))
    def _add_dummy_placeholder_item(self, parent_item, refreshing):
        """
        Create a dummy child item under the given item.

        These items are used in tree views to show that a deferred query didn't
        return any Shotgun record or that the data is being refreshed from Shotgun.

        :param parent_item: A :class:`ShotgunStandardItem` instance.
        :returns: A string, the unique id for the item.
        """
        parent_uid = parent_item.data(self._SG_ITEM_UNIQUE_ID)
        self._deferred_cache.add_item(parent_uid=None,
                                      sg_data={},
                                      field_name="",
                                      is_leaf=False,
                                      uid=parent_uid)
        uid = self._dummy_placeholder_item_uid(parent_item)
        display_name = shotgun_globals.get_type_display_name(
            self._deferred_query["entity_type"])
        if refreshing:
            text = "Retrieving %ss..." % display_name
        else:
            text = "No %ss found" % display_name

        exists = self._deferred_cache.item_exists(uid)
        # Update or create the dummy item in the cache
        self._deferred_cache.add_item(
            parent_uid=parent_uid,
            # We need to use something which looks like a SG Entity dictionary.
            # By having a "text" key and using it for the field name, the tree
            # view will display its contents.
            sg_data={
                "text": text,
                "type": ""
            },
            field_name="text",
            is_leaf=True,
            uid=uid,
        )
        if not exists:
            # Create the item in the model
            sub_item = self._create_item(
                parent=parent_item,
                data_item=self._deferred_cache.get_entry_by_uid(uid))
            sub_item.setData(True, self._SG_ITEM_FETCHED_MORE)
            # This item can't be used.
            sub_item.setSelectable(False)
            sub_item.setEnabled(False)
            sub_item.setIcon(QtGui.QIcon())
        else:
            sub_item = self._get_item_by_unique_id(uid)
            if sub_item:
                self._update_item(sub_item,
                                  self._deferred_cache.get_entry_by_uid(uid))
                # We don't want an icon to appear in the view. Updating the item
                # reset the icon, so we have to reset it after the update.
                sub_item.setIcon(QtGui.QIcon())
        return uid
Ejemplo n.º 6
0
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(490, 618)
        self.verticalLayout = QtGui.QVBoxLayout(Dialog)
        self.verticalLayout.setObjectName("verticalLayout")
        self.browser = SceneBrowserWidget(Dialog)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
                                       QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.browser.sizePolicy().hasHeightForWidth())
        self.browser.setSizePolicy(sizePolicy)
        self.browser.setObjectName("browser")
        self.verticalLayout.addWidget(self.browser)
        self.horizontalLayout_3 = QtGui.QHBoxLayout()
        self.horizontalLayout_3.setSpacing(3)
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.groupBox = QtGui.QGroupBox(Dialog)
        self.groupBox.setTitle("")
        self.groupBox.setObjectName("groupBox")
        self.horizontalLayout_2 = QtGui.QHBoxLayout(self.groupBox)
        self.horizontalLayout_2.setSpacing(10)
        self.horizontalLayout_2.setContentsMargins(2, 2, 2, 2)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label = QtGui.QLabel(self.groupBox)
        self.label.setObjectName("label")
        self.horizontalLayout_2.addWidget(self.label)
        self.chk_green = QtGui.QCheckBox(self.groupBox)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/res/green_bullet.png"),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.chk_green.setIcon(icon)
        self.chk_green.setObjectName("chk_green")
        self.horizontalLayout_2.addWidget(self.chk_green)
        self.chk_red = QtGui.QCheckBox(self.groupBox)
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(":/res/red_bullet.png"),
                        QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.chk_red.setIcon(icon1)
        self.chk_red.setObjectName("chk_red")
        self.horizontalLayout_2.addWidget(self.chk_red)
        self.horizontalLayout_3.addWidget(self.groupBox)
        spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                                       QtGui.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem)
        self.select_all = QtGui.QPushButton(Dialog)
        self.select_all.setObjectName("select_all")
        self.horizontalLayout_3.addWidget(self.select_all)
        self.update = QtGui.QPushButton(Dialog)
        self.update.setObjectName("update")
        self.horizontalLayout_3.addWidget(self.update)
        self.verticalLayout.addLayout(self.horizontalLayout_3)

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
Ejemplo n.º 7
0
    def __init__(self, parent, schema_generation=0, bg_task_manager=None):
        """
        Initialize the Hierarcy model.

        :param parent: The model's parent.
        :type parent: :class:`~PySide.QtGui.QObject`

        """

        super(ShotgunHierarchyModel, self).__init__(parent, bg_task_manager)

        # check for hierarchy support
        (self._hierarchy_is_supported, self._hierarchy_not_supported_reason) = \
            self.__hierarchy_is_supported()

        if not self._hierarchy_is_supported:
            self._log_warning(self._hierarchy_not_supported_reason)

        self._path = None
        self._seed_entity_field = None
        self._entity_fields = None

        self._schema_generation = schema_generation

        # flag to indicate a full refresh
        self._request_full_refresh = False

        # is the model set up with a query?
        self._has_query = False

        # keeps track of the currently running queries by mapping the id
        # returned by the data retriever to the path being queried
        self._running_query_lookup = {}

        # keep these icons around so they're not constantly being created
        self._folder_icon = QtGui.QIcon(
            ":tk-framework-shotgunutils/icon_Folder.png")
        self._none_icon = QtGui.QIcon(
            ":tk-framework-shotgunutils/icon_None_dark.png")

        # Define the foreground color of "empty" items.
        # These special items are used as placeholders in the tree where the
        # parent has no children. An example would be `Shots > No Shots` where
        # `No Shots` is the "empty" item. By default, the color is a mix of the
        # application instance's base and text colors. This will typically
        # result in a dimmed appearance for these special items indicating that
        # they are not clickable. This makes goes outside the typical bounds of
        # the model by pulling the palette colors from the app instance. This
        # can be overridden in subclasses via ``_finalize_item()`` though.
        base_color = QtGui.QApplication.instance().palette().base().color()
        text_color = QtGui.QApplication.instance().palette().text().color()

        # local import to avoid doc generation issues
        from ..utils import color_mix
        self._empty_item_color = color_mix(text_color, 1, base_color, 2)
Ejemplo n.º 8
0
    def __init__(self, parent, command_name, button_name, icon, tooltip,
                 timestamp):
        """
        :param str command_name: Name of the command.
        :param str button_name: Name of the button.
        :param str icon: Path to the icon for this command.
        :param str tooltip: Toolkit for this command.
        :param datetime.datetime timestamp: When the command was last launched.
        """
        super(RecentButton, self).__init__(parent)

        # No borders
        self.setFlat(True)

        self.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
                           QtGui.QSizePolicy.MinimumExpanding)
        self.setFocusPolicy(QtCore.Qt.NoFocus)

        layout = QtGui.QVBoxLayout(self)
        layout.setAlignment(QtCore.Qt.AlignHCenter)
        layout.setSpacing(self.SPACING)
        layout.setContentsMargins(self.MARGIN, self.MARGIN, self.MARGIN,
                                  self.MARGIN)

        self._timestamp = timestamp

        self.icon_label = QtGui.QLabel(self)
        self.icon_label.setAlignment(QtCore.Qt.AlignHCenter)
        self.layout().addWidget(self.icon_label, QtCore.Qt.AlignHCenter)
        # setting the stretch to 0 on the icon means the the text label will
        # stretch and the icon won't creating a more stable looking effect.
        layout.setStretch(0, 0)

        self.text_label = QtGui.QLabel(parent)
        self.text_label.setWordWrap(True)
        self.text_label.setAlignment(QtCore.Qt.AlignHCenter
                                     | QtCore.Qt.AlignTop)
        self.layout().addWidget(self.text_label, QtCore.Qt.AlignHCenter)

        self.setFocusPolicy(QtCore.Qt.NoFocus)
        self.setStyleSheet(BUTTON_STYLE)

        self.text_label.setText(button_name)
        if icon is None:
            self.icon_label.setPixmap(QtGui.QIcon().pixmap(ICON_SIZE))
        else:
            self.icon_label.setPixmap(QtGui.QIcon(icon).pixmap(ICON_SIZE))

        self.setToolTip(tooltip)

        self._command_name = command_name

        self.clicked.connect(lambda: self.command_triggered.emit(
            six.ensure_str(self._command_name)))
Ejemplo n.º 9
0
    def __init__(self, parent):
        """
        :param parent:              The parent QWidget for this control
        :type parent:               :class:`~PySide.QtGui.QWidget`
        """
        # first, call the base class and let it do its thing.
        QtGui.QWidget.__init__(self, parent)

        # now load in the UI that was created in the UI designer
        self.ui = Ui_NoteInputWidget()
        self.ui.setupUi(self)

        self._load_stylesheet()

        # set up some handy references
        self._bundle = sgtk.platform.current_bundle()
        self._camera_icon = QtGui.QIcon(
            QtGui.QPixmap(
                ":/tk_framework_qtwidgets.note_input_widget/camera_hl.png"))
        self._trash_icon = QtGui.QIcon(
            QtGui.QPixmap(
                ":/tk_framework_qtwidgets.note_input_widget/trash.png"))

        # initialize state variables
        self._processing_id = None  # async task id
        self._entity_type = None  # current associated entity
        self._entity_id = None  # current associated entity
        self._pixmap = None  #
        self._attachments = []
        self._cleanup_after_upload = []

        # set up an overlay that spins when note is submitted
        self.__overlay = SmallOverlayWidget(self)

        # create a separate sg data handler for submission
        self.__sg_data_retriever = None

        # hook up signals and slots
        self.ui.screenshot.clicked.connect(self._screenshot_or_clear)
        self.ui.submit.clicked.connect(self._submit)
        self.ui.close.clicked.connect(self._cancel)
        self.ui.close.clicked.connect(self.close_clicked)
        self.ui.attach.clicked.connect(self.open_attachments)
        self.ui.add_attachments.clicked.connect(self._apply_attachments)
        self.ui.close_attachments.clicked.connect(self._cancel_attachments)
        self.ui.add_button.clicked.connect(self._add_attachments)
        self.ui.remove_button.clicked.connect(
            self._remove_selected_attachments)

        # reset state of the UI
        self.pre_submit_callback = None
        self.clear()
Ejemplo n.º 10
0
    def update_tk_templates(self):
        if not self.context:
            self.log.error('TK context is not defined, unable to update TK templates.')
            return

        tk = self._app.context.sgtk

        if not tk:
            self.log.error('Unable to get TK instance, unable to update TK templates.')
            return

        templates = tk.templates

        # Support non-engine template definitions. If None, then use engine key name instead. ie: Data > data > take_data
        app_name = str(self.ui.appComboBox.itemData(self.ui.appComboBox.currentIndex()))
        if app_name:
            app_name = app_name.lower().replace(' ', '').replace('tk-', '')
        else:
            app_name = self.ui.appComboBox.currentText().lower()

        entity_type = self.context.entity['type']

        # Remap entity name
        entity_type = self.custom_entity_name_remap.get(entity_type, entity_type).lower()

        regex = '%s_%s' % (entity_type, app_name)

        active_templates = {}

        for k, v in templates.iteritems():
            if re.search(regex, k):
                active_templates[k] = v

        self.ui.tkTemplateComboBox.clear()

        active_keys = active_templates.keys()
        active_keys.sort()

        self.ui.tkTemplateComboBox.addItem(QtGui.QIcon(':/res/block.png'), 'Select Template')

        for key in active_keys:
            key_title = key.replace(entity_type, '').replace('_', ' ').title()
            self.ui.tkTemplateComboBox.addItem(QtGui.QIcon(':/res/sg_logo.png'), key_title, active_templates[key])

        # Default to "work" template if available
        index = self.ui.tkTemplateComboBox.findText('Work', QtCore.Qt.MatchContains)
        if index > -1:
            self.ui.tkTemplateComboBox.setCurrentIndex(index)

        self.ui.tkTemplateComboBox.currentIndexChanged.connect(self.update_template_definition)

        self.update_template_definition()
Ejemplo n.º 11
0
    def __init__(self, item, parent):
        """
        :param item:
        :param parent: The parent QWidget for this control
        """
        self._item = item
        super(TreeNodeItem, self).__init__(parent)
        self.setFlags(self.flags() | QtCore.Qt.ItemIsSelectable)

        # go ahead and keep a handle on these so they can be reused
        self._expanded_icon = QtGui.QIcon(":/tk_multi_publish2/down_arrow.png")
        self._collapsed_icon = QtGui.QIcon(
            ":/tk_multi_publish2/right_arrow.png")
Ejemplo n.º 12
0
    def choose_thumbnail(self, model_index):
        original_tn = model_index.data(self._ORIGINAL_THUMBNAIL)
        pinned_tn = model_index.data(self._PINNED_THUMBNAIL)
        filter_tn = model_index.data(self._FILTER_THUMBNAIL)

        if pinned_tn:
            return QtGui.QIcon(pinned_tn)
        if filter_tn:
            return QtGui.QIcon(filter_tn)
        if original_tn:
            return QtGui.QIcon(original_tn)

        return None
Ejemplo n.º 13
0
    def update_applications(self):
        self.ui.appComboBox.clear()

        self.ui.appComboBox.addItem(QtGui.QIcon(':/res/block.png'), 'Select Application')

        app_keys = list(self.applications.keys())
        app_keys.sort()

        for appKey in app_keys:
            self.ui.appComboBox.addItem(QtGui.QIcon(':/res/sg_logo.png'), appKey, self.applications[appKey])

        self.ui.appComboBox.currentIndexChanged.connect(self.update_tk_context)
        self.ui.appComboBox.currentIndexChanged.connect(self.update_tk_templates)
Ejemplo n.º 14
0
    def setModelData(self, editor, model, index):
        """
        Gets data from the editor widget and stores it in the specified model at
        the item index.

        :param editor: The editor widget.
        :type editor: :class:`~PySide.QtGui.QWidget`
        :param model: The SG model where the data lives.
        :type model: :class:`~PySide.QtCore.QAbstractItemModel`
        :param index: The index of the model to be edited.
        :type index: :class:`~PySide.QtCore.QModelIndex`
        """
        src_index = _map_to_source(index)
        if not src_index or not src_index.isValid():
            # invalid index, do nothing
            return

        # compare the new/old values to see if there is a change
        new_value = editor.get_value()
        cur_value = src_index.data(self.field_data_role)
        if cur_value == new_value:
            # value didn't change. nothing to do here.
            return

        bundle = sgtk.platform.current_bundle()

        # special case for image fields in the ShotgunModel. The SG model stores
        # the image field in the first column. If the value has changed, set the
        # icon value there.
        if editor.get_field_name() == "image":
            primary_item = src_index.model().item(src_index.row(), 0)
            try:
                if new_value:
                    # update the value locally in the model
                    primary_item.setIcon(QtGui.QIcon(new_value))
                else:
                    primary_item.setIcon(QtGui.QIcon())
            except Exception as e:
                bundle.log_error("Unable to set icon for widget delegate: %s" % (e,))

            return

        successful = src_index.model().setData(
            src_index, new_value, self.field_data_role
        )

        if not successful:
            bundle.log_error(
                "Unable to set model data for widget delegate: %s, %s"
                % (self._entity_type, self._field_name)
            )
Ejemplo n.º 15
0
    def __init__(self, parent=None):
        super(ProgressDialog, self).__init__(parent)

        # Window options
        self.setWindowTitle('tk-cpenv')
        self.setWindowIcon(QtGui.QIcon(res.get_path('module_dark_256.png')))
        self.setWindowFlags(self.windowFlags()
                            | QtCore.Qt.WindowStaysOnTopHint)
        self.hide_timer = None

        # Layout widgets
        self.label = QtGui.QLabel('Starting...')
        self.progress = QtGui.QProgressBar()
        self.progress.setRange(0, 100)
        self.progress.setTextVisible(True)
        self.progress.setAlignment(QtCore.Qt.AlignCenter)
        self.progress.setFormat('starting')
        self.frame = QtGui.QLabel()
        self.button = QtGui.QPushButton('Cancel')
        self.button.setSizePolicy(
            QtGui.QSizePolicy.Maximum,
            QtGui.QSizePolicy.Maximum,
        )
        self.button.clicked.connect(self.cancel)

        self.layout = QtGui.QVBoxLayout()
        self.layout.addWidget(self.label)
        self.layout.addWidget(self.progress)
        self.layout.addWidget(self.frame)
        self.layout.addWidget(self.button)
        self.layout.setAlignment(self.button, QtCore.Qt.AlignRight)
        self.setLayout(self.layout)
    def _populate_thumbnail(self, item, field, path):
        """
        Called whenever a thumbnail for an item has arrived on disk. In the case of
        an already cached thumbnail, this may be called very soon after data has been
        loaded, in cases when the thumbs are downloaded from Shotgun, it may happen later.

        This method will be called only if the model has been instantiated with the
        download_thumbs flag set to be true. It will be called for items which are
        associated with shotgun entities (in a tree data layout, this is typically
        leaf nodes).

        This method makes it possible to control how the thumbnail is applied and associated
        with the item. The default implementation will simply set the thumbnail to be icon
        of the item, but this can be altered by subclassing this method.

        Any thumbnails requested via the _request_thumbnail_download() method will also
        resurface via this callback method.

        :param item: QStandardItem which is associated with the given thumbnail
        :param field: The Shotgun field which the thumbnail is associated with.
        :param path: A path on disk to the thumbnail. This is a file in jpeg format.
        """
        # pass the thumbnail through out special image compositing methods
        # before associating it with the model
        is_folder = item.data(SgLatestPublishModel.IS_FOLDER_ROLE)
        if is_folder:
            # composite the thumbnail nicely on top of the folder icon
            thumb = utils.create_overlayed_folder_thumbnail(path)
        else:
            thumb = utils.create_overlayed_publish_thumbnail(path)
        item.setIcon(QtGui.QIcon(thumb))
Ejemplo n.º 17
0
    def _add_context_menu(self):
        """
        Adds a context menu which displays the current context.
        """
        from sgtk.platform.qt import QtGui
        # create the context menu
        ctx = self.engine.context
        menu = self.root_menu.addMenu(str(ctx))
        style = menu.style()

        action = menu.addAction('Jump to File System')
        action.triggered.connect(self._jump_to_fs)
        action.setIcon(style.standardIcon(style.SP_DialogOpenButton))

        action = menu.addAction('Jump to Shotgun')
        action.triggered.connect(self._jump_to_sg)
        try:
            import sgtk.platform.qt.resources_rc
        except ImportError:
            self.engine.logger.warn(traceback.format_exc())
        else:
            action.setIcon(QtGui.QIcon(':/Tank.Platform.Qt/tank_logo.png'))

        menu.addSeparator()
        return menu
Ejemplo n.º 18
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.º 19
0
    def setupUi(self, BannerWidget):
        BannerWidget.setObjectName("BannerWidget")
        BannerWidget.resize(618, 71)
        self.horizontalLayout = QtGui.QHBoxLayout(BannerWidget)
        self.horizontalLayout.setContentsMargins(6, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.message = QtGui.QLabel(BannerWidget)
        self.message.setStyleSheet("border-style: outset;\n"
                                   "border-color: rgb(0, 0, 0);")
        self.message.setWordWrap(True)
        self.message.setOpenExternalLinks(False)
        self.message.setObjectName("message")
        self.horizontalLayout.addWidget(self.message)
        self.close_button = QtGui.QToolButton(BannerWidget)
        self.close_button.setStyleSheet("border: none;")
        self.close_button.setText("")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/tk-desktop/cross.png"),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.close_button.setIcon(icon)
        self.close_button.setIconSize(QtCore.QSize(30, 30))
        self.close_button.setObjectName("close_button")
        self.horizontalLayout.addWidget(self.close_button)

        self.retranslateUi(BannerWidget)
        QtCore.QMetaObject.connectSlotsByName(BannerWidget)
Ejemplo n.º 20
0
    def __init__(self, environment, parent):
        super(EnvPermissions, self).__init__(parent)

        self.state = {
            'environment': environment,
        }

        self.save_button = QtGui.QPushButton('Save')
        self.cancel_button = QtGui.QPushButton('Cancel')

        # Layout widgets
        button_layout = QtGui.QHBoxLayout()
        button_layout.addWidget(self.save_button)
        button_layout.addWidget(self.cancel_button)

        self.layout = QtGui.QVBoxLayout()
        self.layout.addWidget(QtGui.QLabel('Restrict to Users'))
        self.layout.addLayout(button_layout)
        self.setLayout(self.layout)

        # Connect widgets
        self.save_button.clicked.connect(self.on_save_clicked)
        self.cancel_button.clicked.connect(self.on_cancel_clicked)

        self.setWindowTitle('Environment Permissions')
        self.setWindowIcon(QtGui.QIcon(res.get_path('icon_dark_256.png')))

        shotgun_fields = sgtk.platform.import_framework(
            "tk-framework-qtwidgets",
            "shotgun_fields",
        )
        self._fields_manager = shotgun_fields.ShotgunFieldManager(self)
        self._fields_manager.initialized.connect(self.on_initialized)
        self._fields_manager.initialize()
Ejemplo n.º 21
0
    def __init__(self, parent=None):
        super(Console, self).__init__(parent)

        self.setWindowTitle('Shotgun Desktop Console')
        self.setWindowIcon(QtGui.QIcon(":/tk-desktop/default_systray_icon.png"))

        self.__logs = QtGui.QPlainTextEdit()
        layout = QtGui.QHBoxLayout()
        layout.addWidget(self.__logs)
        self.setLayout(layout)

        # configure the text widget
        self.__logs.setReadOnly(True)
        self.__logs.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.__logs.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
        self.__logs.customContextMenuRequested.connect(self.on_logs_context_menu_request)
        self.__logs.setStyleSheet("QPlainTextEdit:focus { border: none; }")

        # load up previous size
        self._settings_manager = settings.UserSettings(sgtk.platform.current_bundle())
        pos = self._settings_manager.retrieve("console.pos", self.pos(), self._settings_manager.SCOPE_GLOBAL)
        size = self._settings_manager.retrieve(
            "console.size", QtCore.QSize(800, 400), self._settings_manager.SCOPE_GLOBAL)

        self.move(pos)
        self.resize(size)
Ejemplo n.º 22
0
    def __init__(self, parent):
        super(Attachments, self).__init__(parent)

        self.setFlow(QtGui.QListView.LeftToRight)
        self.setViewMode(QtGui.QListView.IconMode)
        self.setResizeMode(QtGui.QListView.Adjust)
        self.setGridSize(QtCore.QSize(36, 36))
        self.setStyleSheet(self.style)
        self.setMaximumHeight(36)
        self.setSelectionMode(self.NoSelection)
        self.setFocusPolicy(QtCore.Qt.NoFocus)
        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self._show_context_menu)

        self._attachments = []
        self._default_items = []

        # Capture button
        self.capture_button = QtGui.QToolButton(
            icon=QtGui.QIcon(res.get_path('camera.png')))
        self.capture_button.setToolTip('Grab part of the screen.')
        self.capture_button.clicked.connect(self._on_capture)
        item = QtGui.QListWidgetItem()
        item.setSizeHint(self.gridSize())
        self.addItem(item)
        self.setItemWidget(item, self.capture_button)
        self._default_items.append(item)
Ejemplo n.º 23
0
    def __init__(self, environments, parent=None):
        super(EnvSelector, self).__init__(parent)

        self.state = {
            'environments': environments,
            'choice': environments[0],
        }

        self.msg = QtGui.QLabel('Select an Environment')
        self.msg.setAlignment(QtCore.Qt.AlignCenter)

        buttons = []
        for environment in environments:
            button = QtGui.QPushButton(environment['code'])
            button.setToolTip(
                'Modules:\n'
                + '\n'.join(environment['sg_requires'].split())
            )
            button.setObjectName('SelectButton')
            button.clicked.connect(self.choose(environment))
            buttons.append(button)

        # Layout widgets
        self.layout = QtGui.QVBoxLayout()
        self.layout.addWidget(self.msg)
        for button in buttons:
            self.layout.addWidget(button)
        self.setLayout(self.layout)

        self.setWindowTitle('tk-cpenv')
        self.setWindowIcon(QtGui.QIcon(res.get_path('icon_dark_256.png')))
        self.setStyleSheet(self.style)
Ejemplo n.º 24
0
    def _populate_thumbnail_image(self, item, field, image, path):
        """
        Called whenever a thumbnail for an item has arrived on disk. In the case of
        an already cached thumbnail, this may be called very soon after data has been
        loaded, in cases when the thumbs are downloaded from Shotgun, it may happen later.

        This method will be called only if the model has been instantiated with the
        download_thumbs flag set to be true. It will be called for items which are
        associated with shotgun entities (in a tree data layout, this is typically
        leaf nodes).

        This method makes it possible to control how the thumbnail is applied and associated
        with the item. The default implementation will simply set the thumbnail to be icon
        of the item, but this can be altered by subclassing this method.

        Any thumbnails requested via the _request_thumbnail_download() method will also
        resurface via this callback method.

        :param item: QStandardItem which is associated with the given thumbnail
        :param field: The Shotgun field which the thumbnail is associated with.
        :param path: A path on disk to the thumbnail. This is a file in jpeg format.
        """        
        if field not in self._sg_formatter.thumbnail_fields: 
            # there may be other thumbnails being loaded in as part of the data flow
            # (in particular, created_by.HumanUser.image) - these ones we just want to 
            # ignore and not display.
            return
        
        sg_data = item.get_sg_data()
        icon = self._sg_formatter.create_thumbnail(image, sg_data)
        item.setIcon(QtGui.QIcon(icon))
    def __init__(self, parent = None ) :
        QtGui.QWidget.__init__(self, parent) 

        lay = QtGui.QHBoxLayout()
        lay.setContentsMargins(0,0,0,0)
        lay.setSpacing(0)

        self.writeTo = ToDoLineEdit("who ?") 
        self.writeWhat = ToDoLineEdit("what ?")
        self.sendButton = QtGui.QPushButton()
        self.sendButton.setIcon(QtGui.QIcon(getRessources("sendNotification") ))

        self.sendButton.setFlat(True);
        self.sendButton.setIconSize(QtCore.QSize(20,20));
        style = 'QPushButton:hover{border: 1px solid rgb(48,226,227)}'
        self.sendButton.setStyleSheet("QPushButton{outline: none;}"+style);
        self.sendButton.notificationAttr = True

        lay.addWidget(self.writeTo)
        lay.addSpacing(5)
        lay.addWidget(self.writeWhat)
        lay.addSpacing(5)
        lay.addWidget(self.sendButton)
        self.setLayout(lay)


        self.writeTo.setMaximumWidth(150)
    def set_status(self, status, message="", info_below=True):
        """
        Set the status for the plugin
        :param status: An integer representing on of the
            status constants defined by the class
        """

        if status not in self._icon_lookup:
            raise ValueError("Invalid icon index!")

        if status == self.NEUTRAL:
            self.ui.status.hide()
        else:
            default_message = "Click for more details."
            if message:
                if info_below:
                    message += "<br>See below or click for more details."
                else:
                    message += "<br>%s" % (default_message, )
            else:
                message = default_message

            self.ui.status.setToolTip(
                QtGui.QApplication.translate(
                    "ItemWidget",
                    "<p>%s</p>" % (message, ),
                    None,
                    QtGui.QApplication.UnicodeUTF8,
                ))

            self.ui.status.show()
            self._status_icon = QtGui.QIcon()
            self._status_icon.addPixmap(self._icon_lookup[status],
                                        QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.ui.status.setIcon(self._status_icon)
Ejemplo n.º 27
0
    def _handle_search_results(self, data):
        """
        Populates the model associated with the completer with the data coming back from Shotgun.

        :param dict data: Data received back from the job sent to the
            :class:`~tk-framework-shotgunutils:shotgun_data.ShotgunDataRetriever` in :method:``_launch_sg_search``.
        """
        matches = data["sg"]["matches"]

        if len(matches) == 0:
            item = QtGui.QStandardItem("No matches found!")
            item.setData(self.MODE_NOT_FOUND, self.MODE_ROLE)
            self.model().appendRow(item)

        # insert new data into model
        for d in matches:
            item = QtGui.QStandardItem(d["name"])
            item.setData(self.MODE_RESULT, self.MODE_ROLE)

            item.setData(shotgun_model.sanitize_for_qt_model(d),
                         self.SG_DATA_ROLE)

            item.setIcon(QtGui.QIcon(self._pixmaps.no_thumbnail))

            if d.get("image") and self._sg_data_retriever:
                uid = self._sg_data_retriever.request_thumbnail(
                    d["image"], d["type"], d["id"], "image", load_image=True)
                self._thumb_map[uid] = {"item": item}

            self.model().appendRow(item)
Ejemplo n.º 28
0
    def _populate_thumbnail_image(self, item, field, image, path):
        """
        Called whenever a thumbnail for an item has arrived on disk. In the case of
        an already cached thumbnail, this may be called very soon after data has been
        loaded, in cases when the thumbs are downloaded from Shotgun, it may happen later.

        This method will be called only if the model has been instantiated with the
        download_thumbs flag set to be true. It will be called for items which are
        associated with shotgun entities (in a tree data layout, this is typically
        leaf nodes).

        This method makes it possible to control how the thumbnail is applied and associated
        with the item. The default implementation will simply set the thumbnail to be icon
        of the item, but this can be altered by subclassing this method.

        Any thumbnails requested via the _request_thumbnail_download() method will also
        resurface via this callback method.

        :param item: QStandardItem which is associated with the given thumbnail
        :param field: The Shotgun field which the thumbnail is associated with.
        :param path: A path on disk to the thumbnail. This is a file in jpeg format.
        """
        if field == "image":
            thumb = QtGui.QPixmap.fromImage(image)
            item.setData(thumb, SgPublishHistoryModel.PUBLISH_THUMB_ROLE)
        else:
            thumb = QtGui.QPixmap.fromImage(image)
            item.setData(thumb, SgPublishHistoryModel.USER_THUMB_ROLE)

        # composite the user thumbnail and the publish thumb into a single image
        thumb = utils.create_overlayed_user_publish_thumbnail(
            item.data(SgPublishHistoryModel.PUBLISH_THUMB_ROLE),
            item.data(SgPublishHistoryModel.USER_THUMB_ROLE),
        )
        item.setIcon(QtGui.QIcon(thumb))
Ejemplo n.º 29
0
    def __init__(self, label, message, parent=None):
        super(ErrorDialog, self).__init__(parent)

        self.setWindowTitle('tk-multi-tickets Error')
        self.setWindowIcon(QtGui.QIcon(res.get_path('icon_256.png')))
        self.setWindowFlags(self.windowFlags()
                            | QtCore.Qt.WindowStaysOnTopHint)

        self.label = QtGui.QLabel(label)
        self.text = QtGui.QPlainTextEdit(message)
        self.text.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)

        self.button = QtGui.QPushButton('Dismiss')
        self.button.setSizePolicy(
            QtGui.QSizePolicy.Maximum,
            QtGui.QSizePolicy.Maximum,
        )
        self.button.clicked.connect(self.accept)

        self.layout = QtGui.QVBoxLayout()
        self.layout.setStretch(1, 1)
        self.layout.addWidget(self.label)
        self.layout.addWidget(self.text)
        self.layout.addWidget(self.button)
        self.layout.setAlignment(self.button, QtCore.Qt.AlignRight)
        self.setLayout(self.layout)
Ejemplo n.º 30
0
    def __init__(self, label, parent=None):
        QtGui.QPushButton.__init__(self, parent)
        self.setIcon(QtGui.QIcon(getRessources("refreshUI.png")))
        self.setFlat(True)
        self.setIconSize(QtCore.QSize(16, 16))

        style = 'QPushButton:hover{border: 1px solid rgb(48,226,227)}'
        self.setStyleSheet("QPushButton{outline: none;}" + style)