Exemple #1
0
 def paintEvent(self, event):
     super(AttachmentLabel, self).paintEvent(event)
     if self.text() != '':
         painter = QtGui.QPainter(self)
         painter.drawLine(QtCore.QPoint(0,
                                        self.height() - 1),
                          QtCore.QPoint(self.width(),
                                        self.height() - 1))
Exemple #2
0
 def set_color(self, step):
     if self.basset_name == 'cc_bundle':
         self.normal_color = QtGui.QLinearGradient(
             QtCore.QPointF(0, 0), QtCore.QPointF(self.w, 0))
         color1 = SPECIAL_COLOR['cc_bundle'][0]
         color2 = SPECIAL_COLOR['cc_bundle'][1]
         self.normal_color.setColorAt(
             0, QtGui.QColor(color1[0], color1[1], color1[2]))
         self.normal_color.setColorAt(
             1, QtGui.QColor(color2[0], color2[1], color2[2]))
         self.fill_color = self.normal_color
     else:
         super(PlaVersionItem, self).set_color(step)
Exemple #3
0
def size(bytes):
    # According to the Si standard KB is 1000 bytes, KiB is 1024
    # but on windows sizes are calculated by dividing by 1024 so we do what they do.
    kb = 1024.0
    mb = 1024.0 * kb
    gb = 1024.0 * mb
    tb = 1024.0 * gb
    if bytes >= tb:
        return "{0} TB".format(QtCore.QLocale().toString(bytes / tb, 'f', 3))
    if bytes >= gb:
        return "{0} GB".format(QtCore.QLocale().toString(bytes / gb, 'f', 2))
    if bytes >= mb:
        return "{0} MB".format(QtCore.QLocale().toString(bytes / mb, 'f', 1))
    if bytes >= kb:
        return "{0} KB".format(QtCore.QLocale().toString(bytes / kb, 'f', 1))
    return "{0} bytes".format(QtCore.QLocale().toString(bytes))
Exemple #4
0
    def __init__(self):
        self.mode_model = QtCore.QStringListModel(["Shot", "Asset"])
        self.upload_type = QtCore.QStringListModel(
            ["Attachment", "Thumbnail", "Reference_qt"])
        self.show_model = QtGui.QStandardItemModel()
        self.path_model = QtWidgets.QDirModel()

        shows = get_approved_shows()
        for show_item in shows.items():
            if show_item[1] in frozenset(['production', 'production2']):
                item = QtGui.QStandardItem(show_item[0])
                item.setData(show_item[1], SG_DATA)
                self.show_model.appendRow(item)
        self.tree_model = QtWidgets.QFileSystemModel()
        self.tree_model.setRootPath("/")
        self.none_tree = QtWidgets.QFileSystemModel()
Exemple #5
0
    def __init__(self, combine_version=False, parent=None):
        super(GraphicsSceneWidget, self).__init__(parent=parent)

        self.scene = GraphicsScene(combine_version=combine_version,
                                   parent=self)
        # orientation: 0-h 1-v
        self.view = GraphicsView()
        self.view.setScene(self.scene)
        self.setGeometry(100, 100, 800, 600)

        self.view.setRenderHint(QtGui.QPainter.Antialiasing)
        self.view.setViewportUpdateMode(
            QtWidgets.QGraphicsView.FullViewportUpdate)

        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.view)
        self.setLayout(layout)

        self.scene.setSceneRect(
            QtCore.QRectF(
                -(self.view.viewport().width() / self.view.current_zoom * 2 +
                  25000) / 2,
                -(self.view.viewport().height() / self.view.current_zoom * 2 +
                  25000) / 2,
                self.view.viewport().width() / self.view.current_zoom * 2 +
                25000,
                self.view.viewport().height() / self.view.current_zoom * 2 +
                25000))

        # self.itemPopulate.connect(self.test, QtCore.Qt.QueuedConnection)
        self.showWidgetSignal.connect(self.show_version_widget,
                                      QtCore.Qt.QueuedConnection)
Exemple #6
0
    def fit_to(self, items=[]):
        if len(items) == 0:
            for item in self.scene().items():
                if isinstance(item, VersionItem):
                    items.append(item)

        max_x = items[0].pos().x()
        min_x = items[0].pos().x()
        max_y = items[0].pos().y()
        min_y = items[0].pos().y()
        for item in items:
            max_x = max(item.pos().x(), max_x)
            min_x = min(item.pos().x(), min_x)
            max_y = max(item.pos().y(), max_y)
            min_y = min(item.pos().y(), min_y)
        center_x = (max_x + min_x) / 2 + 100
        center_y = (max_y + min_y) / 2 + 40
        width = max_x - min_x
        height = max_y - min_y

        zoom_x = 1 / max(
            1,
            float(width + 1000) / self.viewport().width()) / self.current_zoom
        zoom_y = 1 / max(1,
                         float(height + 1000) /
                         self.viewport().height()) / self.current_zoom
        zoom = min(zoom_x, zoom_y)
        self.scale(zoom, zoom)
        self.current_zoom = self.transform().m11()
        self.resize_scene()

        self.centerOn(QtCore.QPointF(center_x, center_y))
