Esempio n. 1
0
 def errored(self, error):
     logger.error("TCP Error " + self.replayVaultSocket.errorString())
 def errored(self, error):
     logger.error("TCP Error " + self.replayVaultSocket.errorString())
Esempio n. 3
0
    def updatemyTree(self):
        self.myTree.clear()

        # We put the replays into buckets by day first, then we add them to the treewidget.
        buckets = {}

        # Iterate
        for infile in os.listdir(util.REPLAY_DIR):
            if infile.endswith(".scfareplay"):
                bucket = buckets.setdefault("legacy", [])

                item = QtGui.QTreeWidgetItem()
                item.setText(1, infile)
                item.filename = os.path.join(util.REPLAY_DIR, infile)
                item.setIcon(0, util.icon("replays/replay.png"))
                item.setTextColor(
                    0, QtGui.QColor(client.instance.getColor("default")))

                bucket.append(item)

            elif infile.endswith(".fafreplay"):
                item = QtGui.QTreeWidgetItem()
                try:
                    item.filename = os.path.join(util.REPLAY_DIR, infile)
                    item.info = json.loads(
                        open(item.filename, "rt").readline())

                    # Parse replayinfo into data
                    if item.info.get('complete', False):
                        game_date = time.strftime(
                            "%Y-%m-%d", time.localtime(item.info['game_time']))
                        game_hour = time.strftime(
                            "%H:%M", time.localtime(item.info['game_time']))

                        bucket = buckets.setdefault(game_date, [])

                        icon = fa.maps.preview(item.info['mapname'])
                        if icon:
                            item.setIcon(0, icon)
                        else:
                            self.client.downloader.downloadMap(
                                item.info['mapname'], item, True)
                            item.setIcon(0, util.icon("games/unknown_map.png"))
                        item.setToolTip(
                            0, fa.maps.getDisplayName(item.info['mapname']))
                        item.setText(0, game_hour)
                        item.setTextColor(
                            0,
                            QtGui.QColor(client.instance.getColor("default")))

                        item.setText(1, item.info['title'])
                        item.setToolTip(1, infile)

                        # Hacky way to quickly assemble a list of all the players, but including the observers
                        playerlist = []
                        for _, players in item.info['teams'].items():
                            playerlist.extend(players)
                        item.setText(2, ", ".join(playerlist))
                        item.setToolTip(2, ", ".join(playerlist))

                        # Add additional info
                        item.setText(3, item.info['featured_mod'])
                        item.setTextAlignment(3, QtCore.Qt.AlignCenter)
                        item.setTextColor(
                            1,
                            QtGui.QColor(
                                client.instance.getUserColor(
                                    item.info.get('recorder', ""))))
                    else:
                        bucket = buckets.setdefault("incomplete", [])
                        item.setIcon(0, util.icon("replays/replay.png"))
                        item.setText(1, infile)
                        item.setText(
                            2, "(replay doesn't have complete metadata)")
                        item.setTextColor(1, QtGui.QColor(
                            "yellow"))  #FIXME: Needs to come from theme

                except:
                    bucket = buckets.setdefault("broken", [])
                    item.setIcon(0, util.icon("replays/broken.png"))
                    item.setText(1, infile)
                    item.setTextColor(
                        1,
                        QtGui.QColor("red"))  #FIXME: Needs to come from theme
                    item.setText(2, "(replay parse error)")
                    item.setTextColor(
                        2,
                        QtGui.QColor("gray"))  #FIXME: Needs to come from theme
                    logger.error("Replay parse error for " + infile)

                bucket.append(item)

        # Now, create a top level treewidgetitem for every bucket, and put the bucket's contents into them
        for bucket in buckets.keys():
            bucket_item = QtGui.QTreeWidgetItem()

            if bucket == "broken":
                bucket_item.setTextColor(
                    0, QtGui.QColor("red"))  #FIXME: Needs to come from theme
                bucket_item.setText(1, "(not watchable)")
                bucket_item.setTextColor(
                    1, QtGui.QColor(client.instance.getColor("default")))
            elif bucket == "incomplete":
                bucket_item.setTextColor(
                    0,
                    QtGui.QColor("yellow"))  #FIXME: Needs to come from theme
                bucket_item.setText(1, "(watchable)")
                bucket_item.setTextColor(
                    1, QtGui.QColor(client.instance.getColor("default")))
            elif bucket == "legacy":
                bucket_item.setTextColor(
                    0, QtGui.QColor(client.instance.getColor("default")))
                bucket_item.setTextColor(
                    1, QtGui.QColor(client.instance.getColor("default")))
                bucket_item.setText(1, "(old replay system)")
            else:
                bucket_item.setTextColor(
                    0, QtGui.QColor(client.instance.getColor("player")))

            bucket_item.setIcon(0, util.icon("replays/bucket.png"))
            bucket_item.setText(0, bucket)
            bucket_item.setText(3, str(len(buckets[bucket])) + " replays")
            bucket_item.setTextColor(
                3, QtGui.QColor(client.instance.getColor("default")))

            self.myTree.addTopLevelItem(bucket_item)
            #self.myTree.setFirstItemColumnSpanned(bucket_item, True)

            for replay in buckets[bucket]:
                bucket_item.addChild(replay)
    def updatemyTree(self):
        self.myTree.clear()
        
        # We put the replays into buckets by day first, then we add them to the treewidget.
        buckets = {}
        
        # Iterate
        for infile in os.listdir(util.REPLAY_DIR):            
            if infile.endswith(".scfareplay"):
                bucket = buckets.setdefault("legacy", [])
                
                item = QtGui.QTreeWidgetItem()
                item.setText(1, infile)
                item.filename = os.path.join(util.REPLAY_DIR, infile)
                item.setIcon(0, util.icon("replays/replay.png"))
                item.setTextColor(0, QtGui.QColor(client.instance.getColor("default")))
                                
                bucket.append(item)
                
            elif infile.endswith(".fafreplay"):
                item = QtGui.QTreeWidgetItem()
                try:
                    item.filename = os.path.join(util.REPLAY_DIR, infile)
                    item.info = json.loads(open(item.filename, "rt").readline())
                    
                    # Parse replayinfo into data
                    if item.info.get('complete', False):
                        game_date = time.strftime("%Y-%m-%d", time.localtime(item.info['game_time']))
                        game_hour = time.strftime("%H:%M", time.localtime(item.info['game_time']))
                        
                        bucket = buckets.setdefault(game_date, [])                    
                        
                        icon = fa.maps.preview(item.info['mapname'])
                        if icon:
                            item.setIcon(0, icon)
                        else:
                            self.client.downloader.downloadMap(item.info['mapname'], item, True)
                            item.setIcon(0,util.icon("games/unknown_map.png"))                                                      
                        item.setToolTip(0, fa.maps.getDisplayName(item.info['mapname']))
                        item.setText(0, game_hour)
                        item.setTextColor(0, QtGui.QColor(client.instance.getColor("default")))
                        
                        item.setText(1, item.info['title'])
                        item.setToolTip(1, infile)
    
                        # Hacky way to quickly assemble a list of all the players, but including the observers
                        playerlist = []
                        for _, players in item.info['teams'].items():
                            playerlist.extend(players)
                        item.setText(2, ", ".join(playerlist))
                        item.setToolTip(2, ", ".join(playerlist))
                        
                        # Add additional info
                        item.setText(3, item.info['featured_mod'])
                        item.setTextAlignment(3, QtCore.Qt.AlignCenter)
                        item.setTextColor(1, QtGui.QColor(client.instance.getUserColor(item.info.get('recorder', ""))))
                    else:
                        bucket = buckets.setdefault("incomplete", [])                    
                        item.setIcon(0, util.icon("replays/replay.png"))
                        item.setText(1, infile)
                        item.setText(2, "(replay doesn't have complete metadata)")
                        item.setTextColor(1, QtGui.QColor("yellow")) #FIXME: Needs to come from theme

                except:
                    bucket = buckets.setdefault("broken", [])                    
                    item.setIcon(0, util.icon("replays/broken.png"))
                    item.setText(1, infile)
                    item.setTextColor(1, QtGui.QColor("red"))   #FIXME: Needs to come from theme
                    item.setText(2, "(replay parse error)")
                    item.setTextColor(2, QtGui.QColor("gray"))  #FIXME: Needs to come from theme
                    logger.error("Replay parse error for " + infile)

                bucket.append(item)
                    
                
            
        # Now, create a top level treewidgetitem for every bucket, and put the bucket's contents into them         
        for bucket in buckets.keys():
            bucket_item = QtGui.QTreeWidgetItem()
            
            if bucket == "broken":
                bucket_item.setTextColor(0, QtGui.QColor("red")) #FIXME: Needs to come from theme
                bucket_item.setText(1, "(not watchable)")
                bucket_item.setTextColor(1, QtGui.QColor(client.instance.getColor("default")))
            elif bucket == "incomplete":
                bucket_item.setTextColor(0, QtGui.QColor("yellow")) #FIXME: Needs to come from theme
                bucket_item.setText(1, "(watchable)")
                bucket_item.setTextColor(1, QtGui.QColor(client.instance.getColor("default")))
            elif bucket == "legacy":
                bucket_item.setTextColor(0, QtGui.QColor(client.instance.getColor("default")))
                bucket_item.setTextColor(1, QtGui.QColor(client.instance.getColor("default")))
                bucket_item.setText(1, "(old replay system)")
            else:
                bucket_item.setTextColor(0, QtGui.QColor(client.instance.getColor("player")))
                
            bucket_item.setIcon(0, util.icon("replays/bucket.png"))                                
            bucket_item.setText(0, bucket)
            bucket_item.setText(3, str(len(buckets[bucket])) + " replays")
            bucket_item.setTextColor(3, QtGui.QColor(client.instance.getColor("default")))
                
            self.myTree.addTopLevelItem(bucket_item)
            #self.myTree.setFirstItemColumnSpanned(bucket_item, True)
                
            for replay in buckets[bucket]:
                bucket_item.addChild(replay)