def update_avatar(self): # FIXME: prodding the underlying C++ object to see if it exists # Needed if we're gone while downloading our avatar # We don't subclass QObject, so we have to do it this way try: self.isSelected() except RuntimeError: return try: avatar = self.user_player.avatar except AttributeError: avatar = None if avatar is not None: self.avatarTip = avatar["tooltip"] url = parse.unquote(avatar["url"]) avatarPix = util.respix(url) if avatarPix: self.avatarItem.setIcon(QtGui.QIcon(avatarPix)) self.avatarItem.setToolTip(self.avatarTip) else: if util.addcurDownloadAvatar(url, self): self.chat_widget.nam.get(QNetworkRequest(QUrl(url))) else: # No avatar set. self.avatarItem.setIcon(QtGui.QIcon()) self.avatarItem.setToolTip(None)
def finishDownloadAvatar(self, reply): ''' this take care of updating the avatars of players once they are downloaded ''' img = QtGui.QImage() img.loadFromData(reply.readAll()) pix = util.respix(reply.url().toString()) if pix: pix = QtGui.QIcon(QtGui.QPixmap(img)) else: util.addrespix(reply.url().toString(), QtGui.QPixmap(img)) for player in util.curDownloadAvatar(reply.url().toString()): for channel in self.channels: if player in self.channels[channel].chatters: self.channels[channel].chatters[player].avatarItem.setIcon( QtGui.QIcon(util.respix(reply.url().toString()))) self.channels[channel].chatters[ player].avatarItem.setToolTip( self.channels[channel].chatters[player].avatarTip)
def finishDownloadAvatar(self, reply): ''' this take care of updating the avatars of players once they are downloaded ''' img = QtGui.QImage() img.loadFromData(reply.readAll()) pix = util.respix(reply.url().toString()) if pix : pix = QtGui.QIcon(QtGui.QPixmap(img)) else : util.addrespix(reply.url().toString(), QtGui.QPixmap(img)) for player in util.curDownloadAvatar(reply.url().toString()) : for channel in self.channels : if player in self.channels[channel].chatters : self.channels[channel].chatters[player].avatarItem.setIcon(QtGui.QIcon(util.respix(reply.url().toString()))) self.channels[channel].chatters[player].avatarItem.setToolTip(self.channels[channel].chatters[player].avatarTip)
def finish_download_avatar(self, reply): """ this take care of updating the avatars of players once they are downloaded """ img = QtGui.QImage() img.loadFromData(reply.readAll()) url = reply.url().toString() if not util.respix(url): util.addrespix(url, QtGui.QPixmap(img)) for chatter in util.curDownloadAvatar(url): # FIXME - hack to prevent touching chatter if it was removed channel = chatter.channel ircuser = chatter.user if ircuser in channel.chatters: chatter.update_avatar() util.delDownloadAvatar(url)
def loadPixmap(self): self.pix = QtGui.QPixmap(40+16 + self.indent, 20) self.pix.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(self.pix) self.avatar = self.group.client.getUserAvatar(self.username) if self.avatar: avatarPix = util.respix(self.avatar['url']) if avatarPix: painter.drawPixmap(0, 0, avatarPix) self.avatarNotLoaded = False else: self.avatarNotLoaded = True if self.country != None: painter.drawPixmap(40 + self.indent, 2, util.icon("chat/countries/%s.png" % self.country.lower(), pix=True)) painter.end()
def updateAvatar(self): if self.avatar: self.avatarTip = self.avatar["tooltip"] url = self.avatar["url"] avatarPix = util.respix(url) if avatarPix: self.avatarItem.setIcon(QtGui.QIcon(avatarPix)) self.avatarItem.setToolTip(self.avatarTip) else: if util.addcurDownloadAvatar(url, self.name): self.lobby.nam.get(QNetworkRequest(QtCore.QUrl(url))) else: # No avatar set. self.avatarItem.setIcon(QtGui.QIcon()) self.avatarItem.setToolTip(None)
def avatarList(self, avatar_list): self.listAvatars.clear() button = QtGui.QPushButton() #self.group_layout.addWidget(button) self.avatars["None"] = button item = QtGui.QListWidgetItem() item.setSizeHint (QtCore.QSize(40,20)) self.item.append(item) self.listAvatars.addItem (item ) self.listAvatars.setItemWidget ( item, button ) button.clicked.connect(self.clicked) for avatar in avatar_list : avatarPix = util.respix(avatar["url"]) button = QtGui.QPushButton() button.clicked.connect(self.create_connect(avatar["url"])) item = QtGui.QListWidgetItem() item.setSizeHint (QtCore.QSize(40,20)) self.item.append(item) self.listAvatars.addItem (item ) button.setToolTip(avatar["tooltip"]) url = QtCore.QUrl(avatar["url"]) self.avatars[avatar["url"]] = button self.listAvatars.setItemWidget ( item, self.avatars[avatar["url"]] ) if not avatarPix : self.nams[url] = QNetworkAccessManager(button) self.nams[url].finished.connect(self.finishRequest) self.nams[url].get(QNetworkRequest(url)) else : self.avatars[avatar["url"]].setIcon(QtGui.QIcon(avatarPix)) self.avatars[avatar["url"]].setIconSize(avatarPix.rect().size())
def avatarList(self, avatar_list): self.listAvatars.clear() button = QtGui.QPushButton() #self.group_layout.addWidget(button) self.avatars["None"] = button item = QtGui.QListWidgetItem() item.setSizeHint(QtCore.QSize(40, 20)) self.item.append(item) self.listAvatars.addItem(item) self.listAvatars.setItemWidget(item, button) button.clicked.connect(self.clicked) for avatar in avatar_list: avatarPix = util.respix(avatar["url"]) button = QtGui.QPushButton() button.clicked.connect(self.create_connect(avatar["url"])) item = QtGui.QListWidgetItem() item.setSizeHint(QtCore.QSize(40, 20)) self.item.append(item) self.listAvatars.addItem(item) button.setToolTip(avatar["tooltip"]) url = QtCore.QUrl(avatar["url"]) self.avatars[avatar["url"]] = button self.listAvatars.setItemWidget(item, self.avatars[avatar["url"]]) if not avatarPix: self.nams[url] = QNetworkAccessManager(button) self.nams[url].finished.connect(self.finishRequest) self.nams[url].get(QNetworkRequest(url)) else: self.avatars[avatar["url"]].setIcon(QtGui.QIcon(avatarPix)) self.avatars[avatar["url"]].setIconSize( avatarPix.rect().size())
def printLine(self, name, text, scroll_forced=False, formatter=Formatters.FORMATTER_MESSAGE): if self.lines > CHAT_TEXT_LIMIT: cursor = self.chatArea.textCursor() cursor.movePosition(QtGui.QTextCursor.Start) cursor.movePosition(QtGui.QTextCursor.Down, QtGui.QTextCursor.KeepAnchor, CHAT_REMOVEBLOCK) cursor.removeSelectedText() self.lines = self.lines - CHAT_REMOVEBLOCK player = self.lobby.client.players.get(name, IRCPlayer(name)) displayName = name if player.clan is not None: displayName = "<b>[%s]</b>%s" % (player.clan, name) # Play a ping sound and flash the title under certain circumstances mentioned = text.find(self.lobby.client.login) != -1 if self.private or mentioned: self.pingWindow() avatar = None if name in self.chatters: chatter = self.chatters[name] color = chatter.textColor().name() if chatter.avatar: avatar = chatter.avatar["url"] avatarTip = chatter.avatarTip or "" else: # Fallback and ask the client. We have no Idea who this is. color = self.lobby.client.players.getUserColor(name) if mentioned: color = self.lobby.client.getColor("you") # scroll if close to the last line of the log scroll_current = self.chatArea.verticalScrollBar().value() scroll_needed = scroll_forced or ((self.chatArea.verticalScrollBar().maximum() - scroll_current) < 20) cursor = self.chatArea.textCursor() cursor.movePosition(QtGui.QTextCursor.End) self.chatArea.setTextCursor(cursor) # This whole block seems to be duplicated further up. # For f***s sake. if avatar: pix = util.respix(avatar) if pix: if not self.chatArea.document().resource(QtGui.QTextDocument.ImageResource, QtCore.QUrl(avatar)) : self.chatArea.document().addResource(QtGui.QTextDocument.ImageResource, QtCore.QUrl(avatar), pix) line = formatter.format(time=self.timestamp(), avatar=avatar, avatarTip=avatarTip, name=displayName, color=color, width=self.maxChatterWidth, text=util.irc_escape(text, self.lobby.a_style)) else: line = formatter.format(time=self.timestamp(), name=displayName, color=color, width=self.maxChatterWidth, text=util.irc_escape(text, self.lobby.a_style)) else: line = formatter.format(time=self.timestamp(), name=displayName, color=color, width=self.maxChatterWidth, text=util.irc_escape(text, self.lobby.a_style)) self.chatArea.insertHtml(line) self.lines = self.lines + 1 if scroll_needed: self.chatArea.verticalScrollBar().setValue(self.chatArea.verticalScrollBar().maximum()) else: self.chatArea.verticalScrollBar().setValue(scroll_current)
def printLine(self, name, text, scroll_forced=False, formatter=Formatters.FORMATTER_MESSAGE): if self.lines > CHAT_TEXT_LIMIT: cursor = self.chatArea.textCursor() cursor.movePosition(QtGui.QTextCursor.Start) cursor.movePosition(QtGui.QTextCursor.Down, QtGui.QTextCursor.KeepAnchor, CHAT_REMOVEBLOCK) cursor.removeSelectedText() self.lines = self.lines - CHAT_REMOVEBLOCK player = self.lobby.client.players.get(name, IRCPlayer(name)) displayName = name if player.clan is not None: displayName = "<b>[%s]</b>%s" % (player.clan, name) # Play a ping sound and flash the title under certain circumstances mentioned = text.find(self.lobby.client.login) != -1 if self.private or mentioned: self.pingWindow() avatar = None if name in self.chatters: chatter = self.chatters[name] color = chatter.textColor().name() if chatter.avatar: avatar = chatter.avatar["url"] avatarTip = chatter.avatarTip or "" else: # Fallback and ask the client. We have no Idea who this is. color = self.lobby.client.players.getUserColor(name) if mentioned: color = self.lobby.client.getColor("you") # scroll if close to the last line of the log scroll_current = self.chatArea.verticalScrollBar().value() scroll_needed = scroll_forced or (( self.chatArea.verticalScrollBar().maximum() - scroll_current) < 20) cursor = self.chatArea.textCursor() cursor.movePosition(QtGui.QTextCursor.End) self.chatArea.setTextCursor(cursor) # This whole block seems to be duplicated further up. # For f***s sake. if avatar: pix = util.respix(avatar) if pix: if not self.chatArea.document().resource( QtGui.QTextDocument.ImageResource, QtCore.QUrl(avatar)): self.chatArea.document().addResource( QtGui.QTextDocument.ImageResource, QtCore.QUrl(avatar), pix) line = formatter.format(time=self.timestamp(), avatar=avatar, avatarTip=avatarTip, name=displayName, color=color, width=self.maxChatterWidth, text=util.irc_escape( text, self.lobby.a_style)) else: line = formatter.format(time=self.timestamp(), name=displayName, color=color, width=self.maxChatterWidth, text=util.irc_escape( text, self.lobby.a_style)) else: line = formatter.format(time=self.timestamp(), name=displayName, color=color, width=self.maxChatterWidth, text=util.irc_escape( text, self.lobby.a_style)) self.chatArea.insertHtml(line) self.lines = self.lines + 1 if scroll_needed: self.chatArea.verticalScrollBar().setValue( self.chatArea.verticalScrollBar().maximum()) else: self.chatArea.verticalScrollBar().setValue(scroll_current)
def print_line(self, chname, text, scroll_forced=False, formatter=Formatters.FORMATTER_MESSAGE): if self.lines > CHAT_TEXT_LIMIT: cursor = self.chatArea.textCursor() cursor.movePosition(QtGui.QTextCursor.Start) cursor.movePosition(QtGui.QTextCursor.Down, QtGui.QTextCursor.KeepAnchor, CHAT_REMOVEBLOCK) cursor.removeSelectedText() self.lines = self.lines - CHAT_REMOVEBLOCK chatter = self._chatterset.get(chname) if chatter is not None and chatter.player is not None: player = chatter.player else: player = IRCPlayer(chname) displayName = chname if player.clan is not None: displayName = "<b>[%s]</b>%s" % (player.clan, chname) sender_is_not_me = chatter.name != self._me.login # Play a ping sound and flash the title under certain circumstances mentioned = text.find(self.chat_widget.client.login) != -1 is_quit_msg = formatter is Formatters.FORMATTER_RAW and text == "quit." private_msg = self.private and not is_quit_msg if (mentioned or private_msg) and sender_is_not_me: self.ping_window() avatar = None avatarTip = "" if chatter is not None and chatter in self.chatters: chatwidget = self.chatters[chatter] color = chatwidget.foreground().color().name() avatarTip = chatwidget.avatarTip or "" if chatter.player is not None: avatar = chatter.player.avatar if avatar is not None: avatar = avatar["url"] else: # Fallback and ask the client. We have no Idea who this is. color = self.chat_widget.client.player_colors.getUserColor( player.id) if mentioned and sender_is_not_me: color = self.chat_widget.client.player_colors.getColor("you") # scroll if close to the last line of the log scroll_current = self.chatArea.verticalScrollBar().value() scroll_needed = scroll_forced or (( self.chatArea.verticalScrollBar().maximum() - scroll_current) < 20) cursor = self.chatArea.textCursor() cursor.movePosition(QtGui.QTextCursor.End) self.chatArea.setTextCursor(cursor) chatter_has_avatar = False line = None if avatar is not None: pix = util.respix(avatar) if pix: self._add_avatar_resource_to_chat_area(avatar, pix) chatter_has_avatar = True if not chatter_has_avatar: formatter = Formatters.convert_to_no_avatar(formatter) line = formatter.format(time=self.timestamp(), avatar=avatar, avatarTip=avatarTip, name=displayName, color=color, width=self.max_chatter_width, text=util.irc_escape(text, self.chat_widget.a_style)) self.chatArea.insertHtml(line) self.lines += 1 if scroll_needed: self.chatArea.verticalScrollBar().setValue( self.chatArea.verticalScrollBar().maximum()) else: self.chatArea.verticalScrollBar().setValue(scroll_current)
def printAction(self, name, text, scroll_forced=False, server_action=False): ''' Print an actual message in the chatArea of the channel ''' try: if self.lines > CHAT_TEXT_LIMIT : cursor = self.chatArea.textCursor() cursor.movePosition(QtGui.QTextCursor.Start) cursor.movePosition(QtGui.QTextCursor.Down, QtGui.QTextCursor.KeepAnchor, CHAT_REMOVEBLOCK) cursor.removeSelectedText() self.lines = self.lines - CHAT_REMOVEBLOCK if server_action : color = self.lobby.client.getColor("server") elif name.lower() in self.lobby.specialUserColors: color = self.lobby.specialUserColors[name.lower()] else: color = self.lobby.client.getUserColor(name) # Play a ping sound if self.private and name != self.lobby.client.login: self.pingWindow() displayName = name clan = self.lobby.client.getUserClan(name) if clan != "": displayName = "<b>[%s]</b>%s" % (clan, name) avatar = None if name in self.chatters: chatter = self.chatters[name] if chatter.avatar : avatar = chatter.avatar["url"] avatarTip = chatter.avatarTip or "" # scroll if close to the last line of the log scroll_current = self.chatArea.verticalScrollBar().value() scroll_needed = scroll_forced or ((self.chatArea.verticalScrollBar().maximum() - scroll_current) < 20) cursor = self.chatArea.textCursor() cursor.movePosition(QtGui.QTextCursor.End) self.chatArea.setTextCursor(cursor) if avatar : pix = util.respix(avatar) if pix: if not self.chatArea.document().resource(QtGui.QTextDocument.ImageResource, QtCore.QUrl(avatar)) : self.chatArea.document().addResource(QtGui.QTextDocument.ImageResource, QtCore.QUrl(avatar), pix) formatter = self.FORMATTER_ACTION_AVATAR line = formatter.format(time=self.timestamp(), avatar=avatar, avatarTip=avatarTip, name=displayName, color=color, width=self.maxChatterWidth, text=util.irc_escape(text, self.lobby.a_style)) else: formatter = self.FORMATTER_ACTION line = formatter.format(time=self.timestamp(), name=displayName, color=color, width=self.maxChatterWidth, text=util.irc_escape(text, self.lobby.a_style)) else: formatter = self.FORMATTER_ACTION line = formatter.format(time=self.timestamp(), name=displayName, color=color, width=self.maxChatterWidth, text=util.irc_escape(text, self.lobby.a_style)) self.chatArea.insertHtml(line) self.lines = self.lines + 1 if scroll_needed: self.chatArea.verticalScrollBar().setValue(self.chatArea.verticalScrollBar().maximum()) else: self.chatArea.verticalScrollBar().setValue(scroll_current) except: pass
def printMsg(self, name, text, scroll_forced=False): ''' Print an actual message in the chatArea of the channel ''' try: if self.lines > CHAT_TEXT_LIMIT : cursor = self.chatArea.textCursor() cursor.movePosition(QtGui.QTextCursor.Start) cursor.movePosition(QtGui.QTextCursor.Down, QtGui.QTextCursor.KeepAnchor, CHAT_REMOVEBLOCK) cursor.removeSelectedText() self.lines = self.lines - CHAT_REMOVEBLOCK avatar = None displayName = name if self.lobby.client.isFoe(name) : text = self.quackerize(text) clan = self.lobby.client.getUserClan(name) if clan != "": displayName = "<b>[%s]</b>%s" % (clan, name) if name.lower() in self.lobby.specialUserColors: color = self.lobby.specialUserColors[name.lower()] else: if name in self.chatters: chatter = self.chatters[name] color = chatter.textColor().name() if chatter.avatar: avatar = chatter.avatar["url"] avatarTip = chatter.avatarTip or "" else: color = self.lobby.client.getUserColor(name) #Fallback and ask the client. We have no Idea who this is. # Play a ping sound and flash the title under certain circumstances if self.private and name != self.lobby.client.login: self.pingWindow() if not self.private and text.find(self.lobby.client.login)!=-1: self.pingWindow() color = self.lobby.client.getColor("tous") # scroll if close to the last line of the log scroll_current = self.chatArea.verticalScrollBar().value() scroll_needed = scroll_forced or ((self.chatArea.verticalScrollBar().maximum() - scroll_current) < 20) cursor = self.chatArea.textCursor() cursor.movePosition(QtGui.QTextCursor.End) self.chatArea.setTextCursor(cursor) if avatar : pix = util.respix(avatar) if pix: if not self.chatArea.document().resource(QtGui.QTextDocument.ImageResource, QtCore.QUrl(avatar)): self.chatArea.document().addResource(QtGui.QTextDocument.ImageResource, QtCore.QUrl(avatar), pix) formatter = self.FORMATTER_MESSAGE_AVATAR line = formatter.format(time=self.timestamp(), avatar=avatar, name=displayName, avatarTip=avatarTip, color=color, width=self.maxChatterWidth, text=util.irc_escape(text, self.lobby.a_style)) else : formatter = self.FORMATTER_MESSAGE line = formatter.format(time=self.timestamp(), name=displayName, color=color, width=self.maxChatterWidth, text=util.irc_escape(text, self.lobby.a_style)) else : formatter = self.FORMATTER_MESSAGE line = formatter.format(time=self.timestamp(), name=displayName, color=color, width=self.maxChatterWidth, text=util.irc_escape(text, self.lobby.a_style)) self.chatArea.insertHtml(line) self.lines = self.lines + 1 if scroll_needed: self.chatArea.verticalScrollBar().setValue(self.chatArea.verticalScrollBar().maximum()) else: self.chatArea.verticalScrollBar().setValue(scroll_current) except: pass