Exemple #7
0
 def set_pixmap(self, color=None):
     self.setPixmap(
         get_pixmap(self.icon,
                    color=color,
                    size=QtCore.QSize(TAG_W * self.scale_factor,
                                      TAG_H * self.scale_factor)))
     self.setScale(1.0 / self.scale_factor)
Exemple #8
0
    def boundingRect(self):
        """Return the bounding box of the Node.

        :return:
        """
        rect = QtCore.QRectF(self.x, self.y, self.w, self.h)

        return rect
Exemple #9
0
    def __init__(self, version, entity, asset, **kwargs):
        super(VersionItemWidget, self).__init__(**kwargs)

        self.version = version
        self.entity = entity
        self.asset = asset
        self.layout1 = QtWidgets.QHBoxLayout()
        self.version_label = Label()
        self.version_label.setStyleSheet('font: italic bold 17px Arial')
        self.color_label = QtWidgets.QLabel()
        self.step_label = Label()
        self.step_label.setStyleSheet('font: bold 17px Arial')
        self.layout1.addWidget(self.version_label)
        self.layout1.addStretch()
        self.layout1.addWidget(self.color_label)
        self.layout1.addWidget(self.step_label)
        self.form_layout = QtWidgets.QFormLayout()
        self.form_layout.setLabelAlignment(QtCore.Qt.AlignLeft)
        self.masterLayout = QtWidgets.QVBoxLayout()
        self.masterLayout.addSpacing(5)
        self.masterLayout.addLayout(self.layout1)
        self.masterLayout.addStretch()
        self.masterLayout.addLayout(self.form_layout)
        self.setLayout(self.masterLayout)
        self.masterLayout.setAlignment(QtCore.Qt.AlignTop)
        self.masterLayout.setContentsMargins(10, 0, 0, 5)
        #
        self.version_label.setText(self.version.name)
        self.color_label.setFixedSize(QtCore.QSize(20, 20))
        self.tooltip_text = None
        basset_name = Label('BAsset:')
        # basset_label = Label(self.exporter.basset_url.asset.name)
        basset_label = Label(self.asset.name)
        entity_name = Label('Entity:')
        entity_label = Label(self.entity.get_full_name())
        for label in [basset_name, entity_name, basset_label, entity_label]:
            # label.setStyleSheet('font: 12px Liberation Sans')
            # label.setStyleSheet('font: 12px Bitstream Vera Sans')
            label.setStyleSheet('font: 12px DejaVu Sans')
        self.form_layout.addRow(basset_name, basset_label)
        self.form_layout.addRow(entity_name, entity_label)
        if self.entity.type == 'step':
            self.step_label.setText(self.entity.name)

        style = """
        *{
            background: transparent;
            color: rgb(220, 220, 220);
        }
        QToolTip{
            color:white;
        }
        """
        self.setStyleSheet(style)
        self.is_highlight = False

        self.resize(200, 80)
