python3GUI--大屏可视化-XX产业大数据指挥舱(附下载地址) By:PyQt5 ...

打印 上一主题 下一主题

主题 577|帖子 577|积分 1731


大小:35.0 M,软件安装包放在了这里!
本软件未使用web相关技能,无嵌套欣赏器!
一.前言

今天又来和大家分享我开发的PyQt5大屏可视化方案了,本次和大家分享一款XX产业大数据指挥舱可视化方案。
二.预览

下面我将截图展示一下本次系统的主要功能
本次软件只有一屏,下面截图为软件主界面

三.软件开发心得

1.使用方法

   双击安装包,点下一步进行安装,双击打开软件即可进入软件主界面,软件默认是全屏的,大家可以按下ESC退出。
  

2.UI设计

   本次UI采用图片+文字的方式,软件整体布局为垂直布局,内部为水平布局,通过将主体内容占比增大的方式凸出主体内容,通过绘制组件实现了组件的重写,主屏增长了盘旋的无人机,增长了软件的机灵性,软件内部有多个模块:病虫害预警、统计数据、硬件设备、灌溉数据、日记模块…每一部分都是单独设计的,简而言之就是每个模块都可以单独调试,制止了整体测试的时间浪费。软件整体颜色采用深色配景、亮色文字的方案,更直观地凸出主体。本次软件实现为代码实现,无设计师,请读者不要和笔者询问.ui文件。
  3.代码架构

源代码文件夹包含多个.py文件,每个文件的互相调用逻辑见下图

4.项目结构

以下为本项目标代码结构,主要源代码在src目录下,目录下分资源、配置、组件包。

四.代码片段分享

1.图片平滑缩放组件

软开主屏中的“太阳”就是这个组件实现的
  1. class ImageResizerLabel(QLabel):
  2.         def __init__(self, parent=None):
  3.                 super().__init__(parent)
  4.                 # Initialize scaling factors and original image
  5.                 self.original_pixmap = None
  6.                 # Set the fixed minimum size of the label (75x75)
  7.                 self.min_size = 75
  8.                 self.max_size = 90
  9.                 # Set up a timer for smooth scaling effect
  10.                 self.timer = QTimer(self)
  11.                 self.timer.timeout.connect(self.resize_image)
  12.                 self.timer.start(30)  # 30ms interval for smooth transition
  13.                 # Initial fixed size for the label (75x75)
  14.                 self.setFixedSize(self.min_size, self.min_size)
  15.                 # Initialize scale factor and flag
  16.                 self.current_size = self.min_size
  17.                 self.scaling_up = True
  18.         def load_image(self, image_path):
  19.                 """Load an image into the label"""
  20.                 self.original_pixmap = QPixmap(image_path)
  21.                 if self.original_pixmap:
  22.                         self.update_image_size()  # Ensure image is resized to fit label size
  23.         def update_image(self, image_path):
  24.                 """Update the image data (called externally to update the image)"""
  25.                 if self.original_pixmap:
  26.                         self.original_pixmap = QPixmap(image_path)
  27.                         self.current_size = self.min_size  # Reset to the minimum size
  28.                         self.scaling_up = True  # Start scaling up again
  29.                         self.update_image_size()  # Update the image size after the update
  30.         def resize_image(self):
  31.                 """Resize the image smoothly"""
  32.                 if self.original_pixmap:
  33.                         if self.scaling_up:
  34.                                 self.current_size += 0.5  # Increase size gradually (0.5 units per step)
  35.                                 if self.current_size >= self.max_size:  # Reached the max size (100)
  36.                                         self.scaling_up = False  # Start scaling down
  37.                         else:
  38.                                 self.current_size -= 0.5  # Decrease size gradually (0.5 units per step)
  39.                                 if self.current_size <= self.min_size:  # Back to the original size (75)
  40.                                         self.scaling_up = True  # Start scaling up
  41.                         # Adjust the label size to match the current size
  42.                         self.setFixedSize(self.current_size, self.current_size)
  43.                         # Scale the image to fit the label size
  44.                         scaled_pixmap = self.original_pixmap.scaled(
  45.                                 self.current_size, self.current_size, Qt.KeepAspectRatio, Qt.SmoothTransformation
  46.                         )
  47.                         # Update the pixmap
  48.                         self.setPixmap(scaled_pixmap)
  49.         def update_image_size(self):
  50.                 """Update the size of the label based on the image size"""
  51.                 if self.original_pixmap:
  52.                         # Adjust the size of the image while maintaining aspect ratio
  53.                         scaled_pixmap = self.original_pixmap.scaled(
  54.                                 self.current_size, self.current_size, Qt.KeepAspectRatio, Qt.SmoothTransformation
  55.                         )
  56.                         self.setPixmap(scaled_pixmap)
  57.         def resizeEvent(self, event):
  58.                 """Handle window resize events to resize the image proportionally"""
  59.                 self.update_image_size()  # Update the image size whenever the widget is resized
  60.                 super().resizeEvent(event)  # Call the base class method to handle the default behavior
