Ejemplo n.º 1
0
class Button_Memory_PRM():

    def __init__(self, buttonId):
        self.buttonId = buttonId
        self.db = RAM_DB()
        self.radioChannels = self.db.getRadioChannels()
        self.audioController = AudioController()

    def onClick(self, isLongClick = False):
        if(self.audioController.getGUICoolDown() == False and isLongClick == False):
            self.audioController.startGUICoolDown(1)
            # If there's an entry in the XML with memorized channel, we assign it to this button/memory bank
            if(self.radioChannels[self.buttonId] != None):
                self.audioController.setCurrentFMFrequency(self.radioChannels[self.buttonId][0])
        elif ((self.audioController.getGUICoolDown() == False and isLongClick == True)):
            # On long click, we memorize the current radio channel to this memory bank :)
            self.db.setRadioChannel(self.buttonId, self.audioController.getCurrentFMFrequency(), self.audioController.getCurrentFMStationName())
            self.radioChannels = self.db.getRadioChannels()
            self.audioController.updateRadioObservers()



    def createButton(self, sizeX, sizeY):
        button = PicButton(QPixmap("themes/default/img/MemoryButton.png"), QPixmap("themes/default/img/MemoryButton_Pressed.png"), sizeX, sizeY, str(self.buttonId), self.onClick)

        return button
    def __init__(self, parent=None):
        """
        Constructor of the RadioMenuChannelMemory class.
        """

        super(RadioMenuChannelMemory, self).__init__(parent)

        self.db = RAM_DB()
        audioController = AudioController()
        radioChannels = self.db.getRadioChannels()

        self.memoryButtons = []
        self.labelsMemoryButtons = []
        for i in range(0, 9):
            self.memoryButtons.append(
                Button_Memory_PRM(i).createButton(60, 60))
            if (audioController.getPlayingRadio() == False
                    or audioController.getGUICoolDown() == True):
                self.memoryButtons[i].setOppacity(0.3)

        for i in range(0, 9):
            if (radioChannels[i] == None):
                memoryButtonLabel = "Vacío"
            else:
                memoryButtonLabel = radioChannels[i][1]

            self.labelsMemoryButtons.append(CustomLabel().createLabel(
                memoryButtonLabel, Qt.AlignCenter, 7))

        hButtonBarBox = QHBoxLayout()

        hButtonBarBox.addStretch()

        for i in range(0, len(self.memoryButtons)):
            vButtonBox = QVBoxLayout()
            hMemoryButtonBox = QHBoxLayout()

            hMemoryButtonBox.addStretch()
            hMemoryButtonBox.addWidget(self.memoryButtons[i])
            hMemoryButtonBox.addStretch()
            vButtonBox.addLayout(hMemoryButtonBox)

            hMemoryLabelBox = QHBoxLayout()
            hMemoryLabelBox.addStretch()
            hMemoryLabelBox.addWidget(self.labelsMemoryButtons[i])
            hMemoryLabelBox.addStretch()
            vButtonBox.addLayout(hMemoryLabelBox)

            hButtonBarBox.addLayout(vButtonBox)
            hButtonBarBox.addStretch()

        self.setLayout(hButtonBarBox)
Ejemplo n.º 3
0
        def __init__(self, notifyAudioController):
            """
            Constructor of the AudioFile class.

            :param notifyAudioController: Method to notify of the changes to the Audio Controller.
            """

            self.savedSecond = 0
            self.status = AudioStatus.NOFILE
            self.audioFileObject = None
            self.db = RAM_DB()
            self.notifyAudioController = notifyAudioController
            (self.fileName, self.pathFiles,
             self.metaDataList) = self.db.getAudioDB()
Ejemplo n.º 4
0
        def __init__(self):
            """
            Constructor of the AudioController class.
            """

            self.db = RAM_DB()
            (self.fileName, self.pathFiles,
             self.metaDataList) = self.db.getAudioDB()
            self.path = None
            self.audioObject = AudioFile(self.notifyController)
            self.currentFMStation = None
            self.SI4703 = SI4703()
            self.playingRadio = False
            self.observers = []
            self.GUICoolDown = False
            self.threadController = ThreadController()
    def __init__(self, controller, parent=None):
        """
        Constructor of the SelectAudioListWidget class.

        :param controller: GUIController object.
        """

        super(SelectAudioListWidget, self).__init__(parent)

        self.db = RAM_DB()
        self.controller = controller

        self.itemClicked.connect(self.item_click)
        self.setMinimumSize(QSize(600, 300))

        # Those lines are for the kinetic scrolling in the list
        QScroller.grabGesture(self, QScroller.LeftMouseButtonGesture)

        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.setAutoScroll(False)

        self.setStyleSheet("background-color: rgb(255,255,255)")

        self.setSelectionMode(QAbstractItemView.NoSelection)
        (fileName, pathFiles, self.metaDataList) = self.db.getAudioDB()
        self.itemsDict = {}

        for i in range(0, len(fileName)):

            customListItemWidget = CustomListItemWidget()
            customListItemWidget.setTextUp(self.metaDataList[i][0])
            customListItemWidget.setTextDown(
                getBandName(self.metaDataList[i][1]))
            customListItemWidget.setIcon(getArtworkPath(self.metaDataList[i]))

            customListItemWidget.setPath(pathFiles[i])

            item = QListWidgetItem()
            item.setSizeHint(customListItemWidget.sizeHint())

            self.addItem(item)
            self.setItemWidget(item, customListItemWidget)
            self.itemsDict[str(item)] = customListItemWidget