Exemple #10
0
class VersionWidget(QtWidgets.QWidget):
    itemChanged = QtCore.pyqtSignal(object)

    def __init__(self, *args, **kwargs):
        super(VersionWidget, self).__init__(*args, **kwargs)

        self.masterLayout = QtWidgets.QVBoxLayout()
        self.layout1 = QtWidgets.QHBoxLayout()
        self.versionNumEdit = QtWidgets.QLineEdit()
        self.versionNumEdit.setPlaceholderText('Display Version Number:')
        self.versionNumEdit.setText(str(rv.commands.readSettings('Dailies', 'versionNum', 5)))
        self.versionNumEdit.editingFinished.connect(self.change_version_number)
        self.refreshButton = QtWidgets.QPushButton('Refresh')
        self.refreshButton.clicked.connect(self.refresh_clicked)
        self.layout1.addWidget(self.versionNumEdit)
        self.layout1.addWidget(self.refreshButton)
        self.masterLayout.addLayout(self.layout1)
        self.versionLists = []
        for i in range(10):
            version_list_widget = VersionList()
            self.masterLayout.addWidget(version_list_widget)
            version_list_widget.setVisible(False)
            version_list_widget.itemSelectionChanged.connect(self.item_select_changed)
            version_list_widget.set_version_num(int(self.versionNumEdit.text()))
            self.versionLists.append(version_list_widget)
        self.setLayout(self.masterLayout)

    def set_sources(self, sources):
        for versionList in self.versionLists:
            versionList.setVisible(False)
        for index, source in enumerate(sources):
            if index < 10:
                filepath = rv.commands.sourceMedia(source)[0]
                range_info = rv.commands.nodeRangeInfo(source)
                self.versionLists[index].set_current_file(filepath,
                                                          cutin=range_info['cutIn'],
                                                          cutout=range_info['cutOut'])
                self.versionLists[index].setVisible(True)

    def item_select_changed(self):
        self.itemChanged.emit(self.sender())

    def change_version_number(self):
        try:
            version_num = int(self.versionNumEdit.text())
            # print version_num
            for versionList in self.versionLists:
                if versionList.isVisible():
                    versionList.set_version_num(version_num)
            rv.commands.writeSettings('Dailies', 'versionNum', version_num)
        except:
            pass

    def refresh_clicked(self):
        for versionList in self.versionLists:
            if versionList.isVisible():
                versionList.refresh_list()
Exemple #11
0
    def __init__(self, combine_version=False, **kwargs):
        super(GraphicsScene, self).__init__(**kwargs)

        self.combine_version = combine_version

        self.depth = 0

        self.max_y_depth = 0

        self.node_dict = {"depth": 2, "nodes": {}}

        self.setSceneRect(QtCore.QRectF(-25000 / 2, -25000 / 2, 25000, 25000))
Exemple #12
0
    def resize_scene(self):
        center_x = self.mapToScene(
            QtCore.QPoint(self.viewport().width() / 2,
                          self.viewport().height() / 2)).x()
        center_y = self.mapToScene(
            QtCore.QPoint(self.viewport().width() / 2,
                          self.viewport().height() / 2)).y()
        w = self.viewport().width() / self.current_zoom * 2 + 25000
        h = self.viewport().height() / self.current_zoom * 2 + 25000

        self.scene().setSceneRect(
            QtCore.QRectF(center_x - w / 2, center_y - h / 2, w, h))

        show_detail = True if self.current_zoom >= 0.5 else False
        point1 = self.mapToScene(QtCore.QPoint(0, 0))
        point2 = self.mapToScene(
            QtCore.QPoint(self.viewport().width(),
                          self.viewport().height()))
        rect = QtCore.QRectF(point1, point2)
        for version_node in self.nodes():
            if hasattr(version_node, 'version_widget'):
                version_node.version_widget.setVisible(show_detail)
            else:
                if rect.contains(version_node.pos()) and show_detail:
                    # version_node.start_show_version_widget()
                    version_node.show_version_widget()
                    QtCore.QCoreApplication.processEvents()
            for knob in version_node.knobs():
                knob.setVisible(show_detail)
            for tag in version_node.tags():
                if tag.auto_hide:
                    tag.setVisible(show_detail)
Exemple #13
0
    def mouseMoveEvent(self, event):
        if self.panning:
            mouse_move = event.pos() - self.prevPos
            newCenter = QtCore.QPointF(
                self.prev_center.x() - mouse_move.x() / self.current_zoom,
                self.prev_center.y() - mouse_move.y() / self.current_zoom)
            self.centerOn(newCenter)

            show_detail = True if self.current_zoom >= 0.5 else False
            if show_detail:
                point1 = self.mapToScene(QtCore.QPoint(0, 0))
                point2 = self.mapToScene(
                    QtCore.QPoint(self.viewport().width(),
                                  self.viewport().height()))
                rect = QtCore.QRectF(point1, point2)
                for version_node in self.nodes():
                    if rect.contains(version_node.pos()) and not hasattr(
                            version_node, 'version_widget'):
                        version_node.start_show_version_widget()
                        # print version_node.pos(), point1, point2

            return
        super(GraphicsView, self).mouseMoveEvent(event)
Exemple #14
0
class UploadThread(QtCore.QThread):
    loadFinish = QtCore.pyqtSignal()

    def __init__(self):
        super(UploadThread, self).__init__()

    def set_files(self, new_note, attach_files):

        self.new_note = new_note
        self.attach_files = attach_files

    def run(self):
        for attach_file in self.attach_files:
            self.new_note.upload_reference_file(attach_file)
        self.loadFinish.emit()
