<commit_before>from PySide import QtGui #@UnresolvedImport
from PySide.QtCore import Qt, QSettings, QSize, QPoint #@UnresolvedImport
from syncplay import utils, constants, version
import sys
import time
import re
import os
from syncplay.utils import formatTime

class MainWindow(QtGui.QMainWindow):
    def addClient(self, client):
        self._syncplayClient = client
        self.roomInput.setText(self._syncplayClient.getRoom())
    
    def promptFor(self, prompt=">", message=""):
        #TODO: Prompt user
        return None

    def showMessage(self, message, noTimestamp=False):
        message = unicode(message)
        message = message.replace("&", "&amp;").replace('"', "&quot;").replace("<", "&lt;").replace(">", "&gt;")
        message = message.replace("&lt;", "<span style=\"color:#367AA9;font-weight:bold;\">&lt;")
        message = message.replace("&gt;", "&gt;</span>")
        message = message.replace("\n", "<br />")
        if(noTimestamp):
            self.newMessage(message + "<br />")
        else:
            self.newMessage(time.strftime(constants.UI_TIME_FORMAT, time.localtime()) + message + "<br />")
    
    def showUserList(self, currentUser, rooms):
        def stripfilename(filename):
            return re.sub(constants.FILENAME_STRIP_REGEX,"",filename) 
        
        self._usertreebuffer = QtGui.QStandardItemModel()
        self._usertreebuffer.setColumnCount(2)
        self._usertreebuffer.setHorizontalHeaderLabels(("Room / User","File being played"))
        usertreeRoot = self._usertreebuffer.invisibleRootItem()
        
        for room in rooms:
            roomitem = QtGui.QStandardItem(room)
            if (room == currentUser.room):
                font = QtGui.QFont()
                font.setWeight(QtGui.QFont.Bold)
                roomitem.setFont(font)
            blankitem = QtGui.QStandardItem("")
            roomitem.setFlags(roomitem.flags()  & ~Qt.ItemIsEditable) 
            blankitem.setFlags(blankitem.flags() & ~Qt.ItemIsEditable)
            usertreeRoot.appendRow((roomitem, blankitem))
            for user in rooms[room]:
                useritem = QtGui.QStandardItem(user.username)
                fileitem = QtGui.QStandardItem("")
                if (user.file):
                    fileitem = QtGui.QStandardItem(user.file['name'] + " ("+formatTime(user.file['duration'])+")")
                    if (currentUser.file):
                        sameName = stripfilename(user.file['name']) == stripfilename(currentUser.file['name'])
                        sameSize = user.file['size'] == currentUser.file['size']
                        sameDuration = abs(round(user.file['duration']) - round(currentUser.file['duration'])) < constants.DIFFFERENT_DURATION_THRESHOLD
                        sameRoom = room == currentUser.room
                        differentName = not sameName
                        differentSize = not sameSize
                        differentDuration = not sameDuration
                        if (sameName or sameRoom):
                            if (differentSize and sameDuration):
                                fileitem = QtGui.QStandardItem(user.file['name'] + " ("+formatTime(user.file['duration'])+")" + " (Different size!)")
                            elif (differentSize and differentDuration):
                                fileitem = QtGui.QStandardItem(user.file['name'] + " ("+formatTime(user.file['duration'])+")" + " (Different size and duration!)")
                            elif (differentDuration):
                                fileitem = QtGui.QStandardItem(user.file['name'] + " ("+formatTime(user.file['duration'])+")" + " (Different duration!)")
                            if (sameRoom and (differentName or differentSize or differentDuration)):
                                fileitem.setForeground(QtGui.QBrush(QtGui.QColor('red')))
                else:
                    fileitem = QtGui.QStandardItem("(No file being played)")
                    if (room == currentUser.room):
                        fileitem.setForeground(QtGui.QBrush(QtGui.QColor('blue')))
                if(currentUser.username == user.username):
                    font = QtGui.QFont()
                    font.setWeight(QtGui.QFont.Bold)
                    useritem.setFont(font)
                useritem.setFlags(useritem.flags()  & ~Qt.ItemIsEditable)
                fileitem.setFlags(fileitem.flags()  & ~Qt.ItemIsEditable)
                roomitem.appendRow((useritem, fileitem))
       
        self.listTreeModel = self._usertreebuffer
        self.listTreeView.setModel(self.listTreeModel)
        self.listTreeView.setItemsExpandable(False)
        self.listTreeView.expandAll()
        self.listTreeView.resizeColumnToContents(0)
        self.listTreeView.resizeColumnToContents(1)

    def roomClicked(self, item):
        while(item.parent().row() != -1):
            item = item.parent()
        self.joinRoom(item.sibling(item.row(), 0).data())
    
    def userListChange(self):
        self._syncplayClient.showUserList()
    
    def showDebugMessage(self, message):
        print(message)
        
    def showErrorMessage(self, message, criticalerror = False):
        message = unicode(message)
        if criticalerror:
            QtGui.QMessageBox.critical(self,"DON'T PANIC", message)
        message = message.replace("&", "&amp;").replace('"', "&quot;").replace("<", "&lt;").replace(">", "&gt;")
        message = message.replace("\n", "<br />")
        message = "<span style=\"color:#FF0000;\">" + message + "</span>"
        self.newMessage(time.strftime(constants.UI_TIME_FORMAT, time.localtime()) + message + "<br />")

    def joinRoom(self, room = None):
        if room == None:
            room = self.roomInput.text()
        if room == "":
            if  self._syncplayClient.userlist.currentUser.file:
                room = self._syncplayClient.userlist.currentUser.file["name"]
            else:
                room = self._syncplayClient.defaultRoom
        self.roomInput.setText(room)
        if(room != self._syncplayClient.getRoom()):
            self._syncplayClient.setRoom(room)
            self._syncplayClient.sendRoom()

    def seekPosition(self):
        s = re.match(constants.UI_SEEK_REGEX, self.seekInput.text())
        if(s):
            sign = self._extractSign(s.group('sign'))
            t = utils.parseTime(s.group('time'))
            if(t is None):
                return
            if(sign):
                t = self._syncplayClient.getGlobalPosition() + sign * t 
            self._syncplayClient.setPosition(t)<commit_msg>Make error pop-up title 'Syncplay' (not a h2g2 reference)<commit_after>from PySide import QtGui #@UnresolvedImport
