Skip to content

Commit

Permalink
Merge pull request #41 from cyh1998/dev-GUI
Browse files Browse the repository at this point in the history
GUI版本更新
  • Loading branch information
Beadd committed Jun 2, 2023
2 parents a52bba3 + b67a9b1 commit 40d75f2
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 126 deletions.
43 changes: 41 additions & 2 deletions EyeD3Music.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@ class Stream(QtCore.QObject):
def write(self, text):
self.textPrint.emit(str(text))

class DownloadWork(QtCore.QObject):
end_sig = QtCore.pyqtSignal()

def __init__(self):
super(DownloadWork, self).__init__()

def download_music(self, mode, id):
musicdownloader.gui_download(mode, id)
self.end_sig.emit()

class MainWindow(QMainWindow, Ui_MusicDownloader):
begin_sig = QtCore.pyqtSignal(int, str)

def __init__(self):
super(MainWindow, self).__init__()
self.setupUi(self)
Expand All @@ -29,8 +41,19 @@ def __init__(self):
self.HDCheckBox.stateChanged.connect(self.hd_state_changed)
self.DownloadPushButton.clicked.connect(self.download_clicked)

# 下载线程初始化
self.download_thread = QtCore.QThread()
self.download_work = DownloadWork()
self.download_work.moveToThread(self.download_thread)
# 下载线程信号绑定
self.begin_sig.connect(self.download_work.download_music)
self.download_work.end_sig.connect(self.download_thread_end)
# 启动线程
self.download_thread.start()

# 关闭响应
def closeEvent(self, event):
self.download_thread.quit()
sys.stdout = stdout_temp
super().closeEvent(event)

Expand All @@ -46,9 +69,19 @@ def output_print(self, text):
def init_style(self):
self.ModeComboBox.setView(QListView())
self.UrlIdLineEdit.setPlaceholderText("请输入网易云单曲ID或链接")
# self.PrintTextEdit.setStyleSheet("color: white; background-color: black")
self.APILineEdit.setText("http://api.injahow.cn/meting/")

# 界面激活
def gui_enabled(self, enabled):
self.ModeComboBox.setEnabled(enabled)
self.UrlIdLineEdit.setEnabled(enabled)
self.APILineEdit.setEnabled(enabled)
self.FrontArtistCheckBox.setEnabled(enabled)
self.RearArtistCheckBox.setEnabled(enabled)
self.LyricCheckBox.setEnabled(enabled)
self.HDCheckBox.setEnabled(enabled)
self.DownloadPushButton.setEnabled(enabled)

# 下载模式修改
def mode_current_index_changed(self, currentIndex):
self.UrlIdLineEdit.clear()
Expand Down Expand Up @@ -82,9 +115,15 @@ def hd_state_changed(self):

# 下载
def download_clicked(self):
self.gui_enabled(False)

mode = self.ModeComboBox.currentIndex() + 1
id = self.UrlIdLineEdit.text()
musicdownloader.gui_download(mode ,id)
self.begin_sig.emit(mode, id)

# 下载完成
def download_thread_end(self):
self.gui_enabled(True)

