Exemple #1
0
class DownloadFrame(ScrollArea):

    def __init__(self, parent=None):
        super().__init__()
        self.parent = parent
        self.setObjectName('downloadMusic')
        with open('QSS/downloadFrame.qss', 'r', encoding="utf-8") as f:
            self.setStyleSheet(f.read())

        self.mainLayout = QVBoxLayout(self)

        self.setHeader()
        self.setMusicTable()

    def setHeader(self):
        # self.titleLabel = QLabel("我的下载")

        self.spaceLine = QFrame(self)
        self.spaceLine.setObjectName("spaceLine")
        self.spaceLine.setFrameShape(QFrame.HLine)
        self.spaceLine.setFrameShadow(QFrame.Plain)
        self.spaceLine.setLineWidth(2)
        
        self.currentStorageFolderLabel = QLabel("当前存储目录: ")
        
        self.currentStorageFolder = QLabel()

        self.selectButton = QPushButton("选择目录")
        self.selectButton.setObjectName('selectButton')

        self.topShowLayout = QHBoxLayout()
        self.topShowLayout.addSpacing(20)
        # self.topShowLayout.addWidget(self.titleLabel)
        self.topShowLayout.addWidget(self.currentStorageFolderLabel)
        self.topShowLayout.addWidget(self.currentStorageFolder)
        self.topShowLayout.addWidget(self.selectButton)
        self.topShowLayout.addStretch(1)

        self.mainLayout.addLayout(self.topShowLayout)
        self.mainLayout.addWidget(self.spaceLine)

    def setMusicTable(self):
        self.singsTable = QTableWidget()
        self.singsTable.setObjectName('singsTable')
        self.singsTable.setMinimumWidth(self.width())
        self.singsTable.setColumnCount(3)
        self.singsTable.setHorizontalHeaderLabels(['音乐标题', '歌手', '时长'])

        self.singsTable.setColumnWidth(0, self.width()/3*1.25)
        self.singsTable.setColumnWidth(1, self.width()/3*1.25)
        self.singsTable.setColumnWidth(2, self.width()/3*0.5)
        self.singsTable.horizontalHeader().setStretchLastSection(True)
        self.singsTable.verticalHeader().setVisible(False)
        self.singsTable.setShowGrid(False)
        self.singsTable.setAlternatingRowColors(True)

        self.singsTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.singsTable.setSelectionBehavior(QAbstractItemView.SelectRows)

        self.mainLayout.addWidget(self.singsTable)
Exemple #2
0
class DownloadFrame(ScrollArea):
    def __init__(self, parent=None):
        super().__init__()
        self.parent = parent
        self.setObjectName('downloadMusic')
        with open('QSS/downloadFrame.qss', 'r', encoding="utf-8") as f:
            self.setStyleSheet(f.read())

        self.mainLayout = QVBoxLayout(self)

        self.setHeader()
        self.setMusicTable()

    def setHeader(self):
        # self.titleLabel = QLabel("我的下载")

        self.spaceLine = QFrame(self)
        self.spaceLine.setObjectName("spaceLine")
        self.spaceLine.setFrameShape(QFrame.HLine)
        self.spaceLine.setFrameShadow(QFrame.Plain)
        self.spaceLine.setLineWidth(2)

        self.currentStorageFolderLabel = QLabel("当前存储目录: ")

        self.currentStorageFolder = QLabel()

        self.selectButton = QPushButton("选择目录")
        self.selectButton.setObjectName('selectButton')

        self.topShowLayout = QHBoxLayout()
        self.topShowLayout.addSpacing(20)
        # self.topShowLayout.addWidget(self.titleLabel)
        self.topShowLayout.addWidget(self.currentStorageFolderLabel)
        self.topShowLayout.addWidget(self.currentStorageFolder)
        self.topShowLayout.addWidget(self.selectButton)
        self.topShowLayout.addStretch(1)

        self.mainLayout.addLayout(self.topShowLayout)
        self.mainLayout.addWidget(self.spaceLine)

    def setMusicTable(self):
        self.singsTable = QTableWidget()
        self.singsTable.setObjectName('singsTable')
        self.singsTable.setMinimumWidth(self.width())
        self.singsTable.setColumnCount(3)
        self.singsTable.setHorizontalHeaderLabels(['音乐标题', '歌手', '时长'])

        self.singsTable.setColumnWidth(0, self.width() / 3 * 1.25)
        self.singsTable.setColumnWidth(1, self.width() / 3 * 1.25)
        self.singsTable.setColumnWidth(2, self.width() / 3 * 0.5)
        self.singsTable.horizontalHeader().setStretchLastSection(True)
        self.singsTable.verticalHeader().setVisible(False)
        self.singsTable.setShowGrid(False)
        self.singsTable.setAlternatingRowColors(True)

        self.singsTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.singsTable.setSelectionBehavior(QAbstractItemView.SelectRows)

        self.mainLayout.addWidget(self.singsTable)