Ejemplo n.º 6
0
class GUIController(object):
    """
    This class has the responsibility of do the change between menus & initialize the GUI.
    """
    def initialize(self):
        """
        Initialize the GUI and load the Main Menu.
        """

        app = QApplication(sys.argv)
        mainWindow = MainWindow()
        self.centralWidget = QStackedWidget()
        mainWindow.setCentralWidget(self.centralWidget)

        self.db = RAM_DB()
        self.mainMenuWidget = MainMenu(self)
        self.audioController = AudioController()

        self.centralWidget.addWidget(self.mainMenuWidget)
        self.centralWidget.setCurrentWidget(self.mainMenuWidget)

        sys.exit(app.exec_())

    def changeToMenu(self, menuname):
        """
        Changes to the menu passed by parameter.

        :param menuname: String with the name of the menu.
        """

        if (menuname == "MainMenu"):
            self.db.setCurrentMenu("MainMenu")
            self.centralWidget.setCurrentWidget(self.mainMenuWidget)

        elif (menuname == "SelectAudioMenu"):
            self.db.setCurrentMenu("SelectAudioMenu")
            self.selectAudioMenuWidget = SelectAudioMenu(self)
            self.centralWidget.addWidget(self.selectAudioMenuWidget)
            self.centralWidget.setCurrentWidget(self.selectAudioMenuWidget)

        elif (menuname == "PlayAudioMenu"):
            self.db.setCurrentMenu("PlayAudioMenu")
            self.playAudioMenuWidget = PlayAudioMenu(self)
            #Observer pattern register
            self.audioController.register(self.playAudioMenuWidget)
            self.centralWidget.addWidget(self.playAudioMenuWidget)
            self.centralWidget.setCurrentWidget(self.playAudioMenuWidget)

        elif (menuname == "PlayRadioMenu"):
            self.db.setCurrentMenu("PlayRadioMenu")
            self.playRadioMenuWidget = PlayRadioMenu(self)
            # Observer pattern register
            self.audioController.register(self.playRadioMenuWidget)
            self.centralWidget.addWidget(self.playRadioMenuWidget)
            self.centralWidget.setCurrentWidget(self.playRadioMenuWidget)
Ejemplo n.º 7
0
    def initialize(self):
        """
        Initialize the GUI and load the Main Menu.
        """

        app = QApplication(sys.argv)
        mainWindow = MainWindow()
        self.centralWidget = QStackedWidget()
        mainWindow.setCentralWidget(self.centralWidget)

        self.db = RAM_DB()
        self.mainMenuWidget = MainMenu(self)
        self.audioController = AudioController()

        self.centralWidget.addWidget(self.mainMenuWidget)
        self.centralWidget.setCurrentWidget(self.mainMenuWidget)

        sys.exit(app.exec_())
Ejemplo n.º 8
0
    def __init__(self, controller, parent=None):
        """
        Constructor of the SelectAudioMenu class.

        :param controller: GUIController object.
        """

        super(SelectAudioMenu, self).__init__(parent)

        self.controller = controller
        self.db = RAM_DB()
        (fileName, pathFiles, self.metaDataList) = self.db.getAudioDB()
        self.audioController = AudioController()

        backButton = Button_Back_SAM(self.controller).createButton(269, 100)
        self.resumeButton = Button_Resume_SAM(self.controller).createButton(
            269, 100)
        selectAudioListWidget = SelectAudioListWidget(self.controller)

        verticalBoxLayout = QVBoxLayout()
        hSelectAudioListBox = QHBoxLayout()
        hButtonsMenuBox = QHBoxLayout()

        verticalBoxLayout.setContentsMargins(0, 0, 0, 0)
        verticalBoxLayout.addStretch()

        hSelectAudioListBox.addStretch()
        hSelectAudioListBox.addWidget(selectAudioListWidget)
        hSelectAudioListBox.addStretch()

        verticalBoxLayout.addLayout(hSelectAudioListBox)

        verticalBoxLayout.addStretch()

        hButtonsMenuBox.addWidget(backButton)
        hButtonsMenuBox.addStretch()
        hButtonsMenuBox.addWidget(self.resumeButton)

        if self.audioController.getStatus() == AudioStatus.NOFILE:
            self.resumeButton.hide()

        verticalBoxLayout.addLayout(hButtonsMenuBox)

        self.setLayout(verticalBoxLayout)
Ejemplo n.º 9
0
    def __init__(self, parent=None):
        """
        Constructor of the CustomListItemWidget class.
        """

        super(CustomListItemWidget, self).__init__(parent)

        self.db = RAM_DB()
        self.textQVBoxLayout = QVBoxLayout()
        self.textUpQLabel = QLabel()
        self.textDownQLabel = QLabel()
        self.path = ""
        self.textQVBoxLayout.addWidget(self.textUpQLabel)
        self.textQVBoxLayout.addWidget(self.textDownQLabel)
        self.allQHBoxLayout = QHBoxLayout()
        self.iconQLabel = QLabel()
        self.iconQLabel.setMaximumHeight(70)
        self.iconQLabel.setMaximumWidth(70)

        self.allQHBoxLayout.addWidget(self.iconQLabel, 0)
        self.allQHBoxLayout.addLayout(self.textQVBoxLayout, 1)
        self.setLayout(self.allQHBoxLayout)

        font1 = QFont('Myriada', 10)
        font1.setBold(True)
        font2 = QFont('Myriada', 9)
        font2.setBold(True)

        self.textUpQLabel.setFont(font1)
        self.textDownQLabel.setFont(font2)

        # setStyleSheet
        self.textUpQLabel.setStyleSheet('''
            color: rgb(10, 0, 0);
        ''')
        self.textDownQLabel.setStyleSheet('''
            color: rgb(128, 128, 128);
        ''')
Ejemplo n.º 10
0
    def __init__(self, notifyAudioController):
        """
        Constructor of the AudioFileVLC class.

        :param notifyAudioController: Method to notify of the changes to the Audio Controller.
        """

        self.vlcInstance = vlc.Instance()
        self.mediaPlayer = self.vlcInstance.media_player_new()
        self.mediaList = self.vlcInstance.media_list_new()
        self.listMediaPlayer = self.vlcInstance.media_list_player_new()
        self.listMediaPlayer.set_media_player(self.mediaPlayer)
        self.db = RAM_DB()
        self.threadController = ThreadController()
        (self.fileName, self.pathFiles, self.metaDataList) = self.db.getAudioDB()
        self.notifyAudioController = notifyAudioController

        #This boolean avoid to notify of unnecesary changes to the AudioController, works as a flag
        self.avoidNotify = False
        #This boolean avoid to stop the medialistplayer when is already stopped because have reached the end of the list.
        self.reproductionEnded = False

        for i in range(0, len(self.pathFiles)):
            self.mediaList.insert_media(self.vlcInstance.media_new(self.pathFiles[i]), i)

        self.listMediaPlayer.set_media_list(self.mediaList)

        #For the VLC Event handler
        self.vlc_eventsMediaList = self.listMediaPlayer.event_manager()
        self.vlc_eventsMediaPlayer = self.mediaPlayer.event_manager()
        self.vlc_eventsMediaPlayer.event_attach(vlc.EventType.MediaPlayerEndReached, self.endOfSong, 1)
        self.vlc_eventsMediaList.event_attach(vlc.EventType.MediaListPlayerNextItemSet, self.nextItem, 1)



        self.reproductionStatusThread = None
