Browse Source

update:Add comments to main.py

master
kdxcxs 5 years ago
parent
commit
e76ce15225
  1. 132
      main.py

132
main.py

@ -1,67 +1,67 @@
# coding:utf-8 # coding:utf-8
''' '''
author:kdxcxs@github.com author:kdxcxs@github.com
''' '''
import sys import sys
from PyQt5.QtWidgets import QMainWindow,QFileDialog,QDialog,QApplication from PyQt5.QtWidgets import QMainWindow,QFileDialog,QDialog,QApplication
from PyQt5.QtGui import QPixmap,QIcon from PyQt5.QtGui import QPixmap,QIcon
from PyQt5.QtCore import QByteArray from PyQt5.QtCore import QByteArray
from icon import iconb64 from icon import iconb64
from mainWindow import Ui_MainWindow from mainWindow import Ui_MainWindow
from dumping import Ui_dumpingDialog from dumping import Ui_dumpingDialog
from ncmdump import dump from ncmdump import dump
class mainWindow(QMainWindow): class mainWindow(QMainWindow):
def __init__(self, scaleRate): def __init__(self, scaleRate):
super(mainWindow, self).__init__(None) super(mainWindow, self).__init__(None)
self.ui = Ui_MainWindow() self.ui = Ui_MainWindow()
self.ui.setupUi(self,scaleRate) self.ui.setupUi(self,scaleRate) # 把所有控件大小和位置都乘以Windows缩放比例来适配Windows缩放
self.setupIcon() self.setupIcon() # 直接通过base64把图标写入程序,避免pyinstaller打包后图标失效
self.dumpingdialog = dumpingDialog(self,self.icon) self.dumpingdialog = dumpingDialog(self,self.icon)
self.initSignal() self.initSignal()
self.show() self.show()
def setupIcon(self): def setupIcon(self):
self.pmap = QPixmap() self.pmap = QPixmap()
self.pmap.loadFromData(QByteArray.fromBase64(iconb64)) self.pmap.loadFromData(QByteArray.fromBase64(iconb64))
self.icon = QIcon(self.pmap) self.icon = QIcon(self.pmap)
self.setWindowIcon(self.icon) self.setWindowIcon(self.icon)
def initSignal(self): def initSignal(self):
self.ui.commandLinkButton.clicked.connect(self.dumper) self.ui.commandLinkButton.clicked.connect(self.dumper)
def dumper(self): def dumper(self):
files,fileType = QFileDialog.getOpenFileNames(self, files,fileType = QFileDialog.getOpenFileNames(self,
"请选择ncm文件", "请选择ncm文件",
"./", "./",
"NeteaseCloudMusic Files (*.ncm)") "NeteaseCloudMusic Files (*.ncm)")
if files: if files:
outputPath = QFileDialog.getExistingDirectory(self, outputPath = QFileDialog.getExistingDirectory(self,
'请选择输出文件夹', '请选择输出文件夹',
'/'.join(files[0].split('/')[:-1])) '/'.join(files[0].split('/')[:-1])) # 初始输出文件夹为第一个ncm文件所在目录
if outputPath: if outputPath:
self.dumpingdialog.show() self.dumpingdialog.show()
filesTotal, filesDumped = len(files), 0 filesTotal, filesDumped = len(files), 0
self.dumpingdialog.ui.label.setText(f'转换中\n{filesDumped}/{filesTotal}') self.dumpingdialog.ui.label.setText(f'转换中\n{filesDumped}/{filesTotal}')
for file in files: for file in files:
dump(file,outputPath+'/'+file.split('/')[-1][:-3]+'mp3') dump(file,outputPath+'/'+file.split('/')[-1][:-3]+'mp3')
filesDumped += 1 filesDumped += 1
self.dumpingdialog.ui.label.setText(f'转换中\n{filesDumped}/{filesTotal}') self.dumpingdialog.ui.label.setText(f'转换中\n{filesDumped}/{filesTotal}')
self.dumpingdialog.setWindowTitle('转换完毕!') self.dumpingdialog.setWindowTitle('转换完毕!')
self.dumpingdialog.ui.label.setText('转换完毕!') self.dumpingdialog.ui.label.setText('转换完毕!')
class ncmDumper(object): class ncmDumper(object):
def __init__(self): def __init__(self):
self.app = QApplication(sys.argv) self.app = QApplication(sys.argv)
self.scaleRate = self.app.screens()[0].logicalDotsPerInch()/96 self.scaleRate = self.app.screens()[0].logicalDotsPerInch()/96 # 获取Windows缩放比例以适配Windows缩放
self.mainwindow = mainWindow(self.scaleRate) self.mainwindow = mainWindow(self.scaleRate)
class dumpingDialog(QDialog): class dumpingDialog(QDialog):
def __init__(self,parent,icon): def __init__(self,parent,icon):
super(dumpingDialog, self).__init__(parent) super(dumpingDialog, self).__init__(parent)
self.ui = Ui_dumpingDialog() self.ui = Ui_dumpingDialog()
self.ui.setupUi(self) self.ui.setupUi(self)
self.setWindowIcon(icon) self.setWindowIcon(icon)
if __name__ == '__main__': if __name__ == '__main__':
dumper = ncmDumper() dumper = ncmDumper()
sys.exit(dumper.app.exec_()) sys.exit(dumper.app.exec_())
Loading…
Cancel
Save