Beispiel #1
0
    def __init__(self, parent):
        super().__init__(parent)

        self.main_window = parent

        self.img_uncheck = os.path.join(abspath, "res/Uncheck_HD.png")
        self.img_check = os.path.join(abspath, "res/Check_HD.png")

        self.box_width = 20
        self.box_height = 20
        self.default_fontsize = 14

        self.default_x = 520
        self.default_y = 145

        self.text = " " + "Use Auto Replay"
        self.setText(self.text)
        self.curfont = self.font()

        self.blur_effect = QGraphicsBlurEffect()
        self.blur_effect.setBlurRadius(0)
        self.setGraphicsEffect(self.blur_effect)

        self.default_width = self.box_width * 1.1 + self.textwidth()
        self.default_height = self.box_height * 1.1

        self.setCheckState(QtCore.Qt.Unchecked)

        super().stateChanged.connect(self.stateChanged)
Beispiel #2
0
    def load_mainWidgets(self, progressbar_x, progressbar_y, progressbar_width,
                         start_width, start_height, clickable, hover):
        blur_effect0 = QGraphicsBlurEffect()
        self.progressBar.setParent(None)
        self.start.setParent(None)

        self.progressBar = progress_bar(progressbar_x, progressbar_y,
                                        self.width() - 20, 32,
                                        "progressbar.png", "progressbar.png",
                                        "", self)
        self.progressBar.show()
        if hover:
            self.start = Label(progressbar_x + progressbar_width - start_width,
                               self.height() - 40 - start_height, start_width,
                               start_height, "start.png", "start_hover.png",
                               "start", True, False, self)
        else:
            self.start = Label(progressbar_x + progressbar_width - start_width,
                               self.height() - 40 - start_height, start_width,
                               start_height, "start.png", "start.png", "start",
                               True, False, self)
        self.start.show()
        if not clickable:
            self.start.setGraphicsEffect(blur_effect0)
            blur_effect0 = QGraphicsBlurEffect()
            self.progressBar.setGraphicsEffect(blur_effect0)
 def __init__(self):
     super(painter, self).__init__()
     self.setFixedSize(self.width, self.height + self.textLineHeight)
     self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
     self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
     self.scene = QGraphicsScene()
     self.setScene(self.scene)
     if len(sys.argv) >= 2:
         if sys.argv[2] == "MLX90641":
             self.blurRaduis = 25
             self.ChipType = "MLX90641"
         elif sys.argv[2] == "MLX90640":
             self.blurRaduis = 50
             self.ChipType = "MLX90640"
     # center het text item
     self.centerTextItem = QGraphicsTextItem()
     self.centerTextItem.setPos(self.width / 2 - self.fontSize, 0)
     self.centerTextItem.setZValue(self.baseZValue + 1)
     self.scene.addItem(self.centerTextItem)
     # center anchor item
     centerX = self.width / 2
     centerY = self.height / 2
     self.ellipseItem = QGraphicsEllipseItem(0, 0, self.ellipseRadius * 2,
                                             self.ellipseRadius * 2)
     self.horLineItem = QGraphicsLineItem(0, 0, self.anchorLineSize, 0)
     self.verLineItem = QGraphicsLineItem(0, 0, 0, self.anchorLineSize)
     self.ellipseItem.setPos(centerX - self.ellipseRadius,
                             centerY - self.ellipseRadius)
     self.horLineItem.setPos(centerX - self.anchorLineSize / 2, centerY)
     self.verLineItem.setPos(centerX, centerY - self.anchorLineSize / 2)
     self.ellipseItem.setPen(QColor(Qt.white))
     self.horLineItem.setPen(QColor(Qt.white))
     self.verLineItem.setPen(QColor(Qt.white))
     self.ellipseItem.setZValue(self.baseZValue + 1)
     self.horLineItem.setZValue(self.baseZValue + 1)
     self.verLineItem.setZValue(self.baseZValue + 1)
     self.scene.addItem(self.ellipseItem)
     self.scene.addItem(self.horLineItem)
     self.scene.addItem(self.verLineItem)
     # camera item
     self.cameraBuffer = QPixmap(self.width,
                                 self.height + self.textLineHeight)
     self.cameraItem = QGraphicsPixmapItem()
     if self.useBlur:
         self.gusBlurEffect = QGraphicsBlurEffect()
         self.gusBlurEffect.setBlurRadius(self.blurRaduis)
         self.cameraItem.setGraphicsEffect(self.gusBlurEffect)
     self.cameraItem.setPos(0, 0)
     self.cameraItem.setZValue(self.baseZValue)
     self.scene.addItem(self.cameraItem)
     # het text item
     self.hetTextBuffer = QPixmap(self.width, self.textLineHeight)
     self.hetTextItem = QGraphicsPixmapItem()
     self.hetTextItem.setPos(0, self.height)
     self.hetTextItem.setZValue(self.baseZValue)
     self.scene.addItem(self.hetTextItem)
Beispiel #4
0
		def blur_objects(blur=True):
			ui_objects = [QLabel, QPushButton, QLineEdit, QCheckBox, QMenu, QMenuBar]

			for item in ui_objects:
				for child in self.findChildren(item):
					if child is not self.ui.progress_label:
						if blur:
							child.setGraphicsEffect(QGraphicsBlurEffect())
						else:
							child.setGraphicsEffect(QGraphicsBlurEffect().setBlurRadius(0))

			QCoreApplication.processEvents(QEventLoop.AllEvents)
Beispiel #5
0
    def __init__(self, nums, parent):
        super().__init__()
        self.nums = nums
        self.parent = parent

        self.tile_events = events.TileInterfaceEvent()
        # Init main widget for master-controlling NumPad
        self.widget = QWidget()
        self.widget.setObjectName('NumPad')
        # Create blur effect for widgets
        self.blur_top_lbl = QGraphicsBlurEffect()
        self.blur_top_lbl.setBlurRadius(0.0)

        self.blur_bottom_lbl = QGraphicsBlurEffect()
        self.blur_bottom_lbl.setBlurRadius(0.0)

        self.opacity_effect = QGraphicsOpacityEffect()
        self.opacity_effect.setOpacity(0.0)

        # Create animation classes
        self.blur_anim = QVariantAnimation()
        self.blur_anim.setEasingCurve(QEasingCurve.InOutQuad)
        self.blur_anim.valueChanged.connect(self.play_animation)

        self.opacity_anim = QPropertyAnimation(self.opacity_effect, b'opacity')
        self.opacity_anim.setEasingCurve(QEasingCurve.InOutQuad)

        elements_hbl = QVBoxLayout()

        # Top label of NumPad
        self.top_lbl = QLabel()
        self.top_lbl.setGraphicsEffect(self.blur_top_lbl)
        self.top_lbl.setText(str(nums))
        self.top_lbl.setObjectName('NumPad')
        self.top_lbl.setAlignment(Qt.AlignCenter)

        # Bottom label of NumPad
        self.bottom_lbl = QLabel()
        self.bottom_lbl.setGraphicsEffect(self.blur_bottom_lbl)
        self.bottom_lbl.setObjectName('NumPad')
        self.bottom_lbl.setAlignment(Qt.AlignCenter)

        elements_hbl.addWidget(self.top_lbl, 50)
        elements_hbl.addWidget(self.bottom_lbl, 50)

        self.widget.setLayout(elements_hbl)

        self.create_master_numpad()

        # Events and signals widget
        self.widget.enterEvent = lambda event: self.enter_event()
        self.widget.leaveEvent = lambda event: self.leave_event()
Beispiel #6
0
        def blur_objects(blur=True):
            objects = [
                QLabel, QPushButton, QLineEdit, QCheckBox, QMenu, QMenuBar
            ]

            for item in objects:
                for child in self.findChildren(item):
                    if child is not self.ui.progress_label and child is not self.gif_label:
                        if blur:
                            child.setGraphicsEffect(QGraphicsBlurEffect())
                        else:
                            child.setGraphicsEffect(
                                QGraphicsBlurEffect().setBlurRadius(0))
Beispiel #7
0
def blurPixmap(pixmap, radius):
    effect = QGraphicsBlurEffect()
    effect.setBlurRadius(radius)
    buffer = QPixmap(pixmap)
    item = QGraphicsPixmapItem(buffer)
    item.setGraphicsEffect(effect)
    output = QPixmap(pixmap.width(), pixmap.height())
    painter = QtGui.QPainter(output)
    scene = QtWidgets.QGraphicsScene()
    view = QtWidgets.QGraphicsView(scene)
    scene.addItem(item)
    scene.render(painter)
    return output
Beispiel #8
0
    def onImageLoaded(self, data):
        pixmap = QtGui.QPixmap()
        pixmap.loadFromData(data)

        pixmap = pixmap.scaledToWidth(self.width, Qt.SmoothTransformation)
        if not pixmap: return None

        self.setPixmap(pixmap)

        # creating a blur effect
        blur_effect = QGraphicsBlurEffect()
        blur_effect.setBlurRadius(1)
        self.setGraphicsEffect(blur_effect)
Beispiel #9
0
def blurPixmap(pixmap, radius):
    effect = QGraphicsBlurEffect()
    effect.setBlurRadius(radius)
    buffer = QPixmap(pixmap)
    item = QGraphicsPixmapItem(buffer)
    item.setGraphicsEffect(effect)
    output = QPixmap(pixmap.width(), pixmap.height())
    painter = QtGui.QPainter(output)
    scene = QtWidgets.QGraphicsScene()
    view = QtWidgets.QGraphicsView(scene)
    scene.addItem(item)
    scene.render(painter)
    return output
