Beispiel #1
0
    def paintEvent(self, event):
        super(ScriptEditorTreeView, self).paintEvent(event)
        if self._drag_over:
            painter = QtGui.QPainter(self.viewport())
            painter.setRenderHint(QtGui.QPainter.Antialiasing)
            rect = self.rect()

            painter.save()

            painter.setBrush(QtGui.QColor(255, 230, 183, 50))
            painter.drawRect(rect)

            painter.restore()

            painter.setPen(
                QtGui.QPen(QtGui.QColor(255, 230, 183), 5, QtCore.Qt.DashLine))
            painter.drawRoundedRect(rect.adjusted(20, 20, -20, -20), 20, 20)
Beispiel #2
0
    def __init__(self, parent=None):
        super(ScriptEditorItemDelegate, self).__init__(parent)
        self.line_numbers_indent = 0

        # Fonts
        self._font_default = QtGui.QFont()
        self._font_default.setWeight(QtGui.QFont.Normal)
        self._font_comment = QtGui.QFont()
        self._font_comment.setWeight(QtGui.QFont.Expanded)
        self._font_has_children = QtGui.QFont()
        self._font_has_children.setWeight(QtGui.QFont.DemiBold)

        # Colors
        self._color_default = QtGui.QColor(210, 210, 210)
        self._color_default_value = QtGui.QColor(255, 167, 21)
        self._color_comment = QtGui.QColor(30, 30, 30)
        self._color_layer_addition = QtGui.QColor(217, 60, 60)
        self._color_stacked_pushed = QtGui.QColor(210, 210, 210)
        self._color_stacked_pushed_value = QtGui.QColor(83, 129, 198)
        self._color_has_children = QtGui.QColor(230, 230, 230)
        self._color_line_number = QtGui.QColor(40, 40, 40)
        self._color_selection = QtGui.QColor(255, 230, 183)
