def paint_data(self, data, painter, rectangle, option=None): painter.save() r = rectangle x = r.bottomLeft().x() y = r.topRight().y() ncolor = len(data) if ncolor: lx = r.width() / ncolor for mat in data: color = (mat.diffuseColor().red, mat.diffuseColor().green, mat.diffuseColor().blue) painter.fillRect(x, y, lx, r.height(), QtGui.QColor(*color)) x += lx painter.restore()
def paintEvent(self, event): if self._edit_mode is False: return painter = QtGui.QPainter(self) painter.setRenderHint(QtGui.QPainter.Antialiasing) pen = painter.pen() if self._hovered: brush = QtGui.QBrush(QtGui.QColor(120, 190, 255, 200)) pen.setColor(QtGui.QColor(255, 255, 255, 255)) else: brush = QtGui.QBrush(QtGui.QColor(120, 190, 255, 70)) pen.setColor(QtGui.QColor(0, 0, 0, 127)) painter.setBrush(brush) painter.setPen(pen) adj = painter.pen().width() rect = self.contentsRect().adjusted(adj, adj, -adj, -adj) if self._bottom: painter.drawConvexPolygon(QtGui.QPolygon([rect.bottomRight(), rect.bottomLeft(), rect.topLeft()])) else: painter.drawConvexPolygon(QtGui.QPolygon([rect.topRight(), rect.bottomRight(), rect.topLeft()]))
def draw(self): if self.isEnabled(): self.setBackgroundColor(self.defaultColor) else: self.setBackgroundColor(QtGui.QColor(150, 150, 150)) self.start = self.pointOnEditionPlane( QtCore.QPoint(0, self.height() - 1)) self.end = self.pointOnEditionPlane(QtCore.QPoint(self.width() - 1, 0)) self.sphere.radius = (self.end[0] - self.start[0]) / 80 self.discretizer.clear() self.curveshape.apply(self.renderer) glColor4f(0.5, 0.5, 0.0, 0.0) self.curveshape.apply(self.ctrlrenderer) self.ctrlpts.apply(self.renderer) self.drawGrid()
def open_color_dialog(self): old_color = self.color() color = None if len(old_color) == 3: col = QtGui.QColorDialog.getColor(QtGui.QColor(*old_color), self) if col.isValid(): color = (col.red(), col.green(), col.blue()) elif len(old_color) == 4: col, ok = QtGui.QColorDialog.getRgba(QtGui.qRgba(*old_color), self) if ok: col = QtGui.QColor.fromRgba(col) color = (col.red(), col.green(), col.blue(), col.alpha()) else: msg = "unable to display this color: %s" % str(self._color) raise ValueError(msg) if color is not None: self.set_value(color)
def __init__(self, node, parent, parameter_str, interface): """Constructor :Parameters: - `node` (Node) - node that own the widget - `parent` (QWidget) - parent widget - `parameter_str` (str) - the parameter key the widget is associated to - `interface` (Ismth) - instance of interface object """ QtGui.QPushButton.__init__(self, parent) IInterfaceWidget.__init__(self, node, parent, parameter_str, interface) self.setMinimumSize(64, 64) self._color = (0, 0, 0) self._brush = QtGui.QBrush(QtGui.QColor(*self._color[:3])) QtCore.QObject.connect(self, QtCore.SIGNAL("clicked(bool)"), self.open_color_dialog) self.notify(node, ("input_modified", self.param_str))
def paintEvent(self, paintEvent): if self.showLines: maxheight = self.editor.viewport().height() maxline = self.editor.document().blockCount() painter = QtGui.QPainter(self) painter.setPen(QtGui.QPen(QtGui.QColor(100, 100, 100))) h = 0 line = -1 while h < maxheight and line < maxline: cursor = self.editor.cursorForPosition(QtCore.QPoint(1, h)) nline = cursor.blockNumber() + 1 rect = self.editor.cursorRect(cursor) if nline > line: line = nline painter.drawText( 0, rect.top() + 2, 40, rect.height() + 2, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop, str(line)) h = rect.top() + rect.height() + 1 painter.end()
def write(self, text): """ Simulate stdin, stdout, and stderr. """ # The output of self.append(text) contains to many newline characters, # so work around QtGui.QTextEdit's policy for handling newline characters. cursor = self.textCursor() cursor.movePosition(QtGui.QTextCursor.End) pos1 = cursor.position() cursor.insertText(text) self.cursor_pos = cursor.position() self.setTextCursor(cursor) self.ensureCursorVisible () # Set the format cursor.setPosition(pos1, QtGui.QTextCursor.KeepAnchor) format = cursor.charFormat() format.setForeground(QtGui.QBrush(QtGui.QColor(0, 0, 0))) cursor.setCharFormat(format)
def highlight(self, val): if val: self.defaultColor = QtGui.QColor(100, 200, 100) else: self.defaultColor = self.bkgdColor self.update()
def set_bg_black(self): color_black = QtGui.QColor(0, 0, 0) self.setBackgroundColor(color_black)
def set_bg_white(self): color_white = QtGui.QColor(255, 255, 255) self.setBackgroundColor(color_white)
# OpenAlea WebSite : http://openalea.gforge.inria.fr # """ Test frame manipulator """ __license__= "Cecill-C" __revision__ = " $Id: __init__.py 2245 2010-02-08 17:11:34Z cokelaer $ " from openalea.vpltk.qt import QtGui from openalea.image.all import rainbow, FrameAnimator qapp = QtGui.QApplication.instance() if qapp: pal = rainbow(99) frames = [] for i in xrange(100) : pix = QtGui.QPixmap(300,200) pix.fill(QtGui.QColor(*tuple(pal[i]) ) ) frames.append(pix) w = FrameAnimator() w.set_frames(frames) w.show()
def set_color(self, color): self._color = color self._brush = QtGui.QBrush(QtGui.QColor(*self._color[:3]))
class MemoRects(QtGui.QGraphicsRectItem): __handleSize = 7.5 __defaultColor = QtGui.QColor(250, 250, 100) def __init__(self, rect, parent=None): QtGui.QGraphicsRectItem.__init__(self, rect, parent) self.__resizing = False self.__handlePoly = QtGui.QPolygonF([ QtCore.QPointF(0, -self.__handleSize), QtCore.QPointF(0, 0), QtCore.QPointF(-self.__handleSize, 0) ]) self.setFlag(QtGui.QGraphicsItem.ItemStacksBehindParent) # -- handle -- self.__handlePos = QtCore.QPointF(0, 0) # -- header -- self.__headerContentRect = None self.__headerRect = None # -- color -- self.__color = None self.__darkerColor = None self.__shadowColor = None self.setColor(self.__defaultColor.darker(110)) # -- optionnal cosmetics -- if safeEffects: fx = QtGui.QGraphicsDropShadowEffect() fx.setOffset(2, 2) fx.setBlurRadius(5) self.setGraphicsEffect(fx) def setColor(self, color): self.__color = color self.__darkerColor = color.darker(140) self.__shadowColor = color.darker(200) self.update() def __moveHandleBottomRightTo(self, point): delta = point - self.__handlePos self.__handlePoly.translate(delta.x(), delta.y()) self.__handlePos = point def setHeaderRect(self, rect): myRect = self.boundingRect() self.__headerContentRect = rect.adjusted(0, 0, 0, 0) #copy rect.setX(0) rect.setY(0) myRect.setX(0) myRect.setY(0) if rect.bottom() >= (myRect.bottom() - self.__handleSize): myRect.setBottom(rect.bottom() + self.__handleSize) if rect.right() >= myRect.right(): myRect.setRight(rect.right()) else: rect.setRight(myRect.right()) self.__headerRect = rect self.__moveHandleBottomRightTo(myRect.bottomRight()) self.setRect(myRect) self.update() def mousePressEvent(self, event): pos = event.pos() bottomRight = self.boundingRect().bottomRight() x, y = bottomRight.x(), bottomRight.y() rect = QtCore.QRectF(x - 5, y - 5, x + 5, y + 5) if self.__handlePoly.containsPoint(pos, QtCore.Qt.OddEvenFill): self.__resizing = True else: QtGui.QGraphicsRectItem.mousePressEvent(self, event) def mouseMoveEvent(self, event): if self.__resizing: delta = event.pos() - event.lastPos() bottomRight = self.boundingRect().bottomRight() + delta newRect = QtCore.QRectF(0., 0., bottomRight.x(), bottomRight.y()) if newRect.contains( self.__headerContentRect.adjusted(0, 0, 0, self.__handleSize)): self.setRect(newRect) self.__headerRect = QtCore.QRectF( 0., 0., bottomRight.x(), self.__headerContentRect.height()) self.__moveHandleBottomRightTo(newRect.bottomRight()) else: QtGui.QGraphicsRectItem.mouseMoveEvent(self, event) def mouseReleaseEvent(self, event): if self.__resizing: self.__resizing = False else: QtGui.QGraphicsRectItem.mouseReleaseEvent(self, event) def paint(self, painter, paintOptions, widget): myRect = self.boundingRect() painter.fillRect(self.__headerRect, self.__darkerColor) gradTop = self.__headerRect.bottomLeft() gradBot = gradTop + QtCore.QPointF(0, 4) gradient = QtGui.QLinearGradient(gradTop, gradBot) gradient.setColorAt(0, self.__shadowColor) gradient.setColorAt(1, self.__color) brush = QtGui.QBrush(gradient) bottomRect = myRect.adjusted(0, self.__headerRect.bottom(), 0, 0) painter.fillRect(bottomRect, brush) if not safeEffects: oldPen = painter.pen() pen = QtGui.QPen() pen.setColor(QtGui.QColor(10, 10, 10, 100)) pen.setWidth(1) painter.setPen(pen) painter.drawRect(myRect.adjusted(0.5, 0.5, -0.5, -0.5)) painter.setPen(oldPen) painter.setBrush(QtGui.QBrush(self.__darkerColor)) painter.drawConvexPolygon(self.__handlePoly)