Ejemplo n.º 11
0
class CustomListItemWidget(QWidget):
    """
    This class provides customized widgets for each element of a list.
    """
    def __init__(self, parent=None):
        """
        Constructor of the CustomListItemWidget class.
        """

        super(CustomListItemWidget, self).__init__(parent)

        self.db = RAM_DB()
        self.textQVBoxLayout = QVBoxLayout()
        self.textUpQLabel = QLabel()
        self.textDownQLabel = QLabel()
        self.path = ""
        self.textQVBoxLayout.addWidget(self.textUpQLabel)
        self.textQVBoxLayout.addWidget(self.textDownQLabel)
        self.allQHBoxLayout = QHBoxLayout()
        self.iconQLabel = QLabel()
        self.iconQLabel.setMaximumHeight(70)
        self.iconQLabel.setMaximumWidth(70)

        self.allQHBoxLayout.addWidget(self.iconQLabel, 0)
        self.allQHBoxLayout.addLayout(self.textQVBoxLayout, 1)
        self.setLayout(self.allQHBoxLayout)

        font1 = QFont('Myriada', 10)
        font1.setBold(True)
        font2 = QFont('Myriada', 9)
        font2.setBold(True)

        self.textUpQLabel.setFont(font1)
        self.textDownQLabel.setFont(font2)

        # setStyleSheet
        self.textUpQLabel.setStyleSheet('''
            color: rgb(10, 0, 0);
        ''')
        self.textDownQLabel.setStyleSheet('''
            color: rgb(128, 128, 128);
        ''')

    def setTextUp(self, text):
        """
        Sets the text of the label on the top of the item.

        :param text: Text of the label.
        """

        self.textUpQLabel.setText(text)

    def setPath(self, pathFile):
        """
        Sets the path to the song that is listed in the item.

        :param pathFile: Path to the file.
        """

        self.path = pathFile

    def getPath(self):
        """
        Returns the path to the song that is listed in the item.

        :return: Path to the song.
        """

        return self.path

    def setTextDown(self, text):
        """
        Sets the text of the label on the bottom of the item.

        :param text: Text of the label.
        """

        self.textDownQLabel.setText(text)

    def setIcon(self, imagePath):
        """
        Sets the icon of the item.

        :param imagePath: Full path to the icon.
        """

        pixmapIcon = QPixmap()

        loaded = pixmapIcon.load(imagePath)

        if (loaded == False):
            pixmapIcon.load(self.db.getArtworkNotFoundPath())

        self.iconQLabel.setPixmap(pixmapIcon.scaled(70, 70))

        return loaded
Ejemplo n.º 12
0
 def __init__(self, buttonId):
     self.buttonId = buttonId
     self.db = RAM_DB()
     self.radioChannels = self.db.getRadioChannels()
     self.audioController = AudioController()
Ejemplo n.º 13
0
class SelectAudioListWidget(QListWidget):
    """
    Class that creates a customiced QListWidget used in the SelectAudioMenu.
    """
    def __init__(self, controller, parent=None):
        """
        Constructor of the SelectAudioListWidget class.

        :param controller: GUIController object.
        """

        super(SelectAudioListWidget, self).__init__(parent)

        self.db = RAM_DB()
        self.controller = controller

        self.itemClicked.connect(self.item_click)
        self.setMinimumSize(QSize(600, 300))

        # Those lines are for the kinetic scrolling in the list
        QScroller.grabGesture(self, QScroller.LeftMouseButtonGesture)

        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.setAutoScroll(False)

        self.setStyleSheet("background-color: rgb(255,255,255)")

        self.setSelectionMode(QAbstractItemView.NoSelection)
        (fileName, pathFiles, self.metaDataList) = self.db.getAudioDB()
        self.itemsDict = {}

        for i in range(0, len(fileName)):

            customListItemWidget = CustomListItemWidget()
            customListItemWidget.setTextUp(self.metaDataList[i][0])
            customListItemWidget.setTextDown(
                getBandName(self.metaDataList[i][1]))
            customListItemWidget.setIcon(getArtworkPath(self.metaDataList[i]))

            customListItemWidget.setPath(pathFiles[i])

            item = QListWidgetItem()
            item.setSizeHint(customListItemWidget.sizeHint())

            self.addItem(item)
            self.setItemWidget(item, customListItemWidget)
            self.itemsDict[str(item)] = customListItemWidget

    def item_click(self, item):
        """
        Changes to the Play Audio Menu when a item is clicked.

        :param item: The clicked item.
        """

        #Set the track selected for playing it
        self.db.setSelection(
            self.db.getIndexByPath(self.itemsDict[str(item)].getPath()))
        #Switch to PlayAudioMenu
        self.controller.changeToMenu("PlayAudioMenu")
        #Call to audioController for load the new audio file...
        audioController = AudioController()
        audioController.loadAudio()