Exemple #3
0
class Window(QWidget):
    """Window 承载整个界面。"""
    def __init__(self):
        super(Window, self).__init__()
        self.setObjectName('MainWindow')
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setWindowIcon(QIcon('resource/format.ico'))
        self.setWindowTitle("Music")

        with open('QSS/window.qss', 'r') as f:
            self.setStyleSheet(f.read())

        self.resize(1022, 670)

        self.header = Header(self)
        self.navigation = Navigation(self)
        self.playWidgets = PlayWidgets(self)
        self.detailSings = DetailSings(self)
        self.mainContent = MainContent(self)
        self.nativeMusic = NativeMusic(self)
        self.searchArea = SearchArea(self)

        self.mainContents = QTabWidget()
        self.mainContents.tabBar().setObjectName("mainTab")

        self.systemTray = SystemTray('resource/logo.png', self)

        # 加载tab设置。
        self.setContents()
        # 添加各类网站的歌单。
        self.addAllPlaylist()
        # 设置布局小细线。
        self.setLines()
        # 设置布局。
        self.setLayouts()
        # 注册功能。
        self.configFeatures()

    def addAllPlaylist(self):
        self.indexNetEaseSings = NetEaseSingsArea(self.mainContent)
        self.indexXiamiSings = XiamiSingsArea(self.mainContent)
        self.indexQQSings = QQSingsArea(self.mainContent)
        self.mainContent.addTab(self.indexNetEaseSings, "网易云歌单")
        self.mainContent.addTab(self.indexXiamiSings, "虾米歌单")
        self.mainContent.addTab(self.indexQQSings, "QQ歌单")

    # 布局。
    def setContents(self):
        """设置tab界面。"""
        # 将需要切换的窗口做成Tab,并隐藏tabBar,这样方便切换,并且可以做前进后退功能。

        self.mainContents.addTab(self.mainContent, '')
        self.mainContents.addTab(self.detailSings, '')
        self.mainContents.addTab(self.nativeMusic, '')
        self.mainContents.addTab(self.searchArea, '')

        self.mainContents.setCurrentIndex(0)

    def setLines(self):
        """设置布局小细线。"""
        self.line1 = QFrame(self)
        self.line1.setObjectName("line1")
        self.line1.setFrameShape(QFrame.HLine)
        self.line1.setFrameShadow(QFrame.Plain)
        self.line1.setLineWidth(2)

    def setLayouts(self):

        self.mainLayout = QVBoxLayout()
        self.mainLayout.addWidget(self.header)
        self.mainLayout.addWidget(self.line1)

        self.contentLayout = QHBoxLayout()
        self.contentLayout.setStretch(0, 70)
        self.contentLayout.setStretch(1, 570)

        self.contentLayout.addWidget(self.navigation)
        self.contentLayout.addWidget(self.mainContents)

        self.contentLayout.setSpacing(0)
        self.contentLayout.setContentsMargins(0, 0, 0, 0)

        self.mainLayout.addLayout(self.contentLayout)
        self.mainLayout.addWidget(self.playWidgets)

        self.mainLayout.setStretch(0, 43)
        self.mainLayout.setStretch(1, 0)
        self.mainLayout.setStretch(2, 576)
        self.mainLayout.setStretch(3, 50)

        self.mainLayout.setSpacing(0)
        self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.mainLayout)

    # 注册所有功能。
    def configFeatures(self):
        self.config = ConfigWindow(self)
        self.header.config = ConfigHeader(self.header)
        self.searchArea.config = ConfigSearchArea(self.searchArea)
        self.navigation.config = ConfigNavigation(self.navigation)
        self.nativeMusic.config = ConfigNative(self.nativeMusic)
        self.mainContent.config = ConfigMainContent(self.mainContent)
        self.detailSings.config = ConfigDetailSings(self.detailSings)
        self.indexNetEaseSings.config = ConfigNetEase(self.indexNetEaseSings)
        self.indexXiamiSings.config = ConfigXiami(self.indexXiamiSings)
        self.indexQQSings.config = ConfigQQ(self.indexQQSings)
        self.systemTray.config = ConfigSystemTray(self.systemTray)

        self.indexNetEaseSings.config.initThread()
        self.indexXiamiSings.config.initThread()
        self.indexQQSings.config.initThread()

    def closeEvent(self, event):
        # 主要是保存cookies.
        self.header.config.saveCookies()
        self.playWidgets.saveCookies()

        # 系统托盘需要先隐藏,否则退出后会残留在任务栏。
        self.systemTray.hide()
