예제 #1
0
    def draw(self):
        (cx1, cy1), (cx2, cy2), (cx3, cy3) = self.get_cpoints()
        cr = self.setup_cr()

        # draw North line and arrowhead
        cr.pen().setCapStyle(QtCore.Qt.RoundCap)
        cr.drawLine(cx1, cy1, cx2, cy2)
        self.draw_arrowhead(cr, cx1, cy1, cx2, cy2)

        # draw East line and arrowhead
        cr.drawLine(cx1, cy1, cx3, cy3)
        self.draw_arrowhead(cr, cx1, cy1, cx3, cy3)

        # draw "N" & "E"
        if not self.fontsize:
            fontsize = self.scale_font()
        else:
            fontsize = self.fontsize
        cr.setFont(QFont('Sans Serif', pointSize=fontsize))
        cx, cy = self.get_textpos(cr, 'N', cx1, cy1, cx2, cy2)
        cr.drawText(cx, cy, 'N')
        cx, cy = self.get_textpos(cr, 'E', cx1, cy1, cx3, cy3)
        cr.drawText(cx, cy, 'E')

        if self.editing:
            self.draw_edit(cr)
        elif self.showcap:
            self.draw_caps(cr, self.cap, ((cx1, cy1), ))
예제 #2
0
 def set_font_from_shape(self, shape):
     if hasattr(shape, 'font'):
         if hasattr(shape, 'fontsize') and shape.fontsize is not None:
             fontsize = shape.fontsize
         else:
             fontsize = shape.scale_font(self.viewer)
         self.cr.setFont(QFont(shape.font, pointSize=fontsize))
예제 #3
0
    def draw(self):
        cpoints = tuple(
            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 = list(
            map(lambda p: QtCore.QPoint(p[0], p[1]),
                (cpoints + (cpoints[0], ))))
        qpoly = QPolygon(qpoints)

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

        if self.editing:
            self.draw_edit(cr)
        elif self.showcap:
            self.draw_caps(cr, self.cap, cpoints)

        if self.drawdims:
            fontsize = self.scale_font()
            cr.setFont(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))
예제 #4
0
 def get_dimensions(self):
     cr = self.setup_cr()
     if not self.fontsize:
         fontsize = self.scale_font()
     else:
         fontsize = self.fontsize
     cr.setFont(QFont(self.font, pointSize=fontsize))
     return self.text_extents(cr, self.text)
예제 #5
0
    def draw(self):
        cx, cy = self.canvascoords(self.x, self.y)

        cr = self.setup_cr()
        if not self.fontsize:
            fontsize = self.scale_font()
        else:
            fontsize = self.fontsize
        cr.setFont(QFont(self.font, pointSize=fontsize))
        cr.drawText(cx, cy, self.text)
예제 #6
0
    def draw(self):
        cx, cy = self.canvascoords(self.x, self.y)

        cr = self.setup_cr()
        if not self.fontsize:
            fontsize = self.scale_font()
        else:
            fontsize = self.fontsize
        cr.setFont(QFont(self.font, pointSize=fontsize))
        cr.drawText(cx, cy, self.text)

        if self.editing:
            self.draw_edit(cr)
        elif self.showcap:
            self.draw_caps(cr, self.cap, ((cx, cy), ))
예제 #7
0
    def __init__(self, logger=None, rgbmap=None, settings=None, render=None):
        ImageView.ImageViewBase.__init__(self,
                                         logger=logger,
                                         rgbmap=rgbmap,
                                         settings=settings)

        if render == None:
            render = 'widget'
        self.wtype = render
        if self.wtype == 'widget':
            self.imgwin = RenderWidget()
        elif self.wtype == 'scene':
            self.scene = QtGui.QGraphicsScene()
            self.imgwin = RenderGraphicsView(self.scene)
        else:
            raise ImageViewQtError("Undefined render type: '%s'" % (render))
        self.imgwin.fitsimage = self
        self.pixmap = None
        # Qt expects 32bit BGRA data for color images
        self._rgb_order = 'BGRA'

        self.t_.setDefaults(show_pan_position=False, onscreen_ff='Sans Serif')

        self.message = None
        self.msgtimer = QtCore.QTimer()
        self.msgtimer.timeout.connect(self.onscreen_message_off)
        self.msgfont = QFont(self.t_['onscreen_ff'], pointSize=24)
        self.set_bg(0.5, 0.5, 0.5, redraw=False)
        self.set_fg(1.0, 1.0, 1.0, redraw=False)

        # cursors
        self.cursor = {}

        # For optomized redrawing
        self._defer_task = QtCore.QTimer()
        self._defer_task.setSingleShot(True)
        self._defer_task.timeout.connect(self.delayed_redraw)
예제 #8
0
 def set_font(self, fontname, fontsize, color='black', alpha=1.0):
     # TODO: setting color a matter of setting the pen?
     self.cr.setFont(QFont(fontname, pointSize=fontsize))
예제 #9
0
 def set_font(self, fontname, fontsize, color='black', alpha=1.0):
     self.set_line(color, alpha=alpha)
     self.cr.setFont(QFont(fontname, pointSize=fontsize))