Ejemplo n.º 14
0
    def __init__(self, controller, parent=None):
        """
        Constructor of the PlayRadioMenu class.

        :param controller: GUIController object.
        """

        super(PlayRadioMenu, self).__init__(parent)

        self.controller = controller
        audioController = AudioController()
        self.db = RAM_DB()
        radioMenuChannelMemoryWidget = RadioMenuChannelMemory()
        # Observer
        audioController.register(radioMenuChannelMemoryWidget)

        self.backButton = Button_Back_PRM(self.controller).createButton(269, 100)
        self.upFreqButton = Button_Upfreq_PRM(self.controller).createButton(60, 60)
        self.downFreqButton = Button_Downfreq_PRM(self.controller).createButton(60, 60)
        self.seekBackButton = Button_SeekBack_PRM(self.controller).createButton(60, 60)
        self.seekForwardButton = Button_SeekForward_PRM(self.controller).createButton(60, 60)

        if(audioController.getPlayingRadio() == False or audioController.getGUICoolDown() == True):
            self.upFreqButton.setOppacity(0.3)
            self.downFreqButton.setOppacity(0.3)
            self.seekBackButton.setOppacity(0.3)
            self.seekForwardButton.setOppacity(0.3)

        audioController.initRadio()

        self.freqLabel = CustomLabel().createLabel(str(audioController.getCurrentFMFrequency()) + " FM", Qt.AlignCenter, 30)

        verticalBoxLayout = QVBoxLayout()
        verticalBoxLayout.setContentsMargins(0, 0, 0, 0)

        verticalBoxLayout.addStretch()
        verticalBoxLayout.addStretch()
        verticalBoxLayout.addWidget(self.freqLabel)
        verticalBoxLayout.addStretch()

        hMenuBox = QHBoxLayout()
        hMenuBox.addStretch()
        hMenuBox.addWidget(self.seekBackButton)
        hMenuBox.addStretch()
        hMenuBox.addWidget(self.downFreqButton)
        hMenuBox.addStretch()
        hMenuBox.addWidget(self.upFreqButton)
        hMenuBox.addStretch()
        hMenuBox.addWidget(self.seekForwardButton)
        hMenuBox.addStretch()
        verticalBoxLayout.addLayout(hMenuBox)

        verticalBoxLayout.addStretch()

        verticalBoxLayout.addWidget(radioMenuChannelMemoryWidget)

        verticalBoxLayout.addStretch()

        hbox = QHBoxLayout()

        hbox.addWidget(self.backButton)
        hbox.addStretch()

        verticalBoxLayout.addLayout(hbox)

        self.setLayout(verticalBoxLayout)
Ejemplo n.º 15
0
    class __AudioFile:
        def __init__(self, notifyAudioController):
            """
            Constructor of the AudioFile class.

            :param notifyAudioController: Method to notify of the changes to the Audio Controller.
            """

            self.savedSecond = 0
            self.status = AudioStatus.NOFILE
            self.audioFileObject = None
            self.db = RAM_DB()
            self.notifyAudioController = notifyAudioController
            (self.fileName, self.pathFiles,
             self.metaDataList) = self.db.getAudioDB()

        def playAudio(self):
            """
            Plays the selected audio file, don't matter what kind of format.
            """

            if (self.status == AudioStatus.NOFILE):
                self.audioFileObject = self.__selectAudioType(
                    self.pathFiles[self.db.getSelection()])
                self.audioFileObject.playAudio()
                self.status = AudioStatus.PLAYING

            elif (self.status == AudioStatus.PLAYING
                  or self.status == AudioStatus.PAUSED):
                self.audioFileObject.stopAudio()
                self.audioFileObject = self.__selectAudioType(
                    self.pathFiles[self.db.getSelection()])
                self.audioFileObject.playAudio()

        def pauseAudio(self):
            """
            Pauses the current audio, managing it with the appropriate lib.
            """

            self.audioFileObject.pauseAudio()
            self.status = AudioStatus.PAUSED

        """
        def resumeAudio(self, savedSecond):

            Resumes the current audio, managing it with the appropriate lib.

            :param savedSecond: Second from where it resumes the reproduction.


            self.audioFileObject.resumeAudio(savedSecond)
            self.status = AudioStatus.PLAYING
        """

        def resumeAudio(self):
            """
            Resumes the current audio, managing it with the appropriate lib.
            """

            self.audioFileObject.resumeAudio()
            self.status = AudioStatus.PLAYING

        def changeAudioSecond(self, second):
            """
            Changes the current reproduction second to another second.

            :param second: New current second.
            """

            self.audioFileObject.changeAudioSecond(second)

        def stopAudio(self):
            """
            Stops the reproduction of the current audio, managing it with the appropriate lib.
            """

            self.status = AudioStatus.NOFILE
            self.audioFileObject.stopAudio()

        def startUpdateStatusThread(self):
            """
            Starts a thread that updates the reproduction status by polling to the vlc lib.
            """

            self.audioFileObject.startUpdateStatusThread()

        def __selectAudioType(self, path):
            """
            Private method that calls to the appropriate object depending on what kind of audio we want to reproduce.
            (Polimorfism)

            :param path: Path to the audio file.
            :return: Audio object using the appropriate lib.
            """

            if (path.endswith(".mp3") or path.endswith(".wav")):
                audioType = AudioFileVLC(self.notifyAudioController)

            return audioType

        def getStatus(self):
            """
            Returns the current status of the reproduction. See AudioStatus class.

            :return: Current status.
            """

            return self.status

        def __str__(self):
            return repr(self) + self.val
