小伙伴们,今天我们利用cursor不写一行代码开发一个电脑的系统状态监控小应用!

下载安装cursor:

网址:https://www.cursor.com/cn

Image

下载后双击安装

Image

Image

Image

  

输入提示词:       

制作一个winswos应用,实现显示时间精确到秒,
显示cpu温度、cpu占用率,显示显卡GPU的温度和使用率,
内存的占用率,用户可自定义窗体界面大小,背景颜色,透明度,显示层级。
字体大小可调节。利用python pyqt5 实现

Image

自动生成代码,选择:accept all

Image

生成的代码 运行结果如下:

Image

我们来进行优化:

优化功能,添加大核小核占用率,cpu gpu 相关数据未能正常读取。 界面优化 参考苹果IOS风格

Image

Image

期间如果遇到问题直接用自然语言提问给cursor,cursor会自动解决更新代码,经过几轮问答最终成果如下:

Image

完整代码:

import sys
import psutil
import requests
import wmi
from datetime import datetime
from PyQt5.QtWidgets import (QApplication, QWidget, QLabel, QVBoxLayout, QColorDialog, QSlider, QPushButton, QFontDialog, QCheckBox, QFrame, QScrollArea
)
from PyQt5.QtCore import QTimer, Qt, QMutex
from PyQt5.QtGui import QColor, QFontclass HardwareMonitor:@staticmethoddef get_data():"""获取硬件数据,支持OpenHardwareMonitor和备用方案"""try:resp = requests.get("http://localhost:8085/data.json", timeout=1)resp.raise_for_status()return resp.json()except Exception:return HardwareMonitor.get_fallback_data()@staticmethoddef get_cpu_temp_wmi():w = wmi.WMI(namespace="root\\wmi")try:temps = w.MSAcpi_ThermalZoneTemperature()if temps:# 温度单位是 1/10 Kelvinreturn [round(t.CurrentTemperature / 10.0 - 273.15, 1) for t in temps]except Exception:passreturn []@staticmethoddef get_fallback_data():"""当OpenHardwareMonitor不可用时使用的备用数据获取方案"""cpu_percent = psutil.cpu_percent()mem = psutil.virtual_memory()cpu_freq = psutil.cpu_freq()# 优先用wmi真实温度cpu_temps = HardwareMonitor.get_cpu_temp_wmi()if cpu_temps:cpu_temp_value = cpu_temps[0]else:cpu_temp_value = HardwareMonitor.estimate_cpu_temp()# 创建模拟的硬件数据结构return {"Children": [{"Text": "CPU","Children": [{"Text": "Temperatures","Children": [{"Text": "CPU", "Value": cpu_temp_value}]},{"Text": "Load","Children": [{"Text": "Total", "Value": cpu_percent}]},{"Text": "Clock","Children": [{"Text": "CPU", "Value": cpu_freq.current if cpu_freq else None}]}]},{"Text": "Memory","Children": [{"Text": "Data","Children": [{"Text": "Used", "Value": mem.percent}]}]}]}@staticmethoddef estimate_cpu_temp():"""根据CPU使用率估算温度(模拟值)"""cpu_percent = psutil.cpu_percent()# 基础温度 + 使用率影响base_temp = 40.0temp_increase = cpu_percent * 0.3return min(base_temp + temp_increase, 95.0)  # 限制最高温度@staticmethoddef parse_temperatures(data):cpu_temp = Nonecpu_candidates = []if not data or "Children" not in data:return None, Nonedef traverse(node):nonlocal cpu_candidatesif"Temperatures"in node.get("Text", ""):for child in node.get("Children", []):value = child.get("Value")if value is not None:name = child.get("Text", "").lower()if"cpu"in name or "package"in name:cpu_candidates.append(value)for child in node.get("Children", []):traverse(child)for child in data["Children"]:traverse(child)if cpu_candidates:cpu_temp = max(cpu_candidates)return cpu_temp, None@staticmethoddef parse_usage(data):cpu_load = Noneif not data or "Children" not in data:return None, []def traverse(node):nonlocal cpu_loadif"Load"in node.get("Text", ""):for child in node.get("Children", []):value = child.get("Value")if value is not None:name = child.get("Text", "").lower()if"cpu"in name or "total"in name:cpu_load = valuefor child in node.get("Children", []):traverse(child)for child in data["Children"]:traverse(child)return cpu_load, []class CardFrame(QFrame):def __init__(self, parent=None):super().__init__(parent)self.setStyleSheet('''QFrame {background: rgba(255,255,255,0.85);border-radius: 14px;border: 1px solid #e0e0e0;margin: 4px;padding: 6px;}''')class MonitorWidget(QWidget):def __init__(self):super().__init__()self.setWindowTitle("系统监控")self.resize(380, 300)self.setWindowOpacity(0.97)self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint)self.setStyleSheet("background: #f6f7fa;")main_layout = QVBoxLayout(self)main_layout.setContentsMargins(8, 8, 8, 8)main_layout.setSpacing(4)# 时间卡片self.card_time = CardFrame()vbox_time = QVBoxLayout(self.card_time)vbox_time.setContentsMargins(4, 2, 4, 2)self.label_date = QLabel()self.label_date.setFont(QFont("Arial", 12, QFont.Bold))self.label_date.setStyleSheet("color: #555; margin-bottom: 0px;")self.label_time = QLabel()self.label_time.setFont(QFont("Arial", 18, QFont.Bold))self.label_time.setStyleSheet("color: #222; margin-bottom: 0px;")vbox_time.addWidget(self.label_date)vbox_time.addWidget(self.label_time)main_layout.addWidget(self.card_time)# CPU卡片self.card_cpu = CardFrame()vbox_cpu = QVBoxLayout(self.card_cpu)vbox_cpu.setContentsMargins(4, 2, 4, 2)self.label_cpu_temp = QLabel("CPU温度: 初始化中...")self.label_cpu_temp.setFont(QFont("Arial", 12))self.label_cpu_temp.setStyleSheet("color: #444;")self.label_cpu_load = QLabel("CPU总占用: 初始化中...")self.label_cpu_load.setFont(QFont("Arial", 12))self.label_cpu_load.setStyleSheet("color: #444;")vbox_cpu.addWidget(self.label_cpu_temp)vbox_cpu.addWidget(self.label_cpu_load)main_layout.addWidget(self.card_cpu)# 内存卡片self.card_mem = CardFrame()vbox_mem = QVBoxLayout(self.card_mem)vbox_mem.setContentsMargins(4, 2, 4, 2)self.label_mem = QLabel()self.label_mem.setFont(QFont("Arial", 12))self.label_mem.setStyleSheet("color: #444;")vbox_mem.addWidget(self.label_mem)main_layout.addWidget(self.card_mem)# 控件卡片self.card_ctrl = CardFrame()vbox_ctrl = QVBoxLayout(self.card_ctrl)vbox_ctrl.setContentsMargins(4, 2, 4, 2)btn_color = QPushButton("背景颜色")btn_color.setFont(QFont("Arial", 10))btn_color.clicked.connect(self.choose_color)vbox_ctrl.addWidget(btn_color)slider_opacity = QSlider(Qt.Horizontal)slider_opacity.setMinimum(50)slider_opacity.setMaximum(100)slider_opacity.setValue(97)slider_opacity.valueChanged.connect(self.set_opacity)vbox_ctrl.addWidget(slider_opacity)btn_font = QPushButton("字体设置")btn_font.setFont(QFont("Arial", 10))btn_font.clicked.connect(self.choose_font)vbox_ctrl.addWidget(btn_font)self.cb_top = QCheckBox("窗口置顶")self.cb_top.setFont(QFont("Arial", 10))self.cb_top.setChecked(True)self.cb_top.stateChanged.connect(self.set_topmost)vbox_ctrl.addWidget(self.cb_top)main_layout.addWidget(self.card_ctrl)# 定时器与刷新锁self.refresh_mutex = QMutex()self.timer = QTimer(self)self.timer.timeout.connect(self.safe_update_info)self.timer.start(1500)def safe_update_info(self):if self.refresh_mutex.tryLock():try:self.update_info()finally:self.refresh_mutex.unlock()else:passdef update_info(self):now = datetime.now()week_map = ['星期一','星期二','星期三','星期四','星期五','星期六','星期日']date_str = now.strftime("%Y-%m-%d ") + week_map[now.weekday()]time_str = now.strftime("%H:%M:%S")self.label_date.setText(date_str)self.label_time.setText(time_str)data = HardwareMonitor.get_data()cpu_temp, _ = HardwareMonitor.parse_temperatures(data)cpu_load, _ = HardwareMonitor.parse_usage(data)mem = psutil.virtual_memory()self.label_cpu_temp.setText(f"CPU温度: {cpu_temp if cpu_temp is not None else 'N/A'}")self.label_cpu_load.setText(f"CPU总占用: {cpu_load if cpu_load is not None else 'N/A'}%")self.label_mem.setText(f"内存占用: {mem.percent:.1f}%")def choose_color(self):color = QColorDialog.getColor()if color.isValid():self.setStyleSheet(f"background: {color.name()};")def set_opacity(self, value):self.setWindowOpacity(value / 100)def choose_font(self):font, ok = QFontDialog.getFont()if ok:for label in [self.label_date, self.label_time, self.label_cpu_temp, self.label_cpu_load,self.label_mem]:label.setFont(font)def set_topmost(self, state):if state == Qt.Checked:self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint)else:self.setWindowFlags(self.windowFlags() & ~Qt.WindowStaysOnTopHint)self.show()if __name__ == "__main__":app = QApplication(sys.argv)w = MonitorWidget()w.show()sys.exit(app.exec_())

