From 3afa12b910205cea3c6703c09e318a6c9acd2ea2 Mon Sep 17 00:00:00 2001 From: Et0h Date: Sat, 24 Oct 2015 16:25:15 +0100 Subject: [PATCH] Initial playlist current file indicator --- syncplay/client.py | 4 ++++ syncplay/constants.py | 1 + syncplay/ui/consoleUI.py | 3 +++ syncplay/ui/gui.py | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/syncplay/client.py b/syncplay/client.py index a6f12b6..3eb91d0 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -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())) diff --git a/syncplay/constants.py b/syncplay/constants.py index c6c2414..b3eba57 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -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/" diff --git a/syncplay/ui/consoleUI.py b/syncplay/ui/consoleUI.py index 338086f..6eb2057 100644 --- a/syncplay/ui/consoleUI.py +++ b/syncplay/ui/consoleUI.py @@ -25,6 +25,9 @@ class ConsoleUI(threading.Thread): def setPlaylist(self, newPlaylist): pass + + def setPlaylistIndexFilename(self, filename): + pass def run(self): try: diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index 61a6d45..9421aad 100644 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -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()