Python Forum
[PyQt] QSlider jump to mouse click position
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] QSlider jump to mouse click position
#1
So I've been searching for a way to make it so that when I click anywhere on a QSlider it would go to that position instead of just jumping one step ahead. But also I'd like to retain the ability to pick and drag the handle to a position and then continue from that position onwards. I found this:

from PySide import QtCore, QtGui

class QJumpSlider(QtGui.QSlider):
	def __init__(self, parent = None):
		super(QJumpSlider, self).__init__(parent)
	
	def mousePressEvent(self, event):
		#Jump to click position
		self.setValue(QtGui.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))
	
	def mouseMoveEvent(self, event):
		#Jump to pointer position while moving
		self.setValue(QtGui.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))
And the way I make the slider is this:
self.seekSlider = QJumpSlider(self.centralwidget)
If I comment out the two functions (mousePressEvent and mouseMoveEvent) everything works as if it's a normal QSlider. So the __init__ is correct. The above code changes the position of the slider but the action of skipping the song to that position does not work and it just goes back to the previous value ignoring my click and the position change.

In short: how to make it so that when I click anywhere on a QSlider, for the music to jump to that spot while also retaining the default handle drag method. I'll post my whole code if you need it to test and see (if you don't understand what I mean). I found the above code from this link.
Reply
#2
I managed to actually make the audio go to the position where I clicked on the QSlider but now I can't figure out how to update the slider value itself. My code is below:
import sys, tkinter, pygame, mutagen, os, time
from tkinter import filedialog
from mutagen import File
from mutagen.easyid3 import EasyID3
from PyLyrics import *
from PySide.QtCore import *
from PySide.QtGui import *
import warnings
from mutagen.mp3 import MP3, MPEGInfo
from PySide import QtCore, QtGui
 
class QJumpSlider(QtGui.QSlider):
	def __init__(self, parent = None):
		super(QJumpSlider, self).__init__(parent)
	
	def mousePressEvent(self, event):
		#Jump to click position
		MusicPlayer.seekMusic(MusicPlayer, QtGui.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))
	
	def mouseMoveEvent(self, event):
		#Jump to pointer position while moving
		MusicPlayer.seekMusic(MusicPlayer, QtGui.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))