Beispiel #3
0
    def paint(self, painter, option, index):
        painter.setRenderHints(QtGui.QPainter.Antialiasing
                               | QtGui.QPainter.TextAntialiasing)
        padding_left = option.rect.left(
        ) + self._padding_item["left"] + self._padding_content["left"]
        padding_right = self._padding_item["right"] + self._padding_content[
            "right"]
        padding_top = option.rect.top() + self._padding_item["top"]

        is_btn = index.data(TreeItem.is_button_role)

        if is_btn:
            text_btn = "show more versions..."

            padding_top += self._fm_desc.height()

            padding_left_btn = option.rect.width() - option.rect.width() * 0.5
            padding_left_btn -= self._fm_desc.width(text_btn) * 0.5

            self._button_rect = QtCore.QRect(option.rect.left(), 0,
                                             option.rect.width(),
                                             option.rect.height())

            self.draw_button(painter, text_btn, padding_left_btn, padding_top,
                             index)

        else:
            asset_type = index.data(TreeItem.asset_type_role)

            name = index.data(TreeItem.name_role)
            version_nb = index.data(TreeItem.version_nb_role)
            publisher = index.data(TreeItem.publisher_role)
            date = index.data(TreeItem.date_role)
            is_edited = index.data(TreeItem.is_edited_role)
            comment = index.data(TreeItem.comment_role)
            locked = index.data(TreeItem.is_locked_role)
            thumbnail = index.data(TreeItem.thumbnail_role)

            locations = index.data(TreeItem.location_role)
            available = index.data(TreeItem.is_available_role)

            main_color = QtGui.QColor()
            main_color.setNamedColor('#333')
            legend_color = QtGui.QColor()
            legend_color.setNamedColor(self._view.asset_color(asset_type))

            # Get status
            if self._is_top_asset_version(index):
                if available is None:
                    background = self._background_regenerated
                elif available:
                    background = self._background
                else:
                    background = self._background_not_available
                background_comment = self._background_comment
                size_thumbnail = self._thumnbail_size

            else:
                if available is None:
                    background = self._background_regenerated
                elif available:
                    background = self._background.lighter(111)
                else:
                    background = self._background_child_not_available
                background_comment = self._background_comment.lighter(111)
                size_thumbnail = self._thumnbail_child_size

            background_comment = main_color
            background = QtGui.QColor()
            background.setNamedColor('#222')
            # Draw background
            if option.state & QtGui.QStyle.State_Selected:
                painter.setPen(
                    QtGui.QPen(QtCore.Qt.lightGray, 2, QtCore.Qt.SolidLine))
            else:
                painter.setPen(QtGui.QPen(background, 0, QtCore.Qt.SolidLine))
            painter.setBrush(background)

            adjusted_rect = option.rect.adjusted(
                self._padding_item["left"], self._padding_item["top"],
                -self._padding_item["right"],
                -self._padding_item["top"] - self._padding_item["bottom"])
            painter.drawRoundedRect(adjusted_rect, 3, 3)

            # Draw type
            type_indicator_rect = QtCore.QRect(adjusted_rect.left() + 3,
                                               adjusted_rect.top() + 3,
                                               self._type_indicator_width - 6,
                                               adjusted_rect.height() - 6)

            painter.setPen(QtGui.QPen(legend_color, 0, QtCore.Qt.SolidLine))
            painter.setBrush(legend_color)

            # painter.drawRoundedRect(type_indicator_rect, 3, 3)

            padding_left += self._type_indicator_width
            padding_top += self._padding_content["top"]

            # Draw thumbnail if necessary
            if self._show_thumbnail:
                if thumbnail is None:
                    pixmap = QtGui.QImage(self._thumnbail_default)
                else:
                    pixmap = QtGui.QImage(thumbnail)

                pixmap_scaled = pixmap.scaled(size_thumbnail,
                                              QtCore.Qt.KeepAspectRatio)

                thumbnail_rect = QtCore.QRect(padding_left, padding_top,
                                              pixmap_scaled.width(),
                                              pixmap_scaled.height())

                painter.setPen(
                    QtGui.QPen(self._background.darker(190), 0.5,
                               QtCore.Qt.SolidLine))
                painter.setBrushOrigin(padding_left, padding_top)
                painter.setBrush(pixmap_scaled)
                painter.drawRoundedRect(thumbnail_rect, 3, 3)

                # If it's a top asset, we draw the legend
                if self._is_top_asset_version(index):
                    padding_top_rect = padding_top + thumbnail_rect.height(
                    ) - self._fm_desc.height()
                    type_rect = QtCore.QRect(
                        padding_left, padding_top_rect - 6,
                        self._fm_desc.width(asset_type) + 10,
                        self._fm_desc.height() + 6)

                    painter.setBrush(legend_color)
                    painter.drawRoundedRect(type_rect, 3, 3)

                    if legend_color.lightness() < 127.5:
                        legend_text_color = legend_color.lighter(190)
                    else:
                        legend_text_color = legend_color.darker(190)

                    painter.setPen(
                        QtGui.QPen(legend_text_color, 0, QtCore.Qt.SolidLine))

                    padding_top_legend = padding_top + thumbnail_rect.height(
                    ) - 6
                    painter.drawText(padding_left + 2, padding_top_legend,
                                     asset_type)

                padding_left += size_thumbnail.width() + 10

            # Draw version number
            if self._is_top_asset_version(index):
                color_number = self._name_color
            else:
                color_number = self._name_color.darker(130)

            painter.setPen(QtGui.QPen(color_number, 1, QtCore.Qt.SolidLine))
            painter.setFont(self._font_name)

            version_nb_str = "v%02d" % version_nb
            painter.drawText(
                option.rect.right() - padding_right -
                self._fm_name.width(version_nb_str),
                padding_top + self._fm_name.height(), version_nb_str)

            # Draw name asset if necessary
            if self._is_top_asset_version(index):
                padding_top += self._fm_name.height()
                painter.drawText(padding_left, padding_top, name)
                padding_top += self._inter_text

            # If publisher is None, that means that the asset is being
            # regenerated
            if publisher != None:

                # Draw publisher
                painter.setPen(
                    QtGui.QPen(self._desc_color, 1, QtCore.Qt.SolidLine))
                painter.setFont(self._font_desc)

                label = "published by " if not is_edited else "edited by "
                padding_top += self._fm_desc.height()
                painter.drawText(padding_left, padding_top,
                                 label + publisher.getName())

                # Draw Date
                painter.setPen(
                    QtGui.QPen(self._owner_color, 1, QtCore.Qt.SolidLine))

                padding_top += self._fm_desc.height() + self._inter_text

                self.draw_date(painter, date, padding_left, padding_top, index)

                self._date_rect = QtCore.QRect(
                    padding_left,
                    padding_top - self._fm_desc.height() - option.rect.top(),
                    option.rect.width() - padding_left - 10,
                    self._fm_desc.height() + 10)

                # # Draw Location if necessary
                # if not available:
                #     locations_info = "Locations: "
                #     if len(locations) > 0:
                #       locations_info += ", ".join(locations)
                #     else:
                #       locations_info += "Hmmm... nowhere?"
                #     painter.setPen(
                #         QtGui.QPen(QtCore.Qt.red, 1, QtCore.Qt.SolidLine))

                #     padding_top += self._fm_desc.height() + self._inter_text
                #     painter.drawText(padding_left, padding_top, locations_info)

                # Draw comment
                painter.setPen(
                    QtGui.QPen(background_comment, 0, QtCore.Qt.SolidLine))
                painter.setBrush(background_comment)

                padding_top += self._inter_text * 2

                r_comment, r_comment_text = self._bounding_boxes(
                    comment, option.rect.width(), padding_left, padding_top)

                painter.drawRoundedRect(r_comment, 3, 3)
                painter.setPen(
                    QtGui.QPen(self._comment_color, 1, QtCore.Qt.SolidLine))
                painter.drawText(r_comment_text, self._comment_flags, comment)

            else:

                # Draw loading asset...
                painter.setPen(
                    QtGui.QPen(self._desc_color, 1, QtCore.Qt.SolidLine))
                painter.setFont(self._font_desc)

                padding_top += self._fm_desc.height()
                painter.drawText(padding_left, padding_top, "Loading...")

        # Get the width to update the sizeHint
        self._width = option.rect.width()
