def __init__(self, path, parent=None):
        global _viewer_instance
        _viewer_instance = self

        super(AlembicView, self).__init__(parent=parent)
        if not isinstance(path, unicode):
            raise ValueError(
                u'Expected <type \'unicode\'>, got {}'.format(type(path)))

        if not self.parent():
            common.set_custom_stylesheet(self)

        file_info = QtCore.QFileInfo(path)
        if not file_info.exists():
            s = '{} does not exists.'.format(path)
            common_ui.ErrorBox(
                u'Error viewing the alembic contents.', s).open()
            log.error(s)
            raise RuntimeError(s)

        self.path = path
        self.view = AlembicTree(path, parent=self)

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setAttribute(QtCore.Qt.WA_NoSystemBackground)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.setWindowFlags(
            QtCore.Qt.Window |
            QtCore.Qt.FramelessWindowHint |
            QtCore.Qt.WindowStaysOnTopHint
        )

        self._create_UI()
        self.view.setStyleSheet(u'QTreeView {{padding:{p}px; border-radius: {p}px; border: {s}px solid black;}}'.format(
            p=common.INDICATOR_WIDTH() * 2, s=common.ROW_SEPARATOR()))
    def paintEvent(self, event):
        if not self.drop_target:
            return

        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
        painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform, True)
        painter.setPen(QtCore.Qt.NoPen)
        painter.setBrush(common.SEPARATOR)
        painter.drawRoundedRect(self.rect(), common.INDICATOR_WIDTH(),
                                common.INDICATOR_WIDTH())

        pixmap = images.ImageCache.get_rsc_pixmap(
            u'slack', common.ADD,
            self.rect().height() - (common.INDICATOR_WIDTH() * 1.5))
        rect = pixmap.rect()
        rect.moveCenter(self.rect().center())
        painter.drawPixmap(rect, pixmap, pixmap.rect())

        o = common.INDICATOR_WIDTH()
        rect = self.rect().marginsRemoved(QtCore.QMargins(o, o, o, o))
        painter.setBrush(QtCore.Qt.NoBrush)
        pen = QtGui.QPen(common.ADD)
        pen.setWidthF(common.ROW_SEPARATOR() * 2.0)
        painter.setPen(pen)
        painter.drawRoundedRect(rect, o, o)
        painter.end()
    def paintEvent(self, event):
        """Custom paint event"""
        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        w = self._width + 0.01
        h = self._height + 0.01

        factor = float(min((self.width(), self.height())) -
                       common.MARGIN()) / max(float(w), float(h))
        w *= factor
        h *= factor

        painter.setBrush(common.SEPARATOR)
        painter.setPen(QtCore.Qt.NoPen)
        painter.setOpacity(0.3)
        painter.drawRect(self.rect())
        painter.setOpacity(1.0)

        rect = QtCore.QRect(0, 0, w, h)
        rect.moveCenter(self.rect().center())

        # Outline
        painter.setOpacity(0.2)
        pen = QtGui.QPen(common.ADD)
        pen.setWidthF(common.ROW_SEPARATOR() * 2.0)
        pen.setStyle(QtCore.Qt.SolidLine)
        pen.setJoinStyle(QtCore.Qt.RoundJoin)
        painter.setPen(pen)
        painter.setBrush(QtCore.Qt.NoBrush)
        painter.drawRect(rect)

        painter.setPen(QtCore.Qt.NoPen)
        painter.setBrush(common.ADD)
        painter.drawRect(rect)
        painter.setOpacity(1.0)

        painter.setPen(common.TEXT)
        font, metrics = common.font_db.primary_font(
            font_size=common.SMALL_FONT_SIZE())
        painter.setFont(font)
        _rect = self.rect()
        _rect.setLeft(rect.left() + common.SMALL_FONT_SIZE())

        text = u'{w}{h}{fps}{pre}{start}{duration}'.format(
            w=u'{}px'.format(int(self._width)) if self._width else u'',
            h=u' * {}px'.format(int(self._height)) if self._height else u'',
            fps=u'  |  {}fps'.format(self._fps) if self._fps else u'',
            pre=u'\n{}'.format(self._prefix) if self._prefix else u'',
            start=u'\nIn: {}'.format(int(self._start)) if self._start else u'',
            duration=u'\nOut: {}\nDuration: {}'.format(
                int(self._start) + int(self._duration),
                int(self._duration) if self._duration else u'')
            if self._duration else u'')
        painter.drawText(
            _rect, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter
            | QtCore.Qt.TextWordWrap,
            text if text else u'Bookmark not yet configured')
        painter.end()
