def printAnnouncement(self, text, color, size, scroll_forced = True): # 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) formatter = Formatters.FORMATTER_ANNOUNCEMENT line = formatter.format(size=size, color=color, text=util.irc_escape(text, self.lobby.a_style)) self.chatArea.insertHtml(line) if scroll_needed: self.chatArea.verticalScrollBar().setValue(self.chatArea.verticalScrollBar().maximum()) else: self.chatArea.verticalScrollBar().setValue(scroll_current)
def setAnnounceText(self,text): self.announceLine.clear() self.announceLine.setText("<style>a{color:cornflowerblue}</style><b><font color=white>" + util.irc_escape(text) + "</font></b>")
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 setAnnounceText(self, text): self.announceLine.clear() self.announceLine.setText( "<style>a{color:cornflowerblue}</style><b><font color=white>" + util.irc_escape(text) + "</font></b>")
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