Beispiel #4
0
    def __init__(self, parent, minimum_width=200, show_thumbnail=True):
        super(TreeDelegateStyle, self).__init__(parent)

        self._view = parent
        self._minimum_width = minimum_width
        self._show_thumbnail = show_thumbnail

        self._thumnbail_default = QtGui.QImage()
        default_thumb = os.environ["FTRACK_SERVER"] + "/img/thumbnail2.png"
        self._thumnbail_default.loadFromData(
            urllib.urlopen(default_thumb).read())

        # Fonts...
        self._font_name = QtGui.QFont()
        self._font_name.setPixelSize(12)
        self._font_name.setWeight(QtGui.QFont.Bold)
        self._fm_name = QtGui.QFontMetrics(self._font_name)

        self._font_desc = QtGui.QFont()
        self._font_desc.setPixelSize(11)
        self._font_desc.setWeight(QtGui.QFont.Normal)
        self._fm_desc = QtGui.QFontMetrics(self._font_desc)

        # Sizes...
        self._thumnbail_size = QtCore.QSize(150, 100)
        self._thumnbail_child_size = QtCore.QSize(96, 64)

        self._type_indicator_width = 12

        # Colors...
        self._background = QtGui.QColor(68, 68, 68)
        self._background_regenerated = QtGui.QColor(20, 20, 20)

        self._background_comment = QtGui.QColor(58, 58, 58)

        self._name_color = QtGui.QColor(195, 207, 164)
        self._desc_color = QtGui.QColor(240, 240, 240)
        self._owner_color = QtGui.QColor(200, 200, 200)
        self._comment_color = QtGui.QColor(240, 240, 240)

        self._btn_color = QtGui.QColor(255, 255, 255, 80)
        self._btn_color_hover = QtGui.QColor(255, 255, 255, 200)
        self._btn_color_pressed = QtGui.QColor(255, 255, 255, 255)

        # Flags...
        self._comment_flags = QtCore.Qt.TextWordWrap | QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop

        # Paddings...
        self._padding_item = dict(left=3, top=3, right=3, bottom=0)
        self._padding_content = dict(left=5, top=5, right=5, bottom=10)
        self._padding_comment = 5
        self._inter_text = 5
        self._inter_item = 3
        self._space_before_btn = 8

        # method...
        self._width = self._minimum_width

        # Keep the QRect of the "show previous versions" button if necessary
        self._button_rect = None

        # Keep the QRect of the "date" to show the real date in hover mode
        self._date_rect = None

        # Hover state
        self._hover_state = dict(no_hover=0,
                                 btn_hover=1,
                                 btn_pressed=2,
                                 date_hover=3)

        # Keep in memory the index under the mouse
        self._current_index = None