Beispiel #4
0
    def paintEvent(self, event):
        """Paint event for smooth font display."""
        painter = QtGui.QPainter()
        painter.begin(self)

        option = QtWidgets.QStyleOption()
        option.initFrom(self)
        hover = option.state & QtWidgets.QStyle.State_MouseOver
        pressed = option.state & QtWidgets.QStyle.State_Sunken
        focus = option.state & QtWidgets.QStyle.State_HasFocus

        color = common.TEXT if self.isEnabled() else common.SECONDARY_TEXT
        color = common.TEXT_SELECTED if hover else color

        bg_color = common.SECONDARY_TEXT if self.isEnabled(
        ) else common.SECONDARY_BACKGROUND.darker(110)
        bg_color = common.TEXT if hover else bg_color
        bg_color = common.SEPARATOR if pressed else bg_color

        if focus:
            pen = QtGui.QPen(common.FAVOURITE)
        else:
            pen = QtGui.QPen(bg_color)
            pen.setWidthF(common.ROW_SEPARATOR())

        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setBrush(bg_color)
        painter.setPen(pen)
        o = common.ROW_SEPARATOR()
        rect = self.rect().marginsRemoved(QtCore.QMargins(o, o, o, o))
        o = common.INDICATOR_WIDTH() * 0.7
        painter.drawRoundedRect(rect, o, o)

        rect = QtCore.QRect(self.rect())
        center = rect.center()
        rect.setWidth(rect.width() - (common.INDICATOR_WIDTH() * 2))
        rect.moveCenter(center)
        common.draw_aliased_text(
            painter,
            common.font_db.primary_font(common.MEDIUM_FONT_SIZE())[0],
            rect,
            self.text(),
            QtCore.Qt.AlignCenter,
            color
        )

        painter.end()
    def paintEvent(self, event):
        """The control button's paint method - shows the the set text and
        an underline if the tab is active."""
        if not self.stacked_widget():
            return

        rect = QtCore.QRect(self.rect())

        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing, True)

        option = QtWidgets.QStyleOptionButton()
        option.initFrom(self)
        hover = option.state & QtWidgets.QStyle.State_MouseOver
        painter.setPen(QtCore.Qt.NoPen)

        if self.current_index() == self.index:
            color = common.TEXT_SELECTED if hover else common.TEXT
            painter.setBrush(color)
        else:
            color = common.TEXT if hover else common.BACKGROUND
            painter.setBrush(color)

        font, metrics = common.font_db.primary_font(common.MEDIUM_FONT_SIZE())

        if (metrics.width(self.text()) +
            (common.MARGIN() * 0.5)) < self.rect().width():
            text = metrics.elidedText(self.text(), QtCore.Qt.ElideRight,
                                      self.rect().width())
            width = metrics.width(text)

            x = (self.width() / 2.0) - (width / 2.0)
            y = self.rect().center().y() + (metrics.ascent() * 0.5)
            path = delegate.get_painter_path(x, y, font, text)
            painter.drawPath(path)
        else:
            pixmap = images.ImageCache.get_rsc_pixmap(self.icon, color,
                                                      common.MARGIN())
            # _rect = QtCore.QRect(self.rect())
            _rect = pixmap.rect()
            _rect.moveCenter(self.rect().center())
            painter.drawPixmap(_rect, pixmap, pixmap.rect())

        rect.setHeight(common.ROW_SEPARATOR() * 2.0)
        painter.setPen(QtCore.Qt.NoPen)
        rect.setWidth(self.rect().width())

        if self.current_index() == self.index:
            painter.setOpacity(0.9)
            color = common.TEXT if hover else common.REMOVE
        else:
            painter.setOpacity(0.3)
            color = common.TEXT if hover else common.FAVOURITE

        painter.setBrush(color)
        painter.drawRect(rect)
        painter.end()
