<commit_before>import player
from enum import Enum

from PyQt5 import QtCore, QtGui, QtWidgets, QtMultimedia

class Ui_MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        self.player = player.Player()
        self.setObjectName("MainWindow")
        self.resize(800, 600)
        self.setWindowTitle('MOYA Player')
        self.centralwidget = QtWidgets.QWidget(self)
        self.centralwidget.setObjectName("centralwidget")

        self.initControlButtons()

        self.progressBar = QtWidgets.QSlider(self.centralwidget)
        self.progressBar.setGeometry(QtCore.QRect(20, 460, 751, 20))
        self.progressBar.setOrientation(QtCore.Qt.Horizontal)
        self.progressBar.setObjectName("progressBar")

        self.positionLabel = QtWidgets.QLabel(self.centralwidget)
        self.positionLabel.setGeometry(QtCore.QRect(30, 440, 59, 18))
        self.positionLabel.setObjectName("position")

        self.durationLabel = QtWidgets.QLabel(self.centralwidget)
        self.durationLabel.setGeometry(QtCore.QRect(710, 440, 59, 18))
        self.durationLabel.setObjectName("duration")

        self.volumeBar = QtWidgets.QSlider(self.centralwidget)
        self.volumeBar.setGeometry(QtCore.QRect(670, 500, 101, 20))
        self.volumeBar.setOrientation(QtCore.Qt.Horizontal)
        self.volumeBar.setObjectName("volumeBar")
        self.volumeBar.setSliderPosition(50)

        self.muteButton = QtWidgets.QPushButton(self.centralwidget)
        self.muteButton.setGeometry(QtCore.QRect(610, 490, 51, 34))
        self.muteButton.setObjectName("muteButton")

        self.playingLabel = QtWidgets.QLabel(self.centralwidget)
        self.playingLabel.setGeometry(QtCore.QRect(150, 440, 491, 18))
        self.playingLabel.setObjectName("playingLabel")

        self.controlBox = QtWidgets.QHBoxLayout()
        self.controlBox.addWidget(self.progressBar)
        self.controlBox.addWidget(self.playButton)
        self.controlBox.addWidget(self.forwardButton)
        self.controlBox.addWidget(self.backwardButton)
        self.controlBox.addWidget(self.playingLabel)

        self.initPlaylistUI()

        self.setCentralWidget(self.centralwidget)

        self.initStatusBar()
        self.initMenuBar()

        self.retranslateUi()
        QtCore.QMetaObject.connectSlotsByName(self)
        self.events()
        self.show()

    def events(self):
        self.library.addToPlaylistButton.clicked.connect(self.addToPlaylist)
        self.library.listWidget.itemDoubleClicked.connect(self.selectPlaying)
        self.progressBar.sliderMoved.connect(self.player.setPosition)
        self.player.positionChanged.connect(self.progressBar.setValue)
        self.volumeBar.valueChanged.connect(self.player.setVolume)
        self.playButton.clicked.connect(self.playOrPause)
        self.player.durationChanged.connect(self.adjustAudioDuration)
        self.playbackButton.statusChanged.connect(self.player.setPlaybackMode)
        self.forwardButton.clicked.connect(self.player.next)
        self.backwardButton.clicked.connect(self.player.previous)
        self.player.changedStatus.connect(self.changePlaying)
        self.player.positionChanged.connect(self.adjustAudioPosition)
        self.stopButton.clicked.connect(self.player.stop)
        self.library.removeFromPlaylistButton.clicked.connect(self.removeFromPlaylist)

    @QtCore.pyqtSlot()
    def playOrPause(self):
        if self.player.state() == QtMultimedia.QMediaPlayer.PlayingState:
            self.playButton.setText("Play")
            self.player.pause()
        else:
            self.playButton.setText("Pause")
            self.player.play()

    def initPlaylistUI(self):
        self.library = Ui_Library(self.centralwidget)<commit_msg>moya-player/player_ui.py: Added other helping slots and functions<commit_after>import player
from enum import Enum

from PyQt5 import QtCore, QtGui, QtWidgets, QtMultimedia