Beispiel #5
0
def ftrackPublishKnobChanged(forceRefresh=False, g=None):
    g = g or nuke.thisNode()

    if 'ftable' in g.knobs():
        header = getHeaderKnob(g)
        nodeAssetType = ''
        if nuke.thisKnob().name() in ['inputChange', 'fscript'
                                      ] or forceRefresh == True:
            thisNodeName = g['name'].value()
            g = nuke.toNode(HelpFunctions.safeString(thisNodeName))
            # Add new labels
            cmdString = ''
            assetType = None
            availableAssetTypes = ['']
            inputMissmatch = None

            tableWidget = g['ftable'].getObject().tableWidget
            tableWidget.setRowCount(0)
            components = []

            for inputNode in range(g.inputs()):
                inNode = g.input(inputNode)

                if inNode:
                    if inNode.Class() in ['Read', 'Write']:
                        nodeAssetType = 'img'
                    elif inNode.Class() in ['WriteGeo']:
                        nodeAssetType = 'geo'
                    else:
                        nodeAssetType = ''

                    if not assetType:
                        assetType = nodeAssetType

                    if assetType != nodeAssetType:
                        inputMissmatch = True

                    if nodeAssetType == 'img':
                        fileComp = str(inNode['file'].value())
                        proxyComp = str(inNode['proxy'].value())
                        nameComp = str(inNode['name'].value()).strip()

                        if inNode.Class() == 'Read':
                            first = str(inNode['first'].value())
                            last = str(inNode['last'].value())
                            if first == '0.0' and last == '0.0':
                                first = str(
                                    int(nuke.root().knob(
                                        "first_frame").value()))
                                last = str(
                                    int(nuke.root().knob(
                                        "last_frame").value()))

                            availableAssetTypes = ['img', 'render']

                        elif inNode.Class() == 'Write':

                            # use the timeline to define the amount of frames
                            first = str(
                                int(nuke.root().knob("first_frame").value()))
                            last = str(
                                int(nuke.root().knob("last_frame").value()))

                            # then in case check if the limit are set
                            if inNode['use_limit'].value():
                                first = str(inNode['first'].value())
                                last = str(inNode['last'].value())

                            # always check how many frames are actually available
                            frames = inNode['file'].value()

                            try:
                                # Try to collect the sequence prefix, padding
                                # and extension. If this fails with a ValueError
                                # we are probably handling a non-sequence file.
                                # If so rely on the first_frame and last_frame
                                # of the root node.
                                prefix, padding, extension = frames.split('.')
                            except ValueError:
                                FnAssetAPI.logging.debug(
                                    'Could not determine prefix, padding '
                                    'and extension from "".'.format(frames))
                                availableAssetTypes = ['render']
                            else:
                                root = os.path.dirname(prefix)
                                files = glob.glob('{0}/*.{1}'.format(
                                    root, extension))
                                collections = clique.assemble(files)

                                for collection in collections[0]:
                                    if prefix in collection.head:
                                        indexes = list(collection.indexes)
                                        first = str(indexes[0])
                                        last = str(indexes[-1])
                                        break

                                availableAssetTypes = ['img']

                        try:
                            compNameComp = inNode['fcompname'].value()
                        except:
                            compNameComp = ''

                        if compNameComp == '':
                            compNameComp = nameComp

                        components.append(
                            (fileComp, compNameComp, first, last, nameComp))
                        if proxyComp != '':
                            components.append(
                                (proxyComp, compNameComp + '_proxy', first,
                                 last, nameComp))

                    elif nodeAssetType == 'geo':
                        fileComp = str(inNode['file'].value())
                        nameComp = str(inNode['name'].value()).strip()
                        first = str(inNode['first'].value())
                        last = str(inNode['last'].value())

                        if first == '0.0' and last == '0.0':
                            first = str(
                                int(nuke.root().knob("first_frame").value()))
                            last = str(
                                int(nuke.root().knob("last_frame").value()))

                        try:
                            compNameComp = inNode['fcompname'].value()
                        except:
                            compNameComp = ''

                        if compNameComp == '':
                            compNameComp = nameComp

                        components.append(
                            (fileComp, compNameComp, first, last, nameComp))

                        availableAssetTypes = ['geo', 'cam']

            rowCount = len(components)

            tableWidget.setRowCount(rowCount)
            if len(components) == 0:
                g.knob('pknob').setEnabled(False)
            else:
                g.knob('pknob').setEnabled(True)

            l = [x[1] for x in components]
            wodup = list(set(l))

            if len(l) != len(wodup):
                g.knob('pknob').setEnabled(False)
                header.setMessage('Components can not have the same name',
                                  'warning')

            rowCntr = 0
            for comp in components:
                cb = QtWidgets.QCheckBox('')
                cb.setChecked(True)
                tableWidget.setCellWidget(rowCntr, 0, cb)

                componentItem = QtWidgets.QTableWidgetItem()
                componentItem.setText(comp[0])
                componentItem.setToolTip(comp[0])
                tableWidget.setItem(rowCntr, 1, componentItem)
                componentItem = QtWidgets.QTableWidgetItem()
                componentItem.setText(comp[1])
                componentItem.setToolTip(comp[1])
                tableWidget.setItem(rowCntr, 2, componentItem)

                try:
                    fileCurrentFrame = nukescripts.replaceHashes(
                        comp[0]) % int(float(comp[2]))
                except:
                    print 'File is not sequence'
                    fileCurrentFrame = comp[0]
                if os.path.isfile(fileCurrentFrame):
                    fileExist = 'T'
                else:
                    fileExist = 'F'

                componentItem = QtWidgets.QTableWidgetItem()
                if fileExist == 'T':
                    componentItem.setBackground(QtGui.QColor(20, 161, 74))
                else:
                    componentItem.setBackground(QtGui.QColor(227, 99, 22))
                componentItem.setToolTip(fileExist)
                tableWidget.setItem(rowCntr, 4, componentItem)

                componentItem = QtWidgets.QTableWidgetItem()
                componentItem.setText(comp[2])
                componentItem.setToolTip(comp[2])
                tableWidget.setItem(rowCntr, 5, componentItem)

                componentItem = QtWidgets.QTableWidgetItem()
                componentItem.setText(comp[3])
                componentItem.setToolTip(comp[3])
                tableWidget.setItem(rowCntr, 6, componentItem)

                componentItem = QtWidgets.QTableWidgetItem()
                componentItem.setText(comp[4])
                componentItem.setToolTip(comp[4])
                tableWidget.setItem(rowCntr, 3, componentItem)

                rowCntr += 1

            g['ftrackassettype'].setValues(availableAssetTypes)

            if inputMissmatch:
                tableWidget.setRowCount(0)
                g['ftrackassettype'].setValues(['Missmatch inputs'])

            if cmdString == '':
                cmdString = 'No inputs connected'

            assetEnums = ['New']
            if nodeAssetType != '':
                # assets = connector.Connector.objectById(os.environ['FTRACK_SHOTID']).getAssets(assetTypes=[g['ftrackassettype'].value()])
                pubto = g.knob('fpubto').getObject().targetTask
                assets = connector.Connector.objectById(pubto).getAssets(
                    assetTypes=[g['ftrackassettype'].value()])
                assets = sorted(assets,
                                key=lambda entry: entry.getName().lower())
                assetEnums = assetEnums + [
                    HelpFunctions.safeString(x.getName()) for x in assets
                ]
                FnAssetAPI.logging.info(assetEnums)
                g['fassetnameexisting'].setValues(assetEnums)

            g = nuke.toNode(HelpFunctions.safeString(thisNodeName))
            g.begin()

            # Add more inputs if full
            realInputCount = 0
            for inputNode in range(g.inputs()):
                if g.input(inputNode):
                    realInputCount += 1
            if realInputCount == g.maxInputs():
                inputNode = nuke.createNode("Input", inpanel=False)
            g.end()
        elif nuke.thisKnob().name() == 'ftrackassettype':
            nodeAssetType = g['ftrackassettype'].value()
            #print nodeAssetType
            assetEnums = ['New']
            if nodeAssetType != '' and nodeAssetType != 'Missmatch inputs':
                # assets = connector.Connector.objectById(os.environ['FTRACK_SHOTID']).getAssets(assetTypes=[nodeAssetType])
                pubto = g.knob('fpubto').getObject().targetTask
                assets = connector.Connector.objectById(pubto).getAssets(
                    assetTypes=[nodeAssetType])
                assetEnums = assetEnums + [
                    HelpFunctions.safeString(x.getName()) for x in assets
                ]
                g['fassetnameexisting'].setValues(assetEnums)