Beispiel #6
0
    def __init__(self, parent=None):
        super(Separator, self).__init__(parent=parent)
        pixmap = QtGui.QPixmap(QtCore.QSize(4096, common.ROW_SEPARATOR()))
        pixmap.fill(common.FAVOURITE)
        self.setPixmap(pixmap)

        self.setHidden(True)

        self.setFocusPolicy(QtCore.Qt.NoFocus)

        self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_NoSystemBackground)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.setAcceptDrops(True)

        self.setSizePolicy(QtWidgets.QSizePolicy.Minimum,
                           QtWidgets.QSizePolicy.Minimum)
        self.setFixedWidth(common.ROW_SEPARATOR())
Beispiel #7
0
 def paintEvent(self, event):
     painter = QtGui.QPainter()
     painter.begin(self)
     pen = QtGui.QPen(common.SEPARATOR)
     pen.setWidthF(common.ROW_SEPARATOR())
     painter.setPen(pen)
     painter.setRenderHint(QtGui.QPainter.Antialiasing)
     painter.setBrush(common.BACKGROUND)
     o = common.MARGIN() * 0.3
     painter.setOpacity(0.95)
     painter.drawRoundedRect(
         self.rect().marginsRemoved(QtCore.QMargins(o, o, o, o)),
         common.INDICATOR_WIDTH(), common.INDICATOR_WIDTH())
     painter.end()
    def paint_background(self, *args):
        """Paints the background."""
        rectangles, painter, option, index, selected, focused, active, archived, favourite, hover, font, metrics, cursor_position = args

        painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
        painter.setBrush(common.SEPARATOR)
        painter.drawRect(option.rect)
        rect = QtCore.QRect(option.rect)
        center = rect.center()
        rect.setHeight(rect.height() - common.ROW_SEPARATOR())
        rect.moveCenter(center)
        background = common.SECONDARY_BACKGROUND
        color = common.BACKGROUND_SELECTED if selected or hover else background
        painter.setBrush(color)
        painter.drawRect(rect)
Beispiel #9
0
    def paintEvent(self, event):
        painter = QtGui.QPainter()
        painter.begin(self)

        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        pen = QtGui.QPen(common.SEPARATOR)
        pen.setWidthF(common.ROW_SEPARATOR())
        painter.setPen(pen)

        o = common.MARGIN()
        rect = self.rect().marginsRemoved(QtCore.QMargins(o, o, o, o))
        rect.setHeight(common.ROW_HEIGHT() + (common.MARGIN() * 2))
        painter.setBrush(common.SECONDARY_BACKGROUND)
        painter.setOpacity(0.9)
        painter.drawRoundedRect(
            rect, common.INDICATOR_WIDTH(), common.INDICATOR_WIDTH())
        painter.end()
    def paintEvent(self, event):
        """Indicating the visibility of the TaskFolderWidget."""
        if not self.view().isHidden():
            painter = QtGui.QPainter()
            painter.begin(self)

            painter.setRenderHint(QtGui.QPainter.Antialiasing)
            painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)
            painter.setPen(QtCore.Qt.NoPen)
            painter.setBrush(QtGui.QColor(0, 0, 0, 30))
            painter.drawRect(self.rect())

            rect = self.rect()
            rect.setHeight(common.ROW_SEPARATOR() * 2.0)
            painter.setBrush(common.ADD)
            painter.drawRect(rect)

            common.draw_aliased_text(
                painter,
                common.font_db.primary_font(common.MEDIUM_FONT_SIZE())[0],
                self.rect(), u'...', QtCore.Qt.AlignCenter, common.BACKGROUND)
            painter.end()
        else:
            super(FilesTabButton, self).paintEvent(event)
