20240316175500
This commit is contained in:
parent
4c83e9e960
commit
9e9add9e4a
60
main.py
60
main.py
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import sys
|
||||
import site
|
||||
import time
|
||||
import logging
|
||||
import pyaudio
|
||||
|
@ -9,7 +10,7 @@ import threading
|
|||
import subprocess
|
||||
from sounddevice import PortAudioError
|
||||
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QMessageBox, QPushButton, QHBoxLayout
|
||||
from PyQt5.QtCore import QTimer, Qt, QPoint, QLibraryInfo
|
||||
from PyQt5.QtCore import QTimer, Qt, QPoint, QCoreApplication
|
||||
|
||||
|
||||
class LoggerFileHandler:
|
||||
|
@ -28,19 +29,19 @@ class LoggerConsHandler:
|
|||
class Logger:
|
||||
logger = None
|
||||
levels = {
|
||||
"CRITICAL": logging.CRITICAL,
|
||||
"FATAL": logging.FATAL,
|
||||
"ERROR": logging.ERROR,
|
||||
"WARNING": logging.WARNING,
|
||||
"WARN": logging.WARN,
|
||||
"INFO": logging.INFO,
|
||||
"DEBUG": logging.DEBUG,
|
||||
"NOTSET": logging.NOTSET,
|
||||
"D": logging.DEBUG,
|
||||
"I": logging.INFO,
|
||||
"W": logging.WARNING,
|
||||
"E": logging.ERROR,
|
||||
"F": logging.FATAL
|
||||
'CRITICAL': logging.CRITICAL,
|
||||
'FATAL': logging.FATAL,
|
||||
'ERROR': logging.ERROR,
|
||||
'WARNING': logging.WARNING,
|
||||
'WARN': logging.WARN,
|
||||
'INFO': logging.INFO,
|
||||
'DEBUG': logging.DEBUG,
|
||||
'NOTSET': logging.NOTSET,
|
||||
'D': logging.DEBUG,
|
||||
'I': logging.INFO,
|
||||
'W': logging.WARNING,
|
||||
'E': logging.ERROR,
|
||||
'F': logging.FATAL
|
||||
}
|
||||
default_format = '{asctime} - {name} - {levelname[0]}: {message}'
|
||||
default_format_style = '{'
|
||||
|
@ -187,7 +188,7 @@ def is_audio_device_connected(device_name):
|
|||
for i in range(audio.get_device_count()):
|
||||
device_info = audio.get_device_info_by_index(i)
|
||||
if device_info.get('maxInputChannels') > 0 or device_info.get('maxOutputChannels') > 0:
|
||||
device_list.append(device_info["name"])
|
||||
device_list.append(device_info['name'])
|
||||
audio.terminate()
|
||||
for item in device_list:
|
||||
if device_name in item:
|
||||
|
@ -203,7 +204,7 @@ class MainWindow(QWidget):
|
|||
sys.exit()
|
||||
self.play_controlled = 0
|
||||
try:
|
||||
self.audio_device_name = open(os.path.join(os.path.dirname(__file__), 'AudioDevice.ini'), "r", encoding="utf-8").read().strip()
|
||||
self.audio_device_name = open(os.path.join(os.path.dirname(__file__), 'AudioDevice.ini'), 'r', encoding='utf-8').read().strip()
|
||||
except Exception as err:
|
||||
self.audio_device_name = '*'
|
||||
QMessageBox.warning(self, '错误', '%s' % (str(err),))
|
||||
|
@ -217,20 +218,20 @@ class MainWindow(QWidget):
|
|||
self.setWindowTitle(self.title)
|
||||
self.setGeometry(0, 0, 200, 100)
|
||||
self.status_label = QLabel('暂无节目播放', self)
|
||||
self.status_label.setStyleSheet("font-size: 20px; font-family: 'Microsoft YaHei'; color: #ffffff;")
|
||||
self.status_label.setStyleSheet('font-size: 20px; font-family: \'Microsoft YaHei\'; color: #ffffff;')
|
||||
self.status_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
||||
self.status_label.setFixedSize(200, 40)
|
||||
|
||||
self.bt_next_shortcut = "F5"
|
||||
self.bt_next_shortcut = 'F5'
|
||||
self.bt_next = QPushButton('%s(%s)' % ('切换', self.bt_next_shortcut), self)
|
||||
self.bt_next.setShortcut(self.bt_next_shortcut)
|
||||
self.bt_next.setStyleSheet("font-size: 14px; font-family: 'Microsoft YaHei'; color: #ffffff;")
|
||||
self.bt_next.setStyleSheet('font-size: 14px; font-family: \'Microsoft YaHei\'; color: #ffffff;')
|
||||
self.bt_next.clicked.connect(self.button_next)
|
||||
|
||||
self.bt_stop_shortcut = "F6"
|
||||
self.bt_stop_shortcut = 'F6'
|
||||
self.bt_stop = QPushButton('%s(%s)' % ('停止', self.bt_stop_shortcut), self)
|
||||
self.bt_stop.setShortcut(self.bt_stop_shortcut)
|
||||
self.bt_stop.setStyleSheet("font-size: 14px; font-family: 'Microsoft YaHei'; color: #ffffff;")
|
||||
self.bt_stop.setStyleSheet('font-size: 14px; font-family: \'Microsoft YaHei\'; color: #ffffff;')
|
||||
self.bt_stop.clicked.connect(self.button_stop)
|
||||
|
||||
layout = QHBoxLayout()
|
||||
|
@ -260,13 +261,13 @@ class MainWindow(QWidget):
|
|||
|
||||
def check_device_status(self):
|
||||
if self.audio_device_name == '*' or is_audio_device_connected(self.audio_device_name):
|
||||
self.setStyleSheet('background-color: #61b64a;')
|
||||
self.setStyleSheet('background-color: #62AC3E;')
|
||||
if (self.play_controlled == 0) == 1:
|
||||
self.play_controlled = 1
|
||||
# audio device connect
|
||||
bat_thread = threading.Thread(
|
||||
target=subprocess.run,
|
||||
args=(os.path.join(os.path.dirname(__file__), "EventConnect.bat"),),
|
||||
args=(os.path.join(os.path.dirname(__file__), 'EventConnect.bat'),),
|
||||
kwargs={'shell': True, 'stdout': subprocess.DEVNULL, 'stderr': subprocess.DEVNULL}
|
||||
)
|
||||
bat_thread.start()
|
||||
|
@ -278,7 +279,7 @@ class MainWindow(QWidget):
|
|||
# audio device disconn
|
||||
bat_thread = threading.Thread(
|
||||
target=subprocess.run,
|
||||
args=(os.path.join(os.path.dirname(__file__), "EventDisconn.bat"),),
|
||||
args=(os.path.join(os.path.dirname(__file__), 'EventDisconn.bat'),),
|
||||
kwargs={'shell': True, 'stdout': subprocess.DEVNULL, 'stderr': subprocess.DEVNULL}
|
||||
)
|
||||
bat_thread.start()
|
||||
|
@ -293,25 +294,25 @@ class MainWindow(QWidget):
|
|||
player.stop() if player.play_status else player.play()
|
||||
|
||||
def event_play(self):
|
||||
self.status_label.setStyleSheet("font-size: 20px; font-family: 'Microsoft YaHei'; color: #ffffff;")
|
||||
self.status_label.setStyleSheet('font-size: 20px; font-family: \'Microsoft YaHei\'; color: #ffffff;')
|
||||
self.title = '正在播放'
|
||||
self.bt_stop.setText('%s(%s)' % ('停止', self.bt_stop_shortcut))
|
||||
self.bt_stop.setShortcut(self.bt_stop_shortcut)
|
||||
bat_thread = threading.Thread(
|
||||
target=subprocess.run,
|
||||
args=(os.path.join(os.path.dirname(__file__), "EventPlay.bat"),),
|
||||
args=(os.path.join(os.path.dirname(__file__), 'EventPlay.bat'),),
|
||||
kwargs={'shell': True, 'stdout': subprocess.DEVNULL, 'stderr': subprocess.DEVNULL}
|
||||
)
|
||||
bat_thread.start()
|
||||
|
||||
def event_stop(self):
|
||||
self.status_label.setStyleSheet("font-size: 20px; font-family: 'Microsoft YaHei'; color: #dd0000;")
|
||||
self.status_label.setStyleSheet('font-size: 20px; font-family: \'Microsoft YaHei\'; color: #dd0000;')
|
||||
self.title = '停止播放'
|
||||
self.bt_stop.setText('%s(%s)' % ('播放', self.bt_stop_shortcut))
|
||||
self.bt_stop.setShortcut(self.bt_stop_shortcut)
|
||||
bat_thread = threading.Thread(
|
||||
target=subprocess.run,
|
||||
args=(os.path.join(os.path.dirname(__file__), "EventStop.bat"),),
|
||||
args=(os.path.join(os.path.dirname(__file__), 'EventStop.bat'),),
|
||||
kwargs={'shell': True, 'stdout': subprocess.DEVNULL, 'stderr': subprocess.DEVNULL}
|
||||
)
|
||||
bat_thread.start()
|
||||
|
@ -322,7 +323,8 @@ class MainWindow(QWidget):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = QLibraryInfo.location(QLibraryInfo.PluginsPath)
|
||||
for i in site.getsitepackages():
|
||||
i.endswith('site-packages') and QCoreApplication.addLibraryPath(os.path.abspath(os.path.join(i, 'PyQt5/Qt5/plugins')))
|
||||
app = QApplication(sys.argv)
|
||||
window_main = MainWindow()
|
||||
player.callback_play = window_main.event_play
|
||||
|
|
Loading…
Reference in New Issue