Beispiel #6
0
    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        # Design the graph
        width_graph = self.width() - (self._pad_left + self._pad_right)
        height_graph = self.height() - (self._pad_top + self._pad_bottom)

        rect = QtCore.QRect(
            self._pad_left, self._pad_top, width_graph, height_graph)
        painter.fillRect(self.rect(), self._color_back_2)
        painter.fillRect(rect, self._color_back_1)

        # Sort graphs to draw the highlighted one at the end
        unhighlight_graphs = [
            p for p in self._points.keys() if p != self._highlight_graph]
        all_graphs_type = unhighlight_graphs + [self._highlight_graph]

        # Collect the axis values to draw it at the end...
        pts_legend_Y = dict()
        pts_legend_X = dict()

        versions = range(self._version_number)
        width_interval = 1 if len(
            versions) == 1 else 1 / float(len(versions) - 1)
        for i in versions:
            pts_legend_X[i] = self._pad_left + width_graph * i * width_interval

        # collect the highlighted point to get the tool-tips..
        points_h = dict()

        # Get the highlighted point
        hover_point = None

        # Draw each graph...
        for type_graph in all_graphs_type:
            if self._points[type_graph] == None:
                continue

            points_tuples = []
            highlighted = type_graph == self._highlight_graph
            for i in sorted(pts_legend_X.keys(), reverse=True):
                hover = False

                try:
                    graph_point = self._points[type_graph][i]

                except IndexError:
                    pass

                else:
                    padding = self._pad_top + height_graph
                    relative_position = height_graph * self.raise_level * 0.1
                    ypos = padding - relative_position * \
                        graph_point.normalized_value

                    pt = (pts_legend_X[i], ypos)
                    points_tuples.append(pt)

                    pts_legend_Y[graph_point.value] = ypos

                    if highlighted:
                        points_h[pt] = graph_point

                        if self._cursor != None and hover_point == None:
                            inter_points = width_interval * width_graph * 0.5
                            if (self._cursor[0] > pts_legend_X[i] - inter_points
                                    and self._cursor[0] < pts_legend_X[i] + inter_points):
                                hover_point = (pts_legend_X[i], ypos)
                                hover = True

                # Draw vertical lines of the graph (and horizontal if
                # necessary)
                color = self._color_dot_lines_hover if hover else self._color_dot_lines
                painter.setPen(
                    QtGui.QPen(QtGui.QColor(color), 1, QtCore.Qt.DotLine))
                line_tuples = [(pts_legend_X[i], self._pad_top),
                               (pts_legend_X[i], self.height() - self._pad_bottom)]
                line_polys = QtGui.QPolygonF(
                    map(lambda p: QtCore.QPointF(*p), line_tuples))
                painter.drawPolyline(line_polys)

                if hover:
                    line_H = [(self._pad_left, hover_point[1]),
                              (self._pad_left + width_graph, hover_point[1])]
                    line_H_polys = QtGui.QPolygonF(
                        map(lambda p: QtCore.QPointF(*p), line_H))
                    painter.drawPolyline(line_H_polys)

            # Draw the lines of the graph
            width_line = 3 if highlighted else 2
            color = self._points_colors[
                type_graph] if highlighted else self._points_colors[type_graph].darker(110)
            painter.setPen(QtGui.QPen(QtGui.QColor(color), width_line))
            points_polys = QtGui.QPolygonF(
                map(lambda p: QtCore.QPointF(*p), points_tuples))
            painter.drawPolyline(points_polys)

            # Draw points
            for point_tuple in points_tuples:
                painter.drawEllipse(
                    QtCore.QRectF(point_tuple[0] - 2, point_tuple[1] - 2, 4, 4))

        # Draw highlighted graph points...
        if hover_point != None and self._highlight_graph in self._points_colors.keys():
            x_pos, y_pos = hover_point
            color = self._points_colors[self._highlight_graph].lighter(160)
            painter.setBrush(QtGui.QBrush(color))
            painter.setPen(QtGui.QPen(QtGui.QColor(QtCore.Qt.black), 1))
            painter.drawEllipse(QtCore.QRectF(x_pos - 5, y_pos - 5, 10, 10))

        painter.setPen(QtGui.QPen(QtGui.QColor(self._color_axis_text), 2))

        # Draw X Axis
        buf_X = 0
        for version_nb in sorted(pts_legend_X.keys(), reverse=True):
            version_str = "v%d" % (version_nb + 1)
            version_position_X = pts_legend_X[
                version_nb] - len(version_str) * 5
            if buf_X == 0 or buf_X - version_position_X > 40:
                pt_legend_X = QtCore.QPointF(version_position_X,
                                             self._pad_top + height_graph + 15)
                painter.drawText(pt_legend_X, version_str)
                buf_X = version_position_X

        # Draw Y Axis
        buf_Y = 0
        for value_Y in sorted(pts_legend_Y.keys(), reverse=True):
            if buf_Y == 0 or pts_legend_Y[value_Y] - buf_Y > 15:
                value_str = str(value_Y)
                pt_legend_Y = QtCore.QPointF(self._pad_left - len(value_str) * 15,
                                             pts_legend_Y[value_Y] + 10)
                bounding_rect = QtCore.QRect(0, pts_legend_Y[value_Y] - 4,
                                             self._pad_left - 15, pts_legend_Y[value_Y] + 10)
                painter.drawText(
                    bounding_rect, QtCore.Qt.AlignRight, value_str)
                buf_Y = pts_legend_Y[value_Y]

        if hover_point != None:
            td = QtGui.QTextDocument()
            td.setHtml(points_h[hover_point].tooltip)
            width_tooltip = 180
            td.setTextWidth(width_tooltip)
            height_tooltip = td.size().height()

            pos_topleft = QtCore.QPoint(
                self._cursor[0] + 5, self._cursor[1] + 5)
            if pos_topleft.x() + width_tooltip > self.width() - self._pad_right - 10:
                pos_topleft.setX(
                    self.width() - self._pad_right - width_tooltip - 10)
            if pos_topleft.y() + height_tooltip > self.height() - self._pad_bottom - 10:
                pos_topleft.setY(
                    self.height() - self._pad_bottom - height_tooltip - 10)

            painter.setOpacity(0.6)
            rect = QtCore.QRect(pos_topleft.x(), pos_topleft.y(),
                                width_tooltip + 20, height_tooltip + 20)
            painter.fillRect(rect, self._color_tooltip)

            painter.setOpacity(1.0)
            painter.translate(pos_topleft.x() + 10, pos_topleft.y() + 10)
            ctx = QtGui.QAbstractTextDocumentLayout.PaintContext()
            ctx.clip = QtCore.QRect(0, 0, width_tooltip, height_tooltip)
            td.documentLayout().draw(painter, ctx)

        # Place the buttons
        pad_left = 5
        pos_bottom = self.height() - 25
        for button_name in ["tracked", "in_tree", "enabled", "total"]:
            if self._buttons[button_name] != None:
                width_btn = self._buttons[button_name].width()
                self._buttons[button_name].move(
                    self.width() - width_btn - pad_left, pos_bottom)
                pad_left += width_btn + 5

                if self._highlight_graph == button_name:
                    btn_css = "background:%s; color:#FFF; border:none; border-radius:3px;" % self._points_colors[
                        button_name].name()
                else:
                    btn_css = "background:#444; color:#FFF; border:none; border-radius:3px;"
                self._buttons[button_name].setStyleSheet(btn_css)