예제 #10
0
    def draw(self):
        cx1, cy1 = self.canvascoords(self.x1, self.y1)
        cx2, cy2 = self.canvascoords(self.x2, self.y2)

        text_x, text_y, text_h = self.get_ruler_distances()

        cr = self.setup_cr()

        if not self.fontsize:
            fontsize = self.scale_font()
        else:
            fontsize = self.fontsize
        cr.setFont(QFont(self.font, pointSize=fontsize))

        cr.pen().setCapStyle(QtCore.Qt.RoundCap)
        cr.drawLine(cx1, cy1, cx2, cy2)
        self.draw_arrowhead(cr, cx1, cy1, cx2, cy2)
        self.draw_arrowhead(cr, cx2, cy2, cx1, cy1)

        pen = cr.pen()

        # calculate offsets and positions for drawing labels
        # try not to cover anything up
        xtwd, xtht = self.text_extents(cr, text_x)
        ytwd, ytht = self.text_extents(cr, text_y)
        htwd, htht = self.text_extents(cr, text_h)

        diag_xoffset = 0
        diag_yoffset = 0
        xplumb_yoffset = 0
        yplumb_xoffset = 0

        diag_yoffset = 14
        if abs(cy1 - cy2) < 5:
            show_angle = 0
        elif cy1 < cy2:
            xplumb_yoffset = -4
        else:
            xplumb_yoffset = 14
            diag_yoffset = -4

        if abs(cx1 - cx2) < 5:
            diag_xoffset = -(4 + htwd)
            show_angle = 0
        elif (cx1 < cx2):
            diag_xoffset = -(4 + htwd)
            yplumb_xoffset = 4
        else:
            diag_xoffset = 4
            yplumb_xoffset = -(4 + ytwd)

        xh = min(cx1, cx2)
        y = cy1 + xplumb_yoffset
        xh += (max(cx1, cx2) - xh) // 2
        yh = min(cy1, cy2)
        x = cx2 + yplumb_xoffset
        yh += (max(cy1, cy2) - yh) // 2

        xd = xh + diag_xoffset
        yd = yh + diag_yoffset
        cr.drawText(xd, yd, text_h)

        pen.setDashPattern([3.0, 4.0, 6.0, 4.0])
        pen.setDashOffset(5.0)
        cr.setPen(pen)
        if self.color2:
            alpha = getattr(self, 'alpha', 1.0)
            self.set_color(cr, self.color2, alpha=alpha)

        # draw X plumb line
        cr.drawLine(cx1, cy1, cx2, cy1)

        # draw Y plumb line
        cr.drawLine(cx2, cy1, cx2, cy2)

        # draw X plum line label
        xh -= xtwd // 2
        cr.drawText(xh, y, text_x)

        # draw Y plum line label
        cr.drawText(x, yh, text_y)

        if self.editing:
            self.draw_edit(cr)
        elif self.showcap:
            self.draw_caps(cr, self.cap, ((cx2, cy1), ))
예제 #11
0
 def getFont(self, fontType, pointSize):
     fontFamily = self.settings.get(fontType)
     font = QFont(fontFamily, pointSize)
     return font
예제 #12
0
파일: ColorBar.py 프로젝트: godber/ginga
    def _draw(self, cr):
        width, height = self.get_size()
        #print "window size is %d,%d" % (width, height)

        x1 = 0
        x2 = width
        clr_wd = width // 256
        rem_px = x2 - (clr_wd * 256)
        if rem_px > 0:
            ival = 256 // rem_px
        else:
            ival = 0
        clr_ht = height
        #print "clr is %dx%d width=%d rem=%d ival=%d" % (
        #    width, height, clr_wd, rem_px, ival)

        dist = self.rgbmap.get_dist()

        j = ival
        off = 0
        range_pts = []
        for i in range(256):

            wd = clr_wd
            if rem_px > 0:
                j -= 1
                if j == 0:
                    rem_px -= 1
                    j = ival
                    wd += 1
            x = off

            (r, g, b) = self.rgbmap.get_rgbval(i)

            color = QColor(r, g, b)
            cr.fillRect(QtCore.QRect(x, 0, wd, clr_ht), color)

            # Draw range scale if we are supposed to
            if self.t_showrange and i in self._interval:
                cb_pct = float(i) / 256.0
                # get inverse of distribution function and calculate value
                # at this position
                rng_pct = dist.get_dist_pct(cb_pct)
                val = int(self.loval + (rng_pct * (self.hival - self.loval)))
                text = "%d" % (val)
                rect = cr.boundingRect(0, 0, 1000, 1000, 0, text)
                x1, y1, x2, y2 = rect.getCoords()
                _wd = x2 - x1
                _ht = y2 - y1
                _ht = 14

                rx = x
                ry = _ht - 2
                range_pts.append((rx, ry, text))

            off += wd

        # draw range
        pen = cr.pen()
        cr.setFont(QFont(self.t_font, pointSize=self.t_fontsize))
        color = QColor()
        color.setRgbF(0.0, 0.0, 0.0)
        pen.setColor(color)
        cr.setPen(pen)

        for (x, y, text) in range_pts:
            # tick
            cr.drawLine(x, 0, x, 2)
            # number
            cr.drawText(x, y, text)