def __init__(self, size, dynamic, controller): layer.__init__(self,size,dynamic) self.controller = controller self.ready = False dotColor = QColor() dotColor.setNamedColor(self.controller.svgLayer.svg.dotPrototype.getAttribute('fill')) dotColor.setAlphaF(float(self.controller.svgLayer.svg.dotPrototype.getAttribute('fill-opacity'))) self.dotColors = [] i = 0 while i <= 1.0: self.dotColors.append(QColor.fromRgbF(dotColor.redF(),dotColor.greenF(),dotColor.blueF(),i)) i += dotColor.alphaF() self.dotWidth = self.controller.svgLayer.svg.dotPrototype.width() self.dotHeight = self.controller.svgLayer.svg.dotPrototype.height() self.halfDotWidth = self.dotWidth/2 self.halfDotHeight = self.dotHeight/2 self.xoffset = self.controller.scatterBounds[0]-self.halfDotWidth self.yoffset = self.controller.scatterBounds[3]-self.halfDotHeight self.xNonNumeric = (self.controller.svgLayer.svg.xNonNumericIcon.left() + self.controller.svgLayer.svg.xNonNumericIcon.right())/2 - self.halfDotWidth self.yNonNumeric = (self.controller.svgLayer.svg.yNonNumericIcon.top() + self.controller.svgLayer.svg.yNonNumericIcon.bottom())/2 - self.halfDotHeight
def paintEvent(self, event): painter = QtGui.QPainter(self) painter.setPen(Qt.NoPen) w = self.width() h = self.height() painter.setBrush(self.originalColor) painter.drawRect(0, 0, w, h / 2) cSolid = QColor(self.previewColor) cSolid.setAlphaF(1) #left 1/2 for solid color painter.setBrush(cSolid) painter.drawRect(0, h / 2, w / 2, h / 2 + 1) #draw chekerGrid x0 = w / 2 y0 = h / 2 w2 = w / 2 h2 = h / 2 painter.setBrush(Qt.white) painter.drawRect(x0, y0, w2, h2) painter.setBrush(QColor.fromRgbF(0.5, 0.5, 0.5)) for y in range(4): for x in range(w2 / 10): if (x % 2) == (y % 2): painter.drawRect(x0 + x * 10, y0 + y * 10, 10, 10) #right 2/3 for color with alpha painter.setBrush(self.previewColor) painter.drawRect(x0, y0, w2 + 1, h2 + 1)
def onTextHexChanged(self, value): if self.updating: return hexText = value color = QColor(value) color.setAlphaF(self.currentColor.alphaF()) self.setColor(color) self.updateColorPlane()
def _fade(self, lineno): cursor = self._get_line_cursor(lineno) fmt = cursor.charFormat() color = QColor('black') color.setAlphaF(0.5) fmt.setForeground(color) cursor.beginEditBlock() cursor.mergeCharFormat(fmt) cursor.endEditBlock()
def _fade(self, lineno): cursor = self._get_line_cursor(lineno) fmt = cursor.charFormat() color=QColor('black') color.setAlphaF(0.5) fmt.setForeground(color) cursor.beginEditBlock() cursor.mergeCharFormat(fmt) cursor.endEditBlock()
def __init__(self, size, dynamic, controller, prototypeLine, opaqueBack = False): layer.__init__(self,size,dynamic) self.controller = controller self.points = set() if opaqueBack: self.backgroundColor = Qt.white else: self.backgroundColor = Qt.transparent lineColor = QColor() lineColor.setNamedColor(prototypeLine.getAttribute('stroke')) lineColor.setAlphaF(float(prototypeLine.getAttribute('stroke-opacity'))) self.pen = QPen(lineColor) self.pen.setWidthF(prototypeLine.getAttribute('stroke-width'))
class WidgetLed(QWidget): def __init__(self, parent, colour='#000000'): QWidget.__init__(self, parent) self._colour = QColor(colour) self.setMinimumSize(10, 10) self._lit = False self._timer = QTimer(self) self._timer.setInterval(200) self._timer.timeout.connect(self.__flashOff) def paintEvent(self, event): painter = QPainter() painter.begin(self) if self._lit: self._colour.setAlphaF(1) else: self._colour.setAlphaF(.25) painter.setPen(QPen(self._colour, 1)) painter.setBrush(QBrush(self._colour)) rect = event.rect() radius = min(rect.width(), rect.height()) / 3 painter.drawEllipse(rect.center(), radius, radius) painter.end() def __flashOff(self): self._timer.stop() self._lit = False self.repaint() def flash(self): self._lit = True self._timer.start() self.repaint() def light(self, on): self._timer.stop() self._lit = on self.repaint()
class selectionLayer(layer): def __init__(self, size, dynamic, controller, prototypeDot): layer.__init__(self,size,dynamic) self.controller = controller self.points = set() self.dotColor = QColor() self.dotColor.setNamedColor(prototypeDot.getAttribute('fill')) self.dotColor.setAlphaF(float(prototypeDot.getAttribute('fill-opacity'))) self.dotWidth = prototypeDot.width() self.xoffset = self.controller.svgLayer.svg.xZeroBar.left()-self.dotWidth/2+1 #self.xoffset = self.controller.scatterBounds[0]-self.dotWidth/2+1 self.dotHeight = prototypeDot.height() self.yoffset = self.controller.svgLayer.svg.yZeroBar.bottom()-self.dotWidth/2+1 #self.yoffset = self.controller.scatterBounds[3]-self.dotHeight/2+1 self.xNonNumeric = (self.controller.svgLayer.svg.xNonNumericIcon.left() + self.controller.svgLayer.svg.xNonNumericIcon.right())/2 - self.dotWidth/2 self.yNonNumeric = (self.controller.svgLayer.svg.yNonNumericIcon.top() + self.controller.svgLayer.svg.yNonNumericIcon.bottom())/2 - self.dotHeight/2 def handleFrame(self, event, signals): return signals def updateAxes(self): self.xoffset = self.controller.svgLayer.svg.xZeroBar.left()-self.dotWidth/2+1 self.yoffset = self.controller.svgLayer.svg.yZeroBar.bottom()-self.dotWidth/2+1 def update(self, points): self.points = points def draw(self,painter): self.reverseXratio = 1.0/self.controller.xAxisRatio self.reverseYratio = 1.0/self.controller.yAxisRatio self.image.fill(Qt.transparent) for x,y in self.controller.vData.get2dData(self.points,self.controller.app.currentXattribute,self.controller.app.currentYattribute): valuePairs = [] if isinstance(x,list): if isinstance(y,list): assert len(x) == len(y) valuePairs = zip(x,y) else: valuePairs = [(x0,y) for x0 in x] elif isinstance(y,list): valuePairs = [(x,y0) for y0 in y] else: valuePairs = [(x,y)] for x0,y0 in valuePairs: if x0 == None or (not isinstance(x0,int) and not isinstance(x0,float)) or math.isinf(x0) or math.isnan(x0): x0 = self.xNonNumeric else: x0 = self.xoffset + x0*self.reverseXratio if y0 == None or (not isinstance(y0,int) and not isinstance(y0,float)) or math.isinf(y0) or math.isnan(y0): y0 = self.yNonNumeric else: y0 = self.yoffset + y0*self.reverseYratio painter.fillRect(x0,y0,self.dotWidth,self.dotHeight,self.dotColor) def getPoints(self, x, y): lowX=self.controller.screenToDataSpace(x-self.controller.cursorXradius, self.controller.scatterBounds[0], self.controller.currentXaxis.minimum, self.controller.xAxisRatio) lowY=self.controller.screenToDataSpace(y+self.controller.cursorYradius, self.controller.scatterBounds[3], self.controller.currentYaxis.minimum, self.controller.yAxisRatio) highX=self.controller.screenToDataSpace(x+self.controller.cursorXradius, self.controller.scatterBounds[0], self.controller.currentXaxis.minimum, self.controller.xAxisRatio) highY=self.controller.screenToDataSpace(y-self.controller.cursorYradius, self.controller.scatterBounds[3], self.controller.currentYaxis.minimum, self.controller.yAxisRatio) if (x + self.controller.cursorXradius >= self.xNonNumeric) and (x - self.controller.cursorXradius <= self.xNonNumeric + self.dotWidth): xSet = self.controller.vData.axisLookups[self.controller.app.currentXattribute].categoricalKeys else: xSet = set() if (y + self.controller.cursorYradius >= self.yNonNumeric) and (y - self.controller.cursorYradius <= self.yNonNumeric + self.dotHeight): ySet = self.controller.vData.axisLookups[self.controller.app.currentXattribute].categoricalKeys else: ySet = set() return self.controller.vData.query2D(self.controller.app.currentXattribute,[(lowX,highX)],xSet, self.controller.app.currentYattribute,[(lowY,highY)],ySet)