from PySide.QtCore import Qt, QSettings, QSize, QPoint #@UnresolvedImport
from syncplay import utils, constants, version
import sys
import time
import re
import os
from syncplay.utils import formatTime

class MainWindow(QtGui.QMainWindow):
    def addClient(self, client):
        self._syncplayClient = client
        self.roomInput.setText(self._syncplayClient.getRoom())
    
    def promptFor(self, prompt=">", message=""):
        #TODO: Prompt user
        return None

    def showMessage(self, message, noTimestamp=False):
        message = unicode(message)
        message = message.replace("&", "&amp;").replace('"', "&quot;").replace("<", "&lt;").replace(">", "&gt;")
        message = message.replace("&lt;", "<span style=\"color:#367AA9;font-weight:bold;\">&lt;")
        message = message.replace("&gt;", "&gt;</span>")
        message = message.replace("\n", "<br />")
        if(noTimestamp):
            self.newMessage(message + "<br />")
        else:
            self.newMessage(time.strftime(constants.UI_TIME_FORMAT, time.localtime()) + message + "<br />")
    
    def showUserList(self, currentUser, rooms):
        def stripfilename(filename):
            return re.sub(constants.FILENAME_STRIP_REGEX,"",filename) 
        
        self._usertreebuffer = QtGui.QStandardItemModel()
        self._usertreebuffer.setColumnCount(2)
        self._usertreebuffer.setHorizontalHeaderLabels(("Room / User","File being played"))
        usertreeRoot = self._usertreebuffer.invisibleRootItem()
        
        for room in rooms:
            roomitem = QtGui.QStandardItem(room)
            if (room == currentUser.room):
                font = QtGui.QFont()
                font.setWeight(QtGui.QFont.Bold)
                roomitem.setFont(font)
            blankitem = QtGui.QStandardItem("")
            roomitem.setFlags(roomitem.flags()  & ~Qt.ItemIsEditable) 
            blankitem.setFlags(blankitem.flags() & ~Qt.ItemIsEditable)
            usertreeRoot.appendRow((roomitem, blankitem))
            for user in rooms[room]:
                useritem = QtGui.QStandardItem(user.username)
                fileitem = QtGui.QStandardItem("")
                if (user.file):
                    fileitem = QtGui.QStandardItem(user.file['name'] + " ("+formatTime(user.file['duration'])+")")
                    if (currentUser.file):
                        sameName = stripfilename(user.file['name']) == stripfilename(currentUser.file['name'])
                        sameSize = user.file['size'] == currentUser.file['size']
                        sameDuration = abs(round(user.file['duration']) - round(currentUser.file['duration'])) < constants.DIFFFERENT_DURATION_THRESHOLD
                        sameRoom = room == currentUser.room
                        differentName = not sameName
                        differentSize = not sameSize
                        differentDuration = not sameDuration
                        if (sameName or sameRoom):
                            if (differentSize and sameDuration):
                                fileitem = QtGui.QStandardItem(user.file['name'] + " ("+formatTime(user.file['duration'])+")" + " (Different size!)")
                            elif (differentSize and differentDuration):
                                fileitem = QtGui.QStandardItem(user.file['name'] + " ("+formatTime(user.file['duration'])+")" + " (Different size and duration!)")
                            elif (differentDuration):
                                fileitem = QtGui.QStandardItem(user.file['name'] + " ("+formatTime(user.file['duration'])+")" + " (Different duration!)")
                            if (sameRoom and (differentName or differentSize or differentDuration)):
                                fileitem.setForeground(QtGui.QBrush(QtGui.QColor('red')))
                else:
                    fileitem = QtGui.QStandardItem("(No file being played)")
                    if (room == currentUser.room):
                        fileitem.setForeground(QtGui.QBrush(QtGui.QColor('blue')))
                if(currentUser.username == user.username):
                    font = QtGui.QFont()
                    font.setWeight(QtGui.QFont.Bold)
                    useritem.setFont(font)
                useritem.setFlags(useritem.flags()  & ~Qt.ItemIsEditable)
                fileitem.setFlags(fileitem.flags()  & ~Qt.ItemIsEditable)
                roomitem.appendRow((useritem, fileitem))
       
        self.listTreeModel = self._usertreebuffer
        self.listTreeView.setModel(self.listTreeModel)
        self.listTreeView.setItemsExpandable(False)
        self.listTreeView.expandAll()
        self.listTreeView.resizeColumnToContents(0)
        self.listTreeView.resizeColumnToContents(1)

    def roomClicked(self, item):
        while(item.parent().row() != -1):
            item = item.parent()
        self.joinRoom(item.sibling(item.row(), 0).data())
    
    def userListChange(self):
        self._syncplayClient.showUserList()
    
    def showDebugMessage(self, message):
        print(message)
        
    def showErrorMessage(self, message, criticalerror = False):
        message = unicode(message)
        if criticalerror:
            QtGui.QMessageBox.critical(self,"Syncplay", message)
        message = message.replace("&", "&amp;").replace('"', "&quot;").replace("<", "&lt;").replace(">", "&gt;")
        message = message.replace("\n", "<br />")
        message = "<span style=\"color:#FF0000;\">" + message + "</span>"
        self.newMessage(time.strftime(constants.UI_TIME_FORMAT, time.localtime()) + message + "<br />")

    def joinRoom(self, room = None):
        if room == None:
            room = self.roomInput.text()
        if room == "":
            if  self._syncplayClient.userlist.currentUser.file:
                room = self._syncplayClient.userlist.currentUser.file["name"]
            else:
                room = self._syncplayClient.defaultRoom
        self.roomInput.setText(room)
        if(room != self._syncplayClient.getRoom()):
            self._syncplayClient.setRoom(room)
            self._syncplayClient.sendRoom()

    def seekPosition(self):
        s = re.match(constants.UI_SEEK_REGEX, self.seekInput.text())
        if(s):
            sign = self._extractSign(s.group('sign'))
            t = utils.parseTime(s.group('time'))
            if(t is None):
                return
            if(sign):
                t = self._syncplayClient.getGlobalPosition() + sign * t 
            self._syncplayClient.setPosition(t)
{'fraction_non_alphanumeric': 0.1309353600722402, 'fraction_numerical': 0.002107005794265934, 'mean_word_length': 2.1725948913821913, 'pattern_counts': {'":': 2, '<': 27, '<?xml version=': 0, '>': 27, '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': '7177077', 'n_tokens_mistral': 3730, 'n_tokens_neox': 3611, 'n_words': 628}