master
45coll 2021-09-17 14:36:57 +08:00
parent 6abe1792c4
commit e7e80aa953
58 changed files with 188 additions and 82 deletions

View File

@ -6,16 +6,13 @@ import threading #引入并行
import numpy as np
import pyqtgraph as pg
import re
RED_COLOR = (255, 92, 92)
GREEN_COLOR = (57, 217, 138)
BLUE_COLOR = (91, 141, 236)
ORANGE_COLOR = (253, 172, 66)
YELLOW_COLOR = (255,255,51)
PURPLE_COLOR = (75,0,130)
MAROON_COLOR = (222,184,135)
from sharedcomponets import GUIToolKit
class MyWindow(QMainWindow, Ui_MainWindow):
signalColors = [GUIToolKit.RED_COLOR, GUIToolKit.BLUE_COLOR, GUIToolKit.PURPLE_COLOR, GUIToolKit.YELLOW_COLOR,
GUIToolKit.MAROON_COLOR, GUIToolKit.ORANGE_COLOR, GUIToolKit.GREEN_COLOR]
signalIcons = ['reddot', 'bluedot', 'purpledot', 'yellowdot', 'maroondot', 'orangedot', 'greendot']
def __init__(self, parent=None):
super(MyWindow, self).__init__(parent)
self.setupUi(self)
@ -29,7 +26,6 @@ class MyWindow(QMainWindow, Ui_MainWindow):
# 设置信号与槽
def CreateSignalSlot(self):
self.wifi_recv_open_pushButton.clicked.connect(self.wifi_recv_open_pushButton_clicked)
self.velocity_horizontalSlider.valueChanged.connect(self.velocity_horizontalSlider_valueChanged)
self.wifi_config_pushButton.clicked.connect(self.wifi_config_pushButton_clicked)
@ -54,16 +50,14 @@ class MyWindow(QMainWindow, Ui_MainWindow):
# 绘图对象
self.plotWidget = pg.PlotWidget()
self.plotWidget.showGrid(x=True, y=True, alpha=0.5)
self.controlPlotWidget = ControlPlotPanel(controllerPlotWidget=self)
# 图表可视化数组
signalColors = [RED_COLOR, BLUE_COLOR, PURPLE_COLOR, YELLOW_COLOR,
MAROON_COLOR, ORANGE_COLOR, GREEN_COLOR]
signalIcons = ['reddot', 'bluedot', 'purpledot', 'yellowdot', 'maroondot', 'orangedot', 'greendot']
self.numberOfSamples = 300
self.signalDataArrays = []
self.signalPlots = []
self.signalPlotFlags = []
self.timeArray = np.arange(-self.numberOfSamples, 0, 1)
for (sig, sigColor, tooltip) in zip(self.re_item, signalColors, self.re_item):
for (sig, sigColor, checkBox,tooltip) in zip(self.re_item, self.signalColors, self.controlPlotWidget.signalCheckBox,self.re_item):
# define signal plot data array
self.signalDataArrays.append(np.zeros(self.numberOfSamples))
# configure signal plot parameters
@ -76,7 +70,7 @@ class MyWindow(QMainWindow, Ui_MainWindow):
self.signalPlotFlags.append(True)
self.gridLayout.addWidget(self.plotWidget)
self.tool_layout.addWidget(self.controlPlotWidget)
# 滑条绑定
def velocity_horizontalSlider_valueChanged(self):
self.target_velocity = self.velocity_horizontalSlider.value()
@ -85,32 +79,27 @@ class MyWindow(QMainWindow, Ui_MainWindow):
print(str(self.target_velocity))
def wifi_config_pushButton_clicked(self):
try:
print(self.wifi_IP_lineEdit.text(),type(self.wifi_IP_lineEdit.text()))
self.udp.udpClientSocket.bind((self.wifi_IP_lineEdit.text(), 2333))
# 第一次接受数据,用于判断项目数,
recv_data = self.udp.udpClientSocket.recv(1024)
recv_data = recv_data.decode('utf-8')
recv_data = recv_data[:-1]
recv_data = recv_data.split(',')
"""处理接受的信息"""
for i, data in enumerate(recv_data):
self.re_item.append(''.join(re.split(r'[^A-Za-z]', data)))
print(self.re_item)
# 图表初始化
self.re_item = ['k','g','l','t']
self.plot_init()
t1 = threading.Thread(target=self.udp_recv)
t1.start()
self.wifi_recv_open_pushButton.setEnabled(True)
except:
# print(self.wifi_IP_lineEdit.text(),type(self.wifi_IP_lineEdit.text()))
# self.udp.udpClientSocket.bind((self.wifi_IP_lineEdit.text(), 2333))
# # 第一次接受数据,用于判断项目数,
# recv_data = self.udp.udpClientSocket.recv(1024)
# recv_data = recv_data.decode('utf-8')
# recv_data = recv_data[:-1]
# recv_data = recv_data.split(',')
# """处理接受的信息"""
# for i, data in enumerate(recv_data):
# self.re_item.append(''.join(re.split(r'[^A-Za-z]', data)))
# print(self.re_item)
# # 图表初始化
# self.plot_init()
# t1 = threading.Thread(target=self.udp_recv)
# t1.start()
# self.wifi_recv_open_pushButton.setEnabled(True)
except Exception as e:
print(e)
QMessageBox.critical(self, "错误", '该请求的地址无效')
def wifi_recv_open_pushButton_clicked(self):
if self.wifi_recv_flag == 0:
# 打开wifi接收
self.wifi_recv_flag = 1
self.wifi_recv_open_pushButton.setText('关闭')
else:
self.wifi_recv_flag = 0
self.wifi_recv_open_pushButton.setText('打开')
def udp_recv(self):
while self.close_flag:
recv_data = self.udp.udpClientSocket.recv(1024)
@ -136,6 +125,53 @@ class MyWindow(QMainWindow, Ui_MainWindow):
def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
self.close_flag = 0
class ControlPlotPanel(QtWidgets.QWidget):
def __init__(self, parent=None, controllerPlotWidget=None):
'''Constructor for ToolsWidget'''
super().__init__(parent)
self.controlledPlot = controllerPlotWidget
self.horizontalLayout1 = QtWidgets.QHBoxLayout()
self.horizontalLayout1.setObjectName('horizontalLayout')
self.setLayout(self.horizontalLayout1)
self.startStopButton = QtWidgets.QPushButton(self)
self.startStopButton.setText('Start')
self.startStopButton.setObjectName('Start')
self.startStopButton.clicked.connect(self.wifi_recv_open_pushButton_clicked)
self.startStopButton.setIcon(GUIToolKit.getIconByName('start'))
self.horizontalLayout1.addWidget(self.startStopButton)
self.zoomAllButton = QtWidgets.QPushButton(self)
self.zoomAllButton.setObjectName('zoomAllButton')
self.zoomAllButton.setText('View all')
self.zoomAllButton.setIcon(GUIToolKit.getIconByName('zoomall'))
self.zoomAllButton.clicked.connect(self.zoomAllPlot)
self.horizontalLayout1.addWidget(self.zoomAllButton)
self.signalCheckBox = []
for i in range(len(self.controlledPlot.re_item)):
checkBox = QtWidgets.QCheckBox(self)
checkBox.setObjectName('signalCheckBox' + str(i))
checkBox.setToolTip(self.controlledPlot.re_item[i])
checkBox.setText(self.controlledPlot.re_item[i])
checkBox.setIcon(GUIToolKit.getIconByName(self.controlledPlot.signalIcons[i]))
checkBox.setChecked(True)
self.signalCheckBox.append(checkBox)
self.horizontalLayout1.addWidget(checkBox)
def zoomAllPlot(self):
self.controlledPlot.plotWidget.enableAutoRange()
def wifi_recv_open_pushButton_clicked(self):
if self.controlledPlot.wifi_recv_flag == 0:
# 打开wifi接收
self.controlledPlot.wifi_recv_flag = 1
self.startStopButton.setText('Stop')
else:
self.controlledPlot.wifi_recv_flag = 0
self.startStopButton.setText('Start')
if __name__ == '__main__':
app = QApplication(sys.argv)
myWin = MyWindow()

