示例#1
0
 def draw_y_axis(self):
     lineItem = QGraphicsLineItem(0,
                                  self.coordY(self.ylim[0]),
                                  0,
                                  self.coordY(self.ylim[1]),
                                  parent=self.item)
     lineItem.setPen(QPen(QColor('black')))
     lineItem.setZValue(10)
     max_w = 0
     for y in set(self.hlines + list(self.ylim)):
         lineItem = QGraphicsLineItem(0,
                                      self.coordY(y),
                                      -5,
                                      self.coordY(y),
                                      parent=self.item)
         lineItem.setPen(QPen(QColor('black')))
         lineItem.setZValue(10)
         text = QGraphicsSimpleTextItem(str(y))
         text.setFont(QFont("Arial", self.fsize - 2))
         text.setParentItem(self.item)
         tw = text.boundingRect().width()
         max_w = tw if tw > max_w else max_w
         th = text.boundingRect().height()
         # Center text according to masterItem size
         text.setPos(-tw - 5, self.coordY(y) - th / 2)
     if self.ylabel:
         text = QGraphicsSimpleTextItem(self.ylabel)
         text.setFont(QFont("Arial", self.fsize - 1))
         text.setParentItem(self.item)
         text.rotate(-90)
         tw = text.boundingRect().width()
         th = text.boundingRect().height()
         # Center text according to masterItem size
         text.setPos(-th - 5 - max_w,
                     tw / 2 + self.coordY(sum(self.ylim) / 2))
示例#2
0
 def initShape(self):
     self.initHeads()
     #Line decoration
     offsetLine = QGraphicsLineItem(QLineF(90, 0, 90, 700))
     asciiLine = QGraphicsLineItem(QLineF(480, 0, 480, 700))
     #Add to scene
     self.__scene.addItem(offsetLine)
     self.__scene.addItem(asciiLine)
示例#3
0
文件: pageView.py 项目: kzwkt/dff
    def setHeads(self, pagesPerBlock):
        if self.heditor.pageOffView:
            self.setOffsetHead()
        else:
            self.setBlockHead()
        self.setPageHead(self.heditor.pagesPerBlock)

        linesize = 95 + (self.heditor.pagesPerBlock * (self.pagew + 2))
        #Decoration
        headLine = QGraphicsLineItem(QLineF(0, 20, linesize, 20))
        self.scene.addItem(headLine)
        headOffLine = QGraphicsLineItem(QLineF(90, 0, 90, 700))
        self.scene.addItem(headOffLine)
示例#4
0
 def initHeads(self):
     self.offHead = QGraphicsTextItem()
     self.hexHead = QGraphicsTextItem()
     self.asciiHead = QGraphicsTextItem()
     #Set Color
     self.offHead.setDefaultTextColor(QColor(Qt.red))
     self.hexHead.setDefaultTextColor(QColor(Qt.black))
     self.asciiHead.setDefaultTextColor(QColor(Qt.darkCyan))
     #Create Font
     self.font = QFont("Gothic")
     self.font.setFixedPitch(1)
     self.font.setBold(False)
     self.font.setPixelSize(14)
     #Set Font
     self.offHead.setFont(self.font)
     self.hexHead.setFont(self.font)
     self.asciiHead.setFont(self.font)
     #Set Text
     self.offHead.setPlainText("Offset")
     self.hexHead.setPlainText(
         "0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F")
     self.asciiHead.setPlainText("Ascii")
     #Position
     self.offHead.setPos(20, 0)
     self.hexHead.setPos(95, 0)
     self.asciiHead.setPos(520, 0)
     #Add to scene
     self.__scene.addItem(self.offHead)
     self.__scene.addItem(self.hexHead)
     self.__scene.addItem(self.asciiHead)
     headLine = QGraphicsLineItem(QLineF(0, 20, 615, 20))
     self.__scene.addItem(headLine)