Exemple #15
0
    def __init__(self, seq_data, parent=None):
        super(SeqFilesItem, self).__init__(parent)

        self._seq_data = seq_data
        self._file_info = QtCore.QFileInfo(self._seq_data["files"][0])
        self.path = self._seq_data["filename"]
        self._icon = QtWidgets.QFileIconProvider().icon(self._file_info)

        self.setText(
            0,
            "{name} {first}-{last}".format(name=os.path.basename(self.path),
                                           first=self._seq_data["first_frame"],
                                           last=self._seq_data["last_frame"]))
        self.setText(1, "")
        self.setText(2, "Sequence")
        self.setText(3, "")
        self.setIcon(0, self._icon)
Exemple #16
0
 def mousePressEvent(self, event):
     """Initiate custom panning using middle mouse button."""
     selected_items = self.scene().selectedItems()
     if event.button() == QtCore.Qt.MiddleButton:
         self.setDragMode(QtWidgets.QGraphicsView.NoDrag)
         self.panning = True
         self.prevPos = event.pos()
         self.prev_center = self.mapToScene(
             QtCore.QPoint(self.viewport().width() / 2,
                           self.viewport().height() / 2))
         self.setCursor(QtCore.Qt.SizeAllCursor)
     elif event.button() == QtCore.Qt.LeftButton:
         self.setDragMode(QtWidgets.QGraphicsView.RubberBandDrag)
     super(GraphicsView, self).mousePressEvent(event)
     if event.button() == QtCore.Qt.MiddleButton:
         for item in selected_items:
             item.setSelected(True)
     self.highlight_connection()
Exemple #17
0
    def paint(self, painter, option, widget):
        """Draw the Tag's shape and label."""
        bbox = self.boundingRect()

        if self.shape is not None:
            painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
            painter.setBrush(QtGui.QBrush(self.fillColor))

            # Draw a filled rectangle.
            if self.shape == 1:
                roundness = 3
                painter.drawRoundedRect(bbox, roundness, roundness)

            # Ellipse
            if self.shape == 2:
                painter.drawEllipse(bbox)

            # Triangle0
            if self.shape == 3:
                points, rects = get_shapes_of_triangle(self.w,
                                                       roundness=2,
                                                       direction=0)
                painter.drawPolygon(QtGui.QPolygonF(points))
                for rect in rects:
                    painter.drawEllipse(rect)

            # Triangle2
            if self.shape == 4:
                points, rects = get_shapes_of_triangle(self.w,
                                                       roundness=2,
                                                       direction=2)
                painter.drawPolygon(QtGui.QPolygonF(points))
                for rect in rects:
                    painter.drawEllipse(rect)

        if self.text is not None:
            painter.setPen(QtGui.QPen(self.textColor))
            font = painter.font()
            fm = QtGui.QFontMetrics(font)
            w = fm.boundingRect(self.text).width() + 10
            h = fm.boundingRect(self.text).height()
            rect = QtCore.QRectF(0 - (w - bbox.width()) / 2.0,
                                 0 - (h - bbox.height()) / 2.0, w, h)
            painter.drawText(rect, QtCore.Qt.AlignCenter, self.text)
Exemple #18
0
class LabelButton(QtWidgets.QLabel):
    clicked = QtCore.pyqtSignal()

    def __init__(self, name='', icon=None, *args, **kwargs):
        super(LabelButton, self).__init__(*args, **kwargs)

        self.setToolTip(name)
        self.setMouseTracking(True)
        self.setFixedSize(20, 20)
        if icon is not None:
            if isinstance(icon, (basestring, str)) and os.path.exists(icon):
                self.setPixmap(QtGui.QPixmap(icon))
            elif isinstance(icon, QtGui.QPixmap):
                self.setPixmap(icon)
        self.setAlignment(QtCore.Qt.AlignCenter)

    def enterEvent(self, event):
        super(LabelButton, self).enterEvent(event)
        self.setCursor(QtCore.Qt.PointingHandCursor)

    def mouseReleaseEvent(self, event):
        super(LabelButton, self).mouseReleaseEvent(event)
        self.clicked.emit()
