update 补拍照
This commit is contained in:
@ -389,7 +389,7 @@ class Feeding(QObject):
|
|||||||
self.take_no_photo_sigal.emit()
|
self.take_no_photo_sigal.emit()
|
||||||
# 继续获取图像
|
# 继续获取图像
|
||||||
# TODO
|
# TODO
|
||||||
|
self.feedConfig.feedLine.set_take_position(self.get_take_position())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1
main.py
1
main.py
@ -1381,6 +1381,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||||||
self.lineEdit_origin_v.setText(str(self.robotClient.origin_position.V))
|
self.lineEdit_origin_v.setText(str(self.robotClient.origin_position.V))
|
||||||
self.lineEdit_origin_w.setText(str(self.robotClient.origin_position.W))
|
self.lineEdit_origin_w.setText(str(self.robotClient.origin_position.W))
|
||||||
|
|
||||||
|
@Slot()
|
||||||
def show_no_photo_message_box(self):
|
def show_no_photo_message_box(self):
|
||||||
self.feeding.pause = True
|
self.feeding.pause = True
|
||||||
self.send_pause_command(pause=1)
|
self.send_pause_command(pause=1)
|
||||||
|
|||||||
135
test.py
135
test.py
@ -1,100 +1,51 @@
|
|||||||
from PySide6.QtWidgets import QApplication, QPushButton, QMainWindow, QMessageBox
|
from PySide6.QtCore import QThread, Signal, Slot
|
||||||
from PySide6.QtCore import QPropertyAnimation, QPoint, QParallelAnimationGroup, QEasingCurve, Property
|
from PySide6.QtWidgets import QApplication, QDialog, QLabel, QVBoxLayout, QPushButton
|
||||||
from PySide6.QtGui import QColor, QPainter, QBrush
|
|
||||||
from PySide6.QtCore import Qt
|
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
import Constant
|
# 定义子线程类
|
||||||
|
class WorkerThread(QThread):
|
||||||
|
# 创建信号,子线程处理完成后通知主线程弹窗
|
||||||
|
show_dialog_signal = Signal(str)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
# 模拟子线程的工作
|
||||||
|
time.sleep(3) # 假设任务执行需要 3 秒钟
|
||||||
|
self.show_dialog_signal.emit("任务完成,弹出对话框") # 发出信号,通知主线程弹窗
|
||||||
|
print("子线程")
|
||||||
|
|
||||||
class RippleButton(QPushButton):
|
# 定义主窗口类
|
||||||
def __init__(self, text, parent=None):
|
class MainWindow(QDialog):
|
||||||
super().__init__(text, parent)
|
|
||||||
self._ripple_radius = 0
|
|
||||||
self._ripple_opacity = 1.0
|
|
||||||
self.ripple_position = QPoint()
|
|
||||||
self.animation_group = QParallelAnimationGroup(self) # 设置父对象
|
|
||||||
self.setStyleSheet("background-color: #3498db; color: white; border-radius: 5px; padding: 10px;")
|
|
||||||
self.setAttribute(Qt.WA_StaticContents)
|
|
||||||
|
|
||||||
def paintEvent(self, event):
|
|
||||||
super().paintEvent(event)
|
|
||||||
if self._ripple_radius > 0:
|
|
||||||
painter = QPainter(self)
|
|
||||||
painter.setRenderHint(QPainter.Antialiasing)
|
|
||||||
color = QColor(255, 255, 255)
|
|
||||||
color.setAlphaF(self._ripple_opacity)
|
|
||||||
painter.setBrush(QBrush(color))
|
|
||||||
painter.setPen(Qt.NoPen)
|
|
||||||
painter.drawEllipse(self.ripple_position, self._ripple_radius, self._ripple_radius)
|
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
|
||||||
if event.button() == Qt.LeftButton:
|
|
||||||
self.ripple_position = event.pos()
|
|
||||||
self.startRippleEffect()
|
|
||||||
super().mousePressEvent(event)
|
|
||||||
|
|
||||||
def startRippleEffect(self):
|
|
||||||
# 取消之前的动画
|
|
||||||
self.animation_group.stop()
|
|
||||||
self.animation_group.clear()
|
|
||||||
|
|
||||||
# 创建半径动画
|
|
||||||
radius_animation = QPropertyAnimation(self, b"rippleRadius")
|
|
||||||
radius_animation.setDuration(600)
|
|
||||||
radius_animation.setStartValue(0)
|
|
||||||
# 计算最大半径,确保覆盖按钮
|
|
||||||
max_radius = max(self.width(), self.height()) * 1.5
|
|
||||||
radius_animation.setEndValue(max_radius)
|
|
||||||
radius_animation.setEasingCurve(QEasingCurve.OutQuad)
|
|
||||||
|
|
||||||
# 创建透明度动画
|
|
||||||
opacity_animation = QPropertyAnimation(self, b"rippleOpacity")
|
|
||||||
opacity_animation.setDuration(600)
|
|
||||||
opacity_animation.setStartValue(0.5) # 初始透明度可以调整
|
|
||||||
opacity_animation.setEndValue(0.0)
|
|
||||||
opacity_animation.setEasingCurve(QEasingCurve.OutQuad)
|
|
||||||
|
|
||||||
# 将动画添加到动画组
|
|
||||||
self.animation_group.addAnimation(radius_animation)
|
|
||||||
self.animation_group.addAnimation(opacity_animation)
|
|
||||||
self.animation_group.start()
|
|
||||||
|
|
||||||
# 使用 @Property 装饰器正确定义属性
|
|
||||||
def getRippleRadius(self):
|
|
||||||
return self._ripple_radius
|
|
||||||
|
|
||||||
def setRippleRadius(self, radius):
|
|
||||||
self._ripple_radius = radius
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
rippleRadius = Property(float, getRippleRadius, setRippleRadius)
|
|
||||||
|
|
||||||
def getRippleOpacity(self):
|
|
||||||
return self._ripple_opacity
|
|
||||||
|
|
||||||
def setRippleOpacity(self, opacity):
|
|
||||||
self._ripple_opacity = opacity
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
rippleOpacity = Property(float, getRippleOpacity, setRippleOpacity)
|
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.setWindowTitle("水滴扩散按钮示例")
|
self.setWindowTitle("主窗口")
|
||||||
self.setFixedSize(400, 300)
|
self.setGeometry(100, 100, 300, 200)
|
||||||
|
|
||||||
self.button = RippleButton("点击我", self)
|
self.button = QPushButton("开始任务", self)
|
||||||
self.button.setGeometry(150, 130, 100, 40)
|
self.button.clicked.connect(self.start_task)
|
||||||
self.button.clicked.connect(self.on_button_click)
|
|
||||||
def on_button_click(self):
|
|
||||||
print("按钮被点击了!")
|
|
||||||
QMessageBox.information(None, "提示", Constant.str_feed_photo_error_msgbox)
|
|
||||||
print("sadf")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
layout = QVBoxLayout(self)
|
||||||
app = QApplication(sys.argv)
|
layout.addWidget(self.button)
|
||||||
window = MainWindow()
|
|
||||||
window.show()
|
@Slot(str)
|
||||||
sys.exit(app.exec())
|
def show_dialog(self, message):
|
||||||
|
# 接收到信号后显示弹窗
|
||||||
|
dialog = QDialog(self)
|
||||||
|
dialog.setWindowTitle("子线程通知")
|
||||||
|
label = QLabel(message, dialog)
|
||||||
|
dialog_layout = QVBoxLayout(dialog)
|
||||||
|
dialog_layout.addWidget(label)
|
||||||
|
dialog.exec()
|
||||||
|
|
||||||
|
def start_task(self):
|
||||||
|
# 创建并启动子线程
|
||||||
|
self.thread = WorkerThread()
|
||||||
|
self.thread.show_dialog_signal.connect(self.show_dialog) # 连接信号到主线程的槽函数
|
||||||
|
self.thread.start()
|
||||||
|
|
||||||
|
# 创建应用程序
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
window = MainWindow()
|
||||||
|
window.show()
|
||||||
|
|
||||||
|
sys.exit(app.exec())
|
||||||
|
|||||||
Reference in New Issue
Block a user