|
|
|
@ -8,7 +8,7 @@ import subprocess
|
|
|
|
|
import qtawesome
|
|
|
|
|
|
|
|
|
|
from PyQt5.QtWidgets import QApplication, QPushButton, QMainWindow, QDockWidget, QToolBar, QAction, QTabWidget, QGridLayout, QWidget, QHBoxLayout, QStackedWidget\
|
|
|
|
|
,QVBoxLayout
|
|
|
|
|
,QVBoxLayout, QProgressBar, QLabel
|
|
|
|
|
from PyQt5.QtCore import Qt, QTimer, QSize
|
|
|
|
|
from PyQt5.QtGui import QIcon, QWindow
|
|
|
|
|
from utils.DBModels.BaseModel import *
|
|
|
|
@ -16,6 +16,29 @@ from model.ClientModel.Client import Client
|
|
|
|
|
from UI.DeviceWidget import DeviceTab
|
|
|
|
|
from model.ProjectModel.DeviceManage import DevicesManange
|
|
|
|
|
|
|
|
|
|
from protocol.BatterySerial.BatteryProtocol import BatteryManange
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QProgressBar, QVBoxLayout, QWidget
|
|
|
|
|
from PyQt5.QtCore import Qt, QRect, QSize
|
|
|
|
|
from PyQt5.QtGui import QPainter, QFont, QColor
|
|
|
|
|
|
|
|
|
|
class CustomProgressBar(QProgressBar):
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
|
super().__init__(parent)
|
|
|
|
|
self.setTextVisible(False)
|
|
|
|
|
self.setFont(QFont("Arial", 10)) # 设置字体大小和类型
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def paintEvent(self, event):
|
|
|
|
|
super().paintEvent(event)
|
|
|
|
|
painter = QPainter(self)
|
|
|
|
|
value = self.value()
|
|
|
|
|
percentage = round(value / self.maximum() * 100, 1)
|
|
|
|
|
text = f"剩余电量{percentage}%"
|
|
|
|
|
painter.drawText(self.rect(), Qt.AlignCenter, text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getHwndByPid(pid):
|
|
|
|
|
def callback(hwnd, hwnds):
|
|
|
|
@ -25,8 +48,15 @@ def getHwndByPid(pid):
|
|
|
|
|
hwnds.append(hwnd)
|
|
|
|
|
|
|
|
|
|
hwnds = []
|
|
|
|
|
win32gui.EnumWindows(callback, hwnds)
|
|
|
|
|
return hwnds[0]
|
|
|
|
|
# win32gui.EnumWindows(callback, hwnds)
|
|
|
|
|
while True:
|
|
|
|
|
win32gui.EnumWindows(callback, hwnds)
|
|
|
|
|
if hwnds:
|
|
|
|
|
return hwnds[0]
|
|
|
|
|
# 如果没有找到窗口,则等待一段时间再尝试
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
# return hwnds
|
|
|
|
|
# return hwnds[0]
|
|
|
|
|
|
|
|
|
|
class CommonHelper:
|
|
|
|
|
def __init__(self):
|
|
|
|
@ -43,6 +73,7 @@ class MainWindow(QWidget):
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.setObjectName("MainWindow")
|
|
|
|
|
self.devicesManange = DevicesManange()
|
|
|
|
|
self.batteryManange = BatteryManange()
|
|
|
|
|
self.process = None
|
|
|
|
|
self.initUI()
|
|
|
|
|
|
|
|
|
@ -50,6 +81,10 @@ class MainWindow(QWidget):
|
|
|
|
|
self.protocolTimer = QTimer()
|
|
|
|
|
self.protocolTimer.timeout.connect(self.readValues)
|
|
|
|
|
|
|
|
|
|
self.batteryTimer = QTimer()
|
|
|
|
|
self.batteryTimer.timeout.connect(self.refreshProgressBar)
|
|
|
|
|
self.batteryTimer.start(3000)
|
|
|
|
|
|
|
|
|
|
# self.toolbarWidget = QWidget()
|
|
|
|
|
# self.addToolBar(Qt.LeftToolBarArea, self.toolbar)
|
|
|
|
|
|
|
|
|
@ -71,9 +106,18 @@ class MainWindow(QWidget):
|
|
|
|
|
self.switchBtn.setCheckable(True)
|
|
|
|
|
self.switchBtn.clicked.connect(self.switchWidget)
|
|
|
|
|
|
|
|
|
|
self.batteryProBar = CustomProgressBar()
|
|
|
|
|
self.batteryProBar.setRange(0, 100)
|
|
|
|
|
|
|
|
|
|
self.batteryStateLabel = QLabel()
|
|
|
|
|
self.batteryStateLabel.setObjectName('batteryLabel')
|
|
|
|
|
|
|
|
|
|
toolbarLayout.addWidget(self.startProtocolBtn, 1)
|
|
|
|
|
toolbarLayout.addWidget(self.switchBtn, 1)
|
|
|
|
|
toolbarLayout.addWidget(QWidget(), 20)
|
|
|
|
|
# toolbarLayout.addWidget(QLabel('电量:'), 1)
|
|
|
|
|
toolbarLayout.addWidget(self.batteryProBar, 1)
|
|
|
|
|
toolbarLayout.addWidget(self.batteryStateLabel, 1)
|
|
|
|
|
toolbarLayout.setSpacing(20)
|
|
|
|
|
toolbarLayout.setContentsMargins(0, 0, 0, 0)
|
|
|
|
|
|
|
|
|
@ -113,6 +157,8 @@ class MainWindow(QWidget):
|
|
|
|
|
|
|
|
|
|
self.setWindowIcon(QIcon('Static/zhjt.ico'))
|
|
|
|
|
self.setWindowTitle("PROFIBUS")
|
|
|
|
|
|
|
|
|
|
self.refreshProgressBar()
|
|
|
|
|
|
|
|
|
|
# self.resize(800, 600)
|
|
|
|
|
# self.showMaximized()
|
|
|
|
@ -161,6 +207,19 @@ class MainWindow(QWidget):
|
|
|
|
|
buttonlayoutWidget.readValues(curIndex = areacurindex)
|
|
|
|
|
# except Exception as e:
|
|
|
|
|
# print(e)
|
|
|
|
|
|
|
|
|
|
def refreshProgressBar(self):
|
|
|
|
|
# self.temp = temp / 10 if temp > -3276.8 else float('nan') # 假设温度值需要除以10得到实际℃数
|
|
|
|
|
# self.current = current # mA
|
|
|
|
|
# self.volt = volt # mV
|
|
|
|
|
# self.remaintime = remaintime # 分钟
|
|
|
|
|
# self.capacity = capacity # mAH
|
|
|
|
|
# self.cappercent = cappercent # 百分比%
|
|
|
|
|
# self.state = state # 充放电状态
|
|
|
|
|
result = self.batteryManange.readBatteryInfo()
|
|
|
|
|
self.batteryProBar.setValue(result.cappercent)
|
|
|
|
|
self.batteryStateLabel.setText(result.chargingStatus)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def switchWidget(self):
|
|
|
|
@ -211,6 +270,7 @@ class MainWindow(QWidget):
|
|
|
|
|
def closeEvent(self, event):
|
|
|
|
|
if self.process:
|
|
|
|
|
self.process.kill()
|
|
|
|
|
self.batteryManange.close()
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|