Exemple #19
0
    def drawBackground(self, painter, rect):
        painter.setBrush(QtGui.QBrush(self.fillColor))
        painter.setPen(QtGui.QPen(self.lineColor))

        painter.drawRect(rect)
        lines = []
        scale = max(int(1 / self.current_zoom / 2), 1)
        line_w = 200 * scale
        line_h = 80 * scale

        point1 = self.mapToScene(QtCore.QPoint(0, 0))
        point2 = self.mapToScene(
            QtCore.QPoint(self.viewport().width(),
                          self.viewport().height()))

        # for i in range(int(point1.y() / line_h), int(self.scene().height() / line_h)):
        for i in range(int(point1.y() / line_h), int(point2.y() / line_h)):
            lines.append(
                QtCore.QLineF(
                    QtCore.QPoint(rect.x(), i * line_h),
                    QtCore.QPoint(rect.x() + rect.width(), i * line_h)))
        # for i in range(int(self.scene().sceneRect().x()), int(self.scene().width() / line_w)):
        for i in range(int(point1.x() / line_w), int(point2.x() / line_w)):
            lines.append(
                QtCore.QLineF(
                    QtCore.QPoint(i * line_w, rect.y()),
                    QtCore.QPoint(i * line_w,
                                  rect.y() + rect.height())))
        painter.drawLines(lines)

        painter.setPen(QtGui.QPen(QtGui.QColor(80, 80, 60, 50)))
        painter.drawLine(
            QtCore.QLineF(QtCore.QPoint(rect.x(), 0),
                          QtCore.QPoint(rect.x() + rect.width(), 0)))
        painter.drawLine(
            QtCore.QLineF(QtCore.QPoint(0, rect.y()),
                          QtCore.QPoint(0,
                                        rect.y() + rect.height())))
Exemple #20
0
def get_rect_of_ellipse(center_x, center_y, radius):
    x = center_x - radius
    y = center_y - radius
    w = 2.0 * radius
    h = 2.0 * radius
    return QtCore.QRectF(x, y, w, h)
Exemple #21
0
class AddNoteTextEdit(QtWidgets.QTextEdit):
    changed = QtCore.pyqtSignal()
    cancelNote = QtCore.pyqtSignal()
    applyNote = QtCore.pyqtSignal(str)

    def __init__(self, attachable=True, *args, **kwargs):
        super(AddNoteTextEdit, self).__init__(*args, **kwargs)

        self.attachable = attachable
        attach_icon = get_pixmap(os.path.join(ICON_DIR, 'file', 'svg',
                                              'ic_attachment_24px.svg'),
                                 size=[20, 20])
        self.attachButton = LabelButton(name='Attachment',
                                        icon=attach_icon,
                                        parent=self)
        self.attachButton.setFixedSize(20, 20)
        self.attachButton.setVisible(attachable)
        self.attach_files = []

        self.cancelButton = QtWidgets.QPushButton('Cancel', self)
        self.applyButton = QtWidgets.QPushButton('Apply', self)
        for button in [self.applyButton, self.cancelButton]:
            button.setFixedSize(50, 20)
            button.setStyleSheet("""
            QPushButton{
                border: none;
                border: 1px solid rgb(200, 200, 220);
                border-radius: 2px;
            }
            """)

        self.setStyleSheet("""
        QTextEdit{
            border: 1px solid rgb(200, 200, 220);
            border-radius: 5px;
        }
        """)

        self.setFixedWidth(350)

        self.set_editable(False)

        self.applyButton.clicked.connect(self.apply_clicked)
        self.cancelButton.clicked.connect(self.cancel_clicked)
        self.attachButton.clicked.connect(self.attach_clicked)

    def mouseReleaseEvent(self, event):
        super(AddNoteTextEdit, self).mouseReleaseEvent(event)
        self.self_clicked()

    def self_clicked(self):
        if self.isReadOnly():
            self.set_editable(True)

    def set_editable(self, editable=True, emit_change=True):
        if editable:
            self.setFixedHeight(80)
            self.clear()
        else:
            self.setFixedHeight(50)
            self.setText('Click to add a note')
        self.setReadOnly(not editable)
        self.set_pos()
        if emit_change:
            self.changed.emit()
        self.setFocus()
        self.applyButton.setVisible(editable)
        self.cancelButton.setVisible(editable)
        self.attachButton.setVisible(self.attachable and editable)

    def apply_clicked(self):
        content = self.toPlainText()
        self.set_editable(False, emit_change=False)
        self.applyNote.emit(content)
        self.attach_files = []

    def cancel_clicked(self):
        self.set_editable(False)
        self.cancelNote.emit()
        self.attach_files = []

    def attach_clicked(self):
        # print 'add attachment'
        result = QtWidgets.QFileDialog.getOpenFileNames(
            None, "Select attachment files", ".")
        if isinstance(result, tuple):
            result = result[0]
        for i in result:
            if not isinstance(i, (basestring, str)):
                i = str(i.toUtf8())
            self.attach_files.append(i)
        # print self.attach_files

    def set_pos(self):
        self.applyButton.move(self.width() - self.applyButton.width(),
                              self.height() - self.applyButton.height())
        self.cancelButton.move(
            self.applyButton.pos().x() - self.cancelButton.width(),
            self.height() - self.cancelButton.height())
        self.attachButton.move(0, self.height() - self.attachButton.height())

    def resizeEvent(self, event):
        super(AddNoteTextEdit, self).resizeEvent(event)
        self.set_pos()