Beispiel #10
0
    def setup(self):
        width, height = getsize(self.img_drop)
        self.default_width *= width
        self.default_height *= height

        self.setGeometry(self.default_x, self.default_y, self.default_width,
                         self.default_height)
        self.setIconSize(QtCore.QSize(self.default_width, self.default_height))
        self.view().setIconSize(QtCore.QSize(
            0, 0))  # for linux machines otherwise texts got hidden
        self.setMaxVisibleItems(7)

        self.blur_effect = QGraphicsBlurEffect()
        self.blur_effect.setBlurRadius(0)
        self.setGraphicsEffect(self.blur_effect)
 def blur_effect(self):
     print('blur effect')
     sel = self.scene().selectedItems()
     for i in range(len(sel)):
         self.effect = QGraphicsBlurEffect(self)
         self.effect.setBlurRadius(5)
         sel[i].setGraphicsEffect(self.effect)
Beispiel #12
0
    def keyPressEvent(self, e):

        if e.key() == Qt.Key_Up:
            self.rotate(30)

        elif e.key() == Qt.Key_Down:
            self.rotate(-30)

        elif e.key() == Qt.Key_Right:
            self.currentSlide += 1
            if self.currentSlide >= len(self.slides):
                #Loop to beginning
                self.currentSlide = 0
            self.text.setPlainText(self.slides[self.currentSlide])
            self.adjustText()
            self.centerText()

        elif e.key() == Qt.Key_Left:
            self.currentSlide -= 1
            if self.currentSlide < 0:
                #Loop to end
                self.currentSlide = len(self.slides) - 1
            self.text.setPlainText(self.slides[self.currentSlide])
            self.adjustText()
            self.centerText()

        elif e.key() == Qt.Key_B:

            shadow = QGraphicsBlurEffect()
            shadow.setBlurRadius(self.shadowSize)
            self.text.setGraphicsEffect(shadow)

        elif e.key() == Qt.Key_S:

            shadow = QGraphicsDropShadowEffect()
            shadow.setBlurRadius(self.shadowSize)
            shadow.setOffset(self.shadowOffset)
            self.text.setGraphicsEffect(shadow)

        elif e.key() == Qt.Key_C:

            self.text.setGraphicsEffect(QGraphicsColorizeEffect())

        elif e.key() == Qt.Key_O:

            self.text.setGraphicsEffect(QGraphicsOpacityEffect())

        elif e.key() == Qt.Key_N:
                self.text.setGraphicsEffect(None)
Beispiel #13
0
 def load_logo(self, clickable):
     logo_w, logo_h = get_scale(1280, 668, 700, 500, self.width(),
                                self.height())
     self.logo = Label(-50, 50, logo_w, logo_h, "osr2mp4_logo.png",
                       "osr2mp4_logo.png", "", False, False, self)
     if not clickable:
         blur_effect0 = QGraphicsBlurEffect()
         self.logo.setGraphicsEffect(blur_effect0)
     self.logo.show()
     self.logo.lower()
     self.extra_widgets.append(self.logo)
Beispiel #14
0
 def movePlayer(self, player: int):
     self.ui.wigdetPlayer_1.show()
     self.ui.wigdetPlayer_2.show()
     if player == 1:
         isFirst = False
         if self.gameMode == GameMode.PVP:
             effectWidget_1 = QGraphicsBlurEffect()
             effectWidget_2 = None
     elif player == 2:
         isFirst = True
         if self.gameMode == GameMode.PVP:
             effectWidget_1 = None
             effectWidget_2 = QGraphicsBlurEffect()
         if self.gameMode == GameMode.PVE:
             QTimer.singleShot(500, self.ai.makeShot)
             isFirst = False
     else:
         raise Exception(f'Player {player} does not supported')
     self.setWidgetsOnOff(isFirst=isFirst)
     if self.gameMode == GameMode.PVP:
         self.ui.wigdetPlayer_1.setGraphicsEffect(effectWidget_1)
         self.ui.wigdetPlayer_2.setGraphicsEffect(effectWidget_2)
Beispiel #15
0
    def __init__(self):
        super(MainWidget, self).__init__()

        self._blur = QGraphicsBlurEffect()
        self._blur.setBlurRadius(0)

        self.image = ImageView()
        self.image.setGraphicsEffect(self._blur)

        self.video = QVideoWidget()

        self.label = QLabel()
        self.label.setMaximumHeight(25)
        self.label.setStyleSheet('color: rgb(200, 200, 200);')

        font = QFont()
        font.setPixelSize(20)
        font.setWeight(QFont.Bold)
        self.label.setFont(font)

        self.setLayout(QVBoxLayout())
        self.layout().addWidget(self.image)
        self.layout().addWidget(self.video)
        self.layout().addWidget(self.label)

        self.mplayer = QMediaPlayer(None, QMediaPlayer.VideoSurface)
        self.mplayer.setVideoOutput(self.video)

        self.mplayer.error.connect(
            lambda: print("Video:", self.mplayer.errorString()))
        self.mplayer.mediaStatusChanged.connect(self.state_changed)

        self.overlay = QLabel(self)
        self.overlay.setFrameStyle(Qt.FramelessWindowHint)
        self.overlay.setStyleSheet(
            'background-color: rgba(0,0,0,0.7); color: rgba(200,200,200,1);')
        self.overlay.setFont(font)
        self.overlay.setVisible(False)
        self.overlay.setWordWrap(True)
Beispiel #16
0
    def setup(self):

        self.img_idle = os.path.join(abspath, self.img_idle)
        self.img_hover = os.path.join(abspath, self.img_hover)
        self.img_click = os.path.join(abspath, self.img_click)

        if self.img_shadow is not None:
            self.setup_shadow()
        else:
            self.shadow.setParent(None)
            self.shadow = None

        self.setIcon(QtGui.QIcon(self.img_idle))
        self.setStyleSheet("""
		QPushButton:flat
		{
			border: none;
			background: none;
			outline: none;
		}""")

        imgsize = getsize(self.img_idle)

        self.setMaximumWidth(imgsize[0])
        self.setMaximumHeight(imgsize[1])

        width = self.default_size * imgsize[0] / 10
        height = self.default_size * imgsize[1] / 10

        self.default_width, self.default_height = width, height

        self.setIconSize(QtCore.QSize(width, height))
        self.setGeometry(self.default_x, self.default_y, width, height)
        self.setFlat(True)
        self.blur_effect = QGraphicsBlurEffect()
        self.blur_effect.setBlurRadius(0)
        self.setGraphicsEffect(self.blur_effect)
  def adaptEncoding(self, codedValue):
    '''
    Adapt coded value to a QGraphicEffect value
    '''
    adaptedValue = None
    if codedValue == 1:
      adaptedValue = QGraphicsBlurEffect()
    elif codedValue == 2:
      adaptedValue = QGraphicsDropShadowEffect()
    #print "Adapted graphic effect:", adaptedValue
    assert adaptedValue is None or isinstance(adaptedValue, QGraphicsEffect)
    return adaptedValue
    


    
Beispiel #18
0
    def __init__(self, path_to_image):
        super().__init__()
        self.image = QPixmap(path_to_image)
        self.setMinimumSize(800, 600)
        self.setGeometry(15, 15, 800, 600)
        self.background = QLabel(self)
        self.background.move(0, 0)
        self.back_pixmap = QPixmap(path_to_image)
        self.back_pixmap = self.back_pixmap.scaled(800, 600)
        self.background.setPixmap(self.back_pixmap)
        self.background.setAlignment(Qt.AlignCenter)
        blur = QGraphicsBlurEffect()
        self.background.setGraphicsEffect(blur)

        self.background.setAlignment(Qt.AlignCenter)

        self.label = QLabel(self)
        self.image = self.image.scaled(700, 500)
        self.label.setAlignment(Qt.AlignCenter)
        self.label.setPixmap(self.image)
        self.label.resize(700, 500)
Beispiel #19
0
class PathImage(Button):
    def __init__(self, parent):
        super(PathImage, self).__init__(parent)
        self.img_idle = self.img_hover = self.img_click = None
        self.text = QLabel(parent)
        self.text.setText("")
        self.default_fontsize = 150
        self.offset = 225

    def setup(self):
        self.img_idle = self.img_hover = self.img_click = self.img
        super().setup()
        self.textblur_effect = QGraphicsBlurEffect()
        self.textblur_effect.setBlurRadius(0)
        self.text.setGraphicsEffect(self.textblur_effect)

    def blur_me(self, blur):
        super().blur_me(blur)
        if blur:
            self.textblur_effect.setBlurRadius(10)
        else:
            self.textblur_effect.setBlurRadius(0)

    def setText(self, text):
        # set stylesheet doesnt work for self.text qtoooltip so who cares./. night
        self.text.setToolTip(text)
        self.setToolTip(text)
        # text = text[:57]  # commented cause u ask me to remove. i dont like following ur oders
        self.text.setText(text)
        self.main_window.settingspage.updatevalue()

    def changesize(self):
        super().changesize()

        scale = self.height() / self.main_window.default_height

        x = self.x() + scale * self.offset
        y = self.y() + scale * self.offset

        fontsize = scale * self.default_fontsize
        self.text.setStyleSheet(
            "QLabel{font-size: %ipt; font-weight: bold; color: white; background-color: transparent;}QToolTip { background-color:white;color: black; }"
            % (fontsize))
        self.text.setGeometry(x, y, self.width() * 0.95, self.height() * 0.5)