感谢大家的点赞和关注,我们下期见!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/97990.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/97990.shtml
英文地址,请注明出处:http://en.pswp.cn/diannao/97990.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

信号调制与解调 matlab仿真

信号调制与解调 matlab仿真 原始信号--频谱为cos(Wt*w)函数,外形如馒头调制解调傅里叶变换测试FT的频谱是否为锯齿波理想低通滤波器,截至频率Wm傅里叶变换频谱为锯齿波函数的时域信号函数傅里叶变换调制频率1理想低通滤波调制频率2理想低通滤波 % 调制定理演示Dem…

IIS服务器下做浏览器缓存

你的这个问题问得非常好&#xff0c;很多开发者在同时使用重写和缓存时都会遇到。简单来说&#xff1a;你添加的 <staticContent> 和 <clientCache> 配置本身不会影响或干扰 重写规则的工作。它们各司其职&#xff0c;在 IIS 处理请求的不同阶段发挥作用。 但是&a…

Flutter 3.35.2 以上版本中 数字转字符串的方法指南

在 Flutter 3.35.2 (对应 Dart 2.19 及以上版本) 中&#xff0c;将数字转换为字符串主要依赖于 Dart 语言本身提供的原生方法。这些方法稳定且向后兼容。下面我为你介绍几种主要的方法和案例。 &#x1f522; 数字转字符串的基本方法方法名适用类型描述常用场景toString()int, …