Exemple #22
0
def get_shapes_of_triangle(a, roundness=0, direction=0):
    points = [
        QtCore.QPointF(1.732 * roundness, a),
        QtCore.QPointF(1.732 / 2 * roundness, a - 1.5 * roundness),
        QtCore.QPointF(0.5 * a - 1.732 / 2 * roundness, 1.5 * roundness),
        QtCore.QPointF(0.5 * a + 1.732 / 2 * roundness, 1.5 * roundness),
        QtCore.QPointF(a - 1.732 / 2 * roundness, a - 1.5 * roundness),
        QtCore.QPointF(a - 1.732 * roundness, a),
    ]
    centers = [
        QtCore.QPointF(0.5 * a, 2.0 * roundness),
        QtCore.QPointF(1.732 * roundness, a - roundness),
        QtCore.QPointF(a - 1.732 * roundness, a - roundness),
    ]
    if direction == 0:
        points = [
            point - QtCore.QPointF(0, 1.732 / 4 * roundness)
            for point in points
        ]
        centers = [
            point - QtCore.QPointF(0, 1.732 / 4 * roundness)
            for point in centers
        ]
    elif direction == 2:
        points = [
            QtCore.QPointF(point.x(),
                           -1 * point.y() + a + 1.732 / 4 * roundness)
            for point in points
        ]
        centers = [
            QtCore.QPointF(point.x(),
                           -1 * point.y() + a + 1.732 / 4 * roundness)
            for point in centers
        ]
    rects = [
        get_rect_of_ellipse(center.x(), center.y(), roundness)
        for center in centers
    ]
    return points, rects
Exemple #23
0
class VersionNotesWidget(QtWidgets.QScrollArea):
    testSignal = QtCore.pyqtSignal(int)

    def __init__(self, text_color=None, show_version=False, parent=None):
        super(VersionNotesWidget, self).__init__(parent)

        self.setStyleSheet("""
        QScrollArea{
            border:none;
        }
        QTextEdit{
            border:none;
            background:transparent;
        }
        QLabel{
            background:transparent;
        }
        QPushButton{
            background:transparent;
            padding:0px;
            margin:0px;
        }
        """)
        self.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.text_color = QtWidgets.QApplication.palette().text().color() if text_color is None else text_color

        self.versionNotesCenterWidget = VersionNotesCenterWidget(text_color=self.text_color,
                                                                 show_version=show_version)
        self.versionNotesCenterWidget.add_note_edit.changed.connect(self.add_note_edit_changed)
        self.setWidget(self.versionNotesCenterWidget)
        # print self.versionNotesCenterWidget.parent().objectName()
        self.versionNotesCenterWidget.parent().setStyleSheet("""
        QWidget{
            background:transparent;
        }
        """)
        self.setWidgetResizable(True)

    def add_note_edit_changed(self):
        self.view_bottom()

    def view_bottom(self):
        # print 'view bottom'
        # self.takeWidget()
        self.setWidget(self.versionNotesCenterWidget)
        self.versionNotesCenterWidget.adjustSize()
        vertical_scroll_bar = self.verticalScrollBar()
        vertical_scroll_bar.setValue(vertical_scroll_bar.maximum())

    def view_widget(self, widget):
        if isinstance(widget, NoteWidget):
            y = widget.pos().y()
        elif isinstance(widget, (AddNoteTextEdit, ReplyWidget)) and isinstance(widget.parent(), NoteWidget):
            # print widget.parent(), widget.pos(), widget.parent().pos()
            # print widget.mapTo(self, widget.pos()), widget.mapToParent(widget.pos())
            y = widget.pos().y() + widget.parent().pos().y()
        else:
            y = widget.pos().y()
        y = y - (self.height() - widget.height()) / 2
        # print y
        vertical_scroll_bar = self.verticalScrollBar()
        vertical_scroll_bar.setValue(y)

    def set_version(self, version):
        self.versionNotesCenterWidget.set_version(version=version)
