图标升级

This commit is contained in:
2026-05-16 00:44:37 +08:00
parent 837996c436
commit d80e8dd05d
2113 changed files with 14850 additions and 244328 deletions

View File

@@ -17,58 +17,58 @@ class AIOPrrintSystemAPI:
def get_status(self):
test_data = {
'job': {
'job': {
'estimatedPrintTime': 1234,
'filament': {'length': 765, 'volume': 24356},
'file': {'display_name': 'Test File','date': None, 'name': '20260508141659_085359c9908947bebcaa0fe7490641e8.gcode', 'origin': 'local', 'path': None, 'size': 1468987},
'lastPrintTime': None,
'user': None
},
'progress': {
'completion': 74.8,
'filepos': 1234,
'printTime': 1235,
'printTimeLeft': 6353,
'printTimeLeftOrigin': 5366
},
'state': 'Operational'
},
'status': {
'sd': {'ready': False},
'state': {
'error': '',
'flags': {
'cancelling': False,
'closedOrError': False,
'error': False,
'finishing': False,
'operational': True,
'paused': False,
'pausing': False,
'printing': False,
'ready': True,
'resuming': False,
'sdReady': False
},
'text': 'Operational test'
},
'temperature': {
'bed': {'actual': 85, 'offset': 0, 'target': 56},
'tool0': {'actual': 0.0, 'offset': 0, 'target': 340}
}
}
}
return test_data
# test_data = {
# 'job': {
# 'job': {
# 'estimatedPrintTime': 1234,
# 'filament': {'length': 765, 'volume': 24356},
# 'file': {'display_name': 'Test File','date': None, 'name': '20260508141659_085359c9908947bebcaa0fe7490641e8.gcode', 'origin': 'local', 'path': None, 'size': 1468987},
# 'lastPrintTime': None,
# 'user': None
# },
# 'progress': {
# 'completion': 74.8,
# 'filepos': 1234,
# 'printTime': 1235,
# 'printTimeLeft': 6353,
# 'printTimeLeftOrigin': 5366
# },
# 'state': 'Operational'
# },
# 'status': {
# 'sd': {'ready': False},
# 'state': {
# 'error': '',
# 'flags': {
# 'cancelling': False,
# 'closedOrError': False,
# 'error': False,
# 'finishing': False,
# 'operational': True,
# 'paused': False,
# 'pausing': False,
# 'printing': False,
# 'ready': True,
# 'resuming': False,
# 'sdReady': False
# },
# 'text': 'Operational test'
# },
# 'temperature': {
# 'bed': {'actual': 85, 'offset': 0, 'target': 56},
# 'tool0': {'actual': 0.0, 'offset': 0, 'target': 340}
# }
# }
# }
# return test_data
# url = f"{self.api_url}/status"
# try:
# r = requests.get(url, headers=self.headers, timeout=5)
# r.raise_for_status()
# return r.json()
# except:
# return {"status": {}, "job": {}}
url = f"{self.api_url}/status"
try:
r = requests.get(url, headers=self.headers, timeout=5)
r.raise_for_status()
return r.json()
except:
return {"status": {}, "job": {}}
def pause_print(self):
return self._post_action("pause_print", action="pause")

View File