Beispiel #20
0
 def load_buttons(self, button_width, button_y, button_height, clickable,
                  hover):
     file_typeCounter = 0
     for x in range(len(self.image_listHover)):
         if hover:
             button = Label(self.width() - button_width, button_y,
                            button_width, button_height,
                            self.image_listIdle[x], self.image_listHover[x],
                            self.file_type[file_typeCounter], clickable,
                            False, self)
         else:
             button = Label(self.width() - button_width, button_y,
                            button_width, button_height,
                            self.image_listIdle[x], self.image_listIdle[x],
                            self.file_type[file_typeCounter], clickable,
                            False, self)
         #button_width-=30
         button_y += int(self.width() / 16)
         file_typeCounter += 1
         if not clickable:
             blur_effect = QGraphicsBlurEffect()
             button.setGraphicsEffect(blur_effect)
         button.show()
         self.main_buttons.append(button)
Beispiel #21
0
class PathBox(Button):
    def __init__(self, parent):
        super(PathBox, self).__init__(parent)
        self.img_idle = self.img_hover = self.img_click = None
        self.text = QLabel(parent)
        self.text.setText("")
        self.default_fontsize = 150
        self.offset = 225

    def setup(self):
        self.img_idle = self.img_hover = self.img_click = self.img
        super().setup()
        self.textblur_effect = QGraphicsBlurEffect()
        self.textblur_effect.setBlurRadius(0)
        self.text.setGraphicsEffect(self.textblur_effect)

    def blur_me(self, blur):
        super().blur_me(blur)
        if blur:
            self.textblur_effect.setBlurRadius(10)
        else:
            self.textblur_effect.setBlurRadius(0)

    def setText(self, text):
        self.text.setToolTip(text)
        self.setToolTip(text)
        self.text.setText(text)
        self.main_window.settingspage.updatevalue()

    def changesize(self):
        super().changesize()

        scale = self.height() / self.main_window.default_height

        x = self.x() + scale * self.offset
        y = self.y() + scale * self.offset

        fontsize = scale * self.default_fontsize
        self.text.setStyleSheet(
            "QLabel{font-size: %ipt; font-weight: bold; color: white; background-color: transparent;}QToolTip { background-color:white;color: black; }"
            % (fontsize))
        self.text.setGeometry(x, y, self.width() * 0.95, self.height() * 0.5)
Beispiel #22
0
class MainWidget(QWidget):
    def __init__(self):
        super(MainWidget, self).__init__()

        self._blur = QGraphicsBlurEffect()
        self._blur.setBlurRadius(0)

        self.image = ImageView()
        self.image.setGraphicsEffect(self._blur)

        self.video = QVideoWidget()

        self.label = QLabel()
        self.label.setMaximumHeight(25)
        self.label.setStyleSheet('color: rgb(200, 200, 200);')

        font = QFont()
        font.setPixelSize(20)
        font.setWeight(QFont.Bold)
        self.label.setFont(font)

        self.setLayout(QVBoxLayout())
        self.layout().addWidget(self.image)
        self.layout().addWidget(self.video)
        self.layout().addWidget(self.label)

        self.mplayer = QMediaPlayer(None, QMediaPlayer.VideoSurface)
        self.mplayer.setVideoOutput(self.video)

        self.mplayer.error.connect(
            lambda: print("Video:", self.mplayer.errorString()))
        self.mplayer.mediaStatusChanged.connect(self.state_changed)

        self.overlay = QLabel(self)
        self.overlay.setFrameStyle(Qt.FramelessWindowHint)
        self.overlay.setStyleSheet(
            'background-color: rgba(0,0,0,0.7); color: rgba(200,200,200,1);')
        self.overlay.setFont(font)
        self.overlay.setVisible(False)
        self.overlay.setWordWrap(True)

    def resize(self):
        self.overlay.setGeometry(0, 3 * self.height() // 4 - 50, self.width(),
                                 100)

    def resizeEvent(self, event):
        super().resizeEvent(event)
        self.resize()

    def state_changed(self, state):
        if state == QMediaPlayer.EndOfMedia:
            self.mplayer.setPosition(0)
            self.mplayer.play()

    @property
    def blur(self):
        return self._blur.blurRadius()

    @blur.setter
    def blur(self, value):
        self._blur.setBlurRadius(value)

    def load(self, pic, *args, **kwargs):
        if isinstance(pic, str):
            still = path.splitext(pic)[1].lower()[1:] not in ('webm', 'mp4')
        else:
            still = pic.is_still if pic else True

        if still:
            self.image.load(pic, *args, **kwargs)
            self.video.hide()
            self.image.show()
            self.mplayer.stop()
        else:
            url = pic if isinstance(pic, str) else pic.filename
            self.mplayer.setMedia(QMediaContent(QUrl.fromLocalFile(url)))
            self.mplayer.setMuted(True)
            self.mplayer.play()
            self.image.hide()
            self.video.show()

        self.overlay.setVisible(False)

    def message(self, msg):
        self.label.setText('<div align="center">{}</div>'.format(msg))

    def flash(self, msg):
        self.overlay.setText('<div align="center">{}</div>'.format(msg))
        self.overlay.setVisible(True)

    def halt(self):
        self.mplayer.stop()
Beispiel #23
0
class Button(QPushButton):
    def __init__(self, parent):
        self.main_window = parent

        self.shadow = QPushButton(self.main_window)
        super(Button, self).__init__(parent)
        self.blur_effect = None
        self.clickable = True
        self.default_width, self.default_height = None, None
        self.default_shadowwidth, self.default_shadowheight = None, None
        self.img_shadow = None

    def setup(self):

        self.img_idle = os.path.join(abspath, self.img_idle)
        self.img_hover = os.path.join(abspath, self.img_hover)
        self.img_click = os.path.join(abspath, self.img_click)

        if self.img_shadow is not None:
            self.setup_shadow()
        else:
            self.shadow.setParent(None)
            self.shadow = None

        self.setIcon(QtGui.QIcon(self.img_idle))
        self.setStyleSheet("""
		QPushButton:flat
		{
			border: none;
			background: none;
			outline: none;
		}""")

        imgsize = getsize(self.img_idle)

        self.setMaximumWidth(imgsize[0])
        self.setMaximumHeight(imgsize[1])

        width = self.default_size * imgsize[0] / 10
        height = self.default_size * imgsize[1] / 10

        self.default_width, self.default_height = width, height

        self.setIconSize(QtCore.QSize(width, height))
        self.setGeometry(self.default_x, self.default_y, width, height)
        self.setFlat(True)
        self.blur_effect = QGraphicsBlurEffect()
        self.blur_effect.setBlurRadius(0)
        self.setGraphicsEffect(self.blur_effect)

    def setup_shadow(self):

        self.img_shadow = os.path.join(abspath, self.img_shadow)

        imgsize = getsize(self.img_shadow)

        width = self.default_size * imgsize[0] / 10 * 1.01
        height = self.default_size * imgsize[1] / 10 * 1.01

        self.default_shadowwidth, self.default_shadowheight = width, height
        self.shadow.setIcon(QtGui.QIcon(self.img_shadow))
        self.shadow.setStyleSheet("""
		QPushButton:flat
		{
			border: none;
			background: none;
                        outline: none;
		}""")
        self.shadow.setIconSize(QtCore.QSize(width, height))
        x, y = get_shadowpos(self, width, height)
        self.shadow.setGeometry(x, y, width, height)
        self.shadow.setFlat(True)

    def blur_me(self, blur):
        if blur:
            self.blur_effect.setBlurRadius(25)
        else:
            self.blur_effect.setBlurRadius(0)

    def mousePressEvent(self, QEvent):
        if self.clickable:
            self.setIcon(QtGui.QIcon(self.img_click))

    def mouseReleaseEvent(self, QEvent):
        if self.clickable:
            self.mouseclicked()
            self.setIcon(QtGui.QIcon(self.img_idle))

    def enterEvent(self, QEvent):
        if self.clickable:
            self.setIcon(QtGui.QIcon(self.img_hover))

    def leaveEvent(self, QEvent):
        self.setIcon(QtGui.QIcon(self.img_idle))

    def mouseclicked(self):
        pass

    def setParent(self, parent):
        super().setParent(parent)
        if self.shadow is not None:
            self.shadow.setParent(parent)

    def changesize(self):
        changesize(self)

        if self.shadow is not None:
            scale = self.main_window.height() / self.main_window.default_height
            width = self.default_shadowwidth * scale
            height = self.default_shadowheight * scale
            self.shadow.setIconSize(QtCore.QSize(width, height))
            x, y = get_shadowpos(self, width, height)
            self.shadow.setGeometry(x, y, width, height)