Exemple #24
0
    def init_ui(self):
        self.checkSelectedButton = QtWidgets.QPushButton()
        self.checkSelectedButton.setToolTip('Check newest of select version')
        self.checkSelectedButton.setIcon(
            get_icon(os.path.join(ICON_DIR, 'action', 'svg',
                                  'ic_find_replace_48px.svg'),
                     color='white'))
        self.checkSelectedButton.setIconSize(QtCore.QSize(25, 25))

        self.checkAllButton = QtWidgets.QPushButton()
        self.checkAllButton.setToolTip('Check newest of all version')
        self.checkAllButton.setIcon(
            get_icon(os.path.join(ICON_DIR, 'action', 'svg',
                                  'ic_autorenew_48px.svg'),
                     color='white'))
        self.checkAllButton.setIconSize(QtCore.QSize(25, 25))

        self.expandAllButton = QtWidgets.QPushButton()
        self.expandAllButton.setToolTip('Expand all versions')
        self.expandAllButton.setIcon(
            get_icon(os.path.join(ICON_DIR, 'action', 'svg',
                                  'ic_swap_horiz_24px.svg'),
                     color='white'))
        self.expandAllButton.setIconSize(QtCore.QSize(25, 25))

        for button in [
                self.checkSelectedButton, self.checkAllButton,
                self.expandAllButton
        ]:
            button.setFixedSize(25, 25)

        self.horizontalLayout.addWidget(self.checkSelectedButton)
        self.horizontalLayout.addWidget(self.checkAllButton)
        self.horizontalLayout.addWidget(self.expandAllButton)

        self.scene_widget = GraphicsSceneWidget(
            combine_version=self.combine_version, parent=self)
        self.scene_widget.itemDoubleClicked.connect(self.__item_double_clicked)
        self.view_layout.addWidget(self.scene_widget)

        self.setStyleSheet("""
        *{
            color:white;
            background-color:rgb(50, 50, 50);
            border:none
        }
        QPushButton:hover{
            background-color:rgb(60, 60, 60);
        }
        QPushButton:pressed{
            background-color:rgb(40, 40, 40);
        }
        QLabel{
            background-color:transparent;
        }
        """)

        self.checkSelectedButton.clicked.connect(
            self.scene_widget.check_selected_version)
        self.checkAllButton.clicked.connect(
            self.scene_widget.check_all_version)
        self.expandAllButton.clicked.connect(self.scene_widget.expand_all)
Exemple #25
0
class VersionGraph(QtWidgets.QWidget):
    version_item_double_clicked = QtCore.pyqtSignal(object)

    def __init__(self,
                 populate_depth=3,
                 combine_version=False,
                 orientation=0,
                 parent=None):
        super(VersionGraph, self).__init__(parent=parent)

        # setup UI -------------------------------------------- #
        ui_file = os.path.join(os.path.dirname(__file__), 'design', 'main.ui')
        uic.loadUi(ui_file, self)

        self.root_version_item = None
        self.default_populate_depth = populate_depth
        self.combine_version = combine_version
        self.orientation = orientation

        self.init_ui()

    def set_orientation(self, value):
        self.orientation = value

    def set_populate_depth(self, value):
        self.default_populate_depth = value

    def init_ui(self):
        self.checkSelectedButton = QtWidgets.QPushButton()
        self.checkSelectedButton.setToolTip('Check newest of select version')
        self.checkSelectedButton.setIcon(
            get_icon(os.path.join(ICON_DIR, 'action', 'svg',
                                  'ic_find_replace_48px.svg'),
                     color='white'))
        self.checkSelectedButton.setIconSize(QtCore.QSize(25, 25))

        self.checkAllButton = QtWidgets.QPushButton()
        self.checkAllButton.setToolTip('Check newest of all version')
        self.checkAllButton.setIcon(
            get_icon(os.path.join(ICON_DIR, 'action', 'svg',
                                  'ic_autorenew_48px.svg'),
                     color='white'))
        self.checkAllButton.setIconSize(QtCore.QSize(25, 25))

        self.expandAllButton = QtWidgets.QPushButton()
        self.expandAllButton.setToolTip('Expand all versions')
        self.expandAllButton.setIcon(
            get_icon(os.path.join(ICON_DIR, 'action', 'svg',
                                  'ic_swap_horiz_24px.svg'),
                     color='white'))
        self.expandAllButton.setIconSize(QtCore.QSize(25, 25))

        for button in [
                self.checkSelectedButton, self.checkAllButton,
                self.expandAllButton
        ]:
            button.setFixedSize(25, 25)

        self.horizontalLayout.addWidget(self.checkSelectedButton)
        self.horizontalLayout.addWidget(self.checkAllButton)
        self.horizontalLayout.addWidget(self.expandAllButton)

        self.scene_widget = GraphicsSceneWidget(
            combine_version=self.combine_version, parent=self)
        self.scene_widget.itemDoubleClicked.connect(self.__item_double_clicked)
        self.view_layout.addWidget(self.scene_widget)

        self.setStyleSheet("""
        *{
            color:white;
            background-color:rgb(50, 50, 50);
            border:none
        }
        QPushButton:hover{
            background-color:rgb(60, 60, 60);
        }
        QPushButton:pressed{
            background-color:rgb(40, 40, 40);
        }
        QLabel{
            background-color:transparent;
        }
        """)

        self.checkSelectedButton.clicked.connect(
            self.scene_widget.check_selected_version)
        self.checkAllButton.clicked.connect(
            self.scene_widget.check_all_version)
        self.expandAllButton.clicked.connect(self.scene_widget.expand_all)

    def show_version(self, version):
        if self.root_version_item and self.root_version_item.version.id == version.id:
            return

        exporter = version.get_exporter()
        self.version_name_label.setText("{} ({})".format(
            version.name, exporter.basset_url.asset.name))
        self.version_info_label.setText(
            exporter.basset_url.entity.get_full_name())

        self.root_version_item = VersionItem.create_item(version)
        self.root_version_item.set_color(self.root_version_item.entity.name)
        self.root_version_item.set_orientation(self.orientation)
        self.scene_widget.set_root_version_item(self.root_version_item,
                                                self.default_populate_depth)

    def keyPressEvent(self, event):
        super(VersionGraph, self).keyPressEvent(event)
        if event.key() == QtCore.Qt.Key_Space:
            if self.isMaximized():
                self.showNormal()
            else:
                self.showMaximized()

    def __item_double_clicked(self, item):
        self.version_item_double_clicked.emit(item)