if __name__ == "__main__":
app = QApplication(sys.argv)
Expand Down
134 changes: 69 additions & 65 deletions MusicDownloader.ui
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<property name="windowTitle">
<string>MusicDownloader</string>
</property>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
Expand All @@ -35,61 +35,19 @@
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="ModeComboBox">
<property name="styleSheet">
<string notr="true">QComboBox QAbstractItemView
{
border: 2px solid darkgray;
selection-background-color: lightgray;
}
QComboBox QAbstractItemView::item
{
height:16px;
}</string>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>歌曲API服务器:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<item>
<property name="text">
<string>网易云单曲</string>
</property>
</item>
<item>
<property name="text">
<string>网易云歌单</string>
</property>
</item>
<item>
<property name="text">
<string>QQ音乐单曲</string>
</property>
</item>
<item>
<property name="text">
<string>QQ音乐歌单</string>
</property>
</item>
<item>
<property name="text">
<string>网易云专辑</string>
</property>
</item>
<item>
<property name="text">
<string>网易云歌手下载</string>
</property>
</item>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="UrlIdLineEdit"/>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="DownloadPushButton">
<property name="text">
<string>下 载</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
Expand Down Expand Up @@ -144,13 +102,72 @@ QComboBox QAbstractItemView::item
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="ModeComboBox">
<property name="styleSheet">
<string notr="true">QComboBox QAbstractItemView
{
border: 2px solid darkgray;
selection-background-color: lightgray;
}
QComboBox QAbstractItemView::item
{
height:16px;
}</string>
</property>
<item>
<property name="text">
<string>网易云单曲</string>
</property>
</item>
<item>
<property name="text">
<string>网易云歌单</string>
</property>
</item>
<item>
<property name="text">
<string>QQ音乐单曲</string>
</property>
</item>
<item>
<property name="text">
<string>QQ音乐歌单</string>
</property>
</item>
<item>
<property name="text">
<string>网易云专辑</string>
</property>
</item>
<item>
<property name="text">
<string>网易云歌手下载</string>
</property>
</item>
</widget>
</item>
<item row="1" column="2" colspan="2">
<widget class="QLineEdit" name="APILineEdit"/>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="DownloadPushButton">
<property name="text">
<string>下 载</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">
<widget class="QTextEdit" name="PrintTextEdit">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 0, 0);</string>
<string notr="true">background-color: rgb(0, 0, 0);
color: rgb(225, 225, 225);</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
Expand All @@ -161,19 +178,6 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="1" column="2" colspan="2">
<widget class="QLineEdit" name="APILineEdit"/>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>歌曲API服务器:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down
90 changes: 46 additions & 44 deletions MusicDownloader_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,40 @@ def setupUi(self, MusicDownloader):
MusicDownloader.resize(700, 350)
MusicDownloader.setMinimumSize(QtCore.QSize(700, 350))
MusicDownloader.setMaximumSize(QtCore.QSize(700, 350))
self.widget = QtWidgets.QWidget(MusicDownloader)
self.widget.setGeometry(QtCore.QRect(10, 10, 681, 331))
self.widget.setObjectName("widget")
self.gridLayout = QtWidgets.QGridLayout(self.widget)
self.layoutWidget = QtWidgets.QWidget(MusicDownloader)
self.layoutWidget.setGeometry(QtCore.QRect(10, 10, 681, 331))
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.layoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.ModeComboBox = QtWidgets.QComboBox(self.widget)
self.label = QtWidgets.QLabel(self.layoutWidget)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 1, 0, 1, 2)
self.UrlIdLineEdit = QtWidgets.QLineEdit(self.layoutWidget)
self.UrlIdLineEdit.setObjectName("UrlIdLineEdit")
self.gridLayout.addWidget(self.UrlIdLineEdit, 0, 2, 1, 1)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
self.horizontalLayout.setObjectName("horizontalLayout")
self.FrontArtistCheckBox = QtWidgets.QCheckBox(self.layoutWidget)
self.FrontArtistCheckBox.setObjectName("FrontArtistCheckBox")
self.horizontalLayout.addWidget(self.FrontArtistCheckBox)
self.RearArtistCheckBox = QtWidgets.QCheckBox(self.layoutWidget)
self.RearArtistCheckBox.setObjectName("RearArtistCheckBox")
self.horizontalLayout.addWidget(self.RearArtistCheckBox)
self.LyricCheckBox = QtWidgets.QCheckBox(self.layoutWidget)
self.LyricCheckBox.setChecked(True)
self.LyricCheckBox.setObjectName("LyricCheckBox")
self.horizontalLayout.addWidget(self.LyricCheckBox)
self.HDCheckBox = QtWidgets.QCheckBox(self.layoutWidget)
self.HDCheckBox.setChecked(True)
self.HDCheckBox.setObjectName("HDCheckBox")
self.horizontalLayout.addWidget(self.HDCheckBox)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.gridLayout.addLayout(self.horizontalLayout, 2, 0, 1, 4)
self.ModeComboBox = QtWidgets.QComboBox(self.layoutWidget)
self.ModeComboBox.setStyleSheet("QComboBox QAbstractItemView\n"
"{\n"
" border: 2px solid darkgray;\n"
Expand All @@ -41,65 +68,40 @@ def setupUi(self, MusicDownloader):
self.ModeComboBox.addItem("")
self.ModeComboBox.addItem("")
self.gridLayout.addWidget(self.ModeComboBox, 0, 0, 1, 2)
self.UrlIdLineEdit = QtWidgets.QLineEdit(self.widget)
self.UrlIdLineEdit.setObjectName("UrlIdLineEdit")
self.gridLayout.addWidget(self.UrlIdLineEdit, 0, 2, 1, 1)
self.DownloadPushButton = QtWidgets.QPushButton(self.widget)
self.APILineEdit = QtWidgets.QLineEdit(self.layoutWidget)
self.APILineEdit.setObjectName("APILineEdit")
self.gridLayout.addWidget(self.APILineEdit, 1, 2, 1, 2)
self.DownloadPushButton = QtWidgets.QPushButton(self.layoutWidget)
self.DownloadPushButton.setObjectName("DownloadPushButton")
self.gridLayout.addWidget(self.DownloadPushButton, 0, 3, 1, 1)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
self.horizontalLayout.setObjectName("horizontalLayout")
self.FrontArtistCheckBox = QtWidgets.QCheckBox(self.widget)
self.FrontArtistCheckBox.setObjectName("FrontArtistCheckBox")
self.horizontalLayout.addWidget(self.FrontArtistCheckBox)
self.RearArtistCheckBox = QtWidgets.QCheckBox(self.widget)
self.RearArtistCheckBox.setObjectName("RearArtistCheckBox")
self.horizontalLayout.addWidget(self.RearArtistCheckBox)
self.LyricCheckBox = QtWidgets.QCheckBox(self.widget)
self.LyricCheckBox.setChecked(True)
self.LyricCheckBox.setObjectName("LyricCheckBox")
self.horizontalLayout.addWidget(self.LyricCheckBox)
self.HDCheckBox = QtWidgets.QCheckBox(self.widget)
self.HDCheckBox.setChecked(True)
self.HDCheckBox.setObjectName("HDCheckBox")
self.horizontalLayout.addWidget(self.HDCheckBox)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.gridLayout.addLayout(self.horizontalLayout, 2, 0, 1, 4)
self.PrintTextEdit = QtWidgets.QTextEdit(self.widget)
self.PrintTextEdit.setEnabled(False)
self.PrintTextEdit.setStyleSheet("background-color: rgb(0, 0, 0);")
self.PrintTextEdit = QtWidgets.QTextEdit(self.layoutWidget)
self.PrintTextEdit.setEnabled(True)
self.PrintTextEdit.setStyleSheet("background-color: rgb(0, 0, 0);\n"
"color: rgb(225, 225, 225);")
self.PrintTextEdit.setReadOnly(True)
self.PrintTextEdit.setObjectName("PrintTextEdit")
self.gridLayout.addWidget(self.PrintTextEdit, 3, 0, 1, 4)
self.APILineEdit = QtWidgets.QLineEdit(self.widget)
self.APILineEdit.setObjectName("APILineEdit")
self.gridLayout.addWidget(self.APILineEdit, 1, 2, 1, 2)
self.label = QtWidgets.QLabel(self.widget)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 1, 0, 1, 2)