示例#5
0
    def moveTo(self, pos):
        #data coordinates
        oldX, oldY = self.pos.x(), self.pos.y()
        x, y = pos.x(), pos.y()

        line = QGraphicsLineItem(oldX, oldY, x, y)
        line.setPen(
            QPen(QBrush(Qt.white), self.brushSize, Qt.SolidLine, Qt.RoundCap,
                 Qt.RoundJoin))
        self.scene.addItem(line)
        self._hasMoved = True

        #update bounding Box
        if not self.bb.isValid():
            self.bb = QRect(QPoint(oldX, oldY), QSize(1, 1))
        #grow bounding box
        self.bb.setLeft(
            min(self.bb.left(), max(0, x - self.brushSize // 2 - 1)))
        self.bb.setRight(
            max(self.bb.right(),
                min(self.sliceRect[0] - 1, x + self.brushSize // 2 + 1)))
        self.bb.setTop(min(self.bb.top(), max(0, y - self.brushSize // 2 - 1)))
        self.bb.setBottom(
            max(self.bb.bottom(),
                min(self.sliceRect[1] - 1, y + self.brushSize // 2 + 1)))

        #update/move position
        self.pos = pos
示例#6
0
    def mouseMoveEvent(self, event):
        if event.buttons() & Qt.LeftButton:

            downPos = event.buttonDownPos(Qt.LeftButton)
            if not self.__tmpLine and self.__dragStartItem and \
                    (downPos - event.pos()).manhattanLength() > \
                        QApplication.instance().startDragDistance():
                # Start a line drag
                line = QGraphicsLineItem(self)
                start = self.__dragStartItem.boundingRect().center()
                start = self.mapFromItem(self.__dragStartItem, start)
                line.setLine(start.x(), start.y(),
                             event.pos().x(),
                             event.pos().y())

                pen = QPen(Qt.black, 4)
                pen.setCapStyle(Qt.RoundCap)
                line.setPen(pen)
                line.show()

                self.__tmpLine = line

            if self.__tmpLine:
                # Update the temp line
                line = self.__tmpLine.line()
                line.setP2(event.pos())
                self.__tmpLine.setLine(line)

        QGraphicsWidget.mouseMoveEvent(self, event)
示例#7
0
 def draw_hlines(self, line, col):
     lineItem = QGraphicsLineItem(0,
                                  self.coordY(line),
                                  self.width,
                                  self.coordY(line),
                                  parent=self.item)
     lineItem.setPen(QPen(QColor(col), 1, Qt.DashLine))
     lineItem.setZValue(10)
示例#8
0
    def draw_x_axis(self):
        lineItem = QGraphicsLineItem(self.col_w / 2,
                                     self.coordY(self.ylim[0]) + 2,
                                     self.width - self.col_w / 2,
                                     self.coordY(self.ylim[0]) + 2,
                                     parent=self.item)
        lineItem.setPen(QPen(QColor('black')))
        lineItem.setZValue(10)
        all_vals = list(range(0, len(self.values), self.x_inter_values))
        if (len(self.values) - 1) % self.x_inter_values:
            all_vals += [len(self.values) - 1]

        hp_x = []
        if self.hp:
            for x in list(range(0, len(self.values))):
                if self.x_values[x] in self.hp:
                    hp_x.append(x)
                    if not x in all_vals:
                        all_vals += [x]
        all_vals.sort()

        for x in all_vals:
            lineItem = QGraphicsLineItem(0,
                                         self.coordY(self.ylim[0]) + 2,
                                         0,
                                         self.coordY(self.ylim[0]) + 6,
                                         parent=self.item)
            lineItem.setX(x * self.col_w + self.col_w / 2)
            lineItem.setPen(QPen(QColor('black')))
            lineItem.setZValue(10)
            if x in hp_x:
                text = QGraphicsSimpleTextItem("*" + str(self.x_values[x]))
                qfont = QFont("Arial", self.fsize - 1)
                #qfont.setBold(True)
                text.setFont(qfont)
            else:
                text = QGraphicsSimpleTextItem(" " + str(self.x_values[x]))
                text.setFont(QFont("Arial", self.fsize - 1))
            text.rotate(-90)
            text.setParentItem(self.item)
            text.setZValue(10)
            tw = text.boundingRect().width()
            th = text.boundingRect().height()
            # Center text according to masterItem size
            text.setPos(x * self.col_w - th / 2 + self.col_w / 2,
                        tw + self.coordY(self.ylim[0]) + 7)
示例#9
0
 def __init__(self, rectf, parent=None):
     super( DummyItem, self ).__init__( parent )
     self.rectf = rectf
     self.line = QGraphicsLineItem( self.rectf.x(),
                                    self.rectf.y(),
                                    self.rectf.x() + self.rectf.width(),
                                    self.rectf.y() + self.rectf.height(),
                                    parent=self )
示例#10
0
 def draw_stick(self, x, y, i):
     lineItem = QGraphicsLineItem(0,
                                  self.coordY(self.ylim[0]),
                                  0,
                                  self.coordY(y),
                                  parent=self.item)
     lineItem.setX(x)
     lineItem.setPen(QPen(QColor(self.colors[i]), 2))
示例#11
0
 def draw_bar(self, x, y, i):
     h = self.coordY(self.ylim[0])  #self.height
     coordY = self.coordY
     item = self.item
     # if value stands out of bound
     if y < self.ylim[0]: return
     if y < self.ylim[1]:
         # left line
         lineItem = QGraphicsLineItem(0, h, 0, coordY(y), parent=item)
         lineItem.setX(x - 3)
         lineItem.setPen(QPen(QColor(self.colors[i]), 2))
         # right line
         lineItem = QGraphicsLineItem(0, h, 0, coordY(y), parent=item)
         lineItem.setX(x + 3)
         lineItem.setPen(QPen(QColor(self.colors[i]), 2))
         # top line
         lineItem = QGraphicsLineItem(0,
                                      coordY(y),
                                      6,
                                      coordY(y),
                                      parent=item)
         lineItem.setX(x - 3)
         lineItem.setPen(QPen(QColor(self.colors[i]), 2))
     else:
         # lower left line
         lineItem = QGraphicsLineItem(0, h, 0, coordY(y), parent=item)
         lineItem.setX(x - 3)
         lineItem.setPen(QPen(QColor(self.colors[i]), 2))
         # lower right line
         lineItem = QGraphicsLineItem(0, h, 0, coordY(y), parent=item)
         lineItem.setX(x + 3)
         lineItem.setPen(QPen(QColor(self.colors[i]), 2))
         # upper left line
         lineItem = QGraphicsLineItem(0,
                                      coordY(y) - 4,
                                      0,
                                      coordY(y) - 7,
                                      parent=item)
         lineItem.setX(x - 3)
         lineItem.setPen(QPen(QColor(self.colors[i]), 2))
         # upper right line
         lineItem = QGraphicsLineItem(0,
                                      coordY(y) - 4,
                                      0,
                                      coordY(y) - 7,
                                      parent=item)
         lineItem.setX(x + 3)
         lineItem.setPen(QPen(QColor(self.colors[i]), 2))
         # top line
         lineItem = QGraphicsLineItem(0,
                                      coordY(y) - 7,
                                      6,
                                      coordY(y) - 7,
                                      parent=item)
         lineItem.setX(x - 3)
         lineItem.setPen(QPen(QColor(self.colors[i]), 2))
示例#12
0
 def draw_curve(self, x, y, i):
     # top line
     lineItem = QGraphicsLineItem(0,
                                  self.coordY(y),
                                  4,
                                  self.coordY(y),
                                  parent=self.item)
     lineItem.setX(x - 2)
     lineItem.setPen(QPen(QColor(self.colors[i]), 2))
     if i > 0:
         prev = self.values[i - 1] if i > 0 else self.values[i]
         lineItem = QGraphicsLineItem(0,
                                      self.coordY(prev),
                                      self.col_w - 4,
                                      self.coordY(y),
                                      parent=self.item)
         lineItem.setX(x - self.col_w + 2)
         lineItem.setPen(QPen(QColor(self.colors[i]), 2))
示例#13
0
    def addLines(self, x, y, w, h, diff, pen):
        if w == 0 or h == 0:
            return

        dist = 20 * diff  # original distance between two lines in pixels
        temp = dist
        canvas = self.canvas
        while temp < w:
            r = QGraphicsLineItem(temp + x, y, temp + x, y + h, None)
            canvas.addItem(r)
            r.setPen(pen)
            temp += dist

        temp = dist
        while temp < h:
            r = QGraphicsLineItem(x, y + temp, x + w, y + temp, None)
            canvas.addItem(r)
            r.setPen(pen)
            temp += dist
示例#14
0
 def draw_errors(self, x, i):
     lower = self.values[i] + self._dw_err[i]
     upper = self.values[i] + self._up_err[i]
     lineItem = QGraphicsLineItem(0,
                                  self.coordY(lower),
                                  0,
                                  self.coordY(upper),
                                  parent=self.item)
     lineItem.setX(x)
     lineItem.setPen(QPen(QColor('black'), 1))
示例#15
0
    def __init__(self,
                 id,
                 title='',
                 title_above=False,
                 title_location=AxisMiddle,
                 line=None,
                 arrows=0,
                 plot=None,
                 bounds=None):
        QGraphicsItem.__init__(self)
        self.setFlag(QGraphicsItem.ItemHasNoContents)
        self.setZValue(AxisZValue)
        self.id = id
        self.title = title
        self.title_location = title_location
        self.data_line = line
        self.plot = plot
        self.graph_line = None
        self.size = None
        self.scale = None
        self.tick_length = (10, 5, 0)
        self.arrows = arrows
        self.title_above = title_above
        self.line_item = QGraphicsLineItem(self)
        self.title_item = QGraphicsTextItem(self)
        self.end_arrow_item = None
        self.start_arrow_item = None
        self.show_title = False
        self.scale = None
        path = QPainterPath()
        path.setFillRule(Qt.WindingFill)
        path.moveTo(0, 3.09)
        path.lineTo(0, -3.09)
        path.lineTo(9.51, 0)
        path.closeSubpath()
        self.arrow_path = path
        self.label_items = []
        self.label_bg_items = []
        self.tick_items = []
        self._ticks = []
        self.zoom_transform = QTransform()
        self.labels = None
        self.values = None
        self._bounds = bounds
        self.auto_range = None
        self.auto_scale = True

        self.zoomable = False
        self.update_callback = None
        self.max_text_width = 50
        self.text_margin = 5
        self.always_horizontal_text = False
示例#16
0
    def onMouseMove_draw( self, imageview, event ):
        self._navIntr.onMouseMove_default( imageview, event )

        o = imageview.scene().data2scene.map(QPointF(imageview.oldX,imageview.oldY))
        n = imageview.scene().data2scene.map(QPointF(imageview.x,imageview.y))

        # Draw temporary line for the brush stroke so the user gets feedback before the data is really updated.
        pen = QPen( QBrush(self._brushingCtrl._brushingModel.drawColor), self._brushingCtrl._brushingModel.brushSize, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
        line = QGraphicsLineItem(o.x(), o.y(), n.x(), n.y())
        line.setPen(pen)
        
        imageview.scene().addItem(line)
        line.setParentItem(imageview.scene().dataRectItem)

        self._lineItems.append(line)
        self._brushingCtrl._brushingModel.moveTo(imageview.mousePos)
示例#17
0
    def update_items(self):
        rect_h = self.height
        if self.x_axis:
            rect_h += 30
        self.item = QGraphicsRectItem(0, 0, self.width + 40, rect_h)
        self.item.setPen(QPen(QColor('white')))

        #X axis

        if self.x_axis:
            self.draw_x_axis()

        # Legend

        self.draw_legend()

        # Y axes and colo rect
        yi = -1
        for model in ["PCOC", "PC", "OC", "Topological", "Identical"]:
            if self.dict_values_pcoc.has_key(model):
                yi += 1
                y = yi * self.col_w

                # Y axes
                ## Stick
                yaxis = (yi + 0.5) * self.col_w
                lineItem = QGraphicsLineItem(self.width,
                                             yaxis,
                                             self.width + 5,
                                             yaxis,
                                             parent=self.item)
                lineItem.setPen(QPen(QColor('black')))
                ## Text
                text = QGraphicsSimpleTextItem(model)
                text.setFont(QFont("Arial", self.fsize - 2))
                text.setParentItem(self.item)
                tw = text.boundingRect().width()
                th = text.boundingRect().height()
                ## Center text according to masterItem size
                text.setPos(self.width + 5, yaxis - th / 2)

                # Color rect for each model
                values = self.dict_values_pcoc[model]
                for i, val in enumerate(values):
                    self.draw_fun(i * self.col_w, y, val, col_width=self.col_w)
示例#18
0
    def __init__(self, parent=None, line=None, label=None, **kwargs):
        super().__init__(parent, **kwargs)
        self.setFlag(pg.GraphicsObject.ItemHasNoContents)

        if line is None:
            line = QLineF(0, 0, 1, 0)

        self._spine = QGraphicsLineItem(line, self)
        angle = QLineF(0, 0, 1, 0).angleTo(line)
        angle = (180 - angle) % 360
        dx = line.x2() - line.x1()
        dy = line.y2() - line.y1()
        rad = numpy.arctan2(dy, dx)
        angle = (rad * 180 / numpy.pi) % 360

        self._arrow = pg.ArrowItem(parent=self, angle=180 - angle)
        self._arrow.setPos(self._spine.line().p2())

        self._label = pg.TextItem(text=label, color=(10, 10, 10))
        self._label.setParentItem(self)
        self._label.setPos(self._spine.line().p2())
示例#19
0
    def test_controlpointline(self):
        control = ControlPointLine()
        line = QGraphicsLineItem(10, 10, 200, 200)

        self.scene.addItem(line)
        self.scene.addItem(control)

        control.setLine(line.line())
        control.setFocus()
        control.lineChanged.connect(line.setLine)

        control.setLine(QLineF(30, 30, 180, 180))
        self.assertEqual(control.line(), line.line())
        self.assertEqual(line.line(), QLineF(30, 30, 180, 180))

        control.lineEdited.connect(line.setLine)

        self.view.show()
        self.app.exec_()

        self.assertEqual(control.line(), line.line())
示例#20
0
    def addLink(self, output, input):
        """
        Add a link between `output` (:class:`OutputSignal`) and `input`
        (:class:`InputSignal`).

        """
        if not compatible_channels(output, input):
            return

        if output not in self.source.output_channels():
            raise ValueError("%r is not an output channel of %r" % \
                             (output, self.source))

        if input not in self.sink.input_channels():
            raise ValueError("%r is not an input channel of %r" % \
                             (input, self.sink))

        if input.single:
            # Remove existing link if it exists.
            for s1, s2, _ in self.__links:
                if s2 == input:
                    self.removeLink(s1, s2)

        line = QGraphicsLineItem(self)

        source_anchor = self.sourceNodeWidget.anchor(output)
        sink_anchor = self.sinkNodeWidget.anchor(input)

        source_pos = source_anchor.boundingRect().center()
        source_pos = self.mapFromItem(source_anchor, source_pos)

        sink_pos = sink_anchor.boundingRect().center()
        sink_pos = self.mapFromItem(sink_anchor, sink_pos)
        line.setLine(source_pos.x(), source_pos.y(), sink_pos.x(),
                     sink_pos.y())
        pen = QPen(Qt.black, 4)
        pen.setCapStyle(Qt.RoundCap)
        line.setPen(pen)

        self.__links.append(_Link(output, input, line))
示例#21
0
    def draw_legend(self):
        legend_h = self.height * ((self.nb_models - 1) / float(self.nb_models))
        if legend_h < 35:
            legend_h = 35
        legend_rect = QGraphicsRectItem(-20, 0, 10, legend_h, parent=self.item)
        x0 = -20
        n_cat = 6.
        for y, str_y in [(1, 1), (1 / n_cat * 5, 0.99), (1 / n_cat * 4, 0.9),
                         (1 / n_cat * 3, 0.8), (1 / n_cat * 2, 0.7),
                         (1 / n_cat * 1, 0.5), (1 / n_cat * 0, 0)]:
            y_stick = legend_h - y * legend_h
            lineItem = QGraphicsLineItem(x0 - 5,
                                         y_stick,
                                         x0,
                                         y_stick,
                                         parent=self.item)
            lineItem.setPen(QPen(QColor('black')))
            text = QGraphicsSimpleTextItem(str(str_y))
            text.setFont(QFont("Arial", self.fsize - 4))
            text.setParentItem(self.item)
            tw = text.boundingRect().width()
            th = text.boundingRect().height()
            # Center text according to masterItem size
            text.setPos(x0 - tw - 7, y_stick - th / 2)

        for (y1, y2, c) in [(1, 1 / n_cat * 5, 0.99),
                            (1 / n_cat * 5, 1 / n_cat * 4, 0.9),
                            (1 / n_cat * 4, 1 / n_cat * 3, 0.8),
                            (1 / n_cat * 3, 1 / n_cat * 2, 0.7),
                            (1 / n_cat * 2, 1 / n_cat * 1, 0.5),
                            (1 / n_cat * 1, 1 / n_cat * 0, 0)]:
            y1_stick = legend_h - y1 * legend_h
            y2_stick = legend_h - y2 * legend_h
            self.draw_fun(x0,
                          y1_stick,
                          c,
                          col_width=10,
                          col_height=y2_stick - y1_stick)
示例#22
0
 def line(x1, y1, x2, y2):
     r = QGraphicsLineItem(x1, y1, x2, y2, None)
     self.canvas.addItem(r)
     r.setPen(QPen(Qt.white, 2))
     r.setZValue(30)
示例#23
0
 def _offseted_line(ax, ay):
     r = QGraphicsLineItem(x + ax, y + ay, x + (ax or w),
                           y + (ay or h))
     self.canvas.addItem(r)
     r.setPen(pen)
示例#24
0
    def setAxisIntersect(self, intersect):
        self._axisIntersect = intersect
        #print "SkeletonsLayer(axis=%d) is updating intersect=%d" % (self._axis, self._axisIntersect)

        nodes, eIntersected, ePlane = self._3d._skeletons.intersect(
            self._axis, self._axisIntersect)

        #update existing items
        toRemove = []
        for node, item in self._node2view.iteritems():
            if node.pos[self._axis] != self._axisIntersect:
                self._scene.removeItem(item)
                toRemove.append(node)
            elif node.pointF(self._axis) != item.pos():
                item.setPos(self._scene.data2scene.map(node.pointF(
                    self._axis)))
            if node.isSelected() != item.isSelected():
                item.setSelected(node.isSelected())
                assert item.isSelected() == node.isSelected()
            i = 0
            newSize = [0, 0]
            for j in range(3):
                if j == self._axis:
                    continue
                newSize[i] = node.shape[j]
                i += 1
            newRectF = QRectF(0, 0, *newSize)
            newRectF = self._scene.data2scene.mapRect(newRectF)

            item.setRect(
                QRectF(-newRectF.width() / 2.0, -newRectF.height() / 2.0,
                       newRectF.width(), newRectF.height()))

        for r in toRemove:
            del self._node2view[r]

        #add new views for nodes
        for n in nodes:
            if n in self._node2view:
                continue

            pos2D = list(n.pos)
            del pos2D[self._axis]

            shape2D = n.shape2D(self._axis)
            itm = QGraphicsSkeletonNode(shape2D,
                                        skeletons=self._3d._skeletons,
                                        node=n)
            itm.setPos(self._scene.data2scene.map(QPointF(*pos2D)))
            itm.setSelected(n.isSelected())

            self._scene.addItem(itm)
            self._node2view[n] = itm

        for itm in self._edge2view.values():
            self._scene.removeItem(itm)
        self._edge2view = dict()

        for e in ePlane:
            l = QLineF(e[0].pointF(), e[1].pointF())

            c1 = e[0].color()
            c2 = e[1].color()
            mixColor = QColor((c1.red() + c2.red()) / 2,
                              (c1.green() + c2.green()) / 2,
                              (c1.blue() + c2.blue()) / 2)

            line = QGraphicsLineItem(self._scene.data2scene.map(l))
            line.setPen(QPen(mixColor))
            self._scene.addItem(line)
            self._edge2view[e] = line

        for theEdge, e in eIntersected:
            c1 = theEdge[0].color()
            c2 = theEdge[1].color()
            mixColor = QColor((c1.red() + c2.red()) / 2,
                              (c1.green() + c2.green()) / 2,
                              (c1.blue() + c2.blue()) / 2)

            nodeSize = 6
            p = QGraphicsRectItem(-nodeSize / 2, -nodeSize / 2, nodeSize,
                                  nodeSize)
            pos2D = list(e)
            del pos2D[self._axis]
            p.setPos(self._scene.data2scene.map(QPointF(*pos2D)))
            p.setPen(QPen(mixColor))
            self._scene.addItem(p)
            self._edge2view[e] = p