Initial playlist current file indicator

This commit is contained in:
Et0h 2015-10-24 16:25:15 +01:00
parent 9d28822731
commit 3afa12b910
4 changed files with 41 additions and 1 deletions

View File

@ -466,6 +466,7 @@ class SyncplayClient(object):
return
try:
filename = self._playlist[index]
self.ui.setPlaylistIndexFilename(filename)
if username is not None and self.userlist.currentUser.file and filename == self.userlist.currentUser.file['name']:
return
except IndexError:
@ -1282,6 +1283,9 @@ class UiManager(object):
def setPlaylist(self, newPlaylist):
self.__ui.setPlaylist(newPlaylist)
def setPlaylistIndexFilename(self, filename):
self.__ui.setPlaylistIndexFilename(filename)
def showDebugMessage(self, message):
if constants.DEBUG_MODE and message.rstrip():
sys.stderr.write("{}{}\n".format(time.strftime(constants.UI_TIME_FORMAT, time.localtime()),message.rstrip()))

View File

@ -177,6 +177,7 @@ FILEITEM_SWITCH_ROLE = 1
FILEITEM_SWITCH_NO_SWITCH = 0
FILEITEM_SWITCH_FILE_SWITCH = 1
FILEITEM_SWITCH_STREAM_SWITCH = 2
PLAYLISTITEM_CURRENTLYPLAYING_ROLE = 3
SYNCPLAY_UPDATE_URL = u"http://syncplay.pl/checkforupdate?{}" # Params
SYNCPLAY_DOWNLOAD_URL = "http://syncplay.pl/download/"

View File

@ -25,6 +25,9 @@ class ConsoleUI(threading.Thread):
def setPlaylist(self, newPlaylist):
pass
def setPlaylistIndexFilename(self, filename):
pass
def run(self):
try:

View File

@ -88,6 +88,7 @@ class MainWindow(QtGui.QMainWindow):
insertPosition = None
playlistState = []
updatingPlaylist = False
playlistIndex = None
def setPlaylistInsertPosition(self, newPosition):
if MainWindow.insertPosition <> newPosition:
@ -96,8 +97,23 @@ class MainWindow(QtGui.QMainWindow):
class PlaylistItemDelegate(QtGui.QStyledItemDelegate):
def paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex):
QtGui.QStyledItemDelegate.paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex)
itemQPainter.save()
currentQAbstractItemModel = indexQModelIndex.model()
currentlyPlayingFile = currentQAbstractItemModel.data(indexQModelIndex, Qt.UserRole + constants.PLAYLISTITEM_CURRENTLYPLAYING_ROLE)
if sys.platform.startswith('win'):
resourcespath = utils.findWorkingDir() + "\\resources\\"
else:
resourcespath = utils.findWorkingDir() + "/resources/"
if currentlyPlayingFile:
fileSwitchIconQPixmap = QtGui.QPixmap(resourcespath + "chevrons_right.png")
itemQPainter.drawPixmap (
(optionQStyleOptionViewItem.rect.x()),
optionQStyleOptionViewItem.rect.y(),
fileSwitchIconQPixmap.scaled(16, 16, Qt.KeepAspectRatio))
optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+16)
QtGui.QStyledItemDelegate.paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex)
lineAbove = False
lineBelow = False
if MainWindow.insertPosition == 0 and indexQModelIndex.row() == 0:
@ -150,6 +166,18 @@ class MainWindow(QtGui.QMainWindow):
class PlaylistWidget(QtGui.QListWidget):
selfWindow = None
playlistIndexFilename = None
def setPlaylistIndexFilename(self, filename):
if filename <> self.playlistIndexFilename:
self.playlistIndexFilename = filename
self.updatePlaylistIndexIcon()
def updatePlaylistIndexIcon(self):
for item in xrange(self.count()):
isPlayingFilename = self.item(item).text() == self.playlistIndexFilename
self.item(item).setData(Qt.UserRole + constants.PLAYLISTITEM_CURRENTLYPLAYING_ROLE, isPlayingFilename)
self.forceUpdate()
def setWindow(self, window):
self.selfWindow = window
@ -172,6 +200,7 @@ class MainWindow(QtGui.QMainWindow):
for index in xrange(self.count()):
self.takeItem(0)
self.insertItems(0, newPlaylist)
self.updatePlaylistIndexIcon()
def remove_selected_items(self):
for item in self.selectedItems():
@ -1308,6 +1337,9 @@ class MainWindow(QtGui.QMainWindow):
self.playlist.updatePlaylist(newPlaylist)
self.updatingPlaylist = False
def setPlaylistIndexFilename(self, filename):
self.playlist.setPlaylistIndexFilename(filename)
def addFileToPlaylist(self, filePath, index = -1):
if os.path.isfile(filePath):
self.removePlaylistNote()