class Graphics(object):
	def setupUi(self, MainWindow):
		MainWindow.setObjectName("MainWindow")
		MainWindow.resize(1125, 865)
		self.centralwidget = QtGui.QWidget(MainWindow)
		self.centralwidget.setObjectName("centralwidget")
		self.playlistWindow = QtGui.QListView(self.centralwidget)
		self.playlistWindow.setGeometry(QtCore.QRect(10, 40, 301, 801))
		self.playlistWindow.setObjectName("playlistWindow")
		self.lyricsWindow = QtGui.QTextBrowser(self.centralwidget)
		self.lyricsWindow.setGeometry(QtCore.QRect(810, 40, 301, 801))
		self.lyricsWindow.setObjectName("lyricsWindow")
		self.albumArt = QtGui.QGraphicsView(self.centralwidget)
		self.albumArt.setGeometry(QtCore.QRect(325, 40, 471, 431))
		self.albumArt.setObjectName("albumArt")
		self.openFileButton = QtGui.QPushButton(self.centralwidget)
		self.openFileButton.setGeometry(QtCore.QRect(523, 10, 75, 23))
		self.openFileButton.setObjectName("openFileButton")
		self.songName = QtGui.QLabel(self.centralwidget)
		self.songName.setGeometry(QtCore.QRect(330, 640, 461, 21))
		self.songName.setObjectName("songName")
		self.artistName = QtGui.QLabel(self.centralwidget)
		self.artistName.setGeometry(QtCore.QRect(330, 670, 461, 21))
		self.artistName.setObjectName("artistName")
		self.albumName = QtGui.QLabel(self.centralwidget)
		self.albumName.setGeometry(QtCore.QRect(330, 700, 461, 21))
		self.albumName.setObjectName("albumName")
		self.songsCount = QtGui.QLabel(self.centralwidget)
		self.songsCount.setGeometry(QtCore.QRect(740, 670, 61, 21))
		self.songsCount.setObjectName("songsCount")
		self.seekSlider = QJumpSlider(self.centralwidget)
		self.seekSlider.setGeometry(QtCore.QRect(330, 500, 461, 22))
		self.seekSlider.setOrientation(QtCore.Qt.Horizontal)
		self.seekSlider.setObjectName("seekSlider")
		self.volumeSlider = QtGui.QSlider(self.centralwidget)
		self.volumeSlider.setGeometry(QtCore.QRect(330, 780, 461, 22))
		self.volumeSlider.setOrientation(QtCore.Qt.Horizontal)
		self.volumeSlider.setObjectName("volumeSlider")
		self.seekLabel = QtGui.QLabel(self.centralwidget)
		self.seekLabel.setGeometry(QtCore.QRect(330, 480, 461, 20))
		self.seekLabel.setObjectName("seekLabel")
		self.prevSongButton = QtGui.QPushButton(self.centralwidget)
		self.prevSongButton.setGeometry(QtCore.QRect(440, 550, 71, 71))
		self.prevSongButton.setText("")
		self.prevSongButton.setIconSize(QtCore.QSize(80, 80))
		self.prevSongButton.setObjectName("prevSongButton")
		self.playPauseButton = QtGui.QPushButton(self.centralwidget)
		self.playPauseButton.setGeometry(QtCore.QRect(520, 550, 81, 71))
		self.playPauseButton.setText("")
		self.playPauseButton.setIconSize(QtCore.QSize(80, 80))
		self.playPauseButton.setObjectName("playPauseButton")
		self.nextSongButton = QtGui.QPushButton(self.centralwidget)
		self.nextSongButton.setGeometry(QtCore.QRect(610, 550, 71, 71))
		self.nextSongButton.setText("")
		self.nextSongButton.setIconSize(QtCore.QSize(80, 80))
		self.nextSongButton.setObjectName("nextSongButton")
		self.volumeLabel = QtGui.QLabel(self.centralwidget)
		self.volumeLabel.setGeometry(QtCore.QRect(330, 760, 461, 20))
		self.volumeLabel.setObjectName("volumeLabel")
		self.minVolLabel = QtGui.QLabel(self.centralwidget)
		self.minVolLabel.setGeometry(QtCore.QRect(330, 810, 21, 21))
		self.minVolLabel.setObjectName("minVolLabel")
		self.maxVolLabel = QtGui.QLabel(self.centralwidget)
		self.maxVolLabel.setGeometry(QtCore.QRect(760, 810, 41, 21))
		self.maxVolLabel.setObjectName("maxVolLabel")
		self.curVolLabel = QtGui.QLabel(self.centralwidget)
		self.curVolLabel.setGeometry(QtCore.QRect(540, 810, 41, 21))
		self.curVolLabel.setObjectName("curVolLabel")
		self.playlistLabel = QtGui.QLabel(self.centralwidget)
		self.playlistLabel.setGeometry(QtCore.QRect(10, 10, 301, 21))
		self.playlistLabel.setObjectName("playlistLabel")
		self.lyricsLabel = QtGui.QLabel(self.centralwidget)
		self.lyricsLabel.setGeometry(QtCore.QRect(810, 10, 301, 21))
		self.lyricsLabel.setObjectName("lyricsLabel")
		self.totalSongTimeLabel = QtGui.QLabel(self.centralwidget)
		self.totalSongTimeLabel.setGeometry(QtCore.QRect(760, 520, 41, 21))
		self.totalSongTimeLabel.setObjectName("totalSongTimeLabel")
		self.curSongTimeLabel = QtGui.QLabel(self.centralwidget)
		self.curSongTimeLabel.setGeometry(QtCore.QRect(320, 520, 41, 21))
		self.curSongTimeLabel.setObjectName("curSongTimeLabel")
		self.blackThemeButton = QtGui.QPushButton(self.centralwidget)
		self.blackThemeButton.setGeometry(QtCore.QRect(330, 10, 71, 23))
		self.blackThemeButton.setObjectName("blackThemeButton")
		self.blueThemeButton = QtGui.QPushButton(self.centralwidget)
		self.blueThemeButton.setGeometry(QtCore.QRect(410, 10, 71, 23))
		self.blueThemeButton.setObjectName("blueThemeButton")
		self.whiteThemeButton = QtGui.QPushButton(self.centralwidget)
		self.whiteThemeButton.setGeometry(QtCore.QRect(720, 10, 71, 23))
		self.whiteThemeButton.setObjectName("whiteThemeButton")
		self.pinkThemeButton = QtGui.QPushButton(self.centralwidget)
		self.pinkThemeButton.setGeometry(QtCore.QRect(640, 10, 71, 23))
		self.pinkThemeButton.setObjectName("pinkThemeButton")
		MainWindow.setCentralWidget(self.centralwidget)
		self.statusbar = QtGui.QStatusBar(MainWindow)
		self.statusbar.setObjectName("statusbar")
		MainWindow.setStatusBar(self.statusbar)
		
		self.retranslateUi(MainWindow)
		QtCore.QMetaObject.connectSlotsByName(MainWindow)
		
	def retranslateUi(self, MainWindow):
		MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Snake MP3 Player", None, QtGui.QApplication.UnicodeUTF8))
		self.lyricsWindow.setHtml(QtGui.QApplication.translate("MainWindow", "<!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:\'MS Shell Dlg 2\'; font-size:8.25pt; 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>", None, QtGui.QApplication.UnicodeUTF8))
		self.openFileButton.setText(QtGui.QApplication.translate("MainWindow", "Open File", None, QtGui.QApplication.UnicodeUTF8))
		self.songName.setText(QtGui.QApplication.translate("MainWindow", "Song:  ", None, QtGui.QApplication.UnicodeUTF8))
		self.artistName.setText(QtGui.QApplication.translate("MainWindow", "Artist:  ", None, QtGui.QApplication.UnicodeUTF8))
		self.albumName.setText(QtGui.QApplication.translate("MainWindow", "Album: ", None, QtGui.QApplication.UnicodeUTF8))
		self.songsCount.setText(QtGui.QApplication.translate("MainWindow", "0 / 0", None, QtGui.QApplication.UnicodeUTF8))
		self.seekLabel.setText(QtGui.QApplication.translate("MainWindow", "<html><head/><body><p align=\"center\">Seek</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
		self.volumeLabel.setText(QtGui.QApplication.translate("MainWindow", "<html><head/><body><p align=\"center\">Volume</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
		self.minVolLabel.setText(QtGui.QApplication.translate("MainWindow", "0 %", None, QtGui.QApplication.UnicodeUTF8))
		self.maxVolLabel.setText(QtGui.QApplication.translate("MainWindow", "100 %", None, QtGui.QApplication.UnicodeUTF8))
		self.curVolLabel.setText(QtGui.QApplication.translate("MainWindow", "100 %", None, QtGui.QApplication.UnicodeUTF8))
		self.playlistLabel.setText(QtGui.QApplication.translate("MainWindow", "Playlist (.m3u)", None, QtGui.QApplication.UnicodeUTF8))
		self.lyricsLabel.setText(QtGui.QApplication.translate("MainWindow", "Lyrics (http://www.lyrics.wikia.com)", None, QtGui.QApplication.UnicodeUTF8))
		self.totalSongTimeLabel.setText(QtGui.QApplication.translate("MainWindow", "0:00", None, QtGui.QApplication.UnicodeUTF8))
		self.curSongTimeLabel.setText(QtGui.QApplication.translate("MainWindow", "0:00", None, QtGui.QApplication.UnicodeUTF8))
		self.blackThemeButton.setText(QtGui.QApplication.translate("MainWindow", "Black Theme", None, QtGui.QApplication.UnicodeUTF8))
		self.blueThemeButton.setText(QtGui.QApplication.translate("MainWindow", "Blue Theme", None, QtGui.QApplication.UnicodeUTF8))
		self.whiteThemeButton.setText(QtGui.QApplication.translate("MainWindow", "White Theme", None, QtGui.QApplication.UnicodeUTF8))
		self.pinkThemeButton.setText(QtGui.QApplication.translate("MainWindow", "Pink Theme", None, QtGui.QApplication.UnicodeUTF8))

class track():
    def __init__(self, length, title, path):
        self.length = length
        self.title = title
        self.path = path
	
def seekStyle():
	return """
		QSlider::groove:horizontal {
			border: 1px solid #bbb;
			background: white;
			height: 10px;
			border-radius: 4px;
		}

		QSlider::sub-page:horizontal {
			background: qlineargradient(x1: 0, y1: 0,    x2: 0, y2: 1,
				stop: 0 #66e, stop: 1 #bbf);
			background: qlineargradient(x1: 0, y1: 0.2, x2: 1, y2: 1,
				stop: 0 #bbf, stop: 1 #55f);
			border: 1px solid #777;
			height: 10px;
			border-radius: 4px;
		}

		QSlider::add-page:horizontal {
			background: #fff;
			border: 1px solid #777;
			height: 10px;
			border-radius: 4px;
		}

		QSlider::handle:horizontal {
			background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
				stop:0 #eee, stop:1 #ccc);
			border: 1px solid #777;
			width: 13px;
			margin-top: -2px;
			margin-bottom: -2px;
			border-radius: 4px;
		}

		QSlider::handle:horizontal:hover {
			background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
				stop:0 #fff, stop:1 #ddd);
			border: 1px solid #444;
			border-radius: 4px;
		}

		QSlider::sub-page:horizontal:disabled {
			background: #bbb;
			border-color: #999;
		}

		QSlider::add-page:horizontal:disabled {
			background: #eee;
			border-color: #999;
		}

		QSlider::handle:horizontal:disabled {
			background: #eee;
			border: 1px solid #aaa;
			border-radius: 4px;
		}
	"""
	
def volumeStyle():
	return """
		QSlider::groove {
			border: 1px solid #999999;
			background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #E6E6E6, stop:1 #EEEEEE);
		}
		
		QSlider::groove:disabled {
			background: #efefef;
		}
		
		QSlider::handle {
			background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 #8f8f8f);
			border: 1px solid #5c5c5c;
			border-radius: 3px;
			width: 15px;
			height: 15px;
		}
		
		QSlider::handle:disabled {
			background: #D3D0CD;
		}
	"""
	
def blackPlaylistWindowStyle():
	return """
	/*Playlist Window Style*/
		QListView {
			background-color: #000000;
			color: #FFFFFF;
		}
		
		QListView::item:selected:!active {
			background-color: #008000;
			color: #FFFFFF;
		}
		
		QListView::item:selected:active {
			background-color: #3B9C9C;
			color: #FFFFFF;
		}
		
		QListView::item:hover {
			background-color: #6698FF;
			color: #FFFFFF;
		}
	"""
	
def blackLyricsWindowStyle():
	return """
	/*Lyrics Window Style*/
		QTextBrowser {
			background-color: #000000;
			color: #FFFFFF;
		}
	"""
	
def blackMediaButtonsStyle():
	return """
	/*Media Buttons Style*/
		QPushButton {
			background-color: #25383C;
		}
		
		QPushButton:hover {
			background-color: #504A4B;
		}
	"""
	
def blackMainWindowStyle():
	return """
	/*Main Window Style*/
		QMainWindow {
			background-color: #000000;
			color: #FFFFFF;
		}
	"""
	
def blackLabelsStyle():
	return """
	/*Labels Style*/
		QLabel {
			color: #FFFFFF;
		}
	"""
	
def blackThemeButtonsStyle():
	return """
	/*Theme Buttons Style*/
		QPushButton {
			background-color: #FFFFFF;
			color: #000000;
		}
	"""
	
def bluePlaylistWindowStyle():
	return """
	/*Playlist Window Style*/
		QListView {
			background-color: #0000A0;
			color: #FFFFFF;
		}
		
		QListView::item:selected:!active {
			background-color: #FFA500;
			color: #000000;
		}
		
		QListView::item:selected:active {
			background-color: #FF0000;
			color: #000000;
		}
		
		QListView::item:hover {
			background-color: #00FFFF;
			color: #000000;
		}
	"""
	
def blueLyricsWindowStyle():
	return """
	/*Lyrics Window Style*/
		QTextBrowser {
			background-color: #0000A0;
			color: #FFFFFF;
		}
	"""
	
def blueMediaButtonsStyle():
	return """
	/*Media Buttons Style*/
		QPushButton {
			background-color: #000000;
		}
		
		QPushButton:hover {
			background-color: #25383C;
		}
	"""
	
def blueMainWindowStyle():
	return """
	/*Main Window Style*/
		QMainWindow {
			background-color: #2B65EC;
			color: #FFFFFF;
		}
	"""
	
def blueLabelsStyle():
	return """
	/*Labels Style*/
		QLabel {
			color: #00FF00;
		}
	"""
	
def blueThemeButtonsStyle():
	return """
	/*Theme Buttons Style*/
		QPushButton {
			background-color: #FFFFFF;
			color: #000000;
		}
	"""
	
def pinkPlaylistWindowStyle():
	return """
	/*Playlist Window Style*/
		QListView {
			background-color: #C12283;
			color: #000000;
		}
		
		QListView::item:selected:!active {
			background-color: #AF7817;
			color: #E5E4E2;
		}
		
		QListView::item:selected:active {
			background-color: #C7A317;
			color: #FAEBD7;
		}
		
		QListView::item:hover {
			background: #3EA99F;
			color: #FAEBD7;
		}
	"""
	
def pinkLyricsWindowStyle():
	return """
	/*Lyrics Window Style*/
		QTextBrowser {
			background-color: #C12283;
			color: #000000;
		}
	"""
	
def pinkMediaButtonsStyle():
	return """
	/*Media Buttons Style*/
		QPushButton {
			background-color: #79BAEC;
		}
		
		QPushButton:hover {
			background-color: #56A5EC;
		}
	"""
	
def pinkMainWindowStyle():
	return """
	/*Main Window Style*/
		QMainWindow {
			background-color: #F535AA;
			color: #000000;
		}
	"""
	
def pinkLabelsStyle():
	return """
	/*Labels Style*/
		QLabel {
			color: #000000;
		}
	"""
	
def pinkThemeButtonsStyle():
	return """
	/*Theme Buttons Style*/
		QPushButton {
			background-color: #FFFFFF;
			color: #000000;
		}
	"""
	
def whitePlaylistWindowStyle():
	return """
	/*Playlist Window Style*/
		QListView {
			background-color: None;
			color: None;
		}
		
		QListView::item:selected:!active {
			background-color: None;
			color: None;
		}
		
		QListView::item:selected:active {
			background-color: None;
			color: None;
		}
		
		QListView::item:hover {
			background: None;
			color: None;
		}
	"""
	
def whiteLyricsWindowStyle():
	return """
	/*Lyrics Window Style*/
		QTextBrowser {
			background-color: None;
			color: None;
		}
	"""
	
def whiteMediaButtonsStyle():
	return """
	/*Media Buttons Style*/
		QPushButton {
			background-color: None;
		}
		
		QPushButton:hover {
			background-color: None;
		}
	"""
	
def whiteMainWindowStyle():
	return """
	/*Main Window Style*/
		QMainWindow {
			background-color: None;
			color: None;
		}
	"""
	
def whiteLabelsStyle():
	return """
	/*Labels Style*/
		QLabel {
			color: None;
		}
	"""
	
def whiteThemeButtonsStyle():
	return """
	/*Theme Buttons Style*/
		QPushButton {
			background-color: None;
			color: None;
		}
	"""

class MusicPlayer(QMainWindow, Graphics):
	def __init__(self, parent = None):
		super(MusicPlayer, self).__init__(parent)
		self.setupUi(self)
		pygame.init()
		pygame.mixer.init()
		warnings.filterwarnings("ignore", category = UserWarning, module = "bs4")
		self.openFileButton.clicked.connect(self.openFileSelectionDialog)
		self.prevIcon = QtGui.QIcon()
		self.prevIconImage = QtGui.QPixmap("icons/prevButton.png")
		self.prevIcon.addPixmap(self.prevIconImage)
		self.prevSongButton.setIcon(self.prevIcon)
		self.playIcon = QtGui.QIcon()
		self.playIconImage = QtGui.QPixmap("icons/playButton.png")
		self.playIcon.addPixmap(self.playIconImage)
		self.playPauseButton.setIcon(self.playIcon)
		self.pauseIcon = QtGui.QIcon()
		self.pauseIconImage = QtGui.QPixmap("icons/pauseButton.png")
		self.pauseIcon.addPixmap(self.pauseIconImage)
		self.nextIcon = QtGui.QIcon()
		self.nextIconImage = QtGui.QPixmap("icons/nextButton.png")
		self.nextIcon.addPixmap(self.nextIconImage)
		self.nextSongButton.setIcon(self.nextIcon)
		self.volumeSlider.setValue(100)
		self.seekSlider.setValue(0)
		self.prevSongButton.clicked.connect(self.previousSongAudioButton)
		self.playPauseButton.clicked.connect(self.playPauseAudioButton)
		self.nextSongButton.clicked.connect(self.nextSongAudioButton)
		self.previousButtonPressed = False
		self.nextButtonPressed = False
		self.isPlaying = False
		self.volumeSlider.setRange(0, 100)
		self.playlistCurrentSongIndex = 0
		self.playlistModel = QtGui.QStandardItemModel(self.playlistWindow)
		self.playlistWindow.setEditTriggers(QAbstractItemView.NoEditTriggers)
		self.playlistWindow.doubleClicked.connect(self.playlistItemDoubleClick)
		self.volumeSlider.valueChanged.connect(self.setVolume)
		self.seekSlider.sliderMoved.connect(self.seekMusic)
		self.fileDialogFilePath = ""
		self.lastVisitedDirectory = ""
		self.workingDirectory = os.getcwd()
		self.nextSongTimer = False
		self.songFileToGetLengthFrom = False
		self.songFileLength = 0
		self.timerCounter = 0
		self.nextSongTimer = QTimer()
		self.nextSongTimer.timeout.connect(self.playNextSongInPlaylist)
		self.nextSongTimer.start(1000)
		self.playerWentToFirstSongAutomatically = False
		self.updateSeekTimer = QTimer()
		self.updateSeekTimer.timeout.connect(self.updateSeekSlider)
		self.updateSeekTimer.start(1000)
		self.curVolLabel.setAlignment(QtCore.Qt.AlignCenter)
		self.playlistLabel.setAlignment(QtCore.Qt.AlignCenter)
		self.lyricsLabel.setAlignment(QtCore.Qt.AlignCenter)
		self.curSongTimeLabel.setAlignment(QtCore.Qt.AlignCenter)
		self.totalSongTimeLabel.setAlignment(QtCore.Qt.AlignCenter)
		self.seekSlider.setStyleSheet(seekStyle())
		self.volumeSlider.setStyleSheet(volumeStyle())
		self.blackThemeButton.clicked.connect(self.switchBlackTheme)
		self.blueThemeButton.clicked.connect(self.switchBlueTheme)
		self.pinkThemeButton.clicked.connect(self.switchPinkTheme)
		self.whiteThemeButton.clicked.connect(self.switchWhiteTheme)
		self.songHasCoverImage = False
		self.putDefaultTheme()
		self.doublePressCounter = 0
		self.loadSettings()
	
	def openFileSelectionDialog(self):
		root = tkinter.Tk()
		root.withdraw()
		if self.lastVisitedDirectory != "":
			self.file_path = filedialog.askopenfilename(initialdir = self.lastVisitedDirectory, title = "Select a song or a playlist", filetypes = (("Media files","*.mp3 *.m3u"),("All files","*.*")))
		else:
			self.file_path = filedialog.askopenfilename(initialdir = self.workingDirectory, title = "Select a song or a playlist", filetypes = (("Media files","*.mp3 *.m3u"),("All files","*.*")))
		self.playlistCurrentSongIndex = 0
		if self.file_path != "":
			self.fileDialogFilePath = self.file_path
			self.lastVisitedDirectory = os.path.dirname(self.file_path)
			self.saveSettings("LastVisitedDirectory", self.lastVisitedDirectory)
			self.playAudioOnFileSelect(self.fileDialogFilePath)
	
	def playAudioOnFileSelect(self, path):
		self.timerCounter = 0
		self.seekSlider.setValue(0)
		if path.endswith(".m3u"):
			self.playlist = self.parseM3U(path)
			if pygame.mixer.get_init() != None:
				pygame.mixer.music.stop()
			pygame.mixer.quit()
			if os.path.exists(self.playlist[self.playlistCurrentSongIndex].path):
				self.info = MPEGInfo(open(self.playlist[self.playlistCurrentSongIndex].path, "rb"))
				self.frequency = self.info.sample_rate
				self.channels = self.info.channels
				pygame.mixer.init(frequency = int(self.frequency), channels = int(self.channels))
				self.loadSettings()
				pygame.mixer.music.load(self.playlist[self.playlistCurrentSongIndex].path.encode("utf8"))
				pygame.mixer.music.play()
				self.songFileToGetLengthFrom = MP3(self.playlist[self.playlistCurrentSongIndex].path)
				self.songFileLength = self.songFileToGetLengthFrom.info.length
				self.seekSlider.setRange(0, self.songFileLength)
				self.showSongInfo(self.playlist[self.playlistCurrentSongIndex].path)
				self.addM3USongsToPlaylistWindow()
				self.setCurrentSongHighlighted()
				self.playPauseButton.setIcon(self.pauseIcon)
			else:
				self.playlistModel.removeRows(0, self.playlistModel.rowCount())
				self.lyricsWindow.setText("The .m3u playlist file you chose appears to be invalid or broken. Please pick another one or play a .mp3 file instead.")
				self.playPauseButton.setIcon(self.playIcon)
				self.songHasCoverImage = False
				self.loadSettings()
		elif path.endswith(".mp3"):
			if pygame.mixer.get_init() != None:
				pygame.mixer.music.stop()
			pygame.mixer.quit()
			self.info = MPEGInfo(open(path, "rb"))
			self.frequency = self.info.sample_rate
			self.channels = self.info.channels
			pygame.mixer.init(frequency = int(self.frequency), channels = int(self.channels))
			self.loadSettings()
			pygame.mixer.music.load(path.encode("utf8"))
			pygame.mixer.music.play()
			self.songFileToGetLengthFrom = MP3(path)
			self.songFileLength = self.songFileToGetLengthFrom.info.length
			self.seekSlider.setRange(0, self.songFileLength)
			self.showSongInfo(path)
			self.playlistModel.removeRows(0, self.playlistModel.rowCount())
			if self.playlistModel.rowCount() == 0:
				self.songFile = EasyID3(path)
				if "title" in self.songFile:
					self.songFileTitle = self.songFile["title"][0]
				else:
					self.songFileTitle = self.fileDialogFilePath.split("/", -1)[-1].split(".mp3")[0]
				self.item = QtGui.QStandardItem("1: " + self.songFileTitle)
				self.playlistModel.appendRow(self.item)
				self.playlistWindow.setModel(self.playlistModel)
				self.setCurrentSongHighlighted()
				self.playPauseButton.setIcon(self.pauseIcon)
		self.playerWentToFirstSongAutomatically = False
		self.isPlaying = True
		
	def playAudioFromSelectedFile(self, path):
		self.timerCounter = 0
		self.seekSlider.setValue(0)
		if pygame.mixer.get_init() != None:
			pygame.mixer.music.stop()
		pygame.mixer.quit()
		self.info = MPEGInfo(open(path, "rb"))
		self.frequency = self.info.sample_rate
		self.channels = self.info.channels
		pygame.mixer.init(frequency = int(self.frequency), channels = int(self.channels))
		self.loadSettings()
		pygame.mixer.music.load(path.encode("utf8"))
		pygame.mixer.music.play()
		self.songFileToGetLengthFrom = MP3(path)
		self.songFileLength = self.songFileToGetLengthFrom.info.length
		self.seekSlider.setRange(0, self.songFileLength)
		self.showSongInfo(path)
		self.setCurrentSongHighlighted()
		self.playPauseButton.setIcon(self.pauseIcon)
		self.playerWentToFirstSongAutomatically = False
		self.isPlaying = True
		
	def playNextSongInPlaylist(self):
		if self.fileDialogFilePath.endswith(".m3u"):
			if self.isPlaying == True:
				if os.path.exists(self.playlist[self.playlistCurrentSongIndex].path):
					self.timerCounter += 1
					self.songFileToGetLengthFrom = MP3(self.playlist[self.playlistCurrentSongIndex].path)
					self.songFileLength = self.songFileToGetLengthFrom.info.length
					if int(self.timerCounter) > int(self.songFileLength):
						if self.playlistCurrentSongIndex + 1 <= (len(self.playlist) - 1):
							self.playlistCurrentSongIndex += 1
							self.playAudioFromSelectedFile(self.playlist[self.playlistCurrentSongIndex].path)
						elif self.playlistCurrentSongIndex + 1 > (len(self.playlist) - 1):
							self.playlistCurrentSongIndex = 0
							self.timerCounter = 0
							self.seekSlider.setValue(0)
							if pygame.mixer.get_init() != None:
								pygame.mixer.music.stop()
							pygame.mixer.quit()
							self.info = MPEGInfo(open(self.playlist[self.playlistCurrentSongIndex].path, "rb"))
							self.frequency = self.info.sample_rate
							self.channels = self.info.channels
							pygame.mixer.init(frequency = int(self.frequency), channels = int(self.channels))
							self.loadSettings()
							pygame.mixer.music.load(self.playlist[self.playlistCurrentSongIndex].path.encode("utf8"))
							self.seekSlider.setRange(0, self.songFileLength)
							self.showSongInfo(self.playlist[self.playlistCurrentSongIndex].path)
							self.setCurrentSongHighlighted()
							self.playPauseButton.setIcon(self.playIcon)
							self.playerWentToFirstSongAutomatically = True
							self.isPlaying = False
		elif self.fileDialogFilePath.endswith(".mp3"):
			if self.isPlaying == True:
				self.timerCounter += 1
				self.songFileToGetLengthFrom = MP3(self.fileDialogFilePath)
				self.songFileLength = self.songFileToGetLengthFrom.info.length
				if int(self.timerCounter) > int(self.songFileLength):
					self.timerCounter = 0
					self.seekSlider.setValue(0)
					if pygame.mixer.get_init() != None:
						pygame.mixer.music.stop()
					pygame.mixer.quit()
					self.info = MPEGInfo(open(self.fileDialogFilePath, "rb"))
					self.frequency = self.info.sample_rate
					self.channels = self.info.channels
					pygame.mixer.init(frequency = int(self.frequency), channels = int(self.channels))
					self.loadSettings()
					pygame.mixer.music.load(self.fileDialogFilePath.encode("utf8"))
					self.seekSlider.setRange(0, self.songFileLength)
					self.showSongInfo(self.fileDialogFilePath)
					self.setCurrentSongHighlighted()
					self.playPauseButton.setIcon(self.playIcon)
					self.playerWentToFirstSongAutomatically = True
					self.isPlaying = False
	
	def playPauseAudioButton(self):
		if self.fileDialogFilePath.endswith(".m3u") or self.fileDialogFilePath.endswith(".mp3"):
			if self.isPlaying == True:
				if pygame.mixer.get_init() != None:
					pygame.mixer.music.pause()
				self.playPauseButton.setIcon(self.playIcon)
				self.previousButtonPressed = False
				self.nextButtonPressed = False
				self.isPlaying = False
			elif self.isPlaying == False:
				if self.previousButtonPressed == True or self.nextButtonPressed == True or self.playerWentToFirstSongAutomatically == True:
					if pygame.mixer.get_init() != None:
						pygame.mixer.music.play()
					self.previousButtonPressed = False
					self.nextButtonPressed = False
					self.playerWentToFirstSongAutomatically = False
					self.playPauseButton.setIcon(self.pauseIcon)
					self.isPlaying = True
				elif self.previousButtonPressed == False or self.nextButtonPressed == False:
					if pygame.mixer.get_init() != None:
						pygame.mixer.music.unpause()
						self.playPauseButton.setIcon(self.pauseIcon)
						self.isPlaying = True
		
	def previousSongAudioButton(self):
		if self.fileDialogFilePath.endswith(".m3u") and self.playlistCurrentSongIndex != 0:
			self.doublePressCounter += 1
			if self.doublePressCounter == 2:
				self.playlistCurrentSongIndex -= 1
			self.doublePressTimer = QTimer()
			self.doublePressTimer.timeout.connect(self.resetDoublePressPreviousButtonCounter)
			self.doublePressTimer.setSingleShot(True)
			self.doublePressTimer.start(50)
			if os.path.exists(self.playlist[self.playlistCurrentSongIndex].path):
				self.playAudioFromSelectedFile(self.playlist[self.playlistCurrentSongIndex].path)
				self.previousButtonPressed = True
		elif self.fileDialogFilePath.endswith(".m3u") and self.playlistCurrentSongIndex == 0:
			if os.path.exists(self.playlist[self.playlistCurrentSongIndex].path):
				self.playAudioFromSelectedFile(self.playlist[self.playlistCurrentSongIndex].path)
				self.previousButtonPressed = True
		elif self.fileDialogFilePath.endswith(".mp3"):
			self.timerCounter = 0
			self.seekSlider.setValue(0)
			self.songFileToGetLengthFrom = MP3(self.fileDialogFilePath)
			self.songFileLength = self.songFileToGetLengthFrom.info.length
			self.seekSlider.setRange(0, self.songFileLength)
			if self.isPlaying == True:
				if pygame.mixer.get_init() != None:
					pygame.mixer.music.stop()
				pygame.mixer.music.play()
				self.previousButtonPressed = True
			elif self.isPlaying == False:
				if pygame.mixer.get_init() != None:
					pygame.mixer.music.stop()
				pygame.mixer.music.load(self.fileDialogFilePath.encode("utf8"))
				self.playPauseButton.setIcon(self.playIcon)
				self.previousButtonPressed = True
		
	def resetDoublePressPreviousButtonCounter(self):
		self.doublePressCounter = 0
		
	def nextSongAudioButton(self):
		if self.fileDialogFilePath.endswith(".m3u"):
			if self.playlistCurrentSongIndex != (len(self.playlist) - 1):
				self.playlistCurrentSongIndex += 1
			elif self.playlistCurrentSongIndex == (len(self.playlist) - 1):
				self.playlistCurrentSongIndex = 0
			if os.path.exists(self.playlist[self.playlistCurrentSongIndex].path):
				self.playAudioFromSelectedFile(self.playlist[self.playlistCurrentSongIndex].path)
				self.nextButtonPressed = True
		elif self.fileDialogFilePath.endswith(".mp3"):
			self.timerCounter = 0
			self.seekSlider.setValue(0)
			self.songFileToGetLengthFrom = MP3(self.fileDialogFilePath)
			self.songFileLength = self.songFileToGetLengthFrom.info.length
			self.seekSlider.setRange(0, self.songFileLength)
			if pygame.mixer.get_init() != None:
				pygame.mixer.music.stop()
			pygame.mixer.music.load(self.fileDialogFilePath.encode("utf8"))
			self.playPauseButton.setIcon(self.playIcon)
			self.isPlaying = False
			self.nextButtonPressed = True
		
	def showSongInfo(self, path):
		self.filePath = File(path)
		self.audioFrames = self.filePath.tags
		if "APIC:" in self.audioFrames:
			self.artworkFrame = self.audioFrames["APIC:"].data
			with open("icons/albumArt.jpg", "wb") as img:
				img.write(self.artworkFrame)
			self.albumArtCoverImage = "icons/albumArt.jpg"
			self.songHasCoverImage = True
		else:
			self.albumArtCoverImage = self.defaultArtPicture
			self.songHasCoverImage = False
		self.albumArtImage = QImage(self.albumArtCoverImage)
		self.pixmapItem = QGraphicsPixmapItem(QPixmap.fromImage(self.albumArtImage))
		self.scene = QGraphicsScene()
		self.scene.addItem(self.pixmapItem)
		self.albumArt.setScene(self.scene)
		self.albumArt.fitInView(self.scene.sceneRect(), Qt.IgnoreAspectRatio)
		self.audioFile = EasyID3(path)
		if "title" in self.audioFile:
			self.audioFileTitle = self.audioFile["title"][0]
		else:
			if self.fileDialogFilePath.endswith(".m3u"):
				self.audioFileTitle = self.playlist[self.playlistCurrentSongIndex].path.split("\\", -1)[-1].split(".mp3")[0]
			else:
				self.audioFileTitle = self.fileDialogFilePath.split("/", -1)[-1].split(".mp3")[0]
		self.songName.setText("Song:  " + self.audioFileTitle)
		if "artist" in self.audioFile:
			self.audioFileArtist = self.audioFile["artist"][0]
		else:
			self.audioFileArtist = "Unknown"
		self.artistName.setText("Artist:  " + self.audioFileArtist)
		if "album" in self.audioFile:
			self.audioFileAlbum = self.audioFile["album"][0]
		else:
			self.audioFileAlbum = "Unknown"
		self.albumName.setText("Album: " + self.audioFileAlbum)
		if ("artist" in self.audioFile) and ("title" in self.audioFile):
			try:
				self.lyricsWindow.setText(PyLyrics.getLyrics(self.audioFile["artist"][0], self.audioFile["title"][0]))
			except ValueError:
				self.lyricsWindow.setText("Sorry, no lyrics found for this song and artist combination.")
		else:
			self.lyricsWindow.setText("Sorry, no lyrics found for this song and artist combination.")
		if self.fileDialogFilePath.endswith(".m3u"):
			self.realSongNumber = self.playlistCurrentSongIndex + 1
			self.maxNumberOfSongs = len(self.playlist)
			self.songsCount.setText(str(self.realSongNumber) + " / " + str(self.maxNumberOfSongs))
		else:
			self.songsCount.setText("1 / 1")
		self.songFileToGetLengthFrom = MP3(path)
		self.songFileLength = self.songFileToGetLengthFrom.info.length
		self.totalSongTimeLabel.setText(time.strftime("%M:%S", time.gmtime(self.songFileLength)))
		
	def addM3USongsToPlaylistWindow(self):
		self.playlistModel.removeRows(0, self.playlistModel.rowCount())
		i = 1
		for track in self.playlist:
			self.playlistSongFile = EasyID3(track.path)
			if "title" in self.playlistSongFile:
				self.playlistSongFileTitle = self.playlistSongFile["title"][0]
			else:
				self.playlistSongFileTitle = track.path.split("\\", -1)[-1].split(".mp3")[0]
			self.item = QtGui.QStandardItem(str(i) + ": " + self.playlistSongFileTitle)
			i += 1
			self.playlistModel.appendRow(self.item)
			self.playlistWindow.setModel(self.playlistModel)
		
	def playlistItemDoubleClick(self):
		if self.fileDialogFilePath.endswith(".m3u"):
			self.selectedIndexes = self.playlistWindow.selectedIndexes()
			for selected in self.selectedIndexes:
				for track in self.playlist:
					self.song = EasyID3(track.path)
					if "title" in self.song:
						self.songTitle = self.song["title"][0]
					else:
						self.songTitle = track.path.split("\\", -1)[-1].split(".mp3")[0]
					self.selectedSongTitleFromWindow = selected.data().split(": ", 1)[1]
					if self.songTitle == self.selectedSongTitleFromWindow:
						self.currentSelectionSongNumber = selected.data().split(": ", 1)[0]
						self.playlistCurrentSongIndex = int(self.currentSelectionSongNumber) - 1
						self.playAudioFromSelectedFile(track.path)
						break
		else:
			self.selectedIndexes = self.playlistWindow.selectedIndexes()
			for selected in self.selectedIndexes:
				self.song = EasyID3(self.fileDialogFilePath)
				if "title" in self.song:
					self.songTitle = self.song["title"][0]
				else:
					self.songTitle = self.fileDialogFilePath.split("/", -1)[-1].split(".mp3")[0]
				self.selectedSongTitleFromWindow = selected.data().split(": ", 1)[1]
				if self.songTitle == self.selectedSongTitleFromWindow:
					self.currentSelectionSongNumber = selected.data().split(": ", 1)[0]
					self.playlistCurrentSongIndex = int(self.currentSelectionSongNumber) - 1
					self.playAudioFromSelectedFile(self.fileDialogFilePath)
					break
					
	def setCurrentSongHighlighted(self):
		if self.fileDialogFilePath.endswith(".m3u"):
			for i in range(self.playlistModel.rowCount()):
				self.index = self.playlistModel.index(self.playlistCurrentSongIndex, 0, QModelIndex())
				self.selectionModel = self.playlistWindow.selectionModel()
				self.selectionModel.clear()
				self.selectionModel.select(self.index, self.selectionModel.Select)
		else:
			for i in range(self.playlistModel.rowCount()):
				self.index = self.playlistModel.index(0, 0, QModelIndex())
				self.selectionModel = self.playlistWindow.selectionModel()
				self.selectionModel.clear()
				self.selectionModel.select(self.index, self.selectionModel.Select)
				
	def setVolume(self, value):
		if pygame.mixer.get_init() != None:
			pygame.mixer.music.set_volume(value / 100)
			self.audioLevel = self.volumeSlider.value()
			self.curVolLabel.setText(str(value) + " %")
			self.saveSettings("AudioLevel", value)
		
	def seekMusic(self, value):
		if pygame.mixer.get_init() != None:
			pygame.mixer.music.rewind()
			pygame.mixer.music.set_pos(value)
			self.timerCounter = value
		
	def updateSeekSlider(self):
		self.seekSlider.setValue(self.timerCounter)
		self.curSongTimeLabel.setText(time.strftime("%M:%S", time.gmtime(self.timerCounter)))
		
	def saveSettings(self, setting, value):
		if setting == "LastVisitedDirectory":
			with open("LastVisitedDirectory.conf", "w") as config:
				config.write(str(setting) + " !=! " + str(value))
		elif setting == "AudioLevel":
			with open("AudioLevel.conf", "w") as config:
				config.write(str(setting) + " !=! " + str(value))
		elif setting == "Theme":
			with open("Theme.conf", "w") as config:
				config.write(str(setting) + " !=! " + str(value))
	
	def loadSettings(self):
		if os.path.isfile("LastVisitedDirectory.conf"):
			with open("LastVisitedDirectory.conf", "r") as config:
				for line in config:
					if "LastVisitedDirectory" in line:
						self.savedLastDir = line.split(" !=! ", 1)[1]
						if os.path.exists(self.savedLastDir):
							self.lastVisitedDirectory = self.savedLastDir
						else:
							self.lastVisitedDirectory = self.workingDirectory
		
		if os.path.isfile("AudioLevel.conf"):
			with open("AudioLevel.conf", "r") as config:
				for line in config:
					if "AudioLevel" in line:
						self.savedAudioLevel = line.split(" !=! ", 1)[1]
						if self.savedAudioLevel != None:
							self.setVolume(int(self.savedAudioLevel))
							self.volumeSlider.setValue(int(self.savedAudioLevel))
						else:
							self.setVolume(100)
							self.volumeSlider.setValue(100)
							
		if os.path.isfile("Theme.conf"):
			with open("Theme.conf", "r") as config:
				for line in config:
					if "Theme" in line:
						self.savedTheme = line.split(" !=! ", 1)[1]
						if self.savedTheme != None:
							if self.savedTheme == "Black":
								self.switchBlackTheme()
							elif self.savedTheme == "Blue":
								self.switchBlueTheme()
							elif self.savedTheme == "Pink":
								self.switchPinkTheme()
							elif self.savedTheme == "White":
								self.switchWhiteTheme()
						else:
							self.switchWhiteTheme()
							
	def parseM3U(self, m3u):
		self.locationOfM3UFile = os.path.dirname(m3u) #folder in which the m3u file is located in
		try:
			assert(type(m3u) == "_io.TextIOWrapper")
		except AssertionError:
			m3u = open(m3u, "r")

		line = m3u.readline()
		if not line.startswith("#EXTM3U"):
		   return

		playlist = []
		song = track(None, None, None)

		for line in m3u:
			line = line.strip()
			if line.startswith("#EXTINF:"):
				length,title = line.split("#EXTINF:")[1].split(",", 1)
				song = track(length, title, None)
			elif len(line) != 0:
				self.songFileName = line.split("\\", -1)[-1] #song file name + extention
				self.newPath = self.locationOfM3UFile + "/" + self.songFileName #the new path to the files (current directory) if the m3u one does not exist
				if os.path.exists(line):
					song.path = line
				elif os.path.exists(self.newPath):
					song.path = self.newPath
				else:
					song.path = ""
				playlist.append(song)
				song = track(None, None, None)
		
		m3u.close()
		
		return playlist
							
	def switchBlackTheme(self):
		self.playlistWindow.setStyleSheet(blackPlaylistWindowStyle())
		self.lyricsWindow.setStyleSheet(blackLyricsWindowStyle())
		self.prevSongButton.setStyleSheet(blackMediaButtonsStyle())
		self.nextSongButton.setStyleSheet(blackMediaButtonsStyle())
		self.playPauseButton.setStyleSheet(blackMediaButtonsStyle())
		self.setStyleSheet(blackMainWindowStyle())
		self.songName.setStyleSheet(blackLabelsStyle())
		self.artistName.setStyleSheet(blackLabelsStyle())
		self.albumName.setStyleSheet(blackLabelsStyle())
		self.songsCount.setStyleSheet(blackLabelsStyle())
		self.seekLabel.setStyleSheet(blackLabelsStyle())
		self.volumeLabel.setStyleSheet(blackLabelsStyle())
		self.minVolLabel.setStyleSheet(blackLabelsStyle())
		self.maxVolLabel.setStyleSheet(blackLabelsStyle())
		self.curVolLabel.setStyleSheet(blackLabelsStyle())
		self.playlistLabel.setStyleSheet(blackLabelsStyle())
		self.lyricsLabel.setStyleSheet(blackLabelsStyle())
		self.totalSongTimeLabel.setStyleSheet(blackLabelsStyle())
		self.curSongTimeLabel.setStyleSheet(blackLabelsStyle())
		self.blackThemeButton.setStyleSheet(blackThemeButtonsStyle())
		self.blueThemeButton.setStyleSheet(blackThemeButtonsStyle())
		self.whiteThemeButton.setStyleSheet(blackThemeButtonsStyle())
		self.pinkThemeButton.setStyleSheet(blackThemeButtonsStyle())
		self.defaultArtPicture = "icons/defaultArtBlack.jpg"
		if self.songHasCoverImage == False:
			self.albumArtImage = QImage(self.defaultArtPicture)
			self.pixmapItem = QGraphicsPixmapItem(QPixmap.fromImage(self.albumArtImage))
			self.scene = QGraphicsScene()
			self.scene.addItem(self.pixmapItem)
			self.albumArt.setScene(self.scene)
			self.albumArt.fitInView(self.scene.sceneRect(), Qt.IgnoreAspectRatio)
		self.saveSettings("Theme", "Black")
		
	def switchBlueTheme(self):
		self.playlistWindow.setStyleSheet(bluePlaylistWindowStyle())
		self.lyricsWindow.setStyleSheet(blueLyricsWindowStyle())
		self.prevSongButton.setStyleSheet(blueMediaButtonsStyle())
		self.nextSongButton.setStyleSheet(blueMediaButtonsStyle())
		self.playPauseButton.setStyleSheet(blueMediaButtonsStyle())
		self.setStyleSheet(blueMainWindowStyle())
		self.songName.setStyleSheet(blueLabelsStyle())
		self.artistName.setStyleSheet(blueLabelsStyle())
		self.albumName.setStyleSheet(blueLabelsStyle())
		self.songsCount.setStyleSheet(blueLabelsStyle())
		self.seekLabel.setStyleSheet(blueLabelsStyle())
		self.volumeLabel.setStyleSheet(blueLabelsStyle())
		self.minVolLabel.setStyleSheet(blueLabelsStyle())
		self.maxVolLabel.setStyleSheet(blueLabelsStyle())
		self.curVolLabel.setStyleSheet(blueLabelsStyle())
		self.playlistLabel.setStyleSheet(blueLabelsStyle())
		self.lyricsLabel.setStyleSheet(blueLabelsStyle())
		self.totalSongTimeLabel.setStyleSheet(blueLabelsStyle())
		self.curSongTimeLabel.setStyleSheet(blueLabelsStyle())
		self.blackThemeButton.setStyleSheet(blueThemeButtonsStyle())
		self.blueThemeButton.setStyleSheet(blueThemeButtonsStyle())
		self.whiteThemeButton.setStyleSheet(blueThemeButtonsStyle())
		self.pinkThemeButton.setStyleSheet(blueThemeButtonsStyle())
		self.defaultArtPicture = "icons/defaultArtBlue.jpg"
		if self.songHasCoverImage == False:
			self.albumArtImage = QImage(self.defaultArtPicture)
			self.pixmapItem = QGraphicsPixmapItem(QPixmap.fromImage(self.albumArtImage))
			self.scene = QGraphicsScene()
			self.scene.addItem(self.pixmapItem)
			self.albumArt.setScene(self.scene)
			self.albumArt.fitInView(self.scene.sceneRect(), Qt.IgnoreAspectRatio)
		self.saveSettings("Theme", "Blue")
		
	def switchPinkTheme(self):
		self.playlistWindow.setStyleSheet(pinkPlaylistWindowStyle())
		self.lyricsWindow.setStyleSheet(pinkLyricsWindowStyle())
		self.prevSongButton.setStyleSheet(pinkMediaButtonsStyle())
		self.nextSongButton.setStyleSheet(pinkMediaButtonsStyle())
		self.playPauseButton.setStyleSheet(pinkMediaButtonsStyle())
		self.setStyleSheet(pinkMainWindowStyle())
		self.songName.setStyleSheet(pinkLabelsStyle())
		self.artistName.setStyleSheet(pinkLabelsStyle())
		self.albumName.setStyleSheet(pinkLabelsStyle())
		self.songsCount.setStyleSheet(pinkLabelsStyle())
		self.seekLabel.setStyleSheet(pinkLabelsStyle())
		self.volumeLabel.setStyleSheet(pinkLabelsStyle())
		self.minVolLabel.setStyleSheet(pinkLabelsStyle())
		self.maxVolLabel.setStyleSheet(pinkLabelsStyle())
		self.curVolLabel.setStyleSheet(pinkLabelsStyle())
		self.playlistLabel.setStyleSheet(pinkLabelsStyle())
		self.lyricsLabel.setStyleSheet(pinkLabelsStyle())
		self.totalSongTimeLabel.setStyleSheet(pinkLabelsStyle())
		self.curSongTimeLabel.setStyleSheet(pinkLabelsStyle())
		self.blackThemeButton.setStyleSheet(pinkThemeButtonsStyle())
		self.blueThemeButton.setStyleSheet(pinkThemeButtonsStyle())
		self.whiteThemeButton.setStyleSheet(pinkThemeButtonsStyle())
		self.pinkThemeButton.setStyleSheet(pinkThemeButtonsStyle())
		self.defaultArtPicture = "icons/defaultArtPink.jpg"
		if self.songHasCoverImage == False:
			self.albumArtImage = QImage(self.defaultArtPicture)
			self.pixmapItem = QGraphicsPixmapItem(QPixmap.fromImage(self.albumArtImage))
			self.scene = QGraphicsScene()
			self.scene.addItem(self.pixmapItem)
			self.albumArt.setScene(self.scene)
			self.albumArt.fitInView(self.scene.sceneRect(), Qt.IgnoreAspectRatio)
		self.saveSettings("Theme", "Pink")
		
	def switchWhiteTheme(self):
		self.playlistWindow.setStyleSheet(whitePlaylistWindowStyle())
		self.lyricsWindow.setStyleSheet(whiteLyricsWindowStyle())
		self.prevSongButton.setStyleSheet(whiteMediaButtonsStyle())
		self.nextSongButton.setStyleSheet(whiteMediaButtonsStyle())
		self.playPauseButton.setStyleSheet(whiteMediaButtonsStyle())
		self.setStyleSheet(whiteMainWindowStyle())
		self.songName.setStyleSheet(whiteLabelsStyle())
		self.artistName.setStyleSheet(whiteLabelsStyle())
		self.albumName.setStyleSheet(whiteLabelsStyle())
		self.songsCount.setStyleSheet(whiteLabelsStyle())
		self.seekLabel.setStyleSheet(whiteLabelsStyle())
		self.volumeLabel.setStyleSheet(whiteLabelsStyle())
		self.minVolLabel.setStyleSheet(whiteLabelsStyle())
		self.maxVolLabel.setStyleSheet(whiteLabelsStyle())
		self.curVolLabel.setStyleSheet(whiteLabelsStyle())
		self.playlistLabel.setStyleSheet(whiteLabelsStyle())
		self.lyricsLabel.setStyleSheet(whiteLabelsStyle())
		self.totalSongTimeLabel.setStyleSheet(whiteLabelsStyle())
		self.curSongTimeLabel.setStyleSheet(whiteLabelsStyle())
		self.blackThemeButton.setStyleSheet(whiteThemeButtonsStyle())
		self.blueThemeButton.setStyleSheet(whiteThemeButtonsStyle())
		self.whiteThemeButton.setStyleSheet(whiteThemeButtonsStyle())
		self.pinkThemeButton.setStyleSheet(whiteThemeButtonsStyle())
		self.defaultArtPicture = "icons/defaultArtWhite.jpg"
		if self.songHasCoverImage == False:
			self.albumArtImage = QImage(self.defaultArtPicture)
			self.pixmapItem = QGraphicsPixmapItem(QPixmap.fromImage(self.albumArtImage))
			self.scene = QGraphicsScene()
			self.scene.addItem(self.pixmapItem)
			self.albumArt.setScene(self.scene)
			self.albumArt.fitInView(self.scene.sceneRect(), Qt.IgnoreAspectRatio)
		self.saveSettings("Theme", "White")
		
	def putDefaultTheme(self):
		self.playlistWindow.setStyleSheet(whitePlaylistWindowStyle())
		self.lyricsWindow.setStyleSheet(whiteLyricsWindowStyle())
		self.prevSongButton.setStyleSheet(whiteMediaButtonsStyle())
		self.nextSongButton.setStyleSheet(whiteMediaButtonsStyle())
		self.playPauseButton.setStyleSheet(whiteMediaButtonsStyle())
		self.setStyleSheet(whiteMainWindowStyle())
		self.songName.setStyleSheet(whiteLabelsStyle())
		self.artistName.setStyleSheet(whiteLabelsStyle())
		self.albumName.setStyleSheet(whiteLabelsStyle())
		self.songsCount.setStyleSheet(whiteLabelsStyle())
		self.seekLabel.setStyleSheet(whiteLabelsStyle())
		self.volumeLabel.setStyleSheet(whiteLabelsStyle())
		self.minVolLabel.setStyleSheet(whiteLabelsStyle())
		self.maxVolLabel.setStyleSheet(whiteLabelsStyle())
		self.curVolLabel.setStyleSheet(whiteLabelsStyle())
		self.playlistLabel.setStyleSheet(whiteLabelsStyle())
		self.lyricsLabel.setStyleSheet(whiteLabelsStyle())
		self.totalSongTimeLabel.setStyleSheet(whiteLabelsStyle())
		self.curSongTimeLabel.setStyleSheet(whiteLabelsStyle())
		self.blackThemeButton.setStyleSheet(whiteThemeButtonsStyle())
		self.blueThemeButton.setStyleSheet(whiteThemeButtonsStyle())
		self.whiteThemeButton.setStyleSheet(whiteThemeButtonsStyle())
		self.pinkThemeButton.setStyleSheet(whiteThemeButtonsStyle())
		self.defaultArtPicture = "icons/defaultArtWhite.jpg"
		if self.songHasCoverImage == False:
			self.albumArtImage = QImage(self.defaultArtPicture)
			self.pixmapItem = QGraphicsPixmapItem(QPixmap.fromImage(self.albumArtImage))
			self.scene = QGraphicsScene()
			self.scene.addItem(self.pixmapItem)
			self.albumArt.setScene(self.scene)
			self.albumArt.fitInView(self.scene.sceneRect(), Qt.IgnoreAspectRatio)
	
if __name__ == "__main__":
	app = QApplication(sys.argv)
	app.setWindowIcon(QIcon("icons/logo.png"))
	window = MusicPlayer()
	window.show()
	sys.exit(app.exec_())
I need to successfully update the value of "self.timerCounter" in the currently running instance of the MusicPlayer class from inside the QJumpSlider class but have no idea how. Is what I did at the top in the QJumpSlider class correct? The functions responsible for updating the QSlider's progress bar are called "def seekMusic(self, value):" and "def updateSeekSlider(self):" in the MusicPlayer class. I'm almost there, just how to update that timerCounter value... :( Otherwise the audio jump is working ok.
Reply
#3
Fixed it this way if anyone's interested:
class QJumpSlider(QtGui.QSlider):
	def __init__(self, parent = None):
		super(QJumpSlider, self).__init__(parent)
	
	def mousePressEvent(self, event):
		#Jump to click position
		window.seekMusic(QtGui.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))
		self.setValue(QtGui.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))
	
	def mouseMoveEvent(self, event):
		#Jump to pointer position while moving
		window.seekMusic(QtGui.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))
		self.setValue(QtGui.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))
where 'window' is the main app made in main() and seekMusic is a function from the MusicPlayer class:
if __name__ == "__main__":
	app = QApplication(sys.argv)
	app.setWindowIcon(QIcon("icons/logo.png"))
	window = MusicPlayer()
	window.show()
	sys.exit(app.exec_())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Mouse click without use bind ATARI_LIVE 8 1,445 Oct-23-2020, 10:41 PM
Last Post: ATARI_LIVE
  [Tkinter] program unresponsive during pynput mouse click RobotTech 1 755 May-07-2020, 04:43 PM
Last Post: RobotTech
  [Tkinter] Mouse click event not working on multiple tkinter window evrydaywannabe 2 1,129 Dec-16-2019, 04:47 AM
Last Post: woooee
  QGraphicsObject at Mouse Position _meshman_ 2 1,148 Oct-27-2019, 02:36 PM
Last Post: _meshman_
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 1,451 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  [PyQt] `QPushButton` without mouse click animation Atalanttore 2 2,175 Apr-22-2019, 01:00 PM
Last Post: Atalanttore
  QTabBar Indexing is wrong for right mouse click xenas 2 990 Jan-04-2019, 10:08 PM
Last Post: xenas
  right mouse button click with PyQt5 brecht83 4 9,598 Nov-09-2018, 02:55 PM
Last Post: brecht83

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020