Exemplo n.º 1
0
    def draw(self):
        cpoints = map(lambda p: self.canvascoords(p[0], p[1]),
                      ((self.x1, self.y1), (self.x2, self.y1),
                       (self.x2, self.y2), (self.x1, self.y2)))
        #qpoints = map(lambda p: QtCore.QPoint(p[0], p[1]), cpoints)
        qpoints = map(lambda p: QtCore.QPoint(p[0], p[1]),
                      cpoints + [cpoints[0]])
        qpoly = QtGui.QPolygon(qpoints)

        cr = self.setup_cr()
        cr.drawPolygon(qpoly)

        if self.cap:
            self.draw_caps(cr, self.cap, cpoints)

        if self.drawdims:
            fontsize = self.scale_font()
            cr.setFont(QtGui.QFont(self.font, pointSize=fontsize))

            cx1, cy1 = cpoints[0]
            cx2, cy2 = cpoints[2]

            # draw label on X dimension
            cx = cx1 + (cx2 - cx1) // 2
            cy = cy2 + -4
            cr.drawText(cx, cy, "%d" % (self.x2 - self.x1))

            # draw label on Y dimension
            cy = cy1 + (cy2 - cy1) // 2
            cx = cx2 + 4
            cr.drawText(cx, cy, "%d" % (self.y2 - self.y1))
Exemplo n.º 2
0
    def draw(self):
        cpoints = map(lambda p: self.canvascoords(p[0], p[1]), self.points)
        cr = self.setup_cr()

        qpoints = map(lambda p: QtCore.QPoint(p[0], p[1]),
                      cpoints + [cpoints[0]])
        qpoly = QtGui.QPolygon(qpoints)

        cr.drawPolygon(qpoly)

        if self.cap:
            self.draw_caps(cr, self.cap, cpoints)