Exemple #4
0
class Header(QFrame):
    def __init__(self, parent=None):
        """头部区域,包括图标/搜索/设置/登陆/最大/小化/关闭。"""

        super(Header, self).__init__()
        self.setObjectName('Header')

        self.parent = parent

        self.loginBox = LoginBox(self)

        with open('QSS/header.qss', 'r', encoding='utf-8') as f:
            self.setStyleSheet(f.read())

        # 加载按钮设置。
        self.setButtons()
        # 加载标签设置。
        self.setLabels()
        # 加载输入框设置。
        self.setLineEdits()
        # 加载小细线装饰。
        self.setLines()
        # 加载布局设置。
        self.setLayouts()

    # 布局。
    def setButtons(self):
        """创建所有的按钮。"""

        self.closeButton = QPushButton('×', self)
        self.closeButton.setObjectName("closeButton")
        self.closeButton.setMinimumSize(21, 17)

        self.showminButton = QPushButton('_', self)
        self.showminButton.setObjectName("minButton")
        self.showminButton.setMinimumSize(21, 17)

        self.loginButton = QPushButton("未登录 ▼", self)
        self.loginButton.setObjectName("loginButton")

        self.prevButton = QPushButton("<")
        self.prevButton.setObjectName("prevButton")
        self.prevButton.setMaximumSize(28, 22)
        self.prevButton.setMinimumSize(28, 22)

        self.nextButton = QPushButton(">")
        self.nextButton.setObjectName("nextButton")
        self.nextButton.setMaximumSize(28, 22)
        self.nextButton.setMinimumSize(28, 22)

    def setLabels(self):
        """创建所需的所有标签。"""
        self.logoLabel = PicLabel(r'resource/format.png', 32, 32)

        self.descriptionLabel = QLabel(self)
        self.descriptionLabel.setText("<b>Music<b>")

        self.userPix = PicLabel(r'resource/no_music.png', 32, 32,
                                r'resource/user_pic_mask.png')
        self.userPix.setMinimumSize(22, 22)
        self.userPix.setObjectName("userPix")

    def setLineEdits(self):
        """创建搜素框。"""
        self.searchLine = SearchLineEdit(self)
        self.searchLine.setPlaceholderText("搜索音乐, 歌手, 歌词, 用户")

    def setLines(self):
        """设置装饰用小细线。"""
        self.line1 = QFrame(self)
        self.line1.setObjectName("line1")
        self.line1.setFrameShape(QFrame.VLine)
        self.line1.setFrameShadow(QFrame.Plain)
        self.line1.setMaximumSize(1, 25)

    def setLayouts(self):
        """设置布局。"""
        self.mainLayout = QHBoxLayout()
        self.mainLayout.setSpacing(0)
        self.mainLayout.addWidget(self.logoLabel)
        self.mainLayout.addWidget(self.descriptionLabel)
        self.mainLayout.addSpacing(70)
        self.mainLayout.addWidget(self.prevButton)
        self.mainLayout.addWidget(self.nextButton)
        self.mainLayout.addSpacing(10)
        self.mainLayout.addWidget(self.searchLine)
        self.mainLayout.addStretch(1)
        self.mainLayout.addWidget(self.userPix)
        self.mainLayout.addSpacing(7)
        self.mainLayout.addWidget(self.loginButton)
        self.mainLayout.addSpacing(7)
        self.mainLayout.addWidget(self.line1)
        self.mainLayout.addSpacing(30)
        self.mainLayout.addWidget(self.showminButton)
        self.mainLayout.addSpacing(3)
        self.mainLayout.addWidget(self.closeButton)

        self.setLayout(self.mainLayout)

    # 事件。
    """重写鼠标事件,实现窗口拖动。"""

    def mousePressEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.parent.m_drag = True
            self.parent.m_DragPosition = event.globalPos() - self.parent.pos()
            event.accept()

    def mouseMoveEvent(self, event):
        try:
            if event.buttons() and Qt.LeftButton:
                self.parent.move(event.globalPos() -
                                 self.parent.m_DragPosition)
                event.accept()
        except AttributeError:
            pass

    def mouseReleaseEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.m_drag = False