#   Raise the curve at the first display....
        if self.raise_level < 10:
            self.raise_level += 1
            time.sleep(0.000015)
            self.update()
Beispiel #7
0
    def __init__(self, nodes_name, version_number, infos_dict=None, in_tree=True, parent=None):
        super(GraphWidget, self).__init__(parent)
        self.setMinimumHeight(360)

        self.setMouseTracking(True)

        self._buttons = dict(
            total=None, enabled=None, in_tree=None, tracked=None)
        self._cursor = None
        self.raise_level = 7

        self.nodes_name = nodes_name
        self.in_tree = in_tree
        self._version_number = version_number

        self._points = dict(total=[], enabled=[], in_tree=None, tracked=None)
        self._highlight_graph = "total"

        self._pad_left = 60
        self._pad_top = 20
        self._pad_right = 20
        self._pad_bottom = 50

        self._color_back_2 = QtGui.QColor()
        self._color_back_1 = QtGui.QColor()

        self._color_back_2.setNamedColor('#222')
        self._color_back_1.setNamedColor('#333')
        self._color_dot_lines = QtGui.QColor(150, 150, 150)
        self._color_dot_lines_hover = QtGui.QColor(80, 80, 80)
        self._color_axis_text = QtGui.QColor(80, 80, 80)
        self._color_tooltip = QtGui.QColor(100, 100, 100)
        self._color_tooltip_text = QtGui.QColor(30, 30, 30)

        self._color_btn_on = QtGui.QColor(170, 170, 170)
        self._color_btn_off = QtGui.QColor(80, 80, 80)

        self._points_colors = dict(total=QtGui.QColor(112, 129, 69),
                                   enabled=QtGui.QColor(83, 128, 162),
                                   in_tree=QtGui.QColor(187, 151, 89),
                                   tracked=QtGui.QColor(131, 30, 22))

        self.set_infos(infos_dict)
        self.set_buttons()