class Ui_MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        self.player = player.Player()
        self.setObjectName("MainWindow")
        self.resize(800, 600)
        self.setWindowTitle('MOYA Player')
        self.centralwidget = QtWidgets.QWidget(self)
        self.centralwidget.setObjectName("centralwidget")

        self.initControlButtons()

        self.progressBar = QtWidgets.QSlider(self.centralwidget)
        self.progressBar.setGeometry(QtCore.QRect(20, 460, 751, 20))
        self.progressBar.setOrientation(QtCore.Qt.Horizontal)
        self.progressBar.setObjectName("progressBar")

        self.positionLabel = QtWidgets.QLabel(self.centralwidget)
        self.positionLabel.setGeometry(QtCore.QRect(30, 440, 59, 18))
        self.positionLabel.setObjectName("position")

        self.durationLabel = QtWidgets.QLabel(self.centralwidget)
        self.durationLabel.setGeometry(QtCore.QRect(710, 440, 59, 18))
        self.durationLabel.setObjectName("duration")

        self.volumeBar = QtWidgets.QSlider(self.centralwidget)
        self.volumeBar.setGeometry(QtCore.QRect(670, 500, 101, 20))
        self.volumeBar.setOrientation(QtCore.Qt.Horizontal)
        self.volumeBar.setObjectName("volumeBar")
        self.volumeBar.setSliderPosition(50)

        self.muteButton = QtWidgets.QPushButton(self.centralwidget)
        self.muteButton.setGeometry(QtCore.QRect(610, 490, 51, 34))
        self.muteButton.setObjectName("muteButton")

        self.playingLabel = QtWidgets.QLabel(self.centralwidget)
        self.playingLabel.setGeometry(QtCore.QRect(150, 440, 491, 18))
        self.playingLabel.setObjectName("playingLabel")

        self.controlBox = QtWidgets.QHBoxLayout()
        self.controlBox.addWidget(self.progressBar)
        self.controlBox.addWidget(self.playButton)
        self.controlBox.addWidget(self.forwardButton)
        self.controlBox.addWidget(self.backwardButton)
        self.controlBox.addWidget(self.playingLabel)

        self.initPlaylistUI()

        self.setCentralWidget(self.centralwidget)

        self.initStatusBar()
        self.initMenuBar()

        self.retranslateUi()
        QtCore.QMetaObject.connectSlotsByName(self)
        self.events()
        self.show()

    def events(self):
        self.library.addToPlaylistButton.clicked.connect(self.addToPlaylist)
        self.library.listWidget.itemDoubleClicked.connect(self.selectPlaying)
        self.progressBar.sliderMoved.connect(self.player.setPosition)
        self.player.positionChanged.connect(self.progressBar.setValue)
        self.volumeBar.valueChanged.connect(self.player.setVolume)
        self.playButton.clicked.connect(self.playOrPause)
        self.player.durationChanged.connect(self.adjustAudioDuration)
        self.playbackButton.statusChanged.connect(self.player.setPlaybackMode)
        self.forwardButton.clicked.connect(self.player.next)
        self.backwardButton.clicked.connect(self.player.previous)
        self.player.changedStatus.connect(self.changePlaying)
        self.player.positionChanged.connect(self.adjustAudioPosition)
        self.stopButton.clicked.connect(self.player.stop)
        self.library.removeFromPlaylistButton.clicked.connect(self.removeFromPlaylist)

    @QtCore.pyqtSlot()
    def removeFromPlaylist(self):
        for item in self.library.listWidget.selectedItems():
            print(item.text())
            self.library.listWidget.removeItemWidget(item)

    @QtCore.pyqtSlot(QtWidgets.QListWidgetItem)
    def selectPlaying(self, itemClicked):
        selectedIndex = self.library.listWidget.row(itemClicked)
        self.player.setIndex(selectedIndex + 1)
        self.playingLabel.setText(self.player.status + ": " + itemClicked.text())

    @QtCore.pyqtSlot('qint64')
    def adjustAudioPosition(self, position):
        self.positionLabel.setText(millisToStr(position))

    @QtCore.pyqtSlot('qint64')
    def adjustAudioDuration(self, duration):
        self.progressBar.setRange(0, duration)
        self.durationLabel.setText(millisToStr(duration))

    @QtCore.pyqtSlot('QString')
    def changePlaying(self, status):
        self.playingLabel.setText(status)

    @QtCore.pyqtSlot()
    def playOrPause(self):
        if self.player.state() == QtMultimedia.QMediaPlayer.PlayingState:
            self.playButton.setText("Play")
            self.player.pause()
        else:
            self.playButton.setText("Pause")
            self.player.play()

    @QtCore.pyqtSlot()
    def addToPlaylist(self):
        path = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file')[0]
        self.player.addToPlaylist(path)
        self.library.listWidget.addItem(player.getSong(path))

    def addSong(self, url):
        self.player.addToPlaylist(url)
        self.library.listWidget.addItem(player.getSong(url))

    def initPlaylistUI(self):
        self.library = Ui_Library(self.centralwidget)
{'fraction_non_alphanumeric': 0.10722742135528245, 'fraction_numerical': 0.016574585635359115, 'mean_word_length': 3.335288367546432, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '85030', 'n_tokens_mistral': 2819, 'n_tokens_neox': 2615, 'n_words': 295}