Beispiel #24
0
    def __init__(self, dataThread):
        super(painter, self).__init__()
        self.dataThread = dataThread
        self.setFixedSize(self.width + 200, self.height + self.textLineHeight)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.scene = QGraphicsScene()
        self.setScene(self.scene)
        # center het text item
        self.centerTextItem = QGraphicsTextItem()
        self.centerTextItem.setPos((self.width + 200) / 2 - self.fontSize, 0)
        self.centerTextItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.centerTextItem)
        # version text item
        self.versionTextItem = QGraphicsTextItem()
        self.versionTextItem.setPos(self.width * 0.8 - self.fontSize,
                                    self.height * 0.8 - self.fontSize)
        self.versionTextItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.versionTextItem)
        self.userCom = None

        # center anchor item
        centerX = self.width / 2
        centerY = self.height / 2
        self.ellipseItem = QGraphicsEllipseItem(0, 0, self.ellipseRadius * 2,
                                                self.ellipseRadius * 2)
        self.horLineItem = QGraphicsLineItem(0, 0, self.anchorLineSize, 0)
        self.verLineItem = QGraphicsLineItem(0, 0, 0, self.anchorLineSize)
        self.ellipseItem.setPos(centerX - self.ellipseRadius,
                                centerY - self.ellipseRadius)
        self.horLineItem.setPos(centerX - self.anchorLineSize / 2, centerY)
        self.verLineItem.setPos(centerX, centerY - self.anchorLineSize / 2)
        self.ellipseItem.setPen(QColor(Qt.white))
        self.horLineItem.setPen(QColor(Qt.white))
        self.verLineItem.setPen(QColor(Qt.white))
        self.ellipseItem.setZValue(self.baseZValue + 1)
        self.horLineItem.setZValue(self.baseZValue + 1)
        self.verLineItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.ellipseItem)
        self.scene.addItem(self.horLineItem)
        self.scene.addItem(self.verLineItem)
        # camera item
        self.cameraBuffer = QPixmap(self.width,
                                    self.height + self.textLineHeight)
        self.cameraItem = QGraphicsPixmapItem()
        if useBlur:
            self.gusBlurEffect = QGraphicsBlurEffect()
            self.gusBlurEffect.setBlurRadius(self.blurRaduis)
            self.cameraItem.setGraphicsEffect(self.gusBlurEffect)
        self.cameraItem.setPos(100, 0)
        self.cameraItem.setZValue(self.baseZValue)
        self.scene.addItem(self.cameraItem)
        # het text item
        self.hetTextBuffer = QPixmap(self.width + 200, self.textLineHeight)
        self.hetTextItem = QGraphicsPixmapItem()
        self.hetTextItem.setPos(0, self.height)
        self.hetTextItem.setZValue(self.baseZValue)
        self.scene.addItem(self.hetTextItem)
        # button item
        self.ctrlOpenButton = QPushButton('Open', self)
        self.ctrlOpenButton.clicked.connect(self.ctrlOpen)
        self.ctrlOpenButton.setGeometry(10, 30, 100, 40)

        self.EvaluateButton = QPushButton('None', self)
        self.EvaluateButton.clicked.connect(self.evaluate)
        self.EvaluateButton.setGeometry(10, 80, 100, 40)

        self.getOnePicButton = QPushButton('Get a frame', self)
        self.getOnePicButton.clicked.connect(self.ctrlSendone)
        self.getOnePicButton.setGeometry(10, 130, 100, 40)
        self.getOnePicButton.setEnabled(False)

        self.modeManualButton = QPushButton('Auto', self)
        self.modeManualButton.clicked.connect(self.modeManual)
        self.modeManualButton.setGeometry(10, 180, 100, 40)

        self.modeObjButton = QPushButton('Body', self)
        self.modeObjButton.clicked.connect(self.objBody)
        self.modeObjButton.setGeometry(10, 230, 100, 40)

        self.modeFpsButton = QPushButton('4FPS', self)
        self.modeFpsButton.clicked.connect(self.rate)
        self.modeFpsButton.setGeometry(10, 280, 100, 40)

        self.modeAutoButton = QPushButton('Get offset', self)
        self.modeAutoButton.clicked.connect(self.commonOffset)
        self.modeAutoButton.setGeometry(570, 30, 100, 40)

        self.modeAutoButton = QPushButton('Get version', self)
        self.modeAutoButton.clicked.connect(self.sysVer)
        self.modeAutoButton.setGeometry(570, 80, 100, 40)

        self.evaluate = 1
        self.evaluateButton = QPushButton('Evaluate', self)
        self.evaluateButton.clicked.connect(self.setEvaluate)
        self.evaluateButton.setGeometry(570, 120, 100, 40)

        self.serial_l = QLabel(self)

        self.serial_l.move(580, 250)
        self.serial_l.resize(60, 30)
        self.serial_l.setStyleSheet(
            "QLabel{color:rgb(0,0,0,255);background-color: rgb(255,255,255);font-size:16px;font-weight:normal;font-family:Arial;}"
        )
        self.serial_l.setText("Serial:")

        self.serialList = SerialComboBox(self)
        self.serialList.setCurrentIndex(0)
        self.serialList.setStyleSheet(
            "border-width: 1px;border-style: solid;border-color: rgb(255, 170, 0);"
        )
        self.serialList.currentIndexChanged.connect(self.serialChange)
        # self.evaluateButton.setGeometry(570,140,100,40)
        self.serialList.move(580, 280)
        self.serialList.resize(120, 30)
        self.serialList.addItem("Please select serial device")