复制代码
2.滚动日记组件

这个组件用于滚动显示日记
  1. class ScrollingMessageWidget(QWidget):
  2.         def __init__(self, parent=None, messages=[]):
  3.                 super().__init__(parent)
  4.                 self.messages = messages  # 初始化中奖信息列表
  5.                 self.message_labels = []  # 保存所有 QLabel
  6.                 self.current_offset = 0  # 当前滚动偏移量
  7.                 self.init_ui()
  8.                 self.start_scrolling()
  9.         def init_ui(self):
  10.                 """初始化UI组件"""
  11.                 # 窗口设置
  12.                 self.setStyleSheet("background-color: transparent;")
  13.                 # 垂直布局
  14.                 self.layout = QVBoxLayout(self)
  15.                 self.layout.setSpacing(0)
  16.                 self.layout.setContentsMargins(0, 0, 0, 0)
  17.                 # 设置字体样式
  18.                 font = QFont("Arial", 7, QFont.Bold)
  19.                 font.setBold(True)
  20.                 # 创建 QLabel 并添加到布局中
  21.                 self.create_labels(font)
  22.         def create_labels(self, font):
  23.                 """根据当前消息列表创建 QLabel"""
  24.                 # 清空原有标签
  25.                 for label in self.message_labels:
  26.                         self.layout.removeWidget(label)
  27.                         label.deleteLater()
  28.                 self.message_labels.clear()
  29.                 # 创建新的标签
  30.                 for message in self.messages:
  31.                         label = QLabel(message, self)
  32.                         label.setAlignment(Qt.AlignCenter)
  33.                         label.setFont(font)
  34.                         label.setStyleSheet("color: rgb(201,206,211);")
  35.                         self.layout.addWidget(label)
  36.                         self.message_labels.append(label)
  37.                 # 首尾相接:复制消息以实现循环效果
  38.                 for message in self.messages:
  39.                         label = QLabel(message, self)
  40.                         label.setAlignment(Qt.AlignCenter)
  41.                         label.setFont(font)
  42.                         label.setStyleSheet("color: rgb(201,206,211);")
  43.                         self.layout.addWidget(label)
  44.                         self.message_labels.append(label)
  45.         def start_scrolling(self):
  46.                 """启动滚动定时器"""
  47.                 self.timer = QTimer(self)
  48.                 self.timer.timeout.connect(self.scroll)
  49.                 self.timer.start(10)  # 每 5 毫秒更新一次
  50.         def scroll(self):
  51.                 """滚动消息"""
  52.                 # 滚动偏移量递增
  53.                 self.current_offset += 1
  54.                 # 检查是否需要重置偏移量
  55.                 if self.current_offset >= self.message_labels[0].height():
  56.                         self.current_offset = 0
  57.                         # 将第一个 QLabel 移动到最后
  58.                         label = self.message_labels.pop(0)
  59.                         self.layout.removeWidget(label)
  60.                         self.layout.addWidget(label)
  61.                         self.message_labels.append(label)
  62.                 # 更新每个 QLabel 的位置
  63.                 for i, label in enumerate(self.message_labels):
  64.                         label.move(0, (i - 1) * label.height() - self.current_offset)
  65.         def update_messages(self, new_messages):
  66.                 """
  67.                 更新中奖信息并刷新显示
  68.                 :param new_messages: 新的中奖信息列表
  69.                 """
  70.                 self.messages = new_messages
  71.                 self.current_offset = 0  # 重置滚动偏移量
  72.                 self.create_labels(QFont("微软雅黑", 7, QFont.Bold))  # 重新创建标签
复制代码
五.心得体会

本次和大家分享了我的大屏可视化方案,软件完全是使用PyQt5实现的,与大家分享了我的软件开发心得与软件代码项目结构另有我的代码片段,希望大家亲身下载体验一下软件,更希望得到大家的反馈!


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

诗林

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表