风格调节

This commit is contained in:
cheng
2026-06-09 14:35:43 +08:00
parent 1f1ee6d8fe
commit 9a3a397e2c
4 changed files with 72 additions and 30 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.3 MiB

+72 -30
View File
@@ -25,11 +25,12 @@ _fix_qt_plugin_path()
_QT_IMPORT_ERROR = None _QT_IMPORT_ERROR = None
try: try:
from PyQt5.QtCore import Qt, QTimer from PyQt5.QtCore import QEasingCurve, QPropertyAnimation, Qt, QTimer
from PyQt5.QtGui import QFont, QImage, QPixmap from PyQt5.QtGui import QFont, QImage, QPixmap
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QApplication, QApplication,
QFrame, QFrame,
QGraphicsOpacityEffect,
QGridLayout, QGridLayout,
QHBoxLayout, QHBoxLayout,
QLabel, QLabel,
@@ -41,10 +42,10 @@ try:
) )
except Exception as exc: except Exception as exc:
_QT_IMPORT_ERROR = exc _QT_IMPORT_ERROR = exc
Qt = QTimer = QFont = QImage = QPixmap = QApplication = None Qt = QTimer = QPropertyAnimation = QEasingCurve = QFont = QImage = QPixmap = QApplication = None
QGridLayout = QHBoxLayout = QLabel = QPushButton = QSizePolicy = None QGridLayout = QHBoxLayout = QLabel = QPushButton = QSizePolicy = None
QVBoxLayout = QWidget = None QVBoxLayout = QWidget = None
QFrame = QMainWindow = object QFrame = QGraphicsOpacityEffect = QMainWindow = object
try: try:
import pyqtgraph as pg import pyqtgraph as pg
@@ -158,46 +159,87 @@ QFrame#Panel {
border-radius: 4px; border-radius: 4px;
} }
QPushButton { QPushButton {
background-color: #1a1a1a; background-color: #171717;
color: #a8a8a8; color: #d8d8d8;
border: 1px solid #333333; border: 1px solid #363636;
border-radius: 4px; border-radius: 4px;
padding: 7px 16px; padding: 7px 16px;
font-size: 13px; font-size: 13px;
} }
QPushButton:hover { QPushButton:hover {
background-color: #262626; background-color: #242424;
color: #d4d4d4; color: #ffffff;
border: 1px solid #555555; border: 1px solid #5a5a5a;
}
QPushButton:pressed {
background-color: #0f0f0f;
border: 1px solid #8a8a8a;
padding-top: 8px;
padding-bottom: 6px;
}
QPushButton:disabled {
background-color: #101010;
color: #606060;
border: 1px solid #242424;
} }
QPushButton#StartButton { QPushButton#StartButton {
background-color: #0d2818; background-color: #171717;
color: #67d79a; color: #d8d8d8;
border: 1px solid #1a4d30; border: 1px solid #363636;
} }
QPushButton#StopButton { QPushButton#StopButton {
background-color: #2b1010; background-color: #171717;
color: #f07070; color: #d8d8d8;
border: 1px solid #4d1a1a; border: 1px solid #363636;
} }
QPushButton#RestartButton { QPushButton#RestartButton {
background-color: #1d1d12; background-color: #171717;
color: #e0c96a; color: #d8d8d8;
border: 1px solid #4d4520; border: 1px solid #363636;
} }
QPushButton#ManualButton { QPushButton#ManualButton {
background-color: #101822; background-color: #171717;
color: #9cc8ff; color: #d8d8d8;
border: 1px solid #23405f; border: 1px solid #363636;
} }
QPushButton#HoldButton { QPushButton#HoldButton {
background-color: #102019; background-color: #171717;
color: #7ee0a2; color: #d8d8d8;
border: 1px solid #24573a; border: 1px solid #363636;
} }
""" """
if QPushButton is not None:
class AnimatedButton(QPushButton):
def __init__(self, text=""):
super().__init__(text)
self._opacity = QGraphicsOpacityEffect(self)
self._opacity.setOpacity(1.0)
self.setGraphicsEffect(self._opacity)
self._animation = QPropertyAnimation(self._opacity, b"opacity", self)
self._animation.setEasingCurve(QEasingCurve.OutCubic)
def _animate_opacity(self, target, duration):
self._animation.stop()
self._animation.setDuration(duration)
self._animation.setStartValue(self._opacity.opacity())
self._animation.setEndValue(target)
self._animation.start()
def mousePressEvent(self, event):
if self.isEnabled():
self._animate_opacity(0.72, 70)
super().mousePressEvent(event)
def mouseReleaseEvent(self, event):
if self.isEnabled():
self._animate_opacity(1.0, 140)
super().mouseReleaseEvent(event)
else:
AnimatedButton = None
class MetricBox(QFrame): class MetricBox(QFrame):
def __init__(self, title, value="--", sub=""): def __init__(self, title, value="--", sub=""):
super().__init__() super().__init__()
@@ -286,23 +328,23 @@ class GripperDemo02Viewer(QMainWindow):
self.status_chip.setObjectName("StatusChip") self.status_chip.setObjectName("StatusChip")
self.action_chip = QLabel("action=--") self.action_chip = QLabel("action=--")
self.action_chip.setObjectName("ActionChip") self.action_chip.setObjectName("ActionChip")
self.start_button = QPushButton("启动") self.start_button = AnimatedButton("启动")
self.start_button.setObjectName("StartButton") self.start_button.setObjectName("StartButton")
self.start_button.clicked.connect(self.start_control) self.start_button.clicked.connect(self.start_control)
self.stop_button = QPushButton("停止") self.stop_button = AnimatedButton("停止")
self.stop_button.setObjectName("StopButton") self.stop_button.setObjectName("StopButton")
self.stop_button.clicked.connect(self.stop_control) self.stop_button.clicked.connect(self.stop_control)
self.stop_button.setEnabled(False) self.stop_button.setEnabled(False)
self.restart_button = QPushButton("重启") self.restart_button = AnimatedButton("重启")
self.restart_button.setObjectName("RestartButton") self.restart_button.setObjectName("RestartButton")
self.restart_button.clicked.connect(self.restart_control) self.restart_button.clicked.connect(self.restart_control)
self.manual_open_button = QPushButton("夹爪张开") self.manual_open_button = AnimatedButton("夹爪张开")
self.manual_open_button.setObjectName("ManualButton") self.manual_open_button.setObjectName("ManualButton")
self.manual_open_button.clicked.connect(lambda: self.send_manual_command("open")) self.manual_open_button.clicked.connect(lambda: self.send_manual_command("open"))
self.manual_close_button = QPushButton("夹爪闭合") self.manual_close_button = AnimatedButton("夹爪闭合")
self.manual_close_button.setObjectName("ManualButton") self.manual_close_button.setObjectName("ManualButton")
self.manual_close_button.clicked.connect(lambda: self.send_manual_command("close")) self.manual_close_button.clicked.connect(lambda: self.send_manual_command("close"))
self.manual_hold_button = QPushButton("保持") self.manual_hold_button = AnimatedButton("保持")
self.manual_hold_button.setObjectName("HoldButton") self.manual_hold_button.setObjectName("HoldButton")
self.manual_hold_button.clicked.connect(self.toggle_manual_hold) self.manual_hold_button.clicked.connect(self.toggle_manual_hold)
self._set_button_state("idle") self._set_button_state("idle")