Exemple #5
0
class Window(QWidget):
    """Window 承载整个界面。"""
    def __init__(self):
        super(Window, self).__init__()
        self.setObjectName('MainWindow')
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setWindowIcon(QIcon('resource/format.ico'))
        self.setWindowTitle("Music")

        self.resize(1022, 670)

        self.header = Header(self)
        self.navigation = Navigation(self)
        self.playWidgets = PlayWidgets(self)
        self.detailSings = DetailSings(self)
        self.mainContent = MainContent(self)
        self.nativeMusic = NativeMusic(self)
        self.downloadFrame = DownloadFrame(self)
        self.searchArea = SearchArea(self)
        self.recommendFrame = RecommendFrame(self)

        self.mainContents = QTabWidget()
        self.mainContents.tabBar().setObjectName("mainTab")

        self.systemTray = SystemTray('resource/logo.png', self)

        # 加载tab设置。
        self.setContents()
        # 添加各类网站的歌单。
        self.addAllPlaylist()
        # 设置布局小细线。
        self.setLines()
        # 设置布局。
        self.setLayouts()
        # 注册功能。
        self.configFeatures()

        with open('QSS/window.qss', 'r') as f:
            self.setStyleSheet(f.read())

    def addAllPlaylist(self):
        self.indexNetEaseSings = NetEaseSingsArea(self.mainContent)
        self.indexXiamiSings = XiamiSingsArea(self.mainContent)
        self.indexQQSings = QQSingsArea(self.mainContent)
        self.mainContent.addTab(self.indexNetEaseSings, "网易云歌单")
        self.mainContent.addTab(self.indexXiamiSings, "虾米歌单")
        self.mainContent.addTab(self.indexQQSings, "QQ歌单")

    # 布局。
    def setContents(self):
        """设置tab界面。"""
        # 将需要切换的窗口做成Tab,并隐藏tabBar,这样方便切换,并且可以做前进后退功能。
        
        self.mainContents.addTab(self.mainContent, '')
        self.mainContents.addTab(self.detailSings, '')
        self.mainContents.addTab(self.nativeMusic, '')
        self.mainContents.addTab(self.downloadFrame, '')
        self.mainContents.addTab(self.recommendFrame, '')
        self.mainContents.addTab(self.searchArea, '')

        self.mainContents.setCurrentIndex(0)

    def setLines(self):
        """设置布局小细线。"""
        self.line1 = QFrame(self)
        self.line1.setObjectName("line1")
        self.line1.setFrameShape(QFrame.HLine)
        self.line1.setFrameShadow(QFrame.Plain)
        self.line1.setLineWidth(2)

    def setLayouts(self):

        self.mainLayout = QVBoxLayout()
        self.mainLayout.addWidget(self.header)
        self.mainLayout.addWidget(self.line1)
        
        self.contentLayout = QHBoxLayout()
        self.contentLayout.setStretch(0, 70)
        self.contentLayout.setStretch(1, 570)
        
        self.contentLayout.addWidget(self.navigation)
        self.contentLayout.addWidget(self.mainContents)

        self.contentLayout.setSpacing(0)
        self.contentLayout.setContentsMargins(0, 0, 0, 0)   

        self.mainLayout.addLayout(self.contentLayout)
        self.mainLayout.addWidget(self.playWidgets)
        
        self.mainLayout.setStretch(0, 43)
        self.mainLayout.setStretch(1, 0)
        self.mainLayout.setStretch(2, 576)
        self.mainLayout.setStretch(3, 50)

        self.mainLayout.setSpacing(0)
        self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.mainLayout)

    # 注册所有功能。
    def configFeatures(self):
        self.config = ConfigWindow(self)
        self.header.config = ConfigHeader(self.header)
        self.downloadFrame.config = ConfigDownloadFrame(self.downloadFrame)
        self.searchArea.config = ConfigSearchArea(self.searchArea)
        self.navigation.config = ConfigNavigation(self.navigation)
        self.nativeMusic.config = ConfigNative(self.nativeMusic)
        self.mainContent.config = ConfigMainContent(self.mainContent)
        self.detailSings.config = ConfigDetailSings(self.detailSings)
        self.indexNetEaseSings.config = ConfigNetEase(self.indexNetEaseSings)
        self.indexXiamiSings.config = ConfigXiami(self.indexXiamiSings)
        self.indexQQSings.config = ConfigQQ(self.indexQQSings)
        self.systemTray.config = ConfigSystemTray(self.systemTray)
        self.recommendFrame.config = ConfigRecommendFrame(self.recommendFrame)

        self.indexNetEaseSings.config.initThread()
        self.indexXiamiSings.config.initThread()
        self.indexQQSings.config.initThread()

        # 当前耦合度过高。
        self.downloadFrame.config.getDownloadSignal()
        
        self.config.pullRecommendSong()

        # move to center.
        screen = QApplication.desktop().availableGeometry()
        self.playWidgets.desktopLyric.resize(screen.width(), 50)
        self.playWidgets.desktopLyric.move(0, screen.height() - 100)

    def closeEvent(self, event):
        # 主要是保存cookies.
        self.header.config.saveCookies()
        self.playWidgets.saveCookies()
        self.downloadFrame.config.saveCookies()

        # 关闭并保存数据库
        self.db.commitAndClose()

        # 系统托盘需要先隐藏,否则退出后会残留在任务栏。
        self.systemTray.hide()

    def resizeEvent(self, event):
       self. playWidgets.currentMusic.move(0, self.height()-64-self.playWidgets.height())