Beispiel #25
0
class painter(QGraphicsView):
    pixelSize = int(15 / narrowRatio)
    width = int(480 / narrowRatio)
    height = int(360 / narrowRatio)
    fontSize = int(15 / narrowRatio)
    anchorLineSize = int(100 / narrowRatio)
    ellipseRadius = int(8 / narrowRatio)
    textInterval = int(90 / narrowRatio)
    col = width / pixelSize
    line = height / pixelSize
    centerIndex = int(round(((line / 2 - 1) * col) + col / 2))
    frameCount = 0
    failedCount = 0
    baseZValue = 0
    mode = 1
    body = 1
    open_status = 0
    textLineHeight = fontSize + 10
    blurRaduis = 50  # Smoother improvement

    def __init__(self, dataThread):
        super(painter, self).__init__()
        self.dataThread = dataThread
        self.setFixedSize(self.width + 200, self.height + self.textLineHeight)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.scene = QGraphicsScene()
        self.setScene(self.scene)
        # center het text item
        self.centerTextItem = QGraphicsTextItem()
        self.centerTextItem.setPos((self.width + 200) / 2 - self.fontSize, 0)
        self.centerTextItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.centerTextItem)
        # version text item
        self.versionTextItem = QGraphicsTextItem()
        self.versionTextItem.setPos(self.width * 0.8 - self.fontSize,
                                    self.height * 0.8 - self.fontSize)
        self.versionTextItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.versionTextItem)
        self.userCom = None

        # center anchor item
        centerX = self.width / 2
        centerY = self.height / 2
        self.ellipseItem = QGraphicsEllipseItem(0, 0, self.ellipseRadius * 2,
                                                self.ellipseRadius * 2)
        self.horLineItem = QGraphicsLineItem(0, 0, self.anchorLineSize, 0)
        self.verLineItem = QGraphicsLineItem(0, 0, 0, self.anchorLineSize)
        self.ellipseItem.setPos(centerX - self.ellipseRadius,
                                centerY - self.ellipseRadius)
        self.horLineItem.setPos(centerX - self.anchorLineSize / 2, centerY)
        self.verLineItem.setPos(centerX, centerY - self.anchorLineSize / 2)
        self.ellipseItem.setPen(QColor(Qt.white))
        self.horLineItem.setPen(QColor(Qt.white))
        self.verLineItem.setPen(QColor(Qt.white))
        self.ellipseItem.setZValue(self.baseZValue + 1)
        self.horLineItem.setZValue(self.baseZValue + 1)
        self.verLineItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.ellipseItem)
        self.scene.addItem(self.horLineItem)
        self.scene.addItem(self.verLineItem)
        # camera item
        self.cameraBuffer = QPixmap(self.width,
                                    self.height + self.textLineHeight)
        self.cameraItem = QGraphicsPixmapItem()
        if useBlur:
            self.gusBlurEffect = QGraphicsBlurEffect()
            self.gusBlurEffect.setBlurRadius(self.blurRaduis)
            self.cameraItem.setGraphicsEffect(self.gusBlurEffect)
        self.cameraItem.setPos(100, 0)
        self.cameraItem.setZValue(self.baseZValue)
        self.scene.addItem(self.cameraItem)
        # het text item
        self.hetTextBuffer = QPixmap(self.width + 200, self.textLineHeight)
        self.hetTextItem = QGraphicsPixmapItem()
        self.hetTextItem.setPos(0, self.height)
        self.hetTextItem.setZValue(self.baseZValue)
        self.scene.addItem(self.hetTextItem)
        # button item
        self.ctrlOpenButton = QPushButton('Open', self)
        self.ctrlOpenButton.clicked.connect(self.ctrlOpen)
        self.ctrlOpenButton.setGeometry(10, 30, 100, 40)

        self.EvaluateButton = QPushButton('None', self)
        self.EvaluateButton.clicked.connect(self.evaluate)
        self.EvaluateButton.setGeometry(10, 80, 100, 40)

        self.getOnePicButton = QPushButton('Get a frame', self)
        self.getOnePicButton.clicked.connect(self.ctrlSendone)
        self.getOnePicButton.setGeometry(10, 130, 100, 40)
        self.getOnePicButton.setEnabled(False)

        self.modeManualButton = QPushButton('Auto', self)
        self.modeManualButton.clicked.connect(self.modeManual)
        self.modeManualButton.setGeometry(10, 180, 100, 40)

        self.modeObjButton = QPushButton('Body', self)
        self.modeObjButton.clicked.connect(self.objBody)
        self.modeObjButton.setGeometry(10, 230, 100, 40)

        self.modeFpsButton = QPushButton('4FPS', self)
        self.modeFpsButton.clicked.connect(self.rate)
        self.modeFpsButton.setGeometry(10, 280, 100, 40)

        self.modeAutoButton = QPushButton('Get offset', self)
        self.modeAutoButton.clicked.connect(self.commonOffset)
        self.modeAutoButton.setGeometry(570, 30, 100, 40)

        self.modeAutoButton = QPushButton('Get version', self)
        self.modeAutoButton.clicked.connect(self.sysVer)
        self.modeAutoButton.setGeometry(570, 80, 100, 40)

        self.evaluate = 1
        self.evaluateButton = QPushButton('Evaluate', self)
        self.evaluateButton.clicked.connect(self.setEvaluate)
        self.evaluateButton.setGeometry(570, 120, 100, 40)

        self.serial_l = QLabel(self)

        self.serial_l.move(580, 250)
        self.serial_l.resize(60, 30)
        self.serial_l.setStyleSheet(
            "QLabel{color:rgb(0,0,0,255);background-color: rgb(255,255,255);font-size:16px;font-weight:normal;font-family:Arial;}"
        )
        self.serial_l.setText("Serial:")

        self.serialList = SerialComboBox(self)
        self.serialList.setCurrentIndex(0)
        self.serialList.setStyleSheet(
            "border-width: 1px;border-style: solid;border-color: rgb(255, 170, 0);"
        )
        self.serialList.currentIndexChanged.connect(self.serialChange)
        # self.evaluateButton.setGeometry(570,140,100,40)
        self.serialList.move(580, 280)
        self.serialList.resize(120, 30)
        self.serialList.addItem("Please select serial device")

    def checkSerial(self):
        reply = QMessageBox.information(self, 'No serial',
                                        "Please select serial device",
                                        QMessageBox.Yes)

        # portlist = SerialComboBox().get_port_list(self)
        # self.userCom = None
        # if portlist is not None:
        #     for port in portlist:
        #         print("port ",port)
        #         self.userCom = port
        #     if self.userCom is not None :
        #         self.dataThread.openSerial(self.userCom)
        #     else:
        #         reply = QMessageBox.information(self, '没有设置串口', "请选择串口" , QMessageBox.Yes)

    def serialChange(self, i):
        print("serialChange", i, self.serialList.currentText())
        if i > 0:
            self.userCom = self.serialList.currentText()
            self.dataThread.initSerialPort(self.userCom)

    def ctrlOpen(self):
        print("self.userCom", self.userCom)
        if self.userCom is None:
            self.checkSerial()
            return

        if self.open_status == 1:
            print('start send C command 0')
            self.open_status = 0

            self.ctrlOpenButton.setText("Open")
            self.dataThread.sendData('CMDC\0')
        else:
            print('start send C command 1')
            self.open_status = 1

            self.ctrlOpenButton.setText("Close")
            self.dataThread.sendData('CMDC\1')

    def evaluate(self):
        if self.userCom is None:
            self.checkSerial()
            return
        global evaluate_mode
        if evaluate_mode == "operate":
            print('start send E command 0')
            evaluate_mode = "evaluate"
            self.EvaluateButton.setText("Evaluate")
            self.dataThread.sendData('CMDE\1')
        else:
            print('start send E command 1')
            evaluate_mode = "operate"
            self.EvaluateButton.setText("Operate")
            self.dataThread.sendData('CMDE\0')

    def ctrlSendone(self):
        if self.userCom is None:
            self.checkSerial()
            return
        print('send a frame')
        self.dataThread.sendData('CMDC\2')

    def modeManual(self):
        if self.userCom is None:
            self.checkSerial()
            return
        if self.mode == 1:
            self.getOnePicButton.setEnabled(True)
            self.modeManualButton.setText("Manual")
            self.dataThread.sendData('CMDM\0')
            self.mode = 0
            print('mode: manual')
        else:

            self.getOnePicButton.setEnabled(False)
            self.modeManualButton.setText("Auto")
            self.dataThread.sendData('CMDM\1')
            print('mode: auto')
            self.mode = 1

    def modeAuto(self):
        if self.userCom is None:
            self.checkSerial()
            return
        print('mode: auto')
        self.dataThread.sendData('CMDM\1')

    def rate(self):
        if self.userCom is None:
            self.checkSerial()
            return
        global btn_index
        btn_index = (btn_index + 1) % 5
        print('FPS:', strButton[btn_index])
        self.modeFpsButton.setText(strButton[btn_index])
        self.dataThread.sendData(strFpsCmd[btn_index])  #'CMDF\0')

    def objBody(self):
        if self.userCom is None:
            self.checkSerial()
            return
        if self.body == 1:
            self.body = 0
            print('obj: Object')
            self.modeObjButton.setText("Object")
            self.dataThread.sendData('CMDO\0')
        else:
            self.body = 1
            print('obj: Human Body')
            self.modeObjButton.setText("Body")
            self.dataThread.sendData('CMDO\1')

    def uiUpdate(self):
        global evaluate_mode
        print("update UI ", evaluate_mode)
        if evaluate_mode == "operate":
            self.EvaluateButton.setText("Operate")
        elif evaluate_mode == "evaluate":
            self.EvaluateButton.setText("Evaluate")
        else:
            self.EvaluateButton.setText("None")

    def cmdUpdate(self):
        if self.userCom is None:
            self.checkSerial()
            return
        print("get evaluate status and version\n")
        time.sleep(0.1)
        self.dataThread.sendData('CMDE\2')
        time.sleep(0.1)
        self.dataThread.sendData('CMDV\0')
        time.sleep(0.1)
        self.dataThread.sendData('CMDT\1')

    def commonOffset(self):
        if self.userCom is None:
            self.checkSerial()
            return
        self.dataThread.sendData('CMDT\1')
        print("Get commonOffset")

    def sysVer(self):
        if self.userCom is None:
            self.checkSerial()
            return
        self.dataThread.sendData('CMDV\1')
        print("Get firmware version and calibration version.")

    def setEvaluate(self):
        if self.userCom is None:
            self.checkSerial()
            return
        if self.evaluate == 1:
            self.evaluate = 0
            self.evaluateButton.setText("Operate")
            self.dataThread.sendData('CMDE\0')
        else:
            self.evaluate = 1
            self.evaluateButton.setText("Evaluate")
            self.dataThread.sendData('CMDE\1')

    def draw(self):
        global minHue
        global maxHue
        global maxHet
        global minHet
        global device_commonOffset
        global evaluate_mode
        if len(displayData) == 0:
            return
        font = QFont()
        color = QColor()
        font.setPointSize(self.fontSize)
        #font.setFamily("Microsoft YaHei")
        font.setLetterSpacing(QFont.AbsoluteSpacing, 0)
        index = 0
        lock.acquire()
        frame = displayData.pop(0)
        lock.release()
        p = QPainter(self.cameraBuffer)
        p.fillRect(0, 0, self.width, self.height + self.textLineHeight,
                   QBrush(QColor(Qt.black)))
        # draw camera
        color = QColor()
        cneter = 0.0
        if chip == "90640":
            if self.centerIndex == 0:
                centerIndex = 12 * 32 + 16
            for yIndex in range(int(self.height / self.pixelSize)):
                for xIndex in range(int(self.width / self.pixelSize)):
                    color.setHsvF(frame[index] / 360, 1.0, 1.0)
                    p.fillRect(xIndex * self.pixelSize,
                               yIndex * self.pixelSize, self.pixelSize,
                               self.pixelSize, QBrush(color))
                    index = index + 1
            cneter = round(
                mapValue(frame[self.centerIndex], minHue, maxHue, minHet,
                         maxHet), 1)
        elif chip == "90621":
            if self.centerIndex == 0 or self.centerIndex >= 64:
                self.centerIndex = 2 * 16 + 8

            cneter = round(
                mapValue(frame[self.centerIndex], minHue, maxHue, minHet,
                         maxHet), 1)
            for yIndex in range(int(self.height / self.pixelSize / 6)):
                for xIndex in range(int(self.width / self.pixelSize / 2)):
                    color.setHsvF(frame[index] / 360, 1.0, 1.0)
                    p.fillRect(xIndex * self.pixelSize * 2,
                               yIndex * self.pixelSize * 2 + 160,
                               self.pixelSize * 2, self.pixelSize * 2,
                               QBrush(color))
                    index = index + 1
        elif chip == "90641":
            if self.centerIndex == 0 or self.centerIndex >= 192:
                self.centerIndex = 6 * 16 + 8

            cneter = round(
                mapValue(frame[self.centerIndex], minHue, maxHue, minHet,
                         maxHet), 1)
            for yIndex in range(int(self.height / self.pixelSize / 2)):
                for xIndex in range(int(self.width / self.pixelSize / 2)):
                    color.setHsvF(frame[index] / 360, 1.0, 1.0)
                    p.fillRect(xIndex * self.pixelSize * 2,
                               yIndex * self.pixelSize * 2, self.pixelSize * 2,
                               self.pixelSize * 2, QBrush(color))
                    index = index + 1
        else:
            print("Dsiplay Error: can't detect any chip type!")

        self.cameraItem.setPixmap(self.cameraBuffer)
        self.frameCount = self.frameCount + 1

        # draw text
        p = QPainter(self.hetTextBuffer)
        p.fillRect(0, 0, self.width + 200, self.height + self.textLineHeight,
                   QBrush(QColor(Qt.black)))

        version = self.dataThread.getID()
        p.setPen(QColor(Qt.white))
        p.setFont(font)
        p.drawText(0, self.fontSize, " max:" + '{:.2f}'.format(maxHet))
        p.drawText(self.textInterval, self.fontSize,
                   " min:" + '{:.2f}'.format(minHet))
        p.drawText(self.textInterval * 2, self.fontSize,
                   "offset:" + '{:.2f}'.format(device_commonOffset))
        p.drawText(self.textInterval * 3, self.fontSize,
                   "mode:" + detect_status)
        p.drawText(self.textInterval * 4, self.fontSize, evaluate_mode)
        p.drawText(self.textInterval * 5, self.fontSize,
                   "ID:" + str(version[0]))
        p.drawText(self.textInterval * 6, self.fontSize,
                   "ver:" + str(version[1] & 0xff))
        p.drawText(self.textInterval * 7, self.fontSize, chip)
        self.hetTextItem.setPixmap(self.hetTextBuffer)
        cneter = round(
            mapValue(frame[self.centerIndex], minHue, maxHue, minHet, maxHet),
            1)
        centerText = "<font color=white>%s</font>"
        self.centerTextItem.setFont(font)
        self.centerTextItem.setHtml(centerText % (str(cneter) + "°"))
        # draw version text
        self.versionTextItem.setFont(font)
