У меня есть Pyqt5 GUI, который отображает видео с использованием потоков UDP
есть кнопки, которые активируют определенные кнопки как (SD1 или SD2 или SD3 активируют TP1 и TP2), а источник 1 активирует TP5 и TP6 и так далее
после нажатия на SD1, TP1 и TP2 будут активны, и если мы нажмем на TP1, он покажет справа определенный поток UDP с названием программы.
но когда я пытаюсь щелкнуть другой SD или источник, мне нравится, когда нужно сбросить старое состояние кнопки и остановить воспроизведение видео и сбросить все кнопки, поэтому у меня не так много кнопок, которые нажимаются и включаются одновременно время.
вот код:
####################################### Important Libraries ##################################
import vlc
import os
import sys
import threading
from QLed import QLed
from functools import partial
from PyQt5.QtGui import QColor, QFont
from PyQt5.QtGui import QPainter, QPen
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QDir, Qt, QUrl, QSize, QPoint, QTimer
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QMainWindow
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QGridLayout, QLCDNumber
class MainProg(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainProg, self).__init__(parent)
self.setObjectName("MainWindow")
self.setFixedSize(1280, 768)
self.setStyleSheet("")
self.setWindowTitle("video player ")
self.instance = vlc.Instance()
self.mediaplayer = self.instance.media_player_new()
################# The Test Points LEDs ######################
self.TPL1 = QLed(self, onColour=QLed.Orange, shape=QLed.Round)
self.TPL1.setGeometry(QtCore.QRect(190, 500, 35, 25))
self.TPL3 = QLed(self, onColour=QLed.Orange, shape=QLed.Round)
self.TPL3.setGeometry(QtCore.QRect(440, 525, 35, 25))
######################## Test Points Geo ##############################################
self.Testpunk1 = QtWidgets.QPushButton(self)
self.Testpunk1.setGeometry(QtCore.QRect(190, 460, 31, 31))
self.Testpunk1.setObjectName("TP1")
self.Testpunk2 = QtWidgets.QPushButton(self)
self.Testpunk2.setGeometry(QtCore.QRect(190, 530, 31, 31))
self.Testpunk2.setObjectName("TP2")
self.Testpunk5 = QtWidgets.QPushButton(self)
self.Testpunk5.setGeometry(QtCore.QRect(440, 490, 31, 31))
self.Testpunk5.setObjectName("TP5")
self.Testpunk6 = QtWidgets.QPushButton(self)
self.Testpunk6.setGeometry(QtCore.QRect(440, 550, 31, 31))
self.Testpunk6.setObjectName("TP6")
##########set text
self.Testpunk1.setText(("TP1"))
self.Testpunk2.setText(("TP2"))
self.Testpunk5.setText(("TP5"))
self.Testpunk6.setText(("TP6"))
############################ The Video and frame #################################
self.videoframe = QtWidgets.QFrame(self)
self.videoframe.setGeometry(QtCore.QRect(850, 40, 391, 291))
self.videoframe.setFrameShape(QtWidgets.QFrame.Box)
self.videoframe.setFrameShadow(QtWidgets.QFrame.Raised)
self.vboxlayout = QVBoxLayout()
self.vboxlayout.addWidget(self.videoframe)
self.mediaplayer.set_hwnd(int(self.videoframe.winId()))
########################################################################################
########################## SD and HD buttons############################################
self.EspSD = QtWidgets.QToolButton(self, text="SD1", checkable=True)
self.EspSD.setGeometry(QtCore.QRect(140, 170, 31, 32))
self.EspSD.setObjectName("SD")
self.DeuSD = QtWidgets.QToolButton(self, text="SD2", checkable=True)
self.DeuSD.setGeometry(QtCore.QRect(140, 220, 31, 32))
self.DeuSD.setObjectName("DeSD")
self.DeupSD = QtWidgets.QToolButton(self, text="SD2", checkable=True)
self.DeupSD.setGeometry(QtCore.QRect(140, 270, 31, 32))
self.DeupSD.setObjectName("DpSD")
##########################source buttons############################################
self.IntS = QtWidgets.QToolButton(self, text="Source5", checkable=True)
self.IntS.setGeometry(QtCore.QRect(240, 170, 65, 32))
self.IntS.setObjectName("5")
self.AstD = QtWidgets.QToolButton(self, text="Source6", checkable=True)
self.AstD.setGeometry(QtCore.QRect(240, 220, 65, 32))
self.AstD.setObjectName("6")
self.IntSdep = QtWidgets.QToolButton(self, text="Source7", checkable=True)
self.IntSdep.setGeometry(QtCore.QRect(240, 270, 65, 32))
self.IntSdep.setObjectName("7")
################################### The Main Window Labels ############################
self.CurrentPro = QtWidgets.QLabel(self)
self.CurrentPro.setFont(QFont('Arial', 10))
self.CurrentPro.setGeometry(QtCore.QRect(580, 55, 140, 35))
self.CurrentPro.setText("Current Program :")
self.CurrentProL = QtWidgets.QLabel(self)
self.CurrentProL.setFont(QFont('Arial', 10))
self.CurrentProL.setGeometry(QtCore.QRect(690, 55, 155, 35))
#################################### The Main Programm Functions ######################
self.Testpunk1.clicked.connect(self.on_tp_clicked_Enc)
self.Testpunk2.clicked.connect(self.on_tp_clicked_Enc)
self.Testpunk5.clicked.connect(self.on_tp_clicked_Mux)
self.Testpunk6.clicked.connect(self.on_tp_clicked_Mux)
self.current_button = None
#self.process = QtCore.QProcess(self)
def on_tp_clicked_Enc(self):
self.TPL1.setValue(True)
if self.EspSD.isChecked():
urls_map = {
self.Testpunk1: "udp://@239.168.1.6:1113",
self.Testpunk2: "udp://@239.168.1.7:1117",
}
url = urls_map.get(self.sender(), "")
if url:
self.play(url)
self.CurrentProL.setText("Program4")
if self.DeuSD.isChecked():
urls_map = {
self.Testpunk1: "udp://@239.168.1.6:1123",
self.Testpunk2: "udp://@239.168.1.7:1127",
}
url = urls_map.get(self.sender(), "")
if url:
self.play(url)
#self.current_button = self.sender()
#self.current_button.setEnabled(False)
self.CurrentProL.setText("Program5")
if self.DeupSD.isChecked():
urls_map = {
self.Testpunk1: "udp://@239.168.1.6:1121",
self.Testpunk2: "udp://@239.168.1.7:1125",
}
url = urls_map.get(self.sender(), "")
if url:
self.play(url)
self.CurrentProL.setText("Program6")
@QtCore.pyqtSlot()
def on_tp_clicked_Mux(self):
self.TPL3.setValue(True) # the LED ON code
if self.IntS.isChecked():
urls_map = {
self.Testpunk5: "udp://@239.168.2.6:2113",
self.Testpunk6: "udp://@239.168.2.7:2123",
}
url = urls_map.get(self.sender(), "")
if url:
self.play(url)
self.CurrentProL.setText("Program3 Source3")
if self.AstD.isChecked():
urls_map = {
self.Testpunk5: "udp://@239.168.2.6:2117",
self.Testpunk6: "udp://@239.168.2.7:2127",
}
url = urls_map.get(self.sender(), "")
if url:
self.play(url)
self.CurrentProL.setText("Program4 Source4")
if self.IntSdep.isChecked():
urls_map = {
self.Testpunk5: "udp://@239.168.2.6:2113",
self.Testpunk6: "udp://@239.168.2.7:2123",
}
url = urls_map.get(self.sender(), "")
if url:
self.play(url)
self.CurrentProL.setText("Program4 Source5")
def play(self, url):
print('the url arrived')
self.media = self.instance.media_new(url)
self.media.get_mrl()
self.mediaplayer.set_media(self.media)
print('last step before video viewing')
self.mediaplayer.play()
#self.TPL1.setValue(False) # the LED ON code
#self.TPL2.setValue(False)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainProg()
w.show()
sys.exit(app.exec_())
############################## End of the Code #########################