def yanal_egim_sol(self): value = self.ui.sliderSolUst.value() egim = (100 - value) / 100 print(str(value) + " egim: " + str(egim)) styleSheet = """ QFrame{ border-top-left-radius: 275px; background-color: qconicalgradient(cx:1, cy:1, angle:180, stop:{STOP_1} rgba(85, 170, 255, 0), stop:{STOP_2} rgba(252, 201, 109, 255)); } """ stop_1 = str(egim - 0.001) stop_2 = str(egim) basdeger = 0 azaltma = 0.0 bas = 0 hizGosterge = value * 1.44 newStyleSheet = styleSheet.replace("{STOP_1}", stop_1).replace("{STOP_2}", stop_2) hizGosterge = int(hizGosterge) self.ui.solUstProgress.setStyleSheet(newStyleSheet) resimegim = value * -2.5 Rightmatrix = QMatrix() Rightmatrix.rotate(resimegim) self.ui.yanal_egim_resim.setPixmap( QPixmap(u"E:\QT Çalışmaları\son_dashboard\kobraon.png"). transformed(Rightmatrix))
def redraw(self): """ Re-draws the buttons. May be called as initialization method too. """ # Pixmap that contains the painter and the DR canvas = QPixmap("assets/" + self.digirule.get_img_name()) self.setPixmap(canvas) painter = QPainter(self.pixmap( )) # Create a painter in which buttons and LEDs are drawn translate_matrix = QMatrix() offset_scale = self.digirule.get_scale_offset() translate_matrix.scale(offset_scale[0], offset_scale[1]) painter.setMatrix(translate_matrix) # Drawing pen = QPen() pen.setWidth(self.digirule.get_buttons_width()) pen.setColor(QColor(0, 0, 0, 0)) # Buttons color painter.setPen(pen) # Buttons for btn in self.digirule.get_buttons_positions_dic(): painter.drawPoint(QPoint(btn[0], btn[1])) pen.setWidth(2) painter.setPen(pen) for btn in self.digirule.get_special_buttons_rects_dic(): # Draw rectangle given the top-left and bottom-right corners coordinates painter.drawRect(self._build_rect(btn))
def dikey_egim_sag(self): value = self.ui.sliderSagAlt.value() #egim = value / 100 egim = (100 - value) / 100 print(str(value) + " egim: " + str(egim)) styleSheet = """ QFrame{ border-bottom-right-radius: 275px;\n background-color: qconicalgradient(cx:0, cy:0, angle:0, stop:{STOP_1} rgba(85, 170, 255, 0), stop:{STOP_2} rgba(121, 50, 190, 255));\n } """ stop_1 = str(egim - 0.001) stop_2 = str(egim) basdeger = 0 azaltma = 0.0 bas = 0 hizGosterge = value * 1.44 newStyleSheet = styleSheet.replace("{STOP_1}", stop_1).replace("{STOP_2}", stop_2) hizGosterge = int(hizGosterge) self.ui.sagAltProgress.setStyleSheet(newStyleSheet) resimegim = value * 2.5 Rightmatrix = QMatrix() Rightmatrix.rotate(resimegim) self.ui.dikey_egim_resim.setPixmap( QPixmap(u"E:\QT Çalışmaları\son_dashboard\kobrayan.png"). transformed(Rightmatrix))
def testMatrixMapping(self): m = QMatrix(1.0, 2.0, 1.0, 3.0, 100.0, 200.0) res = m.map(5, 5) self.assertAlmostEqual(res[0], 5 * 1.0 + 5 * 1.0 + 100.0) self.assertAlmostEqual(res[1], 5 * 2.0 + 5 * 3.0 + 200.0) res = m.map(5.0, 5.0) self.assertAlmostEqual(res[0], 5.0 * 1.0 + 5.0 * 1.0 + 100.0) self.assertAlmostEqual(res[1], 5.0 * 2.0 + 5.0 * 3.0 + 200.0)
def _turn(self, var: QSize): """ turns icon :param var: :return: """ rm = QMatrix() rm.rotate(var.width()) super().setIcon(self.icon.transformed(rm))
def setupMatrix(self): scale = 2**((self.zoomSlider.value() - 250) / 50.0) matrix = QMatrix() matrix.scale(scale, scale) matrix.rotate(self.rotateSlider.value()) self.graphicsView.setMatrix(matrix) self.setResetButtonEnabled()
def setUp(self): self.original = QMatrix(1, 2, 3, 4, 5, 6)
def testMatrixWithWrongType(self): matrix = QMatrix(11, 12, 21, 22, 100, 200) point = QPoint(3, 3) self.assertRaises(TypeError, matrix.__mul__, point)
def testMatrix(self): matrix = QMatrix(11, 12, 21, 22, 100, 200) point = QPoint(3, 3) self.assertEqual(point * matrix, qpointTimesQMatrix(point, matrix))
def set_scaling(self, scaling): matrix = QMatrix() matrix.scale(scaling, scaling) self.setMatrix(matrix)
def testMatrixWithWrongType(self): matrix = QMatrix(11, 12, 21, 22, 100, 200) point = QPoint(3, 3) # This exception may move from a TypeError to a ValueError. self.assertRaises((TypeError, ValueError), matrix.__mul__, point)
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.HighQualityAntialiasing) # determine max width/height of all labels if self._maxLabelWidth is None or self._maxLabelHeight is None: self._maxLabelWidth = 0 self._maxLabelHeight = 0 for k in self.labels.values(): b = painter.boundingRect( QRectF(0, 0, 0, 0), int(Qt.AlignLeft) | int(Qt.AlignVCenter), str(k)) self._maxLabelWidth = max(self._maxLabelWidth, b.width()) self._maxLabelHeight = max(self._maxLabelHeight, b.height()) barRect = self.rect() if self._orientation == 'Vertical': # translate Y axis matrix = QMatrix() matrix.translate(0, self.height() - self.margin) matrix.scale(1, -1) painter.setMatrix(matrix) self.gradient.setFinalStop(0, self.height() - self.margin) barRect.setWidth(self._barThickness) barRect.setHeight(barRect.height() - 2 * self.margin) painter.fillRect(barRect, self.gradient) # restore normal coordinates painter.scale(1, -1) self.setMinimumWidth(self._barThickness + self._labelMargin + self._maxLabelWidth) elif self._orientation == 'Horizontal': self.margin = self._maxLabelWidth / 2 + self._labelMargin barRect.setHeight(self._barThickness) barRect.setLeft( self.margin ) # reduces width by margin (as opposed to shifting) # Reduce the width by another margin to pull off the right hand side barRect.setWidth(barRect.width() - self.margin) painter.fillRect(barRect, self.gradient) line_step = barRect.width() / 20 pos = barRect.left() while pos <= barRect.right(): painter.drawLine(pos, 2 * (barRect.bottom() - barRect.top()) / 3, pos, barRect.bottom()) pos += line_step self.setMinimumHeight(self._maxLabelHeight + self._barThickness + self._labelMargin) for pos, label in self.labels.items(): # Figure coordinate position. 1=height-margin for vertical, or width-margin for horizontal if self._orientation == 'Vertical': lpos = -1 * ((self.height() - (2 * self.margin)) * pos) painter.drawText(self._barThickness + self._labelMargin, (.5 * self._maxLabelHeight) + lpos, label) elif self._orientation == 'Horizontal': text_rect = painter.boundingRect(QRectF(0, 0, 0, 0), int(Qt.AlignLeft), str(label)) lpos = ((self.width() - (2 * self.margin)) * pos ) # Center position lleft = lpos - text_rect.width() / 2 painter.drawText(lleft + self.margin, self.height() - 1, label)
def RDPBitmapToQtImage(width: int, height: int, bitsPerPixel: int, isCompressed: bool, data: bytes): """ Bitmap transformation to Qt object :param width: width of bitmap :param height: height of bitmap :param bitsPerPixel: number of bit per pixel :param isCompressed: use RLE compression :param data: bitmap data """ image = None if bitsPerPixel == 15: if isCompressed: buf = bytearray(width * height * 2) rle.bitmap_decompress(buf, width, height, data, 2) image = QImage(buf, width, height, QImage.Format_RGB555) else: image = QImage(data, width, height, QImage.Format_RGB555).transformed( QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)) elif bitsPerPixel == 16: if isCompressed: buf = bytearray(width * height * 2) rle.bitmap_decompress(buf, width, height, data, 2) image = QImage(buf, width, height, QImage.Format_RGB16) else: image = QImage(data, width, height, QImage.Format_RGB16).transformed( QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)) elif bitsPerPixel == 24: if isCompressed: buf = bytearray(width * height * 3) rle.bitmap_decompress(buf, width, height, data, 3) # This is a ugly patch because there is a bug in the 24bpp decompression in rle.c # where the red and the blue colors are inverted. Fixing this in python causes a performance # issue, but at least it shows the good colors. buf2 = BytesIO(buf) while buf2.tell() < len(buf2.getvalue()): pixel = buf2.read(3) buf[buf2.tell() - 3] = pixel[2] buf[buf2.tell() - 1] = pixel[0] image = QImage(buf, width, height, QImage.Format_RGB888) else: image = QImage(data, width, height, QImage.Format_RGB888).transformed( QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)) elif bitsPerPixel == 32: if isCompressed: buf = bytearray(width * height * 4) rle.bitmap_decompress(buf, width, height, data, 4) image = QImage(buf, width, height, QImage.Format_RGB32) else: image = QImage(data, width, height, QImage.Format_RGB32).transformed( QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)) elif bitsPerPixel == 8: if isCompressed: buf = bytearray(width * height * 1) rle.bitmap_decompress(buf, width, height, data, 1) buf2 = convert8bppTo16bpp(buf) image = QImage(buf2, width, height, QImage.Format_RGB16) else: buf2 = convert8bppTo16bpp(data) image = QImage(buf2, width, height, QImage.Format_RGB16).transformed( QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)) else: log.error("Receive image in bad format") image = QImage(width, height, QImage.Format_RGB32) return image
def show_label_img(self, do_roate=False, do_roate_img=False, do_roate_mask=False, do_clear=False): if not self.all_img_file: return img_path = self.all_img_file[self.all_img_file_index] img = QPixmap(str(img_path)) img_mask_path = img_path.parent.joinpath(f'mask/{img_path.stem}.bmp') img_mask_path.parent.mkdir(parents=True, exist_ok=True) if img_mask_path.is_dir(): QMessageBox.warning( self, '<致命错误>', f'标注文件<{img_mask_path}>是一个目录, 请把它拷贝到别的地方, 然后重新打开标注工具!!!', QMessageBox.Ok) sys.exit(-1) if img_mask_path.exists(): img_mask = QPixmap(str(img_mask_path)) if img_mask.size() != self.mask_img_size: os.remove(str(img_mask_path)) if not img_mask_path.exists() or do_clear: img_mask = QPixmap(self.mask_img_size) img_mask.fill(QColor(0, 0, 0)) img_mask.save(str(img_mask_path)) if do_roate: rm = QMatrix() rm.rotate(90) img = img.transformed(rm) img.save(str(img_path)) img_mask = img_mask.transformed(rm) img_mask.save(str(img_mask_path)) if do_roate_img: rm = QMatrix() rm.rotate(90) img = img.transformed(rm) img.save(str(img_path)) if do_roate_mask: rm = QMatrix() rm.rotate(90) img_mask = img_mask.transformed(rm) img_mask.save(str(img_mask_path)) self.label_img.update_label_img(img, img_mask, str(img_mask_path))