Beispiel #26
0
class painter(QGraphicsView):
    pixelSize = int(15 / narrowRatio)
    width = int(480 / narrowRatio)
    height = int(360 / narrowRatio)
    fontSize = int(30 / narrowRatio)
    anchorLineSize = int(100 / narrowRatio)
    ellipseRadius = int(8 / narrowRatio)
    textInterval = int(90 / narrowRatio)
    col = width / pixelSize
    line = height / pixelSize
    centerIndex = int(round(((line / 2 - 1) * col) + col / 2))
    frameCount = 0
    baseZValue = 0
    mode = 1
    body = 1
    open_status = 0
    textLineHeight = fontSize + 10
    blurRaduis = 50  # Smoother improvement

    def __init__(self, dataThread):
        super(painter, self).__init__()
        self.dataThread = dataThread
        self.setFixedSize(self.width, self.height + self.textLineHeight)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.scene = QGraphicsScene()
        self.setScene(self.scene)
        # center het text item
        self.centerTextItem = QGraphicsTextItem()
        self.centerTextItem.setPos(self.width / 2 - self.fontSize, 0)
        self.centerTextItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.centerTextItem)
        # center anchor item
        centerX = self.width / 2
        centerY = self.height / 2
        self.ellipseItem = QGraphicsEllipseItem(0, 0, self.ellipseRadius * 2,
                                                self.ellipseRadius * 2)
        self.horLineItem = QGraphicsLineItem(0, 0, self.anchorLineSize, 0)
        self.verLineItem = QGraphicsLineItem(0, 0, 0, self.anchorLineSize)
        self.ellipseItem.setPos(centerX - self.ellipseRadius,
                                centerY - self.ellipseRadius)
        self.horLineItem.setPos(centerX - self.anchorLineSize / 2, centerY)
        self.verLineItem.setPos(centerX, centerY - self.anchorLineSize / 2)
        self.ellipseItem.setPen(QColor(Qt.white))
        self.horLineItem.setPen(QColor(Qt.white))
        self.verLineItem.setPen(QColor(Qt.white))
        self.ellipseItem.setZValue(self.baseZValue + 1)
        self.horLineItem.setZValue(self.baseZValue + 1)
        self.verLineItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.ellipseItem)
        self.scene.addItem(self.horLineItem)
        self.scene.addItem(self.verLineItem)
        # camera item
        self.cameraBuffer = QPixmap(self.width,
                                    self.height + self.textLineHeight)
        self.cameraItem = QGraphicsPixmapItem()
        if useBlur:
            self.gusBlurEffect = QGraphicsBlurEffect()
            self.gusBlurEffect.setBlurRadius(self.blurRaduis)
            self.cameraItem.setGraphicsEffect(self.gusBlurEffect)
        self.cameraItem.setPos(0, 0)
        self.cameraItem.setZValue(self.baseZValue)
        self.scene.addItem(self.cameraItem)
        # het text item
        self.hetTextBuffer = QPixmap(self.width, self.textLineHeight)
        self.hetTextItem = QGraphicsPixmapItem()
        self.hetTextItem.setPos(0, self.height)
        self.hetTextItem.setZValue(self.baseZValue)
        self.scene.addItem(self.hetTextItem)
        # button item
        self.ctrlOpenButton = QPushButton('Open', self)
        self.ctrlOpenButton.clicked.connect(self.ctrl_open)
        self.ctrlOpenButton.setGeometry(10, 30, 100, 40)
        '''
        self.ctrlCloseButton = QPushButton('stop send',self)
        self.ctrlCloseButton.clicked.connect(self.ctrl_close)
        self.ctrlCloseButton.setGeometry(10,80,100,40)
        '''
        self.getOnePicButton = QPushButton('send a frame', self)
        self.getOnePicButton.clicked.connect(self.ctrl_sendone)
        self.getOnePicButton.setGeometry(10, 130, 100, 40)
        self.getOnePicButton.setEnabled(False)

        self.modeManualButton = QPushButton('Auto', self)
        self.modeManualButton.clicked.connect(self.mode_manual)
        self.modeManualButton.setGeometry(10, 180, 100, 40)

        self.modeObjButton = QPushButton('Body', self)
        self.modeObjButton.clicked.connect(self.obj_body)
        self.modeObjButton.setGeometry(10, 230, 100, 40)
        '''
        self.modeAutoButton = QPushButton('mode: auto',self)
        self.modeAutoButton.clicked.connect(self.mode_auto)
        self.modeAutoButton.setGeometry(10,230,100,40)
        '''
        self.modeFpsButton = QPushButton('3fps', self)
        self.modeFpsButton.clicked.connect(self.rate_0)
        self.modeFpsButton.setGeometry(10, 280, 100, 40)

        self.blackbodyEdit = QLineEdit()
        self.blackbodyEdit.setGeometry(270, 200, 100, 40)
        self.blackbodyEdit.setText('37')

        self.calibrateButton = QPushButton(calibrateStr[0], self)
        self.calibrateButton.clicked.connect(self.calibrate_handle)
        self.calibrateButton.setGeometry(370, 280, 100, 40)
        '''
        self.modeAutoButton = QPushButton('1fps',self)
        self.modeAutoButton.clicked.connect(self.rate_1)
        self.modeAutoButton.setGeometry(35,280,50,40)

        self.modeAutoButton = QPushButton('2fps',self)
        self.modeAutoButton.clicked.connect(self.rate_2)
        self.modeAutoButton.setGeometry(60,280,50,40)

        self.modeAutoButton = QPushButton('3fps',self)
        self.modeAutoButton.clicked.connect(self.rate_3)
        self.modeAutoButton.setGeometry(85,280,50,40)
        '''
        '''
        self.modeAutoButton = QPushButton('obj: common',self)
        self.modeAutoButton.clicked.connect(self.obj_common)
        self.modeAutoButton.setGeometry(370,80,100,40)
        '''
        # self.modeAutoButton = QPushButton('version',self)
        # self.modeAutoButton.clicked.connect(self.sys_ver)
        # self.modeAutoButton.setGeometry(370,230,100,40)

    def ctrl_open(self):
        if self.open_status == 1:
            print('start send C command 0')
            self.open_status = 0

            self.ctrlOpenButton.setText("Open")
            self.dataThread.send_data('CMDC\0')
        else:
            print('start send C command 1')
            self.open_status = 1

            self.ctrlOpenButton.setText("Close")
            self.dataThread.send_data('CMDC\1')

    '''
    def ctrl_close(self):
        print('stop send')
        self.dataThread.send_data('CMDC\0')
    '''

    def ctrl_sendone(self):
        print('send a frame')
        self.dataThread.send_data('CMDC\2')

    def mode_manual(self):
        if self.mode == 1:
            self.getOnePicButton.setEnabled(True)
            self.modeManualButton.setText("Manual")
            self.dataThread.send_data('CMDM\0')
            self.mode = 0
            print('mode: manual')
        else:

            self.getOnePicButton.setEnabled(False)
            self.modeManualButton.setText("Auto")
            self.dataThread.send_data('CMDM\1')
            print('mode: auto')
            self.mode = 1

    def mode_auto(self):
        print('mode: auto')
        self.dataThread.send_data('CMDM\1')

    def stop_calibration(self):
        global calibration_offset
        calibration_start = False
        self.calibrateButton.setText(calibrateStr[0])
        if (calibration_frame_count):
            reply = QMessageBox.information(self, '信息',
                                            '校准很久都不行,模组是否没有预热20分钟呢?',
                                            QMessageBox.Yes)
        else:
            reply = QMessageBox.information(self, '信息', '校准已完成',
                                            QMessageBox.Yes)

    def calibrate_handle(self):
        global calibration_start
        global calibration_max_list
        global blackbody_temperature
        if calibration_start:
            calibration_start = False
            self.calibrateButton.setText(calibrateStr[0])
        else:
            calibration_max_list.clear()
            blackbody_temperature = float(self.blackbodyEdit.text())
            calibration_start = True
            print(" blackbody_temperature ", blackbody_temperature)
            self.calibrateButton.setText(calibrateStr[1])

    def rate_0(self):
        global btn_index
        btn_index = (btn_index + 1) % 4
        print('FPS:', strButton[btn_index])
        self.modeFpsButton.setText(strButton[btn_index])
        self.dataThread.send_data(strFpsCmd[btn_index])  #'CMDF\0')

    '''
    def rate_1(self):
        print('FPS:1') 
        self.dataThread.send_data('CMDF\1')
    def rate_2(self):
        print('FPS:2') 
        self.dataThread.send_data('CMDF\2')
    def rate_3(self):
        print('FPS:3') 
        self.dataThread.send_data('CMDF\3')
    '''

    def obj_body(self):
        if self.body == 1:
            self.body = 0
            print('obj: Object')
            self.modeObjButton.setText("Object")
            self.dataThread.send_data('CMDO\0')
        else:
            self.body = 1
            print('obj: Human Body')
            self.modeObjButton.setText("Body")
            self.dataThread.send_data('CMDO\1')

    '''
    def obj_common(self):
        print('obj: common') 
        self.dataThread.send_data('CMDO\1')
    def sys_slp(self):
        print('sleep')
        self.dataThread.send_data('CMDS\1')
    '''

    def draw(self):
        if len(hetaData) == 0:
            return
        font = QFont()
        color = QColor()
        font.setPointSize(self.fontSize)
        font.setFamily("Microsoft YaHei")
        font.setLetterSpacing(QFont.AbsoluteSpacing, 0)
        index = 0
        lock.acquire()
        frame = hetaData.pop(0)
        lock.release()
        p = QPainter(self.cameraBuffer)
        p.fillRect(0, 0, self.width, self.height + self.textLineHeight,
                   QBrush(QColor(Qt.black)))
        # draw camera
        color = QColor()
        for yIndex in range(int(self.height / self.pixelSize)):
            for xIndex in range(int(self.width / self.pixelSize)):
                color.setHsvF(frame[index] / 360, 1.0, 1.0)
                p.fillRect(xIndex * self.pixelSize, yIndex * self.pixelSize,
                           self.pixelSize, self.pixelSize, QBrush(color))
                index = index + 1
        self.cameraItem.setPixmap(self.cameraBuffer)
        # draw text
        p = QPainter(self.hetTextBuffer)
        p.fillRect(0, 0, self.width, self.height + self.textLineHeight,
                   QBrush(QColor(Qt.black)))
        hetDiff = maxHet - minHet
        bastNum = round(minHet)
        interval = round(hetDiff / 5)
        for i in range(5):
            hue = constrain(
                mapValue((bastNum + (i * interval)), minHet, maxHet, minHue,
                         maxHue), minHue, maxHue)
            color.setHsvF(hue / 360, 1.0, 1.0)
            p.setPen(color)
            p.setFont(font)
            p.drawText(i * self.textInterval, self.fontSize + 3,
                       str(bastNum + (i * interval)) + "°")
        self.hetTextItem.setPixmap(self.hetTextBuffer)
        # draw center het text
        cneter = round(
            mapValue(frame[self.centerIndex], minHue, maxHue, minHet, maxHet),
            1)
        centerText = "<font color=white>%s</font>"
        self.centerTextItem.setFont(font)
        self.centerTextItem.setHtml(centerText % (str(cneter) + "°"))
        self.frameCount = self.frameCount + 1
        print("picture->" + str(self.frameCount))
