def feed(self, document): self.window.fill(QColor.fromRgba(0xFFFFFFFF)) n_darken = count_multiples(cycle(self.frame_counter), cycle(self.frame_counter + 1), DARKEN_CYCLE) for i in range(n_darken): self.darken_overlay(QPainter(self.overlay)) # Start writing here for m in document["Map"]: m.draw(QPainter(self.map)) if "Photons" in document and document["Photons"] is not None: for photon in document["Photons"]: photon.draw(QPainter(self.overlay)) for bot in document["Bots"]: bot.draw(QPainter(self.map)) self.draw_label(QPainter(self.window), document["Metrics"]) self.compose_layers() self.frame_counter += 1 out_image = QImage(self.window).convertToFormat(QImage.Format_RGB888) width = out_image.width() height = out_image.height() ptr = out_image.constBits() s = ptr.asstring(width * height * 3) arr = np.fromstring(s, dtype=np.uint8).reshape((height, width, 3)) self.pipe.stdin.write(arr.tobytes())
def mousePressEvent(self, event): """Mouse press event to handle mouse clicks with various tools :param event: Source event :type event: QGraphicsSceneMouseEvent """ if event.buttons() == Qt.LeftButton and not self.pasting: self.scene.setColorSwitchEnabled(False) if self.start_pos is None: self.start_pos = QPointF( math.floor(event.pos().x()), math.floor(event.pos().y()) ) self.start_scene_pos = QPointF( math.floor(event.scenePos().x()), math.floor(event.scenePos().y()), ) self.last_pos = self.start_pos if self.tool is Tools.SELECT: self.selecting = False self.select_timer.stop() self.scene.update() if self.tool is Tools.PEN: pixmap = self.pixmap() painter = QPainter(pixmap) pen = QPen(QColor.fromRgba(self.color)) pen.setWidth(1) painter.setPen(pen) painter.drawPoint(self.start_pos) self.setPixmap(pixmap) painter.end()
def _initPredictionLayers(self, predictionSlot): layers = [] opLane = self.topLevelOperatorView # Use a slicer to provide a separate slot for each channel layer opSlicer = OpMultiArraySlicer2(parent=opLane.viewed_operator().parent) opSlicer.Input.connect(predictionSlot) opSlicer.AxisFlag.setValue('c') for channel, channelSlot in enumerate(opSlicer.Slices): if channelSlot.ready(): drange = channelSlot.meta.drange or (0.0, 1.0) predictsrc = LazyflowSource(channelSlot) predictLayer = AlphaModulatedLayer( predictsrc, tintColor=QColor.fromRgba(self._colorTable16[channel + 1]), # FIXME: This is weird. Why are range and normalize both set to the same thing? range=drange, normalize=drange) predictLayer.opacity = 1.0 predictLayer.visible = True predictLayer.name = "Probability Channel #{}".format(channel + 1) layers.append(predictLayer) return layers
def __init__( self, editor, clickFunctor, datasource , colorTable, direct=False, right=True ): assert isinstance(datasource, SourceABC) super(ClickableColortableLayer, self).__init__(datasource, editor, clickFunctor, direct=direct, right=right) self._colorTable = colorTable self.data = datasource self.colortableIsRandom = False self.zeroIsTransparent = (QColor.fromRgba(colorTable[0]).alpha() == 0)
def __choose_color(self): dialog = QColorDialog(self.window()) dialog.setOption(QColorDialog.ShowAlphaChannel, True) dialog.setCurrentColor(QColor.fromRgba(self.__color.argb)) if dialog.exec_() == QColorDialog.Accepted: self.__color = Color(dialog.currentColor().rgba()) self.__refresh_label() self.color_changed.emit(self.__color)
def SetDefaultBeamsStyle(layer, beam='DEFAULT'): ''' Beams Symbol''' style = S.getBeam(beam) symbol = layer.renderer().symbol() symbol.setColor(QColor.fromRgba(style['COLOR'])) #symbol.setColor(QColor.fromRgb(255, 87, 51)) #symbol.setWidth(1) return
def __init__(self, editor, clickFunctor, datasource, colorTable, direct=False, right=True): assert isinstance(datasource, SourceABC) super(ClickableColortableLayer, self).__init__(datasource, editor, clickFunctor, direct=direct, right=right) self._colorTable = colorTable self.data = datasource self.colortableIsRandom = False self.zeroIsTransparent = QColor.fromRgba(colorTable[0]).alpha() == 0
def basefinished(self): if self.basereply.error() != QNetworkReply.NoError: return self.basepixmap = QPixmap() self.basepixmap.loadFromData(self.basereply.readAll()) if self.basepixmap.size() != self.rect.size(): self.basepixmap = self.basepixmap.scaled(self.rect.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation) self.setPixmap(self.basepixmap) # make marker pixmap self.mkpixmap = QPixmap(self.basepixmap.size()) self.mkpixmap.fill(Qt.transparent) br = QBrush(QColor(Config.dimcolor)) painter = QPainter() painter.begin(self.mkpixmap) painter.fillRect(0, 0, self.mkpixmap.width(), self.mkpixmap.height(), br) for marker in self.radar['markers']: pt = getPoint(marker["location"], self.point, self.zoom, self.rect.width(), self.rect.height()) mk2 = QImage() mkfile = 'teardrop' if 'image' in marker: mkfile = marker['image'] if os.path.dirname(mkfile) == '': mkfile = os.path.join('markers', mkfile) if os.path.splitext(mkfile)[1] == '': mkfile += '.png' mk2.load(mkfile) if mk2.format != QImage.Format_ARGB32: mk2 = mk2.convertToFormat(QImage.Format_ARGB32) mkh = 80 # self.rect.height() / 5 if 'size' in marker: if marker['size'] == 'small': mkh = 64 if marker['size'] == 'mid': mkh = 70 if marker['size'] == 'tiny': mkh = 40 if 'color' in marker: c = QColor(marker['color']) (cr, cg, cb, ca) = c.getRgbF() for x in range(0, mk2.width()): for y in range(0, mk2.height()): (r, g, b, a) = QColor.fromRgba(mk2.pixel(x, y)).getRgbF() r = r * cr g = g * cg b = b * cb mk2.setPixel(x, y, QColor.fromRgbF(r, g, b, a).rgba()) mk2 = mk2.scaledToHeight(mkh, 1) painter.drawImage(pt.x - mkh / 2, pt.y - mkh / 2, mk2) painter.end() self.wmk.setPixmap(self.mkpixmap)
def mouseMoveEvent(self, event): """Mouse move event to handle mouse movement after clicking with various tools :param event: Source event :type event: QGraphicsSceneMouseEvent """ if event.buttons() == Qt.LeftButton: if not self.pasting: if self.tool is not Tools.PEN: self.clear() pixmap = self.pixmap() painter = QPainter(pixmap) self.cur_pos = QPointF( math.floor(event.pos().x()), math.floor(event.pos().y()) ) self.cur_scene_pos = QPointF( math.ceil(event.scenePos().x()), math.ceil(event.scenePos().y()), ) pen = QPen(QColor.fromRgba(self.color)) pen.setWidth(1) painter.setPen(pen) if self.filled: brush = QBrush(QColor.fromRgba(self.color)) painter.setBrush(brush) if self.tool is Tools.LINE: painter.drawLine(self.start_pos, self.cur_pos) elif self.tool is Tools.ELLIPSE: painter.drawEllipse(QRectF(self.start_pos, self.cur_pos)) elif self.tool is Tools.RECTANGLE: painter.drawRect(QRectF(self.start_pos, self.cur_pos)) elif self.tool is Tools.PEN: painter.drawLine(self.last_pos, self.cur_pos) elif self.tool is Tools.SELECT: self.selecting = True if not self.select_timer.isActive(): self.select_timer.start(500) self.updateSceneForeground() self.setPixmap(pixmap) self.last_pos = self.cur_pos painter.end() else: self.hoverMoveEvent(event)
def __init__(self, layer, parent=None): super(LayerColortableDialog, self).__init__(parent=parent) h = QHBoxLayout(self) t = QTableWidget(self) t.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) t.setRowCount(len(layer._colorTable)) t.setColumnCount(1) t.setVerticalHeaderLabels(["%d" % i for i in range(len(layer._colorTable))]) for i in range(len(layer._colorTable)): item = QTableWidgetItem(" ") t.setItem(i, 0, item) item.setBackgroundColor(QColor.fromRgba(layer._colorTable[i])) item.setFlags(Qt.ItemIsSelectable) h.addWidget(t)
def __init__(self, layer, parent=None): super(LayerColortableDialog, self).__init__(parent=parent) h = QHBoxLayout(self) t = QTableWidget(self) t.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) t.setRowCount(len(layer._colorTable)) t.setColumnCount(1) t.setVerticalHeaderLabels(["%d" % i for i in range(len(layer._colorTable))]) for i in range(len(layer._colorTable)): item = QTableWidgetItem(" ") t.setItem(i, 0, item) item.setBackgroundColor(QColor.fromRgba(layer._colorTable[i])) item.setFlags(Qt.ItemIsSelectable) h.addWidget(t)
def __init__(self, datasource, colorTable, normalize=False, direct=False): assert isinstance(datasource, DataSourceABC) """ By default, no normalization is performed on ColortableLayers. If the normalize parameter is set to 'auto', your data will be automatically normalized to the length of your colorable. If a tuple (dmin, dmax) is passed, this specifies the range of your data, which is used to normalize the data before the colorable is applied. """ if normalize is "auto": normalize = None super().__init__([datasource], normalize=normalize, direct=direct) self.data = datasource self._colorTable = colorTable self.colortableIsRandom = False self.zeroIsTransparent = QColor.fromRgba(colorTable[0]).alpha() == 0
def updateColorTable(self): layerColorTable = self._layer.colorTable self._colorTable = np.zeros((len(layerColorTable), 4), dtype=np.uint8) for i, c in enumerate(layerColorTable): # note that we use qimage2ndarray.byte_view() on a QImage with Format_ARGB32 below. # this means that the memory layout actually is B, G, R, A if isinstance(c, QColor): color = c else: color = QColor.fromRgba(c) self._colorTable[i, 0] = color.blue() self._colorTable[i, 1] = color.green() self._colorTable[i, 2] = color.red() self._colorTable[i, 3] = color.alpha() self.isDirty.emit(QRect()) # empty rect == everything is dirty
def updateColorTable(self): layerColorTable = self._layer.colorTable self._colorTable = np.zeros((len(layerColorTable), 4), dtype=np.uint8) for i, c in enumerate(layerColorTable): # note that we use qimage2ndarray.byte_view() on a QImage with Format_ARGB32 below. # this means that the memory layout actually is B, G, R, A if isinstance(c, QColor): color = c else: color = QColor.fromRgba(c) self._colorTable[i, 0] = color.blue() self._colorTable[i, 1] = color.green() self._colorTable[i, 2] = color.red() self._colorTable[i, 3] = color.alpha() self.isDirty.emit(QRect()) # empty rect == everything is dirty
def __init__(self, datasource, colorTable, normalize=False, direct=False): assert isinstance(datasource, SourceABC) """ By default, no normalization is performed on ColortableLayers. If the normalize parameter is set to 'auto', your data will be automatically normalized to the length of your colorable. If a tuple (dmin, dmax) is passed, this specifies the range of your data, which is used to normalize the data before the colorable is applied. """ if normalize is "auto": normalize = None range = (0, len(colorTable) - 1) super(ColortableLayer, self).__init__([datasource], range=range, normalize=normalize, direct=direct) self.data = datasource self._colorTable = colorTable self.colortableIsRandom = False self.zeroIsTransparent = QColor.fromRgba(colorTable[0]).alpha() == 0
def paintEvent(self, evt): """ Protected method called to repaint some of the widget. @param evt reference to the paint event object (QPaintEvent) """ painter = QPainter(self) if self.__zoom >= 3 and self.__gridEnabled: painter.setPen(self.palette().windowText().color()) i = 0 while i <= self.__image.width(): painter.drawLine( self.__zoom * i, 0, self.__zoom * i, self.__zoom * self.__image.height()) i += 1 j = 0 while j <= self.__image.height(): painter.drawLine( 0, self.__zoom * j, self.__zoom * self.__image.width(), self.__zoom * j) j += 1 col = QColor("#aaa") painter.setPen(Qt.DashLine) for i in range(0, self.__image.width()): for j in range(0, self.__image.height()): rect = self.__pixelRect(i, j) if evt.region().intersects(rect): color = QColor.fromRgba(self.__image.pixel(i, j)) painter.fillRect(rect, QBrush(Qt.white)) painter.fillRect(QRect(rect.topLeft(), rect.center()), col) painter.fillRect(QRect(rect.center(), rect.bottomRight()), col) painter.fillRect(rect, QBrush(color)) if self.__isMarked(i, j): painter.drawRect(rect.adjusted(0, 0, -1, -1)) painter.end()
def paintEvent(self, evt): """ Protected method called to repaint some of the widget. @param evt reference to the paint event object (QPaintEvent) """ painter = QPainter(self) if self.__zoom >= 3 and self.__gridEnabled: painter.setPen(self.palette().windowText().color()) i = 0 while i <= self.__image.width(): painter.drawLine(self.__zoom * i, 0, self.__zoom * i, self.__zoom * self.__image.height()) i += 1 j = 0 while j <= self.__image.height(): painter.drawLine(0, self.__zoom * j, self.__zoom * self.__image.width(), self.__zoom * j) j += 1 col = QColor("#aaa") painter.setPen(Qt.DashLine) for i in range(0, self.__image.width()): for j in range(0, self.__image.height()): rect = self.__pixelRect(i, j) if evt.region().intersects(rect): color = QColor.fromRgba(self.__image.pixel(i, j)) painter.fillRect(rect, QBrush(Qt.white)) painter.fillRect(QRect(rect.topLeft(), rect.center()), col) painter.fillRect(QRect(rect.center(), rect.bottomRight()), col) painter.fillRect(rect, QBrush(color)) if self.__isMarked(i, j): painter.drawRect(rect.adjusted(0, 0, -1, -1)) painter.end()
def _initPredictionLayers(self, predictionSlot): layers = [] opLane = self.topLevelOperatorView # Use a slicer to provide a separate slot for each channel layer opSlicer = OpMultiArraySlicer2( parent=opLane.viewed_operator().parent ) opSlicer.Input.connect( predictionSlot ) opSlicer.AxisFlag.setValue('c') for channel, channelSlot in enumerate(opSlicer.Slices): if channelSlot.ready(): drange = channelSlot.meta.drange or (0.0, 1.0) predictsrc = LazyflowSource(channelSlot) predictLayer = AlphaModulatedLayer( predictsrc, tintColor=QColor.fromRgba(self._colorTable16[channel+1]), # FIXME: This is weird. Why are range and normalize both set to the same thing? range=drange, normalize=drange ) predictLayer.opacity = 1.0 predictLayer.visible = True predictLayer.name = "Probability Channel #{}".format( channel+1 ) layers.append(predictLayer) return layers
from PyQt5.QtGui import QColor theme_color = 'A0FF0066' foreground_color = QColor.fromRgba(int(theme_color, 16)) base_color = QColor(255, 255, 255) load_color = QColor(180, 180, 180) in_color = foreground_color out_color = QColor(255, 255, 255) # PlayBar playbar_h = 60 # PlayButtons playbar_playbtns_w = 180 playbar_playbtns_big = 50 playbar_playbtns_small = 30 # ProgressBar # 进度点内圆半径 playbar_progress_ir = 1 # 进度点外圆半径 playbar_progress_or = 4
def __convert_color(self, color): return QColor.fromRgba(color.argb)
def color_getter(value): if value is None: return QColor("transparent") return QColor.fromRgba(value)