View File

@ -14,11 +14,11 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 749)
MainWindow.resize(1187, 707)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setGeometry(QtCore.QRect(20, 420, 241, 61))
self.groupBox.setGeometry(QtCore.QRect(20, 460, 241, 61))
self.groupBox.setObjectName("groupBox")
self.horizontalLayoutWidget = QtWidgets.QWidget(self.groupBox)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 20, 221, 31))
@ -34,7 +34,7 @@ class Ui_MainWindow(object):
self.wifi_config_pushButton.setObjectName("wifi_config_pushButton")
self.horizontalLayout.addWidget(self.wifi_config_pushButton)
self.horizontalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(570, 440, 104, 31))
self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(590, 480, 104, 31))
self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
@ -46,7 +46,7 @@ class Ui_MainWindow(object):
self.velocity_lineEdit.setObjectName("velocity_lineEdit")
self.horizontalLayout_2.addWidget(self.velocity_lineEdit)
self.velocity_horizontalSlider = QtWidgets.QSlider(self.centralwidget)
self.velocity_horizontalSlider.setGeometry(QtCore.QRect(410, 420, 261, 22))
self.velocity_horizontalSlider.setGeometry(QtCore.QRect(430, 460, 261, 22))
self.velocity_horizontalSlider.setMinimum(-150)
self.velocity_horizontalSlider.setMaximum(150)
self.velocity_horizontalSlider.setOrientation(QtCore.Qt.Horizontal)
@ -54,7 +54,7 @@ class Ui_MainWindow(object):
self.velocity_horizontalSlider.setTickInterval(10)
self.velocity_horizontalSlider.setObjectName("velocity_horizontalSlider")
self.horizontalLayoutWidget_3 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_3.setGeometry(QtCore.QRect(400, 440, 134, 31))
self.horizontalLayoutWidget_3.setGeometry(QtCore.QRect(420, 480, 134, 31))
self.horizontalLayoutWidget_3.setObjectName("horizontalLayoutWidget_3")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_3)
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
@ -66,21 +66,23 @@ class Ui_MainWindow(object):
self.angle_lineEdit.setObjectName("angle_lineEdit")
self.horizontalLayout_3.addWidget(self.angle_lineEdit)
self.groupBox_2 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_2.setGeometry(QtCore.QRect(190, 0, 601, 391))
self.groupBox_2.setGeometry(QtCore.QRect(370, 10, 811, 431))
self.groupBox_2.setObjectName("groupBox_2")
self.gridLayoutWidget = QtWidgets.QWidget(self.groupBox_2)
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 20, 581, 361))
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 20, 791, 361))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.wifi_recv_open_pushButton = QtWidgets.QPushButton(self.centralwidget)
self.wifi_recv_open_pushButton.setEnabled(False)
self.wifi_recv_open_pushButton.setGeometry(QtCore.QRect(190, 390, 93, 28))
self.wifi_recv_open_pushButton.setObjectName("wifi_recv_open_pushButton")
self.horizontalLayoutWidget_4 = QtWidgets.QWidget(self.groupBox_2)
self.horizontalLayoutWidget_4.setGeometry(QtCore.QRect(10, 370, 791, 51))
self.horizontalLayoutWidget_4.setObjectName("horizontalLayoutWidget_4")
self.tool_layout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_4)
self.tool_layout.setContentsMargins(0, 0, 0, 0)
self.tool_layout.setObjectName("tool_layout")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setGeometry(QtCore.QRect(0, 0, 1187, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
@ -101,4 +103,3 @@ class Ui_MainWindow(object):
self.label_2.setText(_translate("MainWindow", "目标角度:"))
self.angle_lineEdit.setText(_translate("MainWindow", "149"))
self.groupBox_2.setTitle(_translate("MainWindow", "GroupBox"))
self.wifi_recv_open_pushButton.setText(_translate("MainWindow", "打开"))

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>749</height>
<width>1187</width>
<height>707</height>
</rect>
</property>
<property name="windowTitle">
@ -18,7 +18,7 @@
<property name="geometry">
<rect>
<x>20</x>
<y>420</y>
<y>460</y>
<width>241</width>
<height>61</height>
</rect>
@ -59,8 +59,8 @@
<widget class="QWidget" name="horizontalLayoutWidget_2">
<property name="geometry">
<rect>
<x>570</x>
<y>440</y>
<x>590</x>
<y>480</y>
<width>104</width>
<height>31</height>
</rect>
@ -85,8 +85,8 @@
<widget class="QSlider" name="velocity_horizontalSlider">
<property name="geometry">
<rect>
<x>410</x>
<y>420</y>
<x>430</x>
<y>460</y>
<width>261</width>
<height>22</height>
</rect>
@ -110,8 +110,8 @@
<widget class="QWidget" name="horizontalLayoutWidget_3">
<property name="geometry">
<rect>
<x>400</x>
<y>440</y>
<x>420</x>
<y>480</y>
<width>134</width>
<height>31</height>
</rect>
@ -136,10 +136,10 @@
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>190</x>
<y>0</y>
<width>601</width>
<height>391</height>
<x>370</x>
<y>10</y>
<width>811</width>
<height>431</height>
</rect>
</property>
<property name="title">
@ -150,28 +150,23 @@
<rect>
<x>10</x>
<y>20</y>
<width>581</width>
<width>791</width>
<height>361</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout"/>
</widget>
</widget>
<widget class="QPushButton" name="wifi_recv_open_pushButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>190</x>
<y>390</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>打开</string>
</property>
<widget class="QWidget" name="horizontalLayoutWidget_4">
<property name="geometry">
<rect>
<x>10</x>
<y>370</y>
<width>791</width>
<height>51</height>
</rect>
</property>
<layout class="QHBoxLayout" name="tool_layout"/>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
@ -179,7 +174,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<width>1187</width>
<height>26</height>
</rect>
</property>

Binary file not shown.

After

Width:  |  Height:  |  Size: 838 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 823 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 934 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 829 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 501 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 818 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 907 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 997 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 999 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 806 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,74 @@
import os
from PyQt5 import QtGui, QtWidgets, QtCore
class GUIToolKit(object):
''' This class is used to provide icons for the rest of the application
hiding the location of the resources
'''
RED_COLOR = (255, 92, 92)
GREEN_COLOR = (57, 217, 138)
BLUE_COLOR = (91, 141, 236)
ORANGE_COLOR = (253, 172, 66)
YELLOW_COLOR = (255,255,51)
PURPLE_COLOR = (75,0,130)
MAROON_COLOR = (222,184,135)
@staticmethod
def getIconByName(icoName):
file_index = {
'add': 'add.png',
'add_motor': 'add_motor.png',
'tree': 'tree.png',
'gen': 'gen.png',
'home': 'home.png',
'form': 'form.png',
'edit': 'edit.png',
'delete': 'delete.png',
'statistics': 'statistics.png',
'reddot': 'reddot.png',
'orangedot': 'orangedot.png',
'greendot': 'greendot.png',
'bluedot': 'bluedot.png',
'purpledot': 'purpledot.png',
'yellowdot': 'yellowdot.png',
'maroondot': 'maroondot.png',
'send': 'send.png',
'zoomall': 'zoomall.png',
'connect': 'connect.png',
'continue': 'continue.png',
'alert': 'alert.png',
'gear': 'gear.png',
'generalsettings': 'generalsettings.png',
'open': 'open.png',
'loop': 'loop.png',
'save': 'save.png',
'stop': 'stop.png',
'restart': 'continue.png',
'res': 'res.png',
'sensor': 'sensor.png',
'start': 'start.png',
'motor': 'motor.png',
'pause': 'pause.png',
'pull': 'pull.png',
'push': 'push.png',
'list': 'list.png',
'disconnect': 'disconnect.png',
'configure': 'configure.png',
'pidconfig': 'pidconfig.png',
'consoletool': 'consoletool.png',
'fordward': 'fordward.png',
'fastbackward': 'fastbackward.png',
'backward': 'backward.png',
'stopjogging': 'stopjogging.png',
'fastfordward': 'fastfordward.png',
'customcommands':'customcommands.png'
}
currentDir = os.path.dirname(__file__)
icon_path = os.path.join(currentDir, './resources', file_index[icoName])
print(icon_path)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(icon_path), QtGui.QIcon.Normal,
QtGui.QIcon.Off)
return icon