self.retranslateUi(MusicDownloader)
QtCore.QMetaObject.connectSlotsByName(MusicDownloader)

def retranslateUi(self, MusicDownloader):
_translate = QtCore.QCoreApplication.translate
MusicDownloader.setWindowTitle(_translate("MusicDownloader", "MusicDownloader"))
self.label.setText(_translate("MusicDownloader", "歌曲API服务器:"))
self.FrontArtistCheckBox.setText(_translate("MusicDownloader", "歌曲名称前加歌手"))
self.RearArtistCheckBox.setText(_translate("MusicDownloader", "歌曲名称后加歌手"))
self.LyricCheckBox.setText(_translate("MusicDownloader", "歌曲是否下载歌词"))
self.HDCheckBox.setText(_translate("MusicDownloader", "歌曲启用高清封面"))
self.ModeComboBox.setItemText(0, _translate("MusicDownloader", "网易云单曲"))
self.ModeComboBox.setItemText(1, _translate("MusicDownloader", "网易云歌单"))
self.ModeComboBox.setItemText(2, _translate("MusicDownloader", "QQ音乐单曲"))
self.ModeComboBox.setItemText(3, _translate("MusicDownloader", "QQ音乐歌单"))
self.ModeComboBox.setItemText(4, _translate("MusicDownloader", "网易云专辑"))
self.ModeComboBox.setItemText(5, _translate("MusicDownloader", "网易云歌手下载"))
self.DownloadPushButton.setText(_translate("MusicDownloader", "下 载"))
self.FrontArtistCheckBox.setText(_translate("MusicDownloader", "歌曲名称前加歌手"))
self.RearArtistCheckBox.setText(_translate("MusicDownloader", "歌曲名称后加歌手"))
self.LyricCheckBox.setText(_translate("MusicDownloader", "歌曲是否下载歌词"))
self.HDCheckBox.setText(_translate("MusicDownloader", "歌曲启用高清封面"))
self.PrintTextEdit.setHtml(_translate("MusicDownloader", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'SimSun\'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>"))
self.label.setText(_translate("MusicDownloader", "歌曲API服务器:"))
Loading

0 comments on commit 40d75f2

Please sign in to comment.