Beispiel #11
0
    def __initdata__(self):
        """Collects the data needed to populate the bookmarks model.

        Bookmarks are made up of a tuple of ``(server, job, root)`` values and
        are stored in the local user system settings, eg. the Registry
        in under windows. Each bookmarks can be associated with a thumbnail,
        custom description and a list of comments, todo items.

        Note:
            This model does not have threads associated with it as fetching
            necessary data is relatively inexpensive.

        """
        def dflags():
            """The default flags to apply to the item."""
            return (QtCore.Qt.ItemIsDropEnabled
                    | QtCore.Qt.ItemNeverHasChildren | QtCore.Qt.ItemIsEnabled
                    | QtCore.Qt.ItemIsSelectable)

        task_folder = self.task_folder()

        active_paths = settings.local_settings.verify_paths()
        favourites = settings.local_settings.favourites()
        bookmarks = settings.local_settings.value(u'bookmarks')
        bookmarks = bookmarks if bookmarks else {}

        _height = self.ROW_SIZE.height() - common.ROW_SEPARATOR()

        for k, v in bookmarks.iteritems():
            if not all(v.values()):
                continue

            file_info = QtCore.QFileInfo(k)
            exists = file_info.exists()

            if exists:
                flags = dflags()
                pixmap = images.ImageCache.get_rsc_pixmap(
                    u'bookmark_sm', common.ADD, _height)
            else:
                flags = dflags() | common.MarkedAsArchived
                pixmap = images.ImageCache.get_rsc_pixmap(
                    u'failed', common.REMOVE, _height)
            placeholder_image = pixmap
            default_thumbnail_image = pixmap

            filepath = file_info.filePath().lower()

            # Active Flag
            if all((v[u'server'] == active_paths[u'server'],
                    v[u'job'] == active_paths[u'job'],
                    v[u'root'] == active_paths[u'root'])):
                flags = flags | common.MarkedAsActive
            # Favourite Flag
            if filepath in favourites:
                flags = flags | common.MarkedAsFavourite

            text = u'{}  |  {}'.format(
                v[u'job'],
                v[u'root'],
                # v[u'root'].split(u'/').pop(),
            )

            data = self.INTERNAL_MODEL_DATA[task_folder][common.FileItem]
            idx = len(data)

            data[idx] = common.DataDict({
                QtCore.Qt.DisplayRole:
                text,
                QtCore.Qt.EditRole:
                text,
                QtCore.Qt.StatusTipRole:
                filepath,
                QtCore.Qt.ToolTipRole:
                filepath,
                QtCore.Qt.SizeHintRole:
                self.ROW_SIZE,
                #
                common.TextSegmentRole:
                self.get_text_segments(text),
                #
                common.EntryRole: [],
                common.FlagsRole:
                flags,
                common.ParentPathRole: (v[u'server'], v[u'job'], v[u'root']),
                common.DescriptionRole:
                u'',
                common.TodoCountRole:
                0,
                common.FileDetailsRole:
                None,
                common.SequenceRole:
                None,
                common.EntryRole: [],
                common.FileInfoLoaded:
                False,
                common.StartpathRole:
                None,
                common.EndpathRole:
                None,
                #
                common.ThumbnailLoaded:
                False,
                #
                common.TypeRole:
                common.FileItem,
                #
                common.SortByNameRole:
                text,
                common.SortByLastModifiedRole:
                file_info.lastModified().toMSecsSinceEpoch(),
                common.SortBySizeRole:
                file_info.size(),
                #
                common.AssetCountRole:
                0,
                #
                common.IdRole:
                idx
            })

            db = None
            n = 0
            db = bookmark_db.get_db(
                v[u'server'],
                v[u'job'],
                v[u'root'],
            )
            with db.transactions():
                # Item flags
                flags = data[idx][common.FlagsRole]
                v = db.value(data[idx][QtCore.Qt.StatusTipRole], u'flags')
                flags = flags | v if v is not None else flags
                data[idx][common.FlagsRole] = flags

                # Todos are a little more convoluted - the todo count refers to
                # all the current outstanding todos af all assets, including
                # the bookmark itself
                n = 0
                for v in db.values(u'notes').itervalues():
                    if not v:
                        continue
                    if v[u'notes']:
                        try:
                            v = base64.b64decode(v[u'notes'])
                            d = json.loads(v)
                            n += len([
                                k for k in d
                                if not d[k][u'checked'] and d[k][u'text']
                            ])
                        except (ValueError, TypeError):
                            log.error(u'Error decoding JSON notes')

                data[idx][common.TodoCountRole] = n
                self.update_description(db, data[idx])

        self.activeChanged.emit(self.active_index())
