def __init__(self, classifier, granularity, scale, spacing, rect=None): orangeqt.PlotItem.__init__(self) self.classifier = classifier self.rect = rect self.granularity = granularity self.scale = scale self.spacing = spacing self.pixmap_item = QGraphicsPixmapItem(self) self.set_in_background(True) self.setZValue(ProbabilitiesZValue)
def __init__(self, parent=None, direction=Qt.LeftToRight, node=None, icon=None, iconSize=None, **args): super().__init__(parent, **args) self.setAcceptedMouseButtons(Qt.NoButton) self.__direction = direction self.setLayout(QGraphicsLinearLayout(Qt.Horizontal)) # Set the maximum size, otherwise the layout can't grow beyond its # sizeHint (and we need it to grow so the widget can grow and keep the # contents centered vertically. self.layout().setMaximumSize(QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)) self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.__iconSize = iconSize or QSize(64, 64) self.__icon = icon self.__iconItem = QGraphicsPixmapItem(self) self.__iconLayoutItem = GraphicsItemLayoutItem(item=self.__iconItem) self.__channelLayout = QGraphicsGridLayout() self.channelAnchors = [] if self.__direction == Qt.LeftToRight: self.layout().addItem(self.__iconLayoutItem) self.layout().addItem(self.__channelLayout) channel_alignemnt = Qt.AlignRight else: self.layout().addItem(self.__channelLayout) self.layout().addItem(self.__iconLayoutItem) channel_alignemnt = Qt.AlignLeft self.layout().setAlignment(self.__iconLayoutItem, Qt.AlignCenter) self.layout().setAlignment(self.__channelLayout, Qt.AlignVCenter | channel_alignemnt) self.node: Optional[SchemeNode] = None self.channels: Union[List[InputSignal], List[OutputSignal]] = [] if node is not None: self.setSchemeNode(node)
def __init__(self, master, *args): QGraphicsView.__init__(self, *args) self.master = master self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.setRenderHints(QPainter.Antialiasing) scene = QGraphicsScene(self) self.pixmapGraphicsItem = QGraphicsPixmapItem(None) scene.addItem(self.pixmapGraphicsItem) self.setScene(scene) self.setMouseTracking(True) self.viewport().setMouseTracking(True) self.setFocusPolicy(Qt.WheelFocus)
def __init__(self, parent=None, direction=Qt.LeftToRight, node=None, icon=None, iconSize=None, **args): QGraphicsWidget.__init__(self, parent, **args) self.setAcceptedMouseButtons(Qt.NoButton) self.__direction = direction self.setLayout(QGraphicsLinearLayout(Qt.Horizontal)) # Set the maximum size, otherwise the layout can't grow beyond its # sizeHint (and we need it to grow so the widget can grow and keep the # contents centered vertically. self.layout().setMaximumSize(QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)) self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.__iconSize = iconSize or QSize(64, 64) self.__icon = icon self.__iconItem = QGraphicsPixmapItem(self) self.__iconLayoutItem = GraphicsItemLayoutItem(item=self.__iconItem) self.__channelLayout = QGraphicsGridLayout() self.__channelAnchors = [] if self.__direction == Qt.LeftToRight: self.layout().addItem(self.__iconLayoutItem) self.layout().addItem(self.__channelLayout) channel_alignemnt = Qt.AlignRight else: self.layout().addItem(self.__channelLayout) self.layout().addItem(self.__iconLayoutItem) channel_alignemnt = Qt.AlignLeft self.layout().setAlignment(self.__iconLayoutItem, Qt.AlignCenter) self.layout().setAlignment(self.__channelLayout, Qt.AlignVCenter | channel_alignemnt) if node is not None: self.setSchemeNode(node)
class EditLinksNode(QGraphicsWidget): """ A Node representation with channel anchors. `direction` specifies the layout (default `Qt.LeftToRight` will have icon on the left and channels on the right). """ def __init__(self, parent=None, direction=Qt.LeftToRight, node=None, icon=None, iconSize=None, **args): super().__init__(parent, **args) self.setAcceptedMouseButtons(Qt.NoButton) self.__direction = direction self.setLayout(QGraphicsLinearLayout(Qt.Horizontal)) # Set the maximum size, otherwise the layout can't grow beyond its # sizeHint (and we need it to grow so the widget can grow and keep the # contents centered vertically. self.layout().setMaximumSize(QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)) self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.__iconSize = iconSize or QSize(64, 64) self.__icon = icon self.__iconItem = QGraphicsPixmapItem(self) self.__iconLayoutItem = GraphicsItemLayoutItem(item=self.__iconItem) self.__channelLayout = QGraphicsGridLayout() self.channelAnchors = [] if self.__direction == Qt.LeftToRight: self.layout().addItem(self.__iconLayoutItem) self.layout().addItem(self.__channelLayout) channel_alignemnt = Qt.AlignRight else: self.layout().addItem(self.__channelLayout) self.layout().addItem(self.__iconLayoutItem) channel_alignemnt = Qt.AlignLeft self.layout().setAlignment(self.__iconLayoutItem, Qt.AlignCenter) self.layout().setAlignment(self.__channelLayout, Qt.AlignVCenter | channel_alignemnt) if node is not None: self.setSchemeNode(node) def setIconSize(self, size): """ Set the icon size for the node. """ if size != self.__iconSize: self.__iconSize = QSize(size) if self.__icon: self.__iconItem.setPixmap(self.__icon.pixmap(size)) self.__iconLayoutItem.updateGeometry() def iconSize(self): """ Return the icon size. """ return QSize(self.__iconSize) def setIcon(self, icon): """ Set the icon to display. """ if icon != self.__icon: self.__icon = QIcon(icon) self.__iconItem.setPixmap(icon.pixmap(self.iconSize())) self.__iconLayoutItem.updateGeometry() def icon(self): """ Return the icon. """ return QIcon(self.__icon) def setSchemeNode(self, node): """ Set an instance of `SchemeNode`. The widget will be initialized with its icon and channels. """ self.node = node if self.__direction == Qt.LeftToRight: channels = node.output_channels() else: channels = node.input_channels() self.channels = channels loader = icon_loader.from_description(node.description) icon = loader.get(node.description.icon) self.setIcon(icon) label_template = ('<div align="{align}">' '<span class="channelname">{name}</span>' '</div>') if self.__direction == Qt.LeftToRight: align = "right" label_alignment = Qt.AlignVCenter | Qt.AlignRight anchor_alignment = Qt.AlignVCenter | Qt.AlignLeft label_row = 0 anchor_row = 1 else: align = "left" label_alignment = Qt.AlignVCenter | Qt.AlignLeft anchor_alignment = Qt.AlignVCenter | Qt.AlignLeft label_row = 1 anchor_row = 0 self.channelAnchors = [] grid = self.__channelLayout for i, channel in enumerate(channels): text = label_template.format(align=align, name=escape(channel.name)) text_item = GraphicsTextWidget(self) text_item.setHtml(text) text_item.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) text_item.setToolTip( escape(getattr(channel, 'description', type_str(channel.type))) ) grid.addItem(text_item, i, label_row, alignment=label_alignment) anchor = ChannelAnchor(self, channel=channel, rect=QRectF(0, 0, 20, 20)) layout_item = GraphicsItemLayoutItem(grid, item=anchor) grid.addItem(layout_item, i, anchor_row, alignment=anchor_alignment) self.channelAnchors.append(anchor) def anchor(self, channel): """ Return the anchor item for the `channel` name. """ for anchor in self.channelAnchors: if anchor.channel() == channel: return anchor raise ValueError(channel.name) def paint(self, painter, option, widget=None): painter.save() palette = self.palette() border = palette.brush(QPalette.Mid) pen = QPen(border, 1) pen.setCosmetic(True) painter.setPen(pen) painter.setBrush(palette.brush(QPalette.Window)) brect = self.boundingRect() painter.drawRoundedRect(brect, 4, 4) painter.restore()
def itemChange(self, change, variant): if change != QGraphicsItem.ItemSelectedChange: global Dirty; Dirty = True return QGraphicsPixmapItem.itemChange(self, change, variant)
class ProbabilitiesItem(orangeqt.PlotItem): """ Displays class probabilities in the background :param classifier: The classifier for which the probabilities are calculated :type classifier: orange.P2NN :param granularity: The size of individual cells :type granularity: int :param scale: The data scale factor :type scale: float :param spacing: The space between cells :param spacing: int :param rect: The rectangle into which to draw the probabilities. If unspecified, the entire plot is used. :type rect: QRectF """ def __init__(self, classifier, granularity, scale, spacing, rect=None): orangeqt.PlotItem.__init__(self) self.classifier = classifier self.rect = rect self.granularity = granularity self.scale = scale self.spacing = spacing self.pixmap_item = QGraphicsPixmapItem(self) self.set_in_background(True) self.setZValue(ProbabilitiesZValue) def update_properties(self): ## Mostly copied from OWScatterPlotGraph if not self.plot(): return if not self.rect: x,y = self.axes() self.rect = self.plot().data_rect_for_axes(x,y) s = self.graph_transform().mapRect(self.rect).size().toSize() if not s.isValid(): return rx = s.width() ry = s.height() rx -= rx % self.granularity ry -= ry % self.granularity p = self.graph_transform().map(QPointF(0, 0)) - self.graph_transform().map(self.rect.topLeft()) p = p.toPoint() ox = p.x() oy = -p.y() if self.classifier.classVar.is_continuous: imagebmp = orangeom.potentialsBitmap(self.classifier, rx, ry, ox, oy, self.granularity, self.scale) palette = [qRgb(255.*i/255., 255.*i/255., 255-(255.*i/255.)) for i in range(255)] + [qRgb(255, 255, 255)] else: imagebmp, nShades = orangeom.potentialsBitmap(self.classifier, rx, ry, ox, oy, self.granularity, self.scale, self.spacing) palette = [] sortedClasses = get_variable_values_sorted(self.classifier.domain.classVar) for cls in self.classifier.classVar.values: color = self.plot().discPalette.getRGB(sortedClasses.index(cls)) towhite = [255-c for c in color] for s in range(nShades): si = 1-float(s)/nShades palette.append(qRgb(*tuple([color[i]+towhite[i]*si for i in (0, 1, 2)]))) palette.extend([qRgb(255, 255, 255) for i in range(256-len(palette))]) self.potentialsImage = QImage(imagebmp, rx, ry, QImage.Format_Indexed8) self.potentialsImage.setColorTable(palette) self.potentialsImage.setNumColors(256) self.pixmap_item.setPixmap(QPixmap.fromImage(self.potentialsImage)) self.pixmap_item.setPos(self.graph_transform().map(self.rect.bottomLeft())) def data_rect(self): return self.rect if self.rect else QRectF()
def __init__(self, pathway, objects, *args, **kwargs): QGraphicsPixmapItem.__init__(self, *args) self.setTransformationMode(Qt.SmoothTransformation) self.setPathway(pathway) self.setMarkedObjects(objects)
def __init__(self, pathway, objects, *args, **kwargs): QGraphicsPixmapItem.__init__(self, *args) self.setTransformationMode(Qt.SmoothTransformation) self.setPathway(pathway) self.setMarkedObjects(objects, name_mapper=kwargs.get("name_mapper", {}))
class EditLinksNode(QGraphicsWidget): """ A Node representation with channel anchors. `direction` specifies the layout (default `Qt.LeftToRight` will have icon on the left and channels on the right). """ def __init__(self, parent=None, direction=Qt.LeftToRight, node=None, icon=None, iconSize=None, **args): QGraphicsWidget.__init__(self, parent, **args) self.setAcceptedMouseButtons(Qt.NoButton) self.__direction = direction self.setLayout(QGraphicsLinearLayout(Qt.Horizontal)) # Set the maximum size, otherwise the layout can't grow beyond its # sizeHint (and we need it to grow so the widget can grow and keep the # contents centered vertically. self.layout().setMaximumSize(QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)) self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.__iconSize = iconSize or QSize(64, 64) self.__icon = icon self.__iconItem = QGraphicsPixmapItem(self) self.__iconLayoutItem = GraphicsItemLayoutItem(item=self.__iconItem) self.__channelLayout = QGraphicsGridLayout() self.__channelAnchors = [] if self.__direction == Qt.LeftToRight: self.layout().addItem(self.__iconLayoutItem) self.layout().addItem(self.__channelLayout) channel_alignemnt = Qt.AlignRight else: self.layout().addItem(self.__channelLayout) self.layout().addItem(self.__iconLayoutItem) channel_alignemnt = Qt.AlignLeft self.layout().setAlignment(self.__iconLayoutItem, Qt.AlignCenter) self.layout().setAlignment(self.__channelLayout, Qt.AlignVCenter | channel_alignemnt) if node is not None: self.setSchemeNode(node) def setIconSize(self, size): """ Set the icon size for the node. """ if size != self.__iconSize: self.__iconSize = QSize(size) if self.__icon: self.__iconItem.setPixmap(self.__icon.pixmap(size)) self.__iconLayoutItem.updateGeometry() def iconSize(self): """ Return the icon size. """ return QSize(self.__iconSize) def setIcon(self, icon): """ Set the icon to display. """ if icon != self.__icon: self.__icon = QIcon(icon) self.__iconItem.setPixmap(icon.pixmap(self.iconSize())) self.__iconLayoutItem.updateGeometry() def icon(self): """ Return the icon. """ return QIcon(self.__icon) def setSchemeNode(self, node): """ Set an instance of `SchemeNode`. The widget will be initialized with its icon and channels. """ self.node = node if self.__direction == Qt.LeftToRight: channels = node.output_channels() else: channels = node.input_channels() self.channels = channels loader = icon_loader.from_description(node.description) icon = loader.get(node.description.icon) self.setIcon(icon) label_template = ('<div align="{align}">' '<span class="channelname">{name}</span>' '</div>') if self.__direction == Qt.LeftToRight: align = "right" label_alignment = Qt.AlignVCenter | Qt.AlignRight anchor_alignment = Qt.AlignVCenter | Qt.AlignLeft label_row = 0 anchor_row = 1 else: align = "left" label_alignment = Qt.AlignVCenter | Qt.AlignLeft anchor_alignment = Qt.AlignVCenter | Qt.AlignLeft label_row = 1 anchor_row = 0 self.__channelAnchors = [] grid = self.__channelLayout for i, channel in enumerate(channels): text = label_template.format(align=align, name=escape(channel.name)) text_item = GraphicsTextWidget(self) text_item.setHtml(text) text_item.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) text_item.setToolTip( escape(getattr(channel, 'description', channel.type))) grid.addItem(text_item, i, label_row, alignment=label_alignment) anchor = ChannelAnchor(self, channel=channel, rect=QRectF(0, 0, 20, 20)) anchor.setBrush(self.palette().brush(QPalette.Mid)) layout_item = GraphicsItemLayoutItem(grid, item=anchor) grid.addItem(layout_item, i, anchor_row, alignment=anchor_alignment) anchor.setToolTip(escape(channel.type)) self.__channelAnchors.append(anchor) def anchor(self, channel): """ Return the anchor item for the `channel` name. """ for anchor in self.__channelAnchors: if anchor.channel() == channel: return anchor raise ValueError(channel.name) def paint(self, painter, option, widget=None): painter.save() palette = self.palette() border = palette.brush(QPalette.Mid) pen = QPen(border, 1) pen.setCosmetic(True) painter.setPen(pen) painter.setBrush(palette.brush(QPalette.Window)) brect = self.boundingRect() painter.drawRoundedRect(brect, 4, 4) painter.restore()