Ejemplo n.º 16
0
    def __init__(self, controller, parent=None):
        """
        Constructor of the PlayAudioMenu class.

        :param controller: GUIController object.
        """

        super(PlayAudioMenu, self).__init__(parent)

        self.controller = controller
        self.db = RAM_DB()

        backButton = Button_Back_PAM(self.controller).createButton(269, 100)
        self.playButton = Button_Play_PAM(self.controller).createButton(60, 60)
        self.pauseButton = Button_Pause_PAM(self.controller).createButton(
            60, 60)
        nextButton = Button_Next_PAM(self.controller).createButton(60, 60)
        previousButton = Button_Previous_PAM(self.controller).createButton(
            60, 60)

        (self.fileName, self.pathFiles,
         self.metaDataList) = self.db.getAudioDB()
        path = self.pathFiles[self.db.getSelection()]

        audioController = AudioController()
        self.audioObject = audioController.getAudioObject()

        self.textLabel = CustomLabel().createLabel(path, Qt.AlignCenter)
        self.actualTimeLabel = CustomLabel().createLabel(
            "00:00", Qt.AlignCenter)
        self.totalTimeLabel = CustomLabel().createLabel(
            "00:00", Qt.AlignCenter)
        self.timeSlider = TimeSlider(0, 100, 0, self.sliderValueChangedByUser)

        verticalBoxLayout = QVBoxLayout()
        hRepTimeBox = QHBoxLayout()
        hRepButtonsBox = QHBoxLayout()
        hImageBox = QHBoxLayout()
        hButtonsMenuBox = QHBoxLayout()

        verticalBoxLayout.setContentsMargins(0, 0, 0, 0)
        verticalBoxLayout.addStretch()

        verticalBoxLayout.addStretch()
        verticalBoxLayout.addWidget(self.textLabel)
        verticalBoxLayout.addStretch()

        hImageBox.addStretch()
        self.imgQLabel = QLabel()
        self.imgQLabel.setMaximumHeight(150)
        self.imgQLabel.setMaximumWidth(150)

        self.pixmapCover = QPixmap()
        loaded = self.pixmapCover.load(
            getArtworkPath(self.metaDataList[self.db.getSelection()]))

        if (loaded == False):
            self.pixmapCover.load(self.db.getArtworkNotFoundPath())
        self.imgQLabel.setPixmap(self.pixmapCover.scaled(150, 150))

        hImageBox.addWidget(self.imgQLabel)
        hImageBox.addStretch()
        verticalBoxLayout.addLayout(hImageBox)

        verticalBoxLayout.addStretch()

        hRepTimeBox.addWidget(self.actualTimeLabel)
        hRepTimeBox.addStretch()
        hRepTimeBox.addWidget(self.totalTimeLabel)
        verticalBoxLayout.addLayout(hRepTimeBox)
        verticalBoxLayout.addWidget(self.timeSlider)
        verticalBoxLayout.addStretch()

        hRepButtonsBox.addStretch()
        if (self.audioObject.getStatus() == AudioStatus.PAUSED):
            self.pauseButton.hide()
        else:
            self.playButton.hide()
        hRepButtonsBox.addWidget(previousButton)
        hRepButtonsBox.addStretch()
        hRepButtonsBox.addWidget(self.playButton)
        hRepButtonsBox.addWidget(self.pauseButton)
        hRepButtonsBox.addStretch()
        hRepButtonsBox.addWidget(nextButton)
        hRepButtonsBox.addStretch()

        verticalBoxLayout.addLayout(hRepButtonsBox)
        verticalBoxLayout.addStretch()

        hButtonsMenuBox.addWidget(backButton)
        hButtonsMenuBox.addStretch()
        verticalBoxLayout.addLayout(hButtonsMenuBox)

        self.setLayout(verticalBoxLayout)
