def __init__(self, node, fileName, lineNumber, outside, nodeFont): QGraphicsRectItem.__init__(self) self.__node = node self.__fileName = fileName self.__lineNumber = lineNumber self.__outside = outside self.__font = DEFAULT_FONT if nodeFont: self.__font = nodeFont posX = node.posX - node.width / 2.0 posY = node.posY - node.height / 2.0 QGraphicsRectItem.__init__(self, posX, posY, node.width, node.height) self.setRectanglePen() # node.color is like "#fe0400" if node.color.startswith("#"): color = QColor(int(node.color[1:3], 16), int(node.color[3:5], 16), int(node.color[5:], 16)) else: color = QColor(220, 255, 220) self.setBrush(color) # To make item selectable self.setFlag(QGraphicsItem.ItemIsSelectable, os.path.isabs(self.__fileName) and self.__lineNumber > 0) # Set tooltip as a function docstring if fileName != "" and lineNumber != 0: self.setToolTip(GlobalData().getFileLineDocstring( fileName, lineNumber))
def setModified(self, status): """Sets the required tooltip background""" palette = self.info.palette() if status: # Reddish palette.setColor(QPalette.Background, QColor(255, 227, 227)) else: # Blueish palette.setColor(QPalette.Background, QColor(224, 236, 255)) self.info.setPalette(palette)
def buildColor(colorAsStr): """Converts saved color into QColor object""" colorAsStr = colorAsStr.strip() parts = colorAsStr.split(',') length = len(parts) if length == 3: return QColor(int(parts[0]), int(parts[1]), int(parts[2])) if length == 4: return QColor(int(parts[0]), int(parts[1]), int(parts[2]), int(parts[3])) raise Exception("Unexpected color format")
def __init__(self, node): QGraphicsRectItem.__init__(self) self.__node = node posX = node.posX - node.width / 2.0 posY = node.posY - node.height / 2.0 QGraphicsRectItem.__init__(self, posX, posY, node.width, node.height) pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) self.setPen(pen) self.setBrush(QColor(216, 216, 207))
def buildColor(color): """Four options are supported: #hhhhhh hexadecimal rgb #hhhhhhhh hexadecimal rgb and alpha ddd,ddd,ddd decimal rgb ddd,ddd,ddd,ddd decimal rgb and alpha """ if color.startswith('#'): color = color[1:] length = len(color) if length not in [6, 8]: raise Exception("Invalid hexadecimal color format: #" + color) try: # The most common case red = int(color[0:2], 16) checkColorRange(red) green = int(color[2:4], 16) checkColorRange(green) blue = int(color[4:6], 16) checkColorRange(blue) if length == 6: return QColor(red, green, blue) alpha = int(color[6:8], 16) checkColorRange(alpha) return QColor(red, green, blue, alpha) except: raise Exception("Invalid hexadecimal color format: #" + color) parts = color.split(',') length = len(parts) if length not in [3, 4]: raise Exception("Invalid decimal color format: " + color) try: red = int(parts[0].strip()) checkColorRange(red) green = int(parts[1].strip()) checkColorRange(green) blue = int(parts[2].strip()) checkColorRange(blue) if length == 3: return QColor(red, green, blue) alpha = int(parts[3].strip()) checkColorRange(alpha) return QColor(red, green, blue, alpha) except: raise Exception("Invalid decimal color format: " + color)
def getBorderColor(color): """Creates a darker version of the color""" red = color.red() green = color.green() blue = color.blue() delta = 60 if isDark(red, green, blue): # Need lighter color return QColor(min(red + delta, 255), min(green + delta, 255), min(blue + delta, 255), color.alpha()) # Need darker color return QColor(max(red - delta, 0), max(green - delta, 0), max(blue - delta, 0), color.alpha())
def paint(self, painter, option, widget): """Draws a filled rectangle and then adds a title""" # Hide the dotted outline itemOption = QStyleOptionGraphicsItem(option) if itemOption.state & QStyle.State_Selected != 0: itemOption.state = itemOption.state & ~QStyle.State_Selected # Draw the rectangle pen = painter.pen() pen.setJoinStyle(Qt.RoundJoin) painter.setPen(pen) QGraphicsRectItem.paint(self, painter, itemOption, widget) # Draw text over the rectangle painter.setFont(self.__font) painter.setPen(QPen(QColor(255, 255, 255))) painter.drawText(self.__node.posX - self.__node.width / 2.0, self.__node.posY - self.__node.height / 2.0, self.__node.width, self.__node.height, Qt.AlignCenter, self.__node.label.replace('\\n', '\n')) if self.__outside: pixmap = getPixmap("nonprojectentrydgm.png") pixmapPosX = self.__node.posX - self.__node.width / 2.0 + 2 pixmapPosY = self.__node.posY + self.__node.height / 2.0 - \ pixmap.height() - 2 painter.setRenderHint(QPainter.SmoothPixmapTransform) painter.drawPixmap(pixmapPosX, pixmapPosY, pixmap)
def __parseConfigTuple(self, pluginIndicator): """Checks what plugin provided""" if len(pluginIndicator) != 5: raise Exception("Unexpected format of an indicator " "description. Expected 5 values.") # ID field self.identifier = int(pluginIndicator[0]) # Pixmap/text field try: if isinstance(pluginIndicator[1], QPixmap): self.pixmap = QPixmap(pluginIndicator[1]) elif os.path.exists(pluginIndicator[1]): self.pixmap = QPixmap(pluginIndicator[1]) elif os.path.exists(getPixmapPath() + pluginIndicator[1]): self.pixmap = QPixmap(getPixmapPath() + pluginIndicator[1]) else: self.__setText(pluginIndicator[1]) except: self.__setBrokenIndicator("Failed to get plugin indicator " "pixmap. Indicator id: " + str(self.identifier)) return # Foreground color if pluginIndicator[2] is None: self.foregroundColor = None else: if type(pluginIndicator[2]) == str: self.foregroundColor = buildColor(pluginIndicator[2]) else: self.foregroundColor = QColor(pluginIndicator[2]) # Background color if pluginIndicator[3] is None: self.backgroundColor = None else: if type(pluginIndicator[3]) == str: self.backgroundColor = buildColor(pluginIndicator[3]) else: self.backgroundColor = QColor(pluginIndicator[3]) # Default tooltip if pluginIndicator[4] is None: self.defaultTooltip = "" else: self.defaultTooltip = str(pluginIndicator[4]).strip()
def paint(self, painter, option, widget): """Draws a curve and then adds an arrow""" pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) pen.setStyle(Qt.DotLine) self.setPen(pen) QGraphicsPathItem.paint(self, painter, option, widget)
def __init__(self, node, refFile, srcobj): QGraphicsRectItem.__init__(self) self.__node = node self.__srcobj = srcobj self.__refFile = refFile posX = node.posX - node.width / 2.0 posY = node.posY - node.height / 2.0 QGraphicsRectItem.__init__(self, posX, posY, node.width, node.height) pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) self.setPen(pen) # To make double click delivered self.setFlag(QGraphicsItem.ItemIsSelectable, True) self.setBrush(QColor(253, 245, 145))
def paint(self, painter, option, widget): """Draws a curve and then adds an arrow""" pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) self.setPen(pen) painter.setRenderHint(QPainter.Antialiasing, True) QGraphicsPathItem.paint(self, painter, option, widget)
def __paintTopLeft(self, painter): """Paints the scope rectangle""" s = self.canvas.settings painter.setPen(self.getPainterPen(self.isSelected(), self.borderColor)) painter.setBrush(QBrush(self.bgColor)) yPos = self.baseY + s.vCellPadding height = self.canvas.minHeight - 2 * s.vCellPadding if self.aboveBadges.hasAny(): badgeShift = self.aboveBadges.height + s.badgeToScopeVPadding yPos += badgeShift height -= badgeShift if self.kind in [CellElement.FOR_SCOPE, CellElement.WHILE_SCOPE]: cellBelow = self.canvas.cells[self.addr[1] + 1][self.addr[0]] halfDeclHeight = (cellBelow.height + s.scopeRectRadius) / 2 yPos += halfDeclHeight height -= halfDeclHeight painter.drawRoundedRect(self.baseX + s.hCellPadding, yPos, self.canvas.minWidth - 2 * s.hCellPadding, height, s.scopeRectRadius, s.scopeRectRadius) if self.kind in [CellElement.FOR_SCOPE, CellElement.WHILE_SCOPE]: # Brush if self.kind == CellElement.FOR_SCOPE: painter.setBrush(QBrush(s.forScopeHeaderBGColor)) else: painter.setBrush(QBrush(s.whileScopeHeaderBGColor)) # Pen, if not selected if not self.isSelected(): if self.kind == CellElement.FOR_SCOPE: pen = QPen(QColor(s.forScopeHeaderBorderColor)) pen.setWidth(s.forScopeHeaderPenWidth) else: pen = QPen(QColor(s.whileScopeHeaderBorderColor)) pen.setWidth(s.whileScopeHeaderPenWidth) painter.setPen(pen) painter.drawPolygon(QPointF(self.x1, self.y1), QPointF(self.x2, self.y2), QPointF(self.x3, self.y3), QPointF(self.x4, self.y4), QPointF(self.x5, self.y5), QPointF(self.x6, self.y6))
def __init__(self, node, refFile, docstring): QGraphicsRectItem.__init__(self) self.__node = node self.__refFile = refFile self.__docstring = docstring posX = node.posX - node.width / 2.0 posY = node.posY - node.height / 2.0 QGraphicsRectItem.__init__(self, posX, posY, node.width, node.height) pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) self.setPen(pen) self.setBrush(QColor(220, 255, 220)) # System modules are clickable self.setFlag(QGraphicsItem.ItemIsSelectable, True)
def getLabelStyle(modelLabel): """Creates a label stylesheet for the given owner widget""" bgColor = modelLabel.palette().color(modelLabel.backgroundRole()) red = bgColor.red() green = bgColor.green() blue = bgColor.blue() delta = 60 borderColor = QColor(max(red - delta, 0), max(green - delta, 0), max(blue - delta, 0)) bgColor = QColor(min(red + delta, 255), min(green + delta, 255), min(blue + delta, 255)) props = ('border-radius: 3px', 'padding: 4px', 'background-color: ' + colorAsString(bgColor, True), 'border: 1px solid ' + colorAsString(borderColor, True)) return '; '.join(props)
def draw(self, scene, baseX, baseY): """Draws the diagram on the real canvas""" self.baseX = baseX self.baseY = baseY currentY = baseY for row in self.cells: if not row: continue height = row[0].height currentX = baseX for cell in row: if self.settings.debug: pen = QPen(Qt.DotLine) pen.setWidth(1) if cell.kind == CellElement.VCANVAS: pen.setColor(QColor(255, 0, 0, 255)) scene.addLine(currentX + 1, currentY + 1, currentX + cell.width - 2, currentY + 1, pen) scene.addLine(currentX + 1, currentY + 1, currentX + 1, currentY + cell.height - 2, pen) scene.addLine(currentX + 1, currentY + cell.height - 2, currentX + cell.width - 2, currentY + cell.height - 2, pen) scene.addLine(currentX + cell.width - 2, currentY + 1, currentX + cell.width - 2, currentY + cell.height - 2, pen) else: pen.setColor(QColor(0, 255, 0, 255)) scene.addLine(currentX, currentY, currentX + cell.width, currentY, pen) scene.addLine(currentX, currentY, currentX, currentY + cell.height, pen) scene.addLine(currentX, currentY + cell.height, currentX + cell.width, currentY + cell.height, pen) scene.addLine(currentX + cell.width, currentY, currentX + cell.width, currentY + cell.height, pen) cell.draw(scene, currentX, currentY) currentX += cell.width currentY += height
def __markItem(item): """Marks a single item modified""" brush = QBrush(QColor(255, 227, 227)) item.setBackground(0, brush) item.setBackground(1, brush) item.setBackground(2, brush) childIndex = item.childCount() - 1 while childIndex >= 0: childItem = item.child(childIndex) childItem.setModified(True) if searchTooltip.item == childItem: searchTooltip.setModified(True) childIndex -= 1
def paint(self, painter, option, widget): """Draws a filled rectangle and then adds a title""" # Draw the rectangle QGraphicsRectItem.paint(self, painter, option, widget) # Draw text over the rectangle font = QFont("Arial", 10) font.setBold(True) painter.setFont(font) painter.setPen(QPen(QColor(90, 90, 88))) painter.drawText(self.__node.posX - self.__node.width / 2.0, self.__node.posY - self.__node.height / 2.0, self.__node.width, self.__node.height, Qt.AlignCenter, self.__node.label)
def __init__(self, node, refFile, srcobj, deviceDPI): self.__node = node self.__srcobj = srcobj self.__refFile = refFile self.__pixelsPerLine = self.calcPixelsPerLine() posX = node.posX - node.width / 2.0 posY = node.posY - node.height / 2.0 QGraphicsRectItem.__init__(self, posX, posY, node.width, node.height) pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) self.setPen(pen) # To make double click delivered self.setFlag(QGraphicsItem.ItemIsSelectable, True)
def __setBrokenIndicator(self, msg): """Sets the indicator to the broken state""" self.text = BROKEN_INDICATOR self.backgroundColor = QColor(0, 255, 255) self.foregroundColor = QColor(255, 0, 0) self.defaultTooltip = msg
def buildColor(color): """Six options are supported: #hhh hexadecimal rgb #hhhh hexadecimal rgba #hhhhhh hexadecimal rrggbb #hhhhhhhh hexadecimal rrggbbaa ddd,ddd,ddd decimal rgb ddd,ddd,ddd,ddd decimal rgba """ if color.startswith('#'): def normalizeLength(spec): if len(spec) in [6, 8]: return spec normalized = '' for character in spec: normalized += 2 * character return normalized color = color[1:] length = len(color) if length not in [3, 4, 6, 8]: raise Exception("Invalid hexadecimal color format: #" + color) try: # The most common case normColor = normalizeLength(color) red = int(normColor[0:2], 16) checkColorRange(red) green = int(normColor[2:4], 16) checkColorRange(green) blue = int(normColor[4:6], 16) checkColorRange(blue) if length in [3, 6]: return QColor(red, green, blue) alpha = int(normColor[6:8], 16) checkColorRange(alpha) return QColor(red, green, blue, alpha) except: raise Exception("Invalid hexadecimal color format: #" + color) parts = color.split(',') length = len(parts) if length not in [3, 4]: raise Exception("Invalid decimal color format: " + color) try: red = int(parts[0].strip()) checkColorRange(red) green = int(parts[1].strip()) checkColorRange(green) blue = int(parts[2].strip()) checkColorRange(blue) if length == 3: return QColor(red, green, blue) alpha = int(parts[3].strip()) checkColorRange(alpha) return QColor(red, green, blue, alpha) except: raise Exception("Invalid decimal color format: " + color)
PACKAGE_SKIN_DIR = os.path.dirname(os.path.realpath(sys.argv[0])) + \ os.path.sep + 'skins' + os.path.sep USER_SKIN_DIR = SETTINGS_DIR + 'skins' + os.path.sep OVERRIDE_FILE = 'override.json' SAMPLE_SKIN = 'sample' isMac = sys.platform.lower() == 'darwin' _DEFAULT_SKIN_SETTINGS = { 'name': 'default', 'dark': False, 'marginPaper': QColor(228, 228, 228, 255), 'marginPaperDebug': QColor(255, 228, 228, 255), 'marginColor': QColor(128, 128, 128, 255), 'marginColorDebug': QColor(128, 128, 128, 255), 'flakesMarginPaper': QColor(208, 208, 208, 255), 'flakesMarginPaperDebug': QColor(255, 228, 228, 255), 'bpointsMarginPaper': QColor(192, 192, 192, 255), 'findNoMatchPaper': QColor(255, 193, 204, 100), 'findMatchPaper':
def setRectanglePen(self): """Sets the diagram pen""" pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) pen.setJoinStyle(Qt.RoundJoin) self.setPen(pen)
import os import os.path import json from copy import deepcopy from ui.qt import QColor, QFont from .colorfont import buildFont, toJSON, fromJSON from .fileutils import saveToFile, getFileContent from .config import DEFAULT_ENCODING isMac = sys.platform.lower() == 'darwin' _DEFAULT_SKIN_SETTINGS = { 'name': 'default', 'marginPaper': QColor(228, 228, 228, 255), 'marginPaperDebug': QColor(255, 228, 228, 255), 'marginColor': QColor(128, 128, 128, 255), 'marginColorDebug': QColor(128, 128, 128, 255), 'flakesMarginPaper': QColor(208, 208, 208, 255), 'flakesMarginPaperDebug': QColor(255, 228, 228, 255), 'bpointsMarginPaper': QColor(192, 192, 192, 255), 'findNoMatchPaper': QColor(255, 193, 204, 100), 'findMatchPaper':
IND_MISSING = 12 IND_OBSTRUCTED = 13 IND_UNKNOWN = 14 IND_ERROR = 100 pluginHomeDir = os.path.dirname(os.path.abspath(__file__)) + os.path.sep # Integer ID, icon, foreground color or None, # background color or None, default tooltip IND_DESCRIPTION = ( (IND_ADDED, QPixmap(pluginHomeDir + "status-added.png"), None, QColor(255, 255, 160, 255), "Added to SVN repository"), (IND_DELETED, QPixmap(pluginHomeDir + "status-deleted.png"), None, QColor(255, 255, 160, 255), "Deleted from SVN repository"), (IND_IGNORED, QPixmap(pluginHomeDir + "status-ignored.png"), None, QColor(255, 160, 255, 255), "Ignored"), (IND_MERGED, QPixmap(pluginHomeDir + "status-merged.png"), None, QColor(220, 255, 220, 255), "Local modifications received SVN repository modifications"), (IND_MODIFIED_LR, QPixmap(pluginHomeDir + "status-locally-repos-modified.png"),
def __init__(self, node, refFile, srcobj, deviceDPI): ImportsDgmDetailedModuleBase.__init__(self, node, refFile, srcobj, deviceDPI) self.setBrush(QColor(240, 240, 110))
"""Skins support""" import sys import logging import os import os.path import json from copy import deepcopy from ui.qt import QColor, QFont from .colorfont import buildFont, toJSON, fromJSON from .fileutils import saveToFile, getFileContent from .config import DEFAULT_ENCODING _DEFAULT_SKIN_SETTINGS = { 'name': 'default', 'marginPaper': QColor(228, 228, 228, 255), 'marginPaperDebug': QColor(255, 228, 228, 255), 'marginColor': QColor(128, 128, 128, 255), 'marginColorDebug': QColor(128, 128, 128, 255), 'flakesMarginPaper': QColor(208, 208, 208, 255), 'flakesMarginPaperDebug': QColor(255, 228, 228, 255), 'bpointsMarginPaper': QColor(192, 192, 192, 255), 'findNoMatchPaper': QColor(255, 193, 204, 100), 'findMatchPaper': QColor(164, 198, 57, 100), 'findInvalidPaper': QColor(228, 208, 10, 100), 'revisionMarginPaper': QColor(228, 228, 228, 255), 'revisionMarginColor': QColor(0, 128, 0, 255), 'revisionAlterPaper': QColor(238, 240, 241, 255), 'lineNumFont': buildFont('Monospace,12,-1,5,50,0,0,0,0,0'), 'searchMarkColor': QColor(0, 255, 0, 255), 'searchMarkPaper': QColor(255, 0, 255, 255),