Exemple #6
0
class Header(QFrame):

    def __init__(self, parent=None):
        """头部区域,包括图标/搜索/设置/登陆/最大/小化/关闭。"""

        super(Header, self).__init__()
        self.setObjectName('Header')

        self.parent = parent

        self.loginBox = LoginBox(self)

        with open('QSS/header.qss', 'r', encoding='utf-8') as f:
            self.setStyleSheet(f.read())

        # 加载按钮设置。
        self.setButtons()
        # 加载标签设置。
        self.setLabels()
        # 加载输入框设置。
        self.setLineEdits()
        # 加载小细线装饰。
        self.setLines()
        # 加载布局设置。
        self.setLayouts()

    # 布局。
    def setButtons(self):
        """创建所有的按钮。"""

        self.closeButton = QPushButton('×', self)
        self.closeButton.setObjectName("closeButton")
        self.closeButton.setMinimumSize(21, 17)

        self.showminButton = QPushButton('_', self)
        self.showminButton.setObjectName("minButton")
        self.showminButton.setMinimumSize(21, 17)

        self.showmaxButton = QPushButton('□')
        self.showmaxButton.setObjectName("maxButton")
        self.showmaxButton.setMaximumSize(16, 16)

        self.loginButton = QPushButton("未登录 ▼", self)
        self.loginButton.setObjectName("loginButton")

        self.prevButton = QPushButton("<")
        self.prevButton.setObjectName("prevButton")
        self.prevButton.setMaximumSize(28, 22)
        self.prevButton.setMinimumSize(28, 22)

        self.nextButton = QPushButton(">")
        self.nextButton.setObjectName("nextButton")
        self.nextButton.setMaximumSize(28, 22)
        self.nextButton.setMinimumSize(28, 22)

    def setLabels(self):
        """创建所需的所有标签。"""
        self.logoLabel = PicLabel(r'resource/format.png', 32, 32)

        self.descriptionLabel = QLabel(self)
        self.descriptionLabel.setText("<b>Music</b>")

        self.userPix = PicLabel(r'resource/no_music.png', 32, 32, r'resource/user_pic_mask.png')
        self.userPix.setMinimumSize(22, 22)
        self.userPix.setObjectName("userPix")

    def setLineEdits(self):
        """创建搜素框。"""
        self.searchLine = SearchLineEdit(self)
        self.searchLine.setPlaceholderText("搜索音乐, 歌手, 歌词, 用户")

    def setLines(self):
        """设置装饰用小细线。"""
        self.line1 = QFrame(self)
        self.line1.setObjectName("line1")
        self.line1.setFrameShape(QFrame.VLine)
        self.line1.setFrameShadow(QFrame.Plain)
        self.line1.setMaximumSize(1, 25)

    def setLayouts(self):
        """设置布局。"""
        self.mainLayout = QHBoxLayout()
        self.mainLayout.setSpacing(0)
        self.mainLayout.addWidget(self.logoLabel)
        self.mainLayout.addWidget(self.descriptionLabel)
        self.mainLayout.addSpacing(70)
        self.mainLayout.addWidget(self.prevButton)
        self.mainLayout.addWidget(self.nextButton)
        self.mainLayout.addSpacing(10)
        self.mainLayout.addWidget(self.searchLine)
        self.mainLayout.addStretch(1)
        self.mainLayout.addWidget(self.userPix)
        self.mainLayout.addSpacing(7)
        self.mainLayout.addWidget(self.loginButton)
        self.mainLayout.addSpacing(7)
        self.mainLayout.addWidget(self.line1)
        self.mainLayout.addSpacing(30)
        self.mainLayout.addWidget(self.showminButton)
        self.mainLayout.addWidget(self.showmaxButton)
        self.mainLayout.addSpacing(3)
        self.mainLayout.addWidget(self.closeButton)

        self.setLayout(self.mainLayout)

    # 事件。
    """重写鼠标事件,实现窗口拖动。"""
    def mousePressEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.parent.m_drag = True
            self.parent.m_DragPosition = event.globalPos()-self.parent.pos()
            event.accept()

    def mouseMoveEvent(self, event):
        try:
            if event.buttons() and Qt.LeftButton:
                self.parent.move(event.globalPos()-self.parent.m_DragPosition)
                event.accept()
        except AttributeError:
            pass

    def mouseReleaseEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.m_drag = False