Ejemplo n.º 17
0
class PlayAudioMenu(QWidget):
    """
    This class creates a custom widget with the Play Audio Menu elements and layout.
    """

    __metaclass__ = ABCMeta

    def __init__(self, controller, parent=None):
        """
        Constructor of the PlayAudioMenu class.

        :param controller: GUIController object.
        """

        super(PlayAudioMenu, self).__init__(parent)

        self.controller = controller
        self.db = RAM_DB()

        backButton = Button_Back_PAM(self.controller).createButton(269, 100)
        self.playButton = Button_Play_PAM(self.controller).createButton(60, 60)
        self.pauseButton = Button_Pause_PAM(self.controller).createButton(
            60, 60)
        nextButton = Button_Next_PAM(self.controller).createButton(60, 60)
        previousButton = Button_Previous_PAM(self.controller).createButton(
            60, 60)

        (self.fileName, self.pathFiles,
         self.metaDataList) = self.db.getAudioDB()
        path = self.pathFiles[self.db.getSelection()]

        audioController = AudioController()
        self.audioObject = audioController.getAudioObject()

        self.textLabel = CustomLabel().createLabel(path, Qt.AlignCenter)
        self.actualTimeLabel = CustomLabel().createLabel(
            "00:00", Qt.AlignCenter)
        self.totalTimeLabel = CustomLabel().createLabel(
            "00:00", Qt.AlignCenter)
        self.timeSlider = TimeSlider(0, 100, 0, self.sliderValueChangedByUser)

        verticalBoxLayout = QVBoxLayout()
        hRepTimeBox = QHBoxLayout()
        hRepButtonsBox = QHBoxLayout()
        hImageBox = QHBoxLayout()
        hButtonsMenuBox = QHBoxLayout()

        verticalBoxLayout.setContentsMargins(0, 0, 0, 0)
        verticalBoxLayout.addStretch()

        verticalBoxLayout.addStretch()
        verticalBoxLayout.addWidget(self.textLabel)
        verticalBoxLayout.addStretch()

        hImageBox.addStretch()
        self.imgQLabel = QLabel()
        self.imgQLabel.setMaximumHeight(150)
        self.imgQLabel.setMaximumWidth(150)

        self.pixmapCover = QPixmap()
        loaded = self.pixmapCover.load(
            getArtworkPath(self.metaDataList[self.db.getSelection()]))

        if (loaded == False):
            self.pixmapCover.load(self.db.getArtworkNotFoundPath())
        self.imgQLabel.setPixmap(self.pixmapCover.scaled(150, 150))

        hImageBox.addWidget(self.imgQLabel)
        hImageBox.addStretch()
        verticalBoxLayout.addLayout(hImageBox)

        verticalBoxLayout.addStretch()

        hRepTimeBox.addWidget(self.actualTimeLabel)
        hRepTimeBox.addStretch()
        hRepTimeBox.addWidget(self.totalTimeLabel)
        verticalBoxLayout.addLayout(hRepTimeBox)
        verticalBoxLayout.addWidget(self.timeSlider)
        verticalBoxLayout.addStretch()

        hRepButtonsBox.addStretch()
        if (self.audioObject.getStatus() == AudioStatus.PAUSED):
            self.pauseButton.hide()
        else:
            self.playButton.hide()
        hRepButtonsBox.addWidget(previousButton)
        hRepButtonsBox.addStretch()
        hRepButtonsBox.addWidget(self.playButton)
        hRepButtonsBox.addWidget(self.pauseButton)
        hRepButtonsBox.addStretch()
        hRepButtonsBox.addWidget(nextButton)
        hRepButtonsBox.addStretch()

        verticalBoxLayout.addLayout(hRepButtonsBox)
        verticalBoxLayout.addStretch()

        hButtonsMenuBox.addWidget(backButton)
        hButtonsMenuBox.addStretch()
        verticalBoxLayout.addLayout(hButtonsMenuBox)

        self.setLayout(verticalBoxLayout)

    def sliderValueChangedByUser(self):
        """
        Method when the slider notifies a change in his value made by the user.
        """

        self.audioObject.changeAudioSecond(self.timeSlider.getValue())

    @abstractmethod
    def update(self, *args, **kwargs):
        """
        Update method of the observer pattern.

        :param args: args
        :param kwargs: kwargs
        """

        self.updateView(*args, **kwargs)

    def updateView(self, *args, arg1, arg2):
        """
        Update view method of the observer pattern.

        :param args: Name of the notification.
        :param arg1: Other data.
        :param arg2: Other data.
        """

        if (args[0] == "NewMetaData"):
            minutes = round((arg2[16] // 1000.0) // 60.0)
            seconds = round((arg2[16] // 1000.0) % 60.0)

            if minutes < 10:
                strMinutes = "0" + str(minutes)
            else:
                strMinutes = str(minutes)
            if seconds < 10:
                strSeconds = "0" + str(seconds)
            else:
                strSeconds = str(seconds)

            if arg2[1] == None:
                titleText = "Artista desconocido" + " - " + arg2[0]
            else:
                titleText = arg2[1] + " - " + arg2[0]

            self.textLabel.setText(titleText)
            self.totalTimeLabel.setText(strMinutes + ":" + strSeconds)
            self.timeSlider.setMaximum(arg2[16])
            loaded = self.pixmapCover.load(
                getArtworkPath(self.metaDataList[self.db.getSelection()]))

            if (loaded == False):
                self.pixmapCover.load(self.db.getArtworkNotFoundPath())
            self.imgQLabel.setPixmap(self.pixmapCover.scaled(150, 150))

            if (self.audioObject.getStatus() == AudioStatus.PAUSED):
                self.pauseButton.hide()
                self.playButton.show()
            else:
                self.playButton.hide()
                self.pauseButton.show()

        elif (args[0] == "AudioPaused"):
            self.playButton.show()
            self.pauseButton.hide()

        elif (args[0] == "AudioResumed"):
            self.playButton.hide()
            self.pauseButton.show()

        elif (args[0] == "UpdateReproductionSecond"):
            minutes = round((arg1 // 1000) // 60)
            seconds = round((arg1 // 1000)) % 60

            if minutes < 10:
                strMinutes = "0" + str(minutes)
            else:
                strMinutes = str(minutes)
            if seconds < 10:
                strSeconds = "0" + str(seconds)
            else:
                strSeconds = str(seconds)

            self.actualTimeLabel.setText(strMinutes + ":" + strSeconds)
            self.timeSlider.setValue(arg1)
Ejemplo n.º 18
0
    class __AudioController:
        def __init__(self):
            """
            Constructor of the AudioController class.
            """

            self.db = RAM_DB()
            (self.fileName, self.pathFiles,
             self.metaDataList) = self.db.getAudioDB()
            self.path = None
            self.audioObject = AudioFile(self.notifyController)
            self.currentFMStation = None
            self.SI4703 = SI4703()
            self.playingRadio = False
            self.observers = []
            self.GUICoolDown = False
            self.threadController = ThreadController()

        ###############################################################################
        #OBSERVER PATTERN
        ###############################################################################
        def register(self, observer):
            """
            Register method of the observer pattern.

            :param observer: Object to subscribe.
            """

            if not observer in self.observers:
                self.observers.append(observer)

        def unregister(self, observer):
            """
            Untegister method of the observer pattern.

            :param observer: Object to unsubscribe.
            """

            if observer in self.observers:
                self.observers.remove(observer)

        def unregister_all(self):
            """
            Unsubscribe all the subscribers.
            """

            if self.observers:
                del self.observers[:]

        def update_observers(self, *args, **kwargs):
            """
            Notify to all the observers/subscribers.

            :param args: args
            :param kwargs: kwargs
            """

            for observer in self.observers:
                observer.update(*args, **kwargs)

        ###############################################################################

        def getAudioObject(self):
            """
            Returns the audio object, instance of the AudioFile class.
            :return: Current Audio File instance.
            """

            return self.audioObject

        def loadAudio(self):
            """
            Loads an audio file. (Plays it).
            """

            if (self.playingRadio == True):
                self.stopRadio()

            if (self.audioObject.getStatus() == AudioStatus.NOFILE):
                self.audioObject.playAudio()
            else:
                self.audioObject.stopAudio()
                self.audioObject.playAudio()
            self.update_observers(
                "NewMetaData",
                arg1=self.path,
                arg2=self.metaDataList[self.db.getSelection()])

        def startUpdateStatusThread(self):
            """
            Starts a thread that updates the reproduction status by polling to the vlc lib.
            """

            self.audioObject.startUpdateStatusThread()
            self.update_observers(
                "NewMetaData",
                arg1=self.path,
                arg2=self.metaDataList[self.db.getSelection()])

        def nextTrack(self):
            """
            Switch to the next track of the list.
            """

            self.audioObject.stopAudio()
            if (self.db.getSelection() + 1 < len(self.pathFiles)):
                self.db.setSelection(self.db.getSelection() + 1)
            else:
                self.db.setSelection(0)

            self.loadAudio()

        def previousTrack(self):
            """
            Switch to the previous track of the list.
            """

            self.audioObject.stopAudio()
            if (self.db.getSelection() - 1 >= 0):
                self.db.setSelection(self.db.getSelection() - 1)
            else:
                self.db.setSelection(len(self.pathFiles) - 1)
            self.loadAudio()

        def nextTrackEvent(self):
            """
            Manages the automatic change to the next track notifying to the GUI.
            """

            if (self.db.getSelection() + 1 < len(self.pathFiles)):
                self.db.setSelection(self.db.getSelection() + 1)
            else:
                self.db.setSelection(0)
            self.path = self.pathFiles[self.db.getSelection()]
            self.update_observers(
                "NewMetaData",
                arg1=self.path,
                arg2=self.metaDataList[self.db.getSelection()])

        def pause(self):
            """
            Pauses the audio.
            """

            self.audioObject.pauseAudio()
            self.update_observers("AudioPaused", arg1=None, arg2=None)

        def resume(self):
            """
            Resumes a paused audio.
            """

            self.audioObject.resumeAudio()
            self.update_observers("AudioResumed", arg1=None, arg2=None)

        def changeAudioSecond(self, second):
            """
            Changes the current reproduction second to another second.

            :param second: New current second.
            """

            self.audioObject.changeAudioSecond(second)

        def updateReproductionSecondEvent(self, second):
            """
            Send an event to the observers when the current reproduction second changes.
            """

            self.update_observers("UpdateReproductionSecond",
                                  arg1=second,
                                  arg2=None)

        def initRadio(self):
            """
            Initialize the radio module if it's stopped.
            """

            if self.playingRadio == False:
                #STOP the reproduction of Audio
                if self.audioObject.getStatus() != AudioStatus.NOFILE:
                    self.audioObject.stopAudio()

                #Init the radio
                if (self.currentFMStation == None):
                    self.currentFMStation = 92.3
                self.update_observers("UpdateCurrentFMFrequency",
                                      arg1=self.currentFMStation,
                                      arg2=None)
                self.startGUICoolDown(3)
                self.SI4703.initRadio()
                self.SI4703.setVolume(15)
                self.SI4703.setChannel(self.currentFMStation)
                self.playingRadio = True

        def stopRadio(self):
            """
            Stops the radio module if it's working.
            """

            if self.playingRadio == True:
                self.SI4703.stopRadio()
                self.playingRadio = False

        def setCurrentFMFrequency(self, frequency):
            """
            Changes the tuned frequency of the radio module.

            :param frequency: New frequency to tune.
            """

            if (frequency >= 87.5 and frequency <= 108):
                self.currentFMStation = frequency
                self.update_observers("UpdateCurrentFMFrequency",
                                      arg1=self.currentFMStation,
                                      arg2=None)
                self.SI4703.setChannel(self.currentFMStation)

        def getCurrentFMFrequency(self):
            """
            Returns the current tuned frequency.

            :return currentFMStation: Current tuned frequency.
            """

            return self.currentFMStation

        def getCurrentFMStationName(self):
            """
            Returns the name of the FM station (actually the frequency as string)

            :return currentFMStation: Current tuned frequency as string.
            """

            return str(self.currentFMStation)

        def updateRadioObservers(self):
            """
            Update all the observers related to the radio module.
            """

            self.update_observers("UpdateCurrentFMFrequency",
                                  arg1=self.currentFMStation,
                                  arg2=None)
            self.update_observers("UpdateRadioChannelData",
                                  arg1=None,
                                  arg2=None)

        def nextFrequency(self):
            """
            Changes to the next frequency.
            """

            if (self.currentFMStation >= 87.5 and self.currentFMStation < 108):
                self.currentFMStation = round(self.currentFMStation + 0.1, 2)
                self.update_observers("UpdateCurrentFMFrequency",
                                      arg1=self.currentFMStation,
                                      arg2=None)

        def previousFrequency(self):
            """
            Changes to the previous frequency.
            """

            if (self.currentFMStation > 87.5 and self.currentFMStation <= 108):
                self.currentFMStation = round(self.currentFMStation - 0.1, 2)
                self.update_observers("UpdateCurrentFMFrequency",
                                      arg1=self.currentFMStation,
                                      arg2=None)

        def startChangeFrequencyThread(self):
            """
            Starts the thread launched when we change between frequencies manually.
            """

            if (self.threadController.getChangeFrequencyThread() != None):
                self.threadController.getChangeFrequencyThread().stop()
                self.threadController.setChangeFrequencyThread(None)

            self.changeFrequencyThread = ChangeFrequencyThread(
                0.5, self.currentFMStation, self.setCurrentFMFrequency,
                self.startGUICoolDown)
            self.threadController.setChangeFrequencyThread(
                self.changeFrequencyThread)
            self.threadController.getChangeFrequencyThread().start()

        def seekUp(self):
            """
            Seek up a new FM station.
            """

            self.SI4703.seekUp(self.notifyController)

        def seekDown(self):
            """
            Seek down a new FM station.
            """

            self.SI4703.seekDown(self.notifyController)

        def setGUICoolDown(self, state):
            """
            Sets the status of the cooldown of the GUI.

            :param state: State of the cooldown.
            """

            if (state == False):
                self.update_observers("CoolDownEnded", arg1=None, arg2=None)
            self.GUICoolDown = state

        def getGUICoolDown(self):
            """
            Returns the state of the cooldown of the GUI.

            :return GUICoolDown: Status of the cooldown of the GUI.
            """

            return self.GUICoolDown

        def startGUICoolDown(self, ms=0.5):
            """
            Starts the cooldown of the GUI when the radio module is busy.

            :param ms:  Duration of the cooldown.
            """

            self.update_observers("CoolDownStarted", arg1=None, arg2=None)
            buttonCoolDownThread = ButtonCoolDownThread(
                ms, self.setGUICoolDown)
            buttonCoolDownThread.start()

        def getPlayingRadio(self):
            """
            Returns if the radio is being played or not.

            :return playingRadio: Status of the radio.
            """

            return self.playingRadio

        def getStatus(self):
            """
            Returns the current status of the reproduction. See AudioStatus class.

            :return: Current status.
            """

            return self.audioObject.getStatus()

        def notifyController(self, notify, var=0):
            """
            Method that other classes uses to notifie to the AudioController of the changes.

            :param notify: Kind of notification.
            :param var: Attached var.
            """

            if (notify == "nextTrack"):
                self.nextTrackEvent()
            elif (notify == "updateReproductionSecond"):
                self.updateReproductionSecondEvent(var)
            elif (notify == "endOfList"):
                self.nextTrack()
            elif (notify == "seekFrequencyChanged"):
                self.currentFMStation = var
                self.update_observers("UpdateCurrentFMFrequency",
                                      arg1=self.currentFMStation,
                                      arg2=None)

        def __str__(self):
            return repr(self) + self.val
class RadioMenuChannelMemory(QWidget):
    """
    This class provides a customized widget for control the memory banks of the radio channels.
    """

    __metaclass__ = ABCMeta

    def __init__(self, parent=None):
        """
        Constructor of the RadioMenuChannelMemory class.
        """

        super(RadioMenuChannelMemory, self).__init__(parent)

        self.db = RAM_DB()
        audioController = AudioController()
        radioChannels = self.db.getRadioChannels()

        self.memoryButtons = []
        self.labelsMemoryButtons = []
        for i in range(0, 9):
            self.memoryButtons.append(
                Button_Memory_PRM(i).createButton(60, 60))
            if (audioController.getPlayingRadio() == False
                    or audioController.getGUICoolDown() == True):
                self.memoryButtons[i].setOppacity(0.3)

        for i in range(0, 9):
            if (radioChannels[i] == None):
                memoryButtonLabel = "Vacío"
            else:
                memoryButtonLabel = radioChannels[i][1]

            self.labelsMemoryButtons.append(CustomLabel().createLabel(
                memoryButtonLabel, Qt.AlignCenter, 7))

        hButtonBarBox = QHBoxLayout()

        hButtonBarBox.addStretch()

        for i in range(0, len(self.memoryButtons)):
            vButtonBox = QVBoxLayout()
            hMemoryButtonBox = QHBoxLayout()

            hMemoryButtonBox.addStretch()
            hMemoryButtonBox.addWidget(self.memoryButtons[i])
            hMemoryButtonBox.addStretch()
            vButtonBox.addLayout(hMemoryButtonBox)

            hMemoryLabelBox = QHBoxLayout()
            hMemoryLabelBox.addStretch()
            hMemoryLabelBox.addWidget(self.labelsMemoryButtons[i])
            hMemoryLabelBox.addStretch()
            vButtonBox.addLayout(hMemoryLabelBox)

            hButtonBarBox.addLayout(vButtonBox)
            hButtonBarBox.addStretch()

        self.setLayout(hButtonBarBox)

    @abstractmethod
    def update(self, *args, **kwargs):
        """
        Update method of the observer pattern.

        :param args: args
        :param kwargs: kwargs
        """

        self.updateView(*args, **kwargs)

    def updateView(self, *args, arg1, arg2):
        """
        Update view method of the observer pattern.

        :param args: Name of the notification.
        :param arg1: Other data.
        :param arg2: Other data.
        """

        if (args[0] == "UpdateRadioChannelData"):
            radioChannels = self.db.getRadioChannels()
            for i in range(0, len(self.labelsMemoryButtons)):
                self.labelsMemoryButtons[i].setText(radioChannels[i][1])

        elif (args[0] == "CoolDownStarted"):
            for i in range(0, len(self.memoryButtons)):
                self.memoryButtons[i].setOppacity(0.3)

        elif (args[0] == "CoolDownEnded"):
            for i in range(0, len(self.memoryButtons)):
                self.memoryButtons[i].setOppacity(1)
Ejemplo n.º 20
0
class AudioFileVLC:
    """
    Plays MP3/WAV or other supported files using the VLC lib.
    """

    def __init__(self, notifyAudioController):
        """
        Constructor of the AudioFileVLC class.

        :param notifyAudioController: Method to notify of the changes to the Audio Controller.
        """

        self.vlcInstance = vlc.Instance()
        self.mediaPlayer = self.vlcInstance.media_player_new()
        self.mediaList = self.vlcInstance.media_list_new()
        self.listMediaPlayer = self.vlcInstance.media_list_player_new()
        self.listMediaPlayer.set_media_player(self.mediaPlayer)
        self.db = RAM_DB()
        self.threadController = ThreadController()
        (self.fileName, self.pathFiles, self.metaDataList) = self.db.getAudioDB()
        self.notifyAudioController = notifyAudioController

        #This boolean avoid to notify of unnecesary changes to the AudioController, works as a flag
        self.avoidNotify = False
        #This boolean avoid to stop the medialistplayer when is already stopped because have reached the end of the list.
        self.reproductionEnded = False

        for i in range(0, len(self.pathFiles)):
            self.mediaList.insert_media(self.vlcInstance.media_new(self.pathFiles[i]), i)

        self.listMediaPlayer.set_media_list(self.mediaList)

        #For the VLC Event handler
        self.vlc_eventsMediaList = self.listMediaPlayer.event_manager()
        self.vlc_eventsMediaPlayer = self.mediaPlayer.event_manager()
        self.vlc_eventsMediaPlayer.event_attach(vlc.EventType.MediaPlayerEndReached, self.endOfSong, 1)
        self.vlc_eventsMediaList.event_attach(vlc.EventType.MediaListPlayerNextItemSet, self.nextItem, 1)



        self.reproductionStatusThread = None


    def playAudio(self):
        """
        Plays an audio file.
        """

        self.avoidNotify = True
        self.listMediaPlayer.play_item_at_index(self.db.getSelection())
        # We only starts the thread that make polling for gets the current reproduction second if the current menu is the PlayAudioMenu
        if(self.db.getCurrentMenu() == "PlayAudioMenu"):
            self.startUpdateStatusThread()

    def startUpdateStatusThread(self):
        """
        Starts a thread that updates the reproduction status by polling to the vlc lib.
        """

        self.reproductionStatusThread = ReproductionStatusThread(self.mediaPlayer, self.notifyAudioController)
        self.threadController.setReproductionStatusThread(self.reproductionStatusThread)
        self.threadController.getReproductionStatusThread().start()

    def pauseAudio(self):
        """
        Pauses the audio.
        """

        self.listMediaPlayer.pause()

    def changeAudioSecond(self, second):
        """
        Changes the current reproduction second to another second.

        :param second: New current second.
        """

        self.mediaPlayer.set_time(second)

    def resumeAudio(self):
        """
        Resumes a paused audio.
        """

        self.listMediaPlayer.play()

    def stopAudio(self):
        """
        Stops the reproduction of an audio.
        """

        if (self.threadController.getReproductionStatusThread() != None):
            self.threadController.getReproductionStatusThread().stop()

        # At the end of the list, VLC Lib makes a stop() to the media player list by default.
        # If we make a stop() two times, it hangs
        if (self.reproductionEnded == False):
            self.listMediaPlayer.stop()
        else:
            self.reproductionEnded = False

    def getPath(self):
        """
        Returns the path of the file that it's being reproduced.

        :return: String with the path.
        """

        return self.path

    def nextItem(self, *args, **kwds):
        """
        Method called by the VLC event manager when the reproduction item has changed.

        :param args: args
        :param kwds: kwds
        """

        if (self.avoidNotify == False):
            self.notifyAudioController("nextTrack")
        else:
            self.avoidNotify = False

    def endOfSong(self, *args, **kwds):
        """
        Method called by the VLC event manager when the reproduction item ends.

        :param args: args
        :param kwds: kwds
        """

        # If the song ended & is the last of the list, must notify to the controller
        if self.db.getSelection() == (len(self.pathFiles)-1):
            self.reproductionEnded = True
            self.notifyAudioController("endOfList")