Beispiel #27
0
    def __init__(self, dataThread):
        super(painter, self).__init__()
        self.dataThread = dataThread
        self.setFixedSize(self.width, self.height + self.textLineHeight)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.scene = QGraphicsScene()
        self.setScene(self.scene)
        # center het text item
        self.centerTextItem = QGraphicsTextItem()
        self.centerTextItem.setPos(self.width / 2 - self.fontSize, 0)
        self.centerTextItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.centerTextItem)
        # center anchor item
        centerX = self.width / 2
        centerY = self.height / 2
        self.ellipseItem = QGraphicsEllipseItem(0, 0, self.ellipseRadius * 2,
                                                self.ellipseRadius * 2)
        self.horLineItem = QGraphicsLineItem(0, 0, self.anchorLineSize, 0)
        self.verLineItem = QGraphicsLineItem(0, 0, 0, self.anchorLineSize)
        self.ellipseItem.setPos(centerX - self.ellipseRadius,
                                centerY - self.ellipseRadius)
        self.horLineItem.setPos(centerX - self.anchorLineSize / 2, centerY)
        self.verLineItem.setPos(centerX, centerY - self.anchorLineSize / 2)
        self.ellipseItem.setPen(QColor(Qt.white))
        self.horLineItem.setPen(QColor(Qt.white))
        self.verLineItem.setPen(QColor(Qt.white))
        self.ellipseItem.setZValue(self.baseZValue + 1)
        self.horLineItem.setZValue(self.baseZValue + 1)
        self.verLineItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.ellipseItem)
        self.scene.addItem(self.horLineItem)
        self.scene.addItem(self.verLineItem)
        # camera item
        self.cameraBuffer = QPixmap(self.width,
                                    self.height + self.textLineHeight)
        self.cameraItem = QGraphicsPixmapItem()
        if useBlur:
            self.gusBlurEffect = QGraphicsBlurEffect()
            self.gusBlurEffect.setBlurRadius(self.blurRaduis)
            self.cameraItem.setGraphicsEffect(self.gusBlurEffect)
        self.cameraItem.setPos(0, 0)
        self.cameraItem.setZValue(self.baseZValue)
        self.scene.addItem(self.cameraItem)
        # het text item
        self.hetTextBuffer = QPixmap(self.width, self.textLineHeight)
        self.hetTextItem = QGraphicsPixmapItem()
        self.hetTextItem.setPos(0, self.height)
        self.hetTextItem.setZValue(self.baseZValue)
        self.scene.addItem(self.hetTextItem)
        # button item
        self.ctrlOpenButton = QPushButton('Open', self)
        self.ctrlOpenButton.clicked.connect(self.ctrl_open)
        self.ctrlOpenButton.setGeometry(10, 30, 100, 40)
        '''
        self.ctrlCloseButton = QPushButton('stop send',self)
        self.ctrlCloseButton.clicked.connect(self.ctrl_close)
        self.ctrlCloseButton.setGeometry(10,80,100,40)
        '''
        self.getOnePicButton = QPushButton('send a frame', self)
        self.getOnePicButton.clicked.connect(self.ctrl_sendone)
        self.getOnePicButton.setGeometry(10, 130, 100, 40)
        self.getOnePicButton.setEnabled(False)

        self.modeManualButton = QPushButton('Auto', self)
        self.modeManualButton.clicked.connect(self.mode_manual)
        self.modeManualButton.setGeometry(10, 180, 100, 40)

        self.modeObjButton = QPushButton('Body', self)
        self.modeObjButton.clicked.connect(self.obj_body)
        self.modeObjButton.setGeometry(10, 230, 100, 40)
        '''
        self.modeAutoButton = QPushButton('mode: auto',self)
        self.modeAutoButton.clicked.connect(self.mode_auto)
        self.modeAutoButton.setGeometry(10,230,100,40)
        '''
        self.modeFpsButton = QPushButton('3fps', self)
        self.modeFpsButton.clicked.connect(self.rate_0)
        self.modeFpsButton.setGeometry(10, 280, 100, 40)

        self.blackbodyEdit = QLineEdit()
        self.blackbodyEdit.setGeometry(270, 200, 100, 40)
        self.blackbodyEdit.setText('37')

        self.calibrateButton = QPushButton(calibrateStr[0], self)
        self.calibrateButton.clicked.connect(self.calibrate_handle)
        self.calibrateButton.setGeometry(370, 280, 100, 40)
        '''
        self.modeAutoButton = QPushButton('1fps',self)
        self.modeAutoButton.clicked.connect(self.rate_1)
        self.modeAutoButton.setGeometry(35,280,50,40)

        self.modeAutoButton = QPushButton('2fps',self)
        self.modeAutoButton.clicked.connect(self.rate_2)
        self.modeAutoButton.setGeometry(60,280,50,40)

        self.modeAutoButton = QPushButton('3fps',self)
        self.modeAutoButton.clicked.connect(self.rate_3)
        self.modeAutoButton.setGeometry(85,280,50,40)
        '''
        '''
Beispiel #28
0
def drawIconWithShadow(icon: QIcon,
                       rect: QRect,
                       p: QPainter,
                       iconMode: QIcon.Mode = None,
                       dipRadius: int = None,
                       color: QColor = None,
                       dipOffset: QPoint = None):
    if iconMode is None:
        iconMode = QIcon.Normal
    if color is None:
        color = QColor(0, 0, 0, 130)
    if dipRadius is None:
        dipRadius = 3
    if dipOffset is None:
        dipOffset = QPoint(1, -2)

    devicePixelRatio: int = p.device().devicePixelRatio()
    pixmapName = "icon %s %s %s %s" % (icon.cacheKey(), iconMode,
                                       rect.height(), devicePixelRatio)
    cache = QPixmapCache.find(pixmapName)
    if cache is None:
        # High-dpi support: The in parameters (rect, radius, offset) are in
        # device-independent pixels. The call to QIcon::pixmap() below might
        # return a high-dpi pixmap, which will in that case have a devicePixelRatio
        # different than 1. The shadow drawing caluculations are done in device
        # pixels.
        window = p.device().window().windowHandle()
        px = icon.pixmap(window, rect.size(), iconMode)
        radius = dipRadius * devicePixelRatio
        offset = dipOffset * devicePixelRatio
        cache = QPixmap(px.size() + QSize(radius * 2, radius * 2))
        cache.fill(Qt.transparent)
        cachePainter = QPainter(cache)

        if iconMode == QIcon.Disabled:
            hasDisabledState = len(icon.availableSizes()) == len(
                icon.availableSizes(QIcon.Disabled))
            if not hasDisabledState:
                px = disabledSideBarIcon(icon.pixmap(window, rect.size()))
        elif TOOLBAR_ICON_SHADOW:
            # Draw shadow
            tmp = QImage(px.size() + QSize(radius * 2, radius * 2 + 1),
                         QImage.Format_ARGB32_Premultiplied)
            tmp.fill(Qt.transparent)

            tmpPainter = QPainter(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_Source)
            tmpPainter.drawPixmap(
                QRect(radius, radius, px.width(), px.height()), px)
            tmpPainter.end()

            # blur the alpha channel
            blurred = QImage(tmp.size(), QImage.Format_ARGB32_Premultiplied)
            blurred.fill(Qt.transparent)
            blurPainter = QPainter(blurred)
            #qt_blurImage(blurPainter, tmp, radius, False, True)
            # implement qt_blurImage via QLabel with QGraphicsBlurEffect
            # FIXME: alignment is broken
            scene = QGraphicsScene()
            item = QGraphicsPixmapItem(QPixmap.fromImage(tmp))
            effect = QGraphicsBlurEffect()
            effect.setBlurRadius(radius)
            item.setGraphicsEffect(effect)
            scene.addItem(item)
            scene.render(blurPainter)
            blurPainter.end()
            tmp = blurred

            # blacken the image...
            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            # draw the blurred drop shadow...
            cachePainter.drawImage(
                QRect(0, 0,
                      cache.rect().width(),
                      cache.rect().height()), tmp)

        # Draw the actual pixmap...
        cachePainter.drawPixmap(
            QRect(
                QPoint(radius, radius) + offset, QSize(px.width(),
                                                       px.height())), px)
        cachePainter.end()
        cache.setDevicePixelRatio(devicePixelRatio)
        QPixmapCache.insert(pixmapName, cache)

    targetRect = cache.rect()
    targetRect.setSize(targetRect.size() / cache.devicePixelRatio())
    targetRect.moveCenter(rect.center() - dipOffset)
    p.drawPixmap(targetRect, cache)
Beispiel #29
0
 def setup(self):
     self.img_idle = self.img_hover = self.img_click = self.img
     super().setup()
     self.textblur_effect = QGraphicsBlurEffect()
     self.textblur_effect.setBlurRadius(0)
     self.text.setGraphicsEffect(self.textblur_effect)
Beispiel #30
0
class painter(QGraphicsView):
    narrowRatio = int(sys.argv[4]) if len(sys.argv) >= 5 else 1
    useBlur = sys.argv[5] != "False" if len(sys.argv) >= 6 else True
    pixelSize = int(15 / narrowRatio)
    width = int(480 / narrowRatio)
    height = int(360 / narrowRatio)
    fontSize = int(30 / narrowRatio)
    anchorLineSize = int(100 / narrowRatio)
    ellipseRadius = int(8 / narrowRatio)
    textInterval = int(90 / narrowRatio)
    col = width / pixelSize
    line = height / pixelSize
    centerIndex = int(round(((line / 2 - 1) * col) + col / 2))
    frameCount = 0
    baseZValue = 0
    textLineHeight = fontSize + 10
    blurRaduis = 50  # Smoother improvement

    def __init__(self):
        super(painter, self).__init__()
        self.setFixedSize(self.width, self.height + self.textLineHeight)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.scene = QGraphicsScene()
        self.setScene(self.scene)
        # center het text item
        self.centerTextItem = QGraphicsTextItem()
        self.centerTextItem.setPos(self.width / 2 - self.fontSize, 0)
        self.centerTextItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.centerTextItem)
        # center anchor item
        centerX = self.width / 2
        centerY = self.height / 2
        self.ellipseItem = QGraphicsEllipseItem(0, 0, self.ellipseRadius * 2,
                                                self.ellipseRadius * 2)
        self.horLineItem = QGraphicsLineItem(0, 0, self.anchorLineSize, 0)
        self.verLineItem = QGraphicsLineItem(0, 0, 0, self.anchorLineSize)
        self.ellipseItem.setPos(centerX - self.ellipseRadius,
                                centerY - self.ellipseRadius)
        self.horLineItem.setPos(centerX - self.anchorLineSize / 2, centerY)
        self.verLineItem.setPos(centerX, centerY - self.anchorLineSize / 2)
        self.ellipseItem.setPen(QColor(Qt.white))
        self.horLineItem.setPen(QColor(Qt.white))
        self.verLineItem.setPen(QColor(Qt.white))
        self.ellipseItem.setZValue(self.baseZValue + 1)
        self.horLineItem.setZValue(self.baseZValue + 1)
        self.verLineItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.ellipseItem)
        self.scene.addItem(self.horLineItem)
        self.scene.addItem(self.verLineItem)
        # camera item
        self.cameraBuffer = QPixmap(self.width,
                                    self.height + self.textLineHeight)
        self.cameraItem = QGraphicsPixmapItem()
        if self.useBlur:
            self.gusBlurEffect = QGraphicsBlurEffect()
            self.gusBlurEffect.setBlurRadius(self.blurRaduis)
            self.cameraItem.setGraphicsEffect(self.gusBlurEffect)
        self.cameraItem.setPos(0, 0)
        self.cameraItem.setZValue(self.baseZValue)
        self.scene.addItem(self.cameraItem)
        # het text item
        self.hetTextBuffer = QPixmap(self.width, self.textLineHeight)
        self.hetTextItem = QGraphicsPixmapItem()
        self.hetTextItem.setPos(0, self.height)
        self.hetTextItem.setZValue(self.baseZValue)
        self.scene.addItem(self.hetTextItem)

    def draw(self):
        if len(hetaData) == 0:
            return
        font = QFont()
        color = QColor()
        font.setPointSize(self.fontSize)
        font.setFamily("Microsoft YaHei")
        font.setLetterSpacing(QFont.AbsoluteSpacing, 0)
        index = 0
        lock.acquire()
        frame = hetaData.pop(0)
        lock.release()
        maxHet = frame["maxHet"]
        minHet = frame["minHet"]
        frame = frame["frame"]
        p = QPainter(self.cameraBuffer)
        p.fillRect(0, 0, self.width, self.height + self.textLineHeight,
                   QBrush(QColor(Qt.black)))
        # draw camera
        color = QColor()
        for yIndex in range(int(self.height / self.pixelSize)):
            for xIndex in range(int(self.width / self.pixelSize)):
                tempData = constrain(
                    mapValue(frame[index], minHet, maxHet, minHue, maxHue),
                    minHue, maxHue)
                color.setHsvF(tempData / 360, 1.0, 1.0)
                p.fillRect(xIndex * self.pixelSize, yIndex * self.pixelSize,
                           self.pixelSize, self.pixelSize, QBrush(color))
                index = index + 1
        self.cameraItem.setPixmap(self.cameraBuffer)
        # draw text
        p = QPainter(self.hetTextBuffer)
        p.fillRect(0, 0, self.width, self.height + self.textLineHeight,
                   QBrush(QColor(Qt.black)))
        hetDiff = maxHet - minHet
        bastNum = round(minHet)
        interval = round(hetDiff / 5)
        for i in range(5):
            hue = constrain(
                mapValue((bastNum + (i * interval)), minHet, maxHet, minHue,
                         maxHue), minHue, maxHue)
            color.setHsvF(hue / 360, 1.0, 1.0)
            p.setPen(color)
            p.setFont(font)
            p.drawText(i * self.textInterval, self.fontSize + 3,
                       str(bastNum + (i * interval)) + "°")
        self.hetTextItem.setPixmap(self.hetTextBuffer)
        # draw center het text
        cneter = round(frame[self.centerIndex], 1)
        centerText = "<font color=white>%s</font>"
        self.centerTextItem.setFont(font)
        self.centerTextItem.setHtml(centerText % (str(cneter) + "°"))
        self.frameCount = self.frameCount + 1
        print("picture->" + str(self.frameCount))
Beispiel #31
0
    def __init__(self):
        super(painter, self).__init__()

        if chip_type == 'mlx90641':
            self.width = int(240 / self.narrowRatio)
            self.height = int(180 / self.narrowRatio)
            self.col = self.width / self.pixelSize
            self.line = self.height / self.pixelSize
            self.centerIndex = int(
                round(((self.line / 2 - 1) * self.col) + self.col / 2))
            self.fontSize = int(15 / self.narrowRatio)
            self.anchorLineSize = int(50 / self.narrowRatio)
            self.ellipseRadius = int(4 / self.narrowRatio)
            self.textInterval = int(45 / self.narrowRatio)
            self.textLineHeight = self.fontSize + 5
            self.blurRaduis = 25

        print("painter width:", self.width, " height:", self.height,
              " pixelSize:", self.pixelSize, " col:", self.col, " line:",
              self.line)

        self.setFixedSize(self.width, self.height + self.textLineHeight)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.scene = QGraphicsScene()
        self.setScene(self.scene)
        # center het text item
        self.centerTextItem = QGraphicsTextItem()
        self.centerTextItem.setPos(self.width / 2 - self.fontSize, 0)
        self.centerTextItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.centerTextItem)
        # center anchor item
        centerX = self.width / 2
        centerY = self.height / 2
        self.ellipseItem = QGraphicsEllipseItem(0, 0, self.ellipseRadius * 2,
                                                self.ellipseRadius * 2)
        self.horLineItem = QGraphicsLineItem(0, 0, self.anchorLineSize, 0)
        self.verLineItem = QGraphicsLineItem(0, 0, 0, self.anchorLineSize)
        self.ellipseItem.setPos(centerX - self.ellipseRadius,
                                centerY - self.ellipseRadius)
        self.horLineItem.setPos(centerX - self.anchorLineSize / 2, centerY)
        self.verLineItem.setPos(centerX, centerY - self.anchorLineSize / 2)
        self.ellipseItem.setPen(QColor(Qt.white))
        self.horLineItem.setPen(QColor(Qt.white))
        self.verLineItem.setPen(QColor(Qt.white))
        self.ellipseItem.setZValue(self.baseZValue + 1)
        self.horLineItem.setZValue(self.baseZValue + 1)
        self.verLineItem.setZValue(self.baseZValue + 1)
        self.scene.addItem(self.ellipseItem)
        self.scene.addItem(self.horLineItem)
        self.scene.addItem(self.verLineItem)
        # camera item
        self.cameraBuffer = QPixmap(self.width,
                                    self.height + self.textLineHeight)
        self.cameraItem = QGraphicsPixmapItem()
        if self.useBlur:
            self.gusBlurEffect = QGraphicsBlurEffect()
            self.gusBlurEffect.setBlurRadius(self.blurRaduis)
            self.cameraItem.setGraphicsEffect(self.gusBlurEffect)
        self.cameraItem.setPos(0, 0)
        self.cameraItem.setZValue(self.baseZValue)
        self.scene.addItem(self.cameraItem)
        # het text item
        self.hetTextBuffer = QPixmap(self.width, self.textLineHeight)
        self.hetTextItem = QGraphicsPixmapItem()
        self.hetTextItem.setPos(0, self.height)
        self.hetTextItem.setZValue(self.baseZValue)
        self.scene.addItem(self.hetTextItem)