Beispiel #12
0
    def _create_UI(self):
        def get_row(vertical=False, parent=None):
            row = QtWidgets.QWidget(parent=parent)
            if vertical:
                QtWidgets.QVBoxLayout(row)
            else:
                QtWidgets.QHBoxLayout(row)
            row.layout().setContentsMargins(0, 0, 0, 0)
            row.layout().setSpacing(0)
            row.setSizePolicy(
                QtWidgets.QSizePolicy.Expanding,
                QtWidgets.QSizePolicy.Expanding,
            )
            parent.layout().addWidget(row)
            return row

        QtWidgets.QHBoxLayout(self)
        o = 0
        self.layout().setContentsMargins(o, o, o, o)
        self.layout().setSpacing(o)

        main_row = get_row(parent=self)
        main_row.layout().setContentsMargins(0, 0, 0, 0)
        main_row.layout().setSpacing(0)

        columns = get_row(vertical=True, parent=main_row)
        columns.layout().setContentsMargins(0, 0, 0, 0)
        columns.layout().setSpacing(0)

        short_text_row = get_row(parent=columns)

        columns.layout().addWidget(short_text_row, 1)
        long_text_row = get_row(parent=columns)

        pixmap = images.ImageCache.get_rsc_pixmap(
            self.icon, self.secondary_color.lighter(150), common.ROW_HEIGHT())
        label = QtWidgets.QLabel(parent=self)
        label.setPixmap(pixmap)
        label.setSizePolicy(
            QtWidgets.QSizePolicy.Minimum,
            QtWidgets.QSizePolicy.Expanding,
        )
        label.setStyleSheet(
            u'padding: {}px; background-color: rgba({});'.format(
                common.MEDIUM_FONT_SIZE(),
                common.rgb(self.primary_color)
            )
        )

        main_row.layout().insertWidget(0, label)

        short_text_row.layout().addWidget(self.short_text_label)
        self.short_text_label.setStyleSheet(
            u'padding:{m}px {s}px {m}px {s}px; background-color: rgba({c}); font-size: {s}px;'.format(
                m=common.MARGIN(),
                c=common.rgb(self.secondary_color.lighter(125)),
                s=common.MEDIUM_FONT_SIZE()
            ))
        self.short_text_label.setAlignment(QtCore.Qt.AlignLeft)

        long_text_row.layout().addWidget(self.long_text_label)
        self.long_text_label.setStyleSheet(
            u'padding:{m}px;background-color: rgba({c}); font-size:{s}px;'.format(
                m=common.MARGIN(),
                c=common.rgb(self.secondary_color),
                s=common.SMALL_FONT_SIZE()
            ))
        self.long_text_label.setAlignment(QtCore.Qt.AlignLeft)

        buttons_row = get_row(parent=columns)
        buttons_row.setStyleSheet(
            u'background-color: rgba({});'.format(common.rgb(self.secondary_color)))
        self.ok_button = QtWidgets.QPushButton(u'Ok', parent=self)
        buttons_row.layout().addWidget(self.ok_button)

        self.ok_button.setStyleSheet(
            """
        QPushButton {{
            font-size: {px}px;
            color: rgba(255,255,255,150);
            border-radius: {i}px;
            border: {s}px solid {c};
            margin: {i}px;
            padding: {i}px;
            background-color: rgba({p});
        }}
        QPushButton:hover {{
            color: white;
            background-color: rgba({pl});
        }}
        QPushButton:pressed {{
            color: rgba(255,255,255,150);
            background-color: rgba({pd});
        }}
        """.format(
                px=common.SMALL_FONT_SIZE(),
                i=common.INDICATOR_WIDTH(),
                s=common.ROW_SEPARATOR(),
                c=common.rgb(self.secondary_color.lighter(150)),
                p=common.rgb(self.primary_color),
                pl=common.rgb(self.primary_color.lighter(120)),
                pd=common.rgb(self.primary_color.darker(120))
            )
        )