@@ -223,14 +223,11 @@ class GCodeViewerWidget(QOpenGLWidget):
"""
def __init__(self, parent=None):
# 请求 OpenGL ES 2.0 上下文
fmt = QSurfaceFormat()
fmt.setRenderableType(QSurfaceFormat.RenderableType.OpenGLES)
fmt.setVersion(2, 0)
super().__init__(parent)
self.setMinimumSize(400, 300)
self.setAttribute(Qt.WidgetAttribute.WA_AcceptTouchEvents, True)
@@ -276,6 +273,7 @@ class GCodeViewerWidget(QOpenGLWidget):
self._pinch_start_center = None
self._pinch_start_trans = (0.0, 0.0)
self._ignore_wheel = False
self._rot_sensitivity = 0.1
# 着色器程序
self.shader_program = None
@@ -491,9 +489,9 @@ class GCodeViewerWidget(QOpenGLWidget):
dx = event.position().x() - self.last_mouse_pos.x()
dy = event.position().y() - self.last_mouse_pos.y()
if event.buttons() & Qt.MouseButton.LeftButton:
self.view_rot_x += dy * 0.5
self.view_rot_x += dy * self._rot_sensitivity
self.view_rot_x = max(-90.0, min(0.0, self.view_rot_x)) # 限制垂直视角的翻转
self.view_rot_z += dx * 0.5
self.view_rot_z += dx * self._rot_sensitivity
self.last_mouse_pos = event.position()
self.update()
@@ -536,9 +534,9 @@ class GCodeViewerWidget(QOpenGLWidget):
last = self._touch_points[p.id()]
dx = p.position().x() - last.x()
dy = p.position().y() - last.y()
self.view_rot_x += dy * 0.5
self.view_rot_x += dy * self._rot_sensitivity
self.view_rot_x = max(-90.0, min(0.0, self.view_rot_x)) # 限制垂直视角的翻转
self.view_rot_z += dx * 0.5
self.view_rot_z += dx * self._rot_sensitivity
self._touch_points[p.id()] = p.position()
self.update()

View File

@@ -0,0 +1,55 @@
import re
import os
import base64
from PyQt6.QtGui import QPixmap, QIcon
BOOTSTRAP_ICON_BASE_PATH = "third_party/Bootstrap/bootstrap-icons-1.13.1/"
def get_colored_icon(name: str, color: str, width: int = 50, height: int = 50) -> QIcon:
"""读取SVG内容并替换currentColor为目标颜色然后生成QIcon"""
try:
path = os.path.join(BOOTSTRAP_ICON_BASE_PATH, name)
with open(path, 'r', encoding='utf-8') as f:
svg_content = f.read()
svg_content = svg_content.replace('currentColor', color)
svg_content = re.sub(r'width="\d+"', f'width="{width}"', svg_content)
svg_content = re.sub(r'height="\d+"', f'height="{height}"', svg_content)
pi = QPixmap()
pi.loadFromData(svg_content.encode('utf-8'), "SVG")
return QIcon(pi)
except Exception:
return None
def get_colored_pixmap(name: str, color: str, width: int = 16, height: int = 16, view_box: str = None) -> QPixmap:
"""读取SVG内容并替换currentColor为目标颜色然后生成QPixmap"""
try:
path = os.path.join(BOOTSTRAP_ICON_BASE_PATH, name)
with open(path, 'r', encoding='utf-8') as f:
svg_content = f.read()
svg_content = svg_content.replace('currentColor', color)
svg_content = re.sub(r'width="\d+"', f'width="{width}"', svg_content)
svg_content = re.sub(r'height="\d+"', f'height="{height}"', svg_content)
if view_box is not None:
svg_content = re.sub(r'viewBox="[^"]*"', f'viewBox="{view_box}"', svg_content)
pi = QPixmap()
pi.loadFromData(svg_content.encode('utf-8'), "SVG")
return pi
except Exception:
return None
def get_colored_svg_uri(name: str, color: str, width: int = 16, height: int = 16, view_box: str = None) -> str:
"""读取SVG内容并替换currentColor为空目标颜色最后转换为HTML可识别的Base64字符串"""
try:
path = os.path.join(BOOTSTRAP_ICON_BASE_PATH, name)
with open(path, 'r', encoding='utf-8') as f:
svg_content = f.read()
svg_content = svg_content.replace('currentColor', color)
svg_content = re.sub(r'width="\d+"', f'width="{width}"', svg_content)
svg_content = re.sub(r'height="\d+"', f'height="{height}"', svg_content)
if view_box is not None:
svg_content = re.sub(r'viewBox="[^"]*"', f'viewBox="{view_box}"', svg_content)
b64 = base64.b64encode(svg_content.encode('utf-8')).decode('utf-8')
return f"data:image/svg+xml;base64,{b64}"
except Exception:
return None