Exemple #26
0
class GraphicsSceneWidget(QtWidgets.QWidget):
    """Display the node graph and offer editing functionality."""

    itemDoubleClicked = QtCore.pyqtSignal(object)
    # itemPopulate = QtCore.pyqtSignal(int, object)
    showWidgetSignal = QtCore.pyqtSignal(int)

    def __init__(self, combine_version=False, parent=None):
        super(GraphicsSceneWidget, self).__init__(parent=parent)

        self.scene = GraphicsScene(combine_version=combine_version,
                                   parent=self)
        # orientation: 0-h 1-v
        self.view = GraphicsView()
        self.view.setScene(self.scene)
        self.setGeometry(100, 100, 800, 600)

        self.view.setRenderHint(QtGui.QPainter.Antialiasing)
        self.view.setViewportUpdateMode(
            QtWidgets.QGraphicsView.FullViewportUpdate)

        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.view)
        self.setLayout(layout)

        self.scene.setSceneRect(
            QtCore.QRectF(
                -(self.view.viewport().width() / self.view.current_zoom * 2 +
                  25000) / 2,
                -(self.view.viewport().height() / self.view.current_zoom * 2 +
                  25000) / 2,
                self.view.viewport().width() / self.view.current_zoom * 2 +
                25000,
                self.view.viewport().height() / self.view.current_zoom * 2 +
                25000))

        # self.itemPopulate.connect(self.test, QtCore.Qt.QueuedConnection)
        self.showWidgetSignal.connect(self.show_version_widget,
                                      QtCore.Qt.QueuedConnection)

    def set_root_version_item(self, version_item, populate_layer):
        self.scene.clear()
        self.scene.addItem(version_item)

        version_item.setPos(0, 0)
        version_item.show_version_widget()
        version_item.populate_children(populate_layer, reset_pos=True)

        self.view.fit_to(self.scene.selectedItems())
        # self.showWidgetSignal.emit(0)

    def check_selected_version(self):
        for item in self.scene.selectedItems():
            item.check_new_version()

    def check_all_version(self):
        for item in self.scene.items():
            if isinstance(item, VersionItem):
                item.check_new_version()

    def expand_all(self):
        if len(self.scene.selectedItems()) == 0:
            for node in self.view.nodes():
                node.populate_children(populate_layer=100, reset_pos=True)
        else:
            for node in self.scene.selectedItems():
                if isinstance(node, VersionItem):
                    node.populate_children(populate_layer=100, reset_pos=True)

    def show_version_widget(self, index):
        if index < len(self.view.nodes()):
            node_item = self.view.nodes()[index]
            node_item.show_version_widget()
            self.showWidgetSignal.emit(index + 1)

    def event(self, event):
        # if event.type() == PopulateEvent.eventType:
        #     # print event.index, event.item
        #     if event.index < event.item.dependent_versions_count:
        #         event.item.populate_child(event.index)
        #         QtCore.QCoreApplication.postEvent(self, PopulateEvent(event.index + 1, event.item))
        #     return True
        if event.type() == ShowVersionWidgetEvent.eventType:
            event.item.show_version_widget()
            return True
        return super(GraphicsSceneWidget, self).event(event)