Make individual columns for filename, size & duration

This commit is contained in:
Et0h 2014-10-24 19:58:56 +01:00
parent 76e1d977cf
commit 1e715cc11c
3 changed files with 53 additions and 32 deletions

View File

@ -172,7 +172,9 @@ en = {
"pause-guibuttonlabel" : "Pause", "pause-guibuttonlabel" : "Pause",
"roomuser-heading-label" : "Room / User", "roomuser-heading-label" : "Room / User",
"fileplayed-heading-label" : "File being played", "size-heading-label" : "Size",
"duration-heading-label" : "Length",
"filename-heading-label" : "Filename",
"notifications-heading-label" : "Notifications", "notifications-heading-label" : "Notifications",
"userlist-heading-label" : "List of who is playing what", "userlist-heading-label" : "List of who is playing what",
"othercommands-heading-label" : "Other commands", "othercommands-heading-label" : "Other commands",
@ -192,6 +194,8 @@ en = {
"setoffset-msgbox-label" : "Set offset", "setoffset-msgbox-label" : "Set offset",
"offsetinfo-msgbox-label" : "Offset (see http://syncplay.pl/guide/ for usage instructions):", "offsetinfo-msgbox-label" : "Offset (see http://syncplay.pl/guide/ for usage instructions):",
"mebibyte-suffix" : " MiB",
# Tooltips # Tooltips
"host-tooltip" : "Hostname or IP to connect to, optionally including port (e.g. syncplay.pl:8999). Only synchronised with people on same server/port.", "host-tooltip" : "Hostname or IP to connect to, optionally including port (e.g. syncplay.pl:8999). Only synchronised with people on same server/port.",

View File

@ -6,7 +6,7 @@ import sys
import time import time
import re import re
import os import os
from syncplay.utils import formatTime, sameFilename, sameFilesize, sameFileduration, RoomPasswordProvider from syncplay.utils import formatTime, sameFilename, sameFilesize, sameFileduration, RoomPasswordProvider, formatSize
class UserlistItemDelegate(QtGui.QStyledItemDelegate): class UserlistItemDelegate(QtGui.QStyledItemDelegate):
def __init__(self): def __init__(self):
@ -92,9 +92,8 @@ class MainWindow(QtGui.QMainWindow):
def showUserList(self, currentUser, rooms): def showUserList(self, currentUser, rooms):
self._usertreebuffer = QtGui.QStandardItemModel() self._usertreebuffer = QtGui.QStandardItemModel()
self._usertreebuffer.setColumnCount(2)
self._usertreebuffer.setHorizontalHeaderLabels( self._usertreebuffer.setHorizontalHeaderLabels(
(getMessage("roomuser-heading-label"), getMessage("fileplayed-heading-label"))) (getMessage("roomuser-heading-label"), getMessage("size-heading-label"), getMessage("duration-heading-label"), getMessage("filename-heading-label") ))
usertreeRoot = self._usertreebuffer.invisibleRootItem() usertreeRoot = self._usertreebuffer.invisibleRootItem()
for room in rooms: for room in rooms:
@ -113,49 +112,54 @@ class MainWindow(QtGui.QMainWindow):
isController = user.isController() isController = user.isController()
useritem.setData(isController, Qt.UserRole + constants.USERITEM_CONTROLLER_ROLE) useritem.setData(isController, Qt.UserRole + constants.USERITEM_CONTROLLER_ROLE)
if user.file: if user.file:
fileitem = QtGui.QStandardItem(u"{} ({})".format(user.file['name'], formatTime(user.file['duration']))) filesizeitem = QtGui.QStandardItem(formatSize(user.file['size']))
filedurationitem = QtGui.QStandardItem("({})".format(formatTime(user.file['duration'])))
filenameitem = QtGui.QStandardItem((user.file['name']))
if currentUser.file: if currentUser.file:
sameName = sameFilename(user.file['name'], currentUser.file['name']) sameName = sameFilename(user.file['name'], currentUser.file['name'])
sameSize = sameFilesize(user.file['size'], currentUser.file['size']) sameSize = sameFilesize(user.file['size'], currentUser.file['size'])
sameDuration = sameFileduration(user.file['duration'], currentUser.file['duration']) sameDuration = sameFileduration(user.file['duration'], currentUser.file['duration'])
sameRoom = room == currentUser.room sameRoom = room == currentUser.room
differentName = not sameName if sameRoom:
differentSize = not sameSize if not sameName:
differentDuration = not sameDuration filenameitem.setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_DIFFERENTITEM_COLOR)))
if sameName or sameRoom: if not sameSize:
if differentSize and sameDuration: if currentUser.file is not None and formatSize(user.file['size']) == formatSize(currentUser.file['size']):
fileitem = QtGui.QStandardItem( filesizeitem = QtGui.QStandardItem(formatSize(user.file['size'],precise=True))
u"{} ({}) ({})".format(user.file['name'], formatTime(user.file['duration']), filesizeitem.setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_DIFFERENTITEM_COLOR)))
getMessage("differentsize-note"))) if not sameDuration:
elif differentSize and differentDuration: filedurationitem.setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_DIFFERENTITEM_COLOR)))
fileitem = QtGui.QStandardItem(
u"{} ({}) ({})".format(user.file['name'], formatTime(user.file['duration']),
getMessage("differentsizeandduration-note")))
elif differentDuration:
fileitem = QtGui.QStandardItem(
u"{} ({}) ({})".format(user.file['name'], formatTime(user.file['duration']),
getMessage("differentduration-note")))
if sameRoom and (differentName or differentSize or differentDuration):
fileitem.setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_DIFFERENTITEM_COLOR)))
else: else:
fileitem = QtGui.QStandardItem(getMessage("nofile-note")) filenameitem = QtGui.QStandardItem(getMessage("nofile-note"))
filedurationitem = QtGui.QStandardItem("")
filesizeitem = QtGui.QStandardItem("")
if room == currentUser.room: if room == currentUser.room:
fileitem.setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_NOFILEITEM_COLOR))) filenameitem.setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_NOFILEITEM_COLOR)))
if currentUser.username == user.username: if currentUser.username == user.username:
font = QtGui.QFont() font = QtGui.QFont()
font.setWeight(QtGui.QFont.Bold) font.setWeight(QtGui.QFont.Bold)
useritem.setFont(font) useritem.setFont(font)
useritem.setFlags(useritem.flags() & ~Qt.ItemIsEditable) useritem.setFlags(useritem.flags() & ~Qt.ItemIsEditable)
fileitem.setFlags(fileitem.flags() & ~Qt.ItemIsEditable) filenameitem.setFlags(filenameitem.flags() & ~Qt.ItemIsEditable)
roomitem.appendRow((useritem, fileitem)) filesizeitem.setFlags(filesizeitem.flags() & ~Qt.ItemIsEditable)
filedurationitem.setFlags(filedurationitem.flags() & ~Qt.ItemIsEditable)
roomitem.appendRow((useritem, filesizeitem, filedurationitem, filenameitem))
self.listTreeModel = self._usertreebuffer self.listTreeModel = self._usertreebuffer
self.listTreeView.setModel(self.listTreeModel) self.listTreeView.setModel(self.listTreeModel)
self.listTreeView.setItemDelegate(UserlistItemDelegate()) self.listTreeView.setItemDelegate(UserlistItemDelegate())
self.listTreeView.setItemsExpandable(False) self.listTreeView.setItemsExpandable(False)
self.listTreeView.expandAll() self.listTreeView.expandAll()
self.listTreeView.resizeColumnToContents(0) self.listTreeView.header().setStretchLastSection(False)
self.listTreeView.resizeColumnToContents(1) self.listTreeView.header().setResizeMode(0, QtGui.QHeaderView.ResizeToContents)
self.listTreeView.header().setResizeMode(1, QtGui.QHeaderView.ResizeToContents)
self.listTreeView.header().setResizeMode(2, QtGui.QHeaderView.ResizeToContents)
self.listTreeView.header().setResizeMode(3, QtGui.QHeaderView.ResizeToContents)
NarrowTabsWidth = self.listTreeView.header().sectionSize(0)+self.listTreeView.header().sectionSize(1)+self.listTreeView.header().sectionSize(2)
if self.listTreeView.header().width() < (NarrowTabsWidth+self.listTreeView.header().sectionSize(3)):
self.listTreeView.header().resizeSection(3,self.listTreeView.header().width()-NarrowTabsWidth)
else:
self.listTreeView.header().setResizeMode(3, QtGui.QHeaderView.Stretch)
self.listTreeView.expandAll()
def roomClicked(self, item): def roomClicked(self, item):
while item.parent().row() != -1: while item.parent().row() != -1:
@ -356,8 +360,8 @@ class MainWindow(QtGui.QMainWindow):
window.topSplit.addWidget(window.outputFrame) window.topSplit.addWidget(window.outputFrame)
window.topSplit.addWidget(window.listFrame) window.topSplit.addWidget(window.listFrame)
window.topSplit.setStretchFactor(0, 4) window.topSplit.setStretchFactor(0,4)
window.topSplit.setStretchFactor(1, 5) window.topSplit.setStretchFactor(1,5)
window.mainLayout.addWidget(window.topSplit) window.mainLayout.addWidget(window.topSplit)
window.topSplit.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding) window.topSplit.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)

View File

@ -93,6 +93,19 @@ def formatTime(timeInSeconds, weeksAsTitles=True):
formattedTime = "{0:} (Title {1:.0f})".format(formattedTime, title) formattedTime = "{0:} (Title {1:.0f})".format(formattedTime, title)
return formattedTime return formattedTime
def formatSize (bytes, precise=False):
if bytes == 0: # E.g. when file size privacy is enabled
return "???"
try:
mebibytes = int(bytes) / 1048576.0
if precise:
mebibytes = round(mebibytes, 1)
else:
mebibytes = int(mebibytes)
return str(mebibytes) + getMessage("mebibyte-suffix")
except: # E.g. when filesize is hashed
return "???"
def findWorkingDir(): def findWorkingDir():
frozen = getattr(sys, 'frozen', '') frozen = getattr(sys, 'frozen', '')
if not frozen: if not frozen: