def __get_color(self, color): if isinstance(color, tuple): clr = QtGui.QColor() clr.setRgbF(color[0], color[1], color[2]) else: clr = QtGui.QColor(color) return clr
def __init__(self, color='red'): pm = QtGui.QPixmap(16, 16) mask = QtGui.QBitmap(16, 16) black = QtCore.Qt.color1 white = QtCore.Qt.color0 clr = QtGui.QColor(color) pm.fill(clr) mask.fill(black) p1 = QtGui.QPainter(mask) p1.setPen(white) p1.drawLine(0, 6, 5, 6) p1.drawLine(0, 8, 5, 8) p1.drawLine(10, 6, 15, 6) p1.drawLine(10, 8, 15, 8) p1.drawLine(6, 0, 6, 5) p1.drawLine(8, 0, 8, 5) p1.drawLine(6, 10, 6, 15) p1.drawLine(8, 10, 8, 15) p1.end() pm.setAlphaChannel(mask) self.cur = QtGui.QCursor(pm, 8, 8)
def _render_offscreen(self, drawable, data, dst_x, dst_y, width, height): # NOTE [A] daht, dawd, depth = data.shape self.logger.debug("data shape is %dx%dx%d" % (dawd, daht, depth)) # Get qimage for copying pixel data qimage = self._get_qimage(data) painter = QtGui.QPainter(drawable) painter.setWorldMatrixEnabled(True) # fill pixmap with background color imgwin_wd, imgwin_ht = self.get_window_size() painter.fillRect(QtCore.QRect(0, 0, imgwin_wd, imgwin_ht), self.img_bg) # draw image data from buffer to offscreen pixmap painter.drawImage(QtCore.QRect(dst_x, dst_y, width, height), qimage, QtCore.QRect(0, 0, width, height)) # Draw a cross in the center of the window in debug mode if self.t_['show_pan_position']: clr = QtGui.QColor() clr.setRgbF(1.0, 0.0, 0.0) painter.setPen(clr) ctr_x, ctr_y = self.get_center() painter.drawLine(ctr_x - 10, ctr_y, ctr_x + 10, ctr_y) painter.drawLine(ctr_x, ctr_y - 10, ctr_x, ctr_y + 10) # render self.message if self.message: self.draw_message(painter, imgwin_wd, imgwin_ht, self.message)
def _get_color(self, r, g, b): n = 255.0 clr = QtGui.QColor(int(r * n), int(g * n), int(b * n)) return clr
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) j = ival off = 0 range_pts = [] for i in xrange(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 = QtGui.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 self._interval.has_key(i): pct = float(i) / 256.0 val = int(self.loval + 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(QtGui.QFont(self.t_font, pointSize=self.t_fontsize)) color = QtGui.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)