C#基础(⑤ProcessStartInfo类和Process类)

1. 它是什么&#xff1f;ProcessStartInfo 是 C# 里的一个类&#xff08;属于 System.Diagnostics 命名空间&#xff09;&#xff0c;作用是&#xff1a;定义要启动的程序路径&#xff08;比如 notepad.exe&#xff09;设置启动时的参数&#xff08;比如打开哪个文件&#xff0…

《设计模式之禅》笔记摘录 - 19.备忘录模式

备忘录模式的定义备忘录模式(Memento Pattern)提供了一种弥补真实世界缺陷的方法&#xff0c;让“后悔药”在程界序的世界中真实可行&#xff0c;其定义如下&#xff1a;Without violating encapsulation, capture and externalize an objects internal state so that the obje…

22、Jenkins容器化部署Java应用

22、Jenkins容器化部署Java应用 1、准备Dockerfile 将Dockerfile文件放入项目目录下 FROM registry.cn-hangzhou.aliyuncs.com/xx_blog/openjdk:21-jdk LABEL maintainer"xxqq.com" #复制打好的jar包 COPY target/*.jar /app.jar RUN apk add -U tzdata; \ ln -sf /…

基于单片机智能水龙头/智能洗漱台设计

传送门 &#x1f449;&#x1f449;&#x1f449;&#x1f449;其他作品题目速选一览表 &#x1f449;&#x1f449;&#x1f449;&#x1f449;其他作品题目功能速览 概述 该设计采用单片机作为核心控制器&#xff0c;结合红外传感器、水流传感器和电磁阀等模块&#xf…

GD32入门到实战30--产品配置参数存储方案 (EEPROM)

我们之前已经实现eeprom的驱动了&#xff0c;我们在应用层实现产品配置参数存储方案我们要实现&#xff1a;原本设定的modebus从机&#xff08;单片机&#xff09;地址是01&#xff0c;存储在eeprom里&#xff0c;按下按键后修改地址为03&#xff0c;重新上电modebus从机&#…

find_code 插件 react_vite

find_code 插件 react_vite const fs require("fs"); const path require("path"); const parser require("babel/parser"); const traverse require("babel/traverse").default; const generate require("babel/generator&…

手机秒变全栈IDE:Claude Code UI的深度体验

还在为只能在命令行中使用Claude Code而苦恼吗&#xff1f;想在移动设备上继续你的AI编程对话吗&#xff1f;Claude Code UI的出现彻底改变了这一切。这个开源项目为Anthropic官方的Claude Code CLI工具提供了现代化的Web界面&#xff0c;让你能够在任何设备、任何地方与AI编程…

F5发布后量子API安全解决方案,以AI驱动全面防护应对量子计算威胁

量子计算的飞速演进&#xff0c;正对传统加密体系构成日益严峻的安全威胁。Gartner预测显示&#xff0c;到2029年&#xff0c;量子计算机有望攻破目前普遍采用的公钥加密算法&#xff0c;这一风险正倒逼全球企业加速密码体系的更迭与升级。面对这一挑战&#xff0c;F5公司——应…

深度剖析 DC - DC 转换器在新能源汽车中的关键应用

在新能源汽车的发展进程中&#xff0c;DC - DC 转换器扮演着至关重要的角色。以下将详细介绍其在新能源汽车上的应用&#xff0c;包括作用、电路组成以及工作原理等方面。DC - DC 转换器的作用简单来说&#xff0c;新能源汽车上的 DC - DC 转换器是一个 “降压型电压变换器”。…

【标准项目】在线五子棋对决(下)

在线五子棋对决一. 项目介绍及链接二. 项目结构设计项目模块划分业务处理模块的子模块划分项目流程图玩家流程图服务器流程图三. 数据管理模块数据库设计创建 user_table 类四. 在线用户管理模块五. 游戏房间管理模块游戏房间类实现游戏房间管理类实现六. Session 管理模块Sess…

重构导航之核:高德地图的深度学习架构解析 导论:从数字化世界到可计算世界

导论&#xff1a;从数字化世界到可计算世界 数字地图的演进&#xff0c;本质上是一场关于“世界可计算性”的持续探索。第一代地图的核心任务是数字化转录&#xff08;Digital Transcription&#xff09;&#xff0c;它成功地将物理世界的静态元素——道路、建筑、兴趣点&#…

逻辑回归(sigmoid函数、混淆矩阵、精确率召回率F1)

目录 一、概述 1、逻辑回归 2、激活函数 sigmoid函数 3、最大似然估计 二、逻辑回归 1、原理 2、损失函数 3、代码 三、混淆矩阵 1、定义 2、举例 3、代码 四、分类评估方法 1、精确率&#xff08;Precision&#xff09; 2、召回率&#xff08;Recall&#xff09; 3、F1&#…

Redis底层实现原理之五大基础结构

文章目录1. 基础结构和编码类型2. 编码类型和数据结构实现2.1 字符串&#xff08;String&#xff09;2.2 压缩列表&#xff08;listpack&#xff09;2.3 哈希表&#xff08;hashtable&#xff09;2.4 快速列表&#xff08;quicklist&#xff09;2.5 整数集合&#xff08;intset…

火山引擎数据智能体DataAgent总结分享

数据的冰山:看得见的资产与看不见的鸿沟 这张图片用“冰山”类比的方式展示了数据资产管理中的可见与不可见问题,并突出了数据利用的核心挑战与潜在陷阱。 1. 冰山之上的“看得见的资产” 内容:数据库、报表、指标等结构化、显性的数据资源。 核心挑战: 需要从“采集存储”…

100种高级数据结构 (速查表)

一、 基础结构的扩展与组合 (Advanced Linear Structures) 这些结构在数组、链表、队列、栈等基础结构上增加了特定功能或约束。双端队列 (Deque - Double-Ended Queue) 介绍&#xff1a;允许在队列的前后两端都进行插入和删除操作的线性结构。应用场景&#xff1a;工作窃取算法…

一个开源的企业官网简介

简介一个完美的企业官网系统,支持手机端和电脑端展示企业风采,还可以展示企业产品/企业新闻资讯等等.普通用户PC端展示普通用户手机端展示管理后台

TCP实现线程池竞争任务

服务端&#xff1a;#include<stdio.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<netinet/ip.h> #include<strings.h> #include<unistd.h> #include<ctype.h> #include<arpa/inet.h&…