Пример #1
0
    def __init__(self, chatrooms=None, room=None, users=None):
        self.lines = []
        self.chatrooms = chatrooms
        self.frame = chatrooms.frame
        self.room = room
        QtGui.QWidget.__init__(self, None)
        self.ui = Ui_Room()
        self.ui.setupUi(self)
        #self.connect(self, SIGNAL("PrivateMessage(PyQt_PyObject,PyQt_PyObject, PyQt_PyObject)"), self.frame.Networking.PrivateMessage)
        self.ui.UserList.setHeaderLabels(("", "User", "Speed", "Files"))
        self.ui.UserList.setIndentation(0)
        self.ui.UserList.setColumnWidth(0, 20)
        self.ui.UserList.setColumnWidth(1, 100)
        self.ui.UserList.setColumnWidth(2, 100)
        self.ui.UserList.setColumnWidth(3, 50)
        self.ui.UserList.setColumnCount(4)

        self.ui.UserList.sortItems(1, Qt.AscendingOrder)
        self.tag_remote = self.frame.makecolour(self.ui.UserList, "chatremote")
        self.tag_local = self.frame.makecolour(self.ui.UserList, "chatlocal")
        self.tag_me = self.frame.makecolour(self.ui.UserList, "chatme")
        self.tag_hilite = self.frame.makecolour(self.ui.UserList, "chathilite")

        self.users = {}
        for username, stats in users.items():
            self.users[username] = QTreeWidgetItem(
                self.ui.UserList.invisibleRootItem())

            status, speed, downloads, files, dirs = self.frame.user_stats[
                username] = [stats[0], stats[1], stats[2], stats[3], stats[4]]
            hspeed = self.frame.HumanSpeed(speed)
            hfiles = self.frame.Humanize(files)
            #print self.frame.user_stats[user]
            self.users[username].setIcon(
                0, self.frame.GetStatusImage(username, status))
            self.users[username].setText(1, username)
            self.users[username].setText(2, hspeed)
            self.users[username].setTextAlignment(2, Qt.AlignRight)
            self.users[username].setText(3, hfiles)
            self.users[username].setTextAlignment(3, Qt.AlignRight)
            self.users[username].setText(4, str(status))
            self.users[username].setData(5, 0, QVariant(speed))
            self.users[username].setData(6, 0, QVariant(files))
            #newuser.setText(0, status)
        self.connect(self.ui.ChatEntry, SIGNAL("returnPressed()"),
                     self.SayRoom)
        self.connect(self.ui.Close, SIGNAL("clicked()"), self.LeaveRoom)
        self.tag_log = None
        self.ui.UserList.resizeColumnToContents(0)
        #self.ui.UserList.resizeColumnToContents(1)
        self.ui.UserList.resizeColumnToContents(2)
Пример #2
0
	def __init__(self, chatrooms=None, room=None, users=None):
		self.lines = []
		self.chatrooms = chatrooms
		self.frame = chatrooms.frame
		self.room = room
		QtGui.QWidget.__init__(self, None)
		self.ui = Ui_Room()
		self.ui.setupUi(self)
		#self.connect(self, SIGNAL("PrivateMessage(PyQt_PyObject,PyQt_PyObject, PyQt_PyObject)"), self.frame.Networking.PrivateMessage)
		self.ui.UserList.setHeaderLabels(("", "User", "Speed", "Files"))
		self.ui.UserList.setIndentation(0)
		self.ui.UserList.setColumnWidth(0, 20)
		self.ui.UserList.setColumnWidth(1, 100)
		self.ui.UserList.setColumnWidth(2, 100)
		self.ui.UserList.setColumnWidth(3, 50)
		self.ui.UserList.setColumnCount(4);
		
		self.ui.UserList.sortItems(1, Qt.AscendingOrder);
		self.tag_remote = self.frame.makecolour(self.ui.UserList, "chatremote")
		self.tag_local = self.frame.makecolour(self.ui.UserList, "chatlocal")
		self.tag_me = self.frame.makecolour(self.ui.UserList, "chatme")
		self.tag_hilite = self.frame.makecolour(self.ui.UserList, "chathilite")
		
		self.users = {}
		for username,stats in users.items():
			self.users[username] = QTreeWidgetItem(self.ui.UserList.invisibleRootItem())
			
			status, speed, downloads, files, dirs = self.frame.user_stats[username] = [stats[0], stats[1], stats[2], stats[3], stats[4]]
			hspeed = self.frame.HumanSpeed(speed)
			hfiles = self.frame.Humanize(files)
			#print self.frame.user_stats[user]
			self.users[username].setIcon(0, self.frame.GetStatusImage(username, status))
			self.users[username].setText(1, username)
			self.users[username].setText(2, hspeed)
			self.users[username].setTextAlignment(2, Qt.AlignRight)
			self.users[username].setText(3, hfiles)
			self.users[username].setTextAlignment(3, Qt.AlignRight)
			self.users[username].setText(4, str(status))
			self.users[username].setData(5, 0, QVariant(speed))
			self.users[username].setData(6, 0, QVariant(files))
			#newuser.setText(0, status)
		self.connect(self.ui.ChatEntry, SIGNAL("returnPressed()" ), self.SayRoom)
		self.connect(self.ui.Close, SIGNAL("clicked()"), self.LeaveRoom)
		self.tag_log = None
		self.ui.UserList.resizeColumnToContents(0)
		#self.ui.UserList.resizeColumnToContents(1)
		self.ui.UserList.resizeColumnToContents(2)
Пример #3
0
class Chatroom(QtGui.QWidget):
    def __init__(self, chatrooms=None, room=None, users=None):
        self.lines = []
        self.chatrooms = chatrooms
        self.frame = chatrooms.frame
        self.room = room
        QtGui.QWidget.__init__(self, None)
        self.ui = Ui_Room()
        self.ui.setupUi(self)
        #self.connect(self, SIGNAL("PrivateMessage(PyQt_PyObject,PyQt_PyObject, PyQt_PyObject)"), self.frame.Networking.PrivateMessage)
        self.ui.UserList.setHeaderLabels(("", "User", "Speed", "Files"))
        self.ui.UserList.setIndentation(0)
        self.ui.UserList.setColumnWidth(0, 20)
        self.ui.UserList.setColumnWidth(1, 100)
        self.ui.UserList.setColumnWidth(2, 100)
        self.ui.UserList.setColumnWidth(3, 50)
        self.ui.UserList.setColumnCount(4)

        self.ui.UserList.sortItems(1, Qt.AscendingOrder)
        self.tag_remote = self.frame.makecolour(self.ui.UserList, "chatremote")
        self.tag_local = self.frame.makecolour(self.ui.UserList, "chatlocal")
        self.tag_me = self.frame.makecolour(self.ui.UserList, "chatme")
        self.tag_hilite = self.frame.makecolour(self.ui.UserList, "chathilite")

        self.users = {}
        for username, stats in users.items():
            self.users[username] = QTreeWidgetItem(
                self.ui.UserList.invisibleRootItem())

            status, speed, downloads, files, dirs = self.frame.user_stats[
                username] = [stats[0], stats[1], stats[2], stats[3], stats[4]]
            hspeed = self.frame.HumanSpeed(speed)
            hfiles = self.frame.Humanize(files)
            #print self.frame.user_stats[user]
            self.users[username].setIcon(
                0, self.frame.GetStatusImage(username, status))
            self.users[username].setText(1, username)
            self.users[username].setText(2, hspeed)
            self.users[username].setTextAlignment(2, Qt.AlignRight)
            self.users[username].setText(3, hfiles)
            self.users[username].setTextAlignment(3, Qt.AlignRight)
            self.users[username].setText(4, str(status))
            self.users[username].setData(5, 0, QVariant(speed))
            self.users[username].setData(6, 0, QVariant(files))
            #newuser.setText(0, status)
        self.connect(self.ui.ChatEntry, SIGNAL("returnPressed()"),
                     self.SayRoom)
        self.connect(self.ui.Close, SIGNAL("clicked()"), self.LeaveRoom)
        self.tag_log = None
        self.ui.UserList.resizeColumnToContents(0)
        #self.ui.UserList.resizeColumnToContents(1)
        self.ui.UserList.resizeColumnToContents(2)
        #self.ui.Close.setIcon(self.frame.images["close"])
    def ConnClose(self):
        self.ui.UserList.clear()
        self.users.clear()

    def Rejoined(self, users):
        self.ui.UserList.clear()
        self.users.clear()
        for username, stats in users.items():
            self.users[username] = QTreeWidgetItem(
                self.ui.UserList.invisibleRootItem())
            status, speed, downloads, files, dirs = self.frame.user_stats[
                username] = [stats[0], stats[1], stats[2], stats[3], stats[4]]
            hspeed = self.frame.HumanSpeed(speed)
            hfiles = self.frame.Humanize(files)
            #print self.frame.user_stats[user]
            self.users[username].setIcon(
                0, self.frame.GetStatusImage(username, status))
            self.users[username].setText(1, username)
            self.users[username].setText(2, hspeed)
            self.users[username].setTextAlignment(2, Qt.AlignRight)
            self.users[username].setText(3, hfiles)
            self.users[username].setTextAlignment(3, Qt.AlignRight)
            self.users[username].setText(4, str(status))
            self.users[username].setData(5, 0, QVariant(speed))
            self.users[username].setData(6, 0, QVariant(files))

    def LeaveRoom(self):
        self.frame.Networking.LeaveRoom(self.room)

    def SayRoom(self):
        self.frame.Networking.SayRoom(self.room, str(self.ui.ChatEntry.text()))
        self.ui.ChatEntry.clear()

    def GetUserStatus(self, user, status):
        if not self.users.has_key(user):
            return
        #print self.users[user].text(0)
        if status != int(self.users[user].text(4)):
            self.users[user].setText(4, str(status))
            img = self.frame.GetStatusImage(user, status)
            self.users[user].setIcon(0, QIcon(img))
        else:
            return
        if status == 1:
            action = ("%s has gone away")
        else:
            action = ("%s has returned")
        AppendLine(self.ui.StatusLog, action % user)  #, self.tag_log)
        #if user in self.tag_users.keys():
        #color = self.getUserStatusColor(status)
        #self.changecolour(self.tag_users[user], color)
        #self.usersmodel.set(self.users[user], 0, img, 4, status)

    def SayInChatRoom(self, user, line):
        #line = line.replace("<", "<pre><")
        #if len(self.lines) >= 400:
        #buffer = self.chatview.get_buffer()
        #start = buffer.get_start_iter()
        #end = buffer.get_iter_at_line(self.lines[200])
        #self.chatview.get_buffer().delete(start, end)
        #del self.lines[0:200]

        # Display /me messages as "* username message"
        if line[:4] == "/me ":
            message = "* %s %s" % (user, line[4:])
            tag = Qt.green
        else:
            message = "[%s] %s" % (user, line.replace("<", "\\<"))
            if user == self.frame.username:
                tag = self.tag_local
            elif line.upper().find(self.frame.username.upper()) > -1:
                tag = self.tag_hilite
            else:
                tag = self.tag_remote
        message = "\n-- ".join(message.split("\n"))
        #message = "%s %s" % (recode(time.strftime("%H:%M:%S")), message)
        #if user in self.tag_users.keys():
        #usertag = self.tag_users[user]
        #else:
        #usertag = self.tag_users[user] = self.makecolour(self.chatview.get_buffer(), color, username=user)
        #self.lines.append(AppendLine(self.chatview, message, tag=tag, username=user, usertag=usertag))
        AppendLine(self.ui.ChatLog, message, tag)
        #if self.frame.username is not None:
        #if user != self.frame.username and self.frame.username in message:
        #self.chatrooms.request_hilite(self.Main)
        #else:
        #self.chatrooms.request_changed(self.Main)
        #self.frame.RequestIcon(self.frame.ChatRoomLabel)

    def UserJoinedRoom(self, username):
        if self.users.has_key(username):
            return

        status, speed, downloads, files, dirs = self.frame.user_stats[username]
        AppendLine(self.ui.StatusLog,
                   _("%s joined the room") % username)  #, self.tag_log)
        img = self.frame.GetStatusImage(username, status)
        hspeed = self.frame.HumanSpeed(speed)
        hfiles = self.frame.Humanize(files)
        self.users[username] = QTreeWidgetItem(
            self.ui.UserList.invisibleRootItem())
        hspeed = self.frame.HumanSpeed(speed)
        hfiles = self.frame.Humanize(files)
        self.users[username].setIcon(
            0, self.frame.GetStatusImage(username, status))
        self.users[username].setText(1, username)
        self.users[username].setText(2, hspeed)
        self.users[username].setTextAlignment(2, Qt.AlignRight)
        self.users[username].setText(3, hfiles)
        self.users[username].setTextAlignment(3, Qt.AlignRight)
        self.users[username].setText(4, str(status))
        self.users[username].setData(5, 0, QVariant(speed))
        self.users[username].setData(6, 0, QVariant(files))
        #iter = username.ui.append([img, username, hfiles, hspeed, status])
        #self.users[username] = iter
        #color = self.getUserStatusColor(status)
        #if username in self.tag_users.keys():
        #self.changecolour(self.tag_users[username], color)
        #else:
        #self.tag_users[username] = self.makecolour(self.chatview.get_buffer(), color, username=username)

    def UserLeftRoom(self, username):
        if not self.users.has_key(username):
            return
        AppendLine(self.ui.StatusLog,
                   _("%s left the room") % username, self.tag_log)
        #self.usersmodel.remove(self.users[username])
        #self.users[username].close()
        self.ui.UserList.invisibleRootItem().removeChild(self.users[username])
        del self.users[username]
Пример #4
0
class Chatroom(QtGui.QWidget):
	def __init__(self, chatrooms=None, room=None, users=None):
		self.lines = []
		self.chatrooms = chatrooms
		self.frame = chatrooms.frame
		self.room = room
		QtGui.QWidget.__init__(self, None)
		self.ui = Ui_Room()
		self.ui.setupUi(self)
		#self.connect(self, SIGNAL("PrivateMessage(PyQt_PyObject,PyQt_PyObject, PyQt_PyObject)"), self.frame.Networking.PrivateMessage)
		self.ui.UserList.setHeaderLabels(("", "User", "Speed", "Files"))
		self.ui.UserList.setIndentation(0)
		self.ui.UserList.setColumnWidth(0, 20)
		self.ui.UserList.setColumnWidth(1, 100)
		self.ui.UserList.setColumnWidth(2, 100)
		self.ui.UserList.setColumnWidth(3, 50)
		self.ui.UserList.setColumnCount(4);
		
		self.ui.UserList.sortItems(1, Qt.AscendingOrder);
		self.tag_remote = self.frame.makecolour(self.ui.UserList, "chatremote")
		self.tag_local = self.frame.makecolour(self.ui.UserList, "chatlocal")
		self.tag_me = self.frame.makecolour(self.ui.UserList, "chatme")
		self.tag_hilite = self.frame.makecolour(self.ui.UserList, "chathilite")
		
		self.users = {}
		for username,stats in users.items():
			self.users[username] = QTreeWidgetItem(self.ui.UserList.invisibleRootItem())
			
			status, speed, downloads, files, dirs = self.frame.user_stats[username] = [stats[0], stats[1], stats[2], stats[3], stats[4]]
			hspeed = self.frame.HumanSpeed(speed)
			hfiles = self.frame.Humanize(files)
			#print self.frame.user_stats[user]
			self.users[username].setIcon(0, self.frame.GetStatusImage(username, status))
			self.users[username].setText(1, username)
			self.users[username].setText(2, hspeed)
			self.users[username].setTextAlignment(2, Qt.AlignRight)
			self.users[username].setText(3, hfiles)
			self.users[username].setTextAlignment(3, Qt.AlignRight)
			self.users[username].setText(4, str(status))
			self.users[username].setData(5, 0, QVariant(speed))
			self.users[username].setData(6, 0, QVariant(files))
			#newuser.setText(0, status)
		self.connect(self.ui.ChatEntry, SIGNAL("returnPressed()" ), self.SayRoom)
		self.connect(self.ui.Close, SIGNAL("clicked()"), self.LeaveRoom)
		self.tag_log = None
		self.ui.UserList.resizeColumnToContents(0)
		#self.ui.UserList.resizeColumnToContents(1)
		self.ui.UserList.resizeColumnToContents(2)
		#self.ui.Close.setIcon(self.frame.images["close"])
	def ConnClose(self):
		self.ui.UserList.clear()
		self.users.clear()
		
	def Rejoined(self, users):
		self.ui.UserList.clear()
		self.users.clear()
		for username,stats in users.items():
			self.users[username] = QTreeWidgetItem(self.ui.UserList.invisibleRootItem())
			status, speed, downloads, files, dirs = self.frame.user_stats[username] = [stats[0], stats[1], stats[2], stats[3], stats[4]]
			hspeed = self.frame.HumanSpeed(speed)
			hfiles = self.frame.Humanize(files)
			#print self.frame.user_stats[user]
			self.users[username].setIcon(0, self.frame.GetStatusImage(username, status))
			self.users[username].setText(1, username)
			self.users[username].setText(2, hspeed)
			self.users[username].setTextAlignment(2, Qt.AlignRight)
			self.users[username].setText(3, hfiles)
			self.users[username].setTextAlignment(3, Qt.AlignRight)
			self.users[username].setText(4, str(status))
			self.users[username].setData(5, 0, QVariant(speed))
			self.users[username].setData(6, 0, QVariant(files))
			
		
	def LeaveRoom(self):
		self.frame.Networking.LeaveRoom(self.room)
		
	def SayRoom(self):
		self.frame.Networking.SayRoom(self.room, str(self.ui.ChatEntry.text()))
		self.ui.ChatEntry.clear()
		
	def GetUserStatus(self, user, status):
		if not self.users.has_key(user):
			return
		#print self.users[user].text(0)
		if status != int(self.users[user].text(4)):
			self.users[user].setText(4,  str(status))
			img = self.frame.GetStatusImage(user, status)
			self.users[user].setIcon(0, QIcon(img))
		else:
			return
		if status == 1:
			action = ("%s has gone away")
		else:
			action = ("%s has returned")
		AppendLine(self.ui.StatusLog, action % user) #, self.tag_log)
		#if user in self.tag_users.keys():
			#color = self.getUserStatusColor(status)
			#self.changecolour(self.tag_users[user], color)
		#self.usersmodel.set(self.users[user], 0, img, 4, status)
			
	def SayInChatRoom(self, user, line):
		#line = line.replace("<", "<pre><")
		#if len(self.lines) >= 400:
			#buffer = self.chatview.get_buffer()
			#start = buffer.get_start_iter()
			#end = buffer.get_iter_at_line(self.lines[200])
			#self.chatview.get_buffer().delete(start, end)
			#del self.lines[0:200]
		
		# Display /me messages as "* username message"
		if line[:4] == "/me ":
			message = "* %s %s"  % (user,line[4:])
			tag = Qt.green
		else:
			message = "[%s] %s" % (user, line.replace("<", "\\<"))
			if user == self.frame.username:
				tag = self.tag_local
			elif line.upper().find(self.frame.username.upper()) > -1:
				tag = self.tag_hilite
			else:
				tag = self.tag_remote
		message = "\n-- ".join(message.split("\n"))
		#message = "%s %s" % (recode(time.strftime("%H:%M:%S")), message)
		#if user in self.tag_users.keys():
			#usertag = self.tag_users[user]
		#else:
			#usertag = self.tag_users[user] = self.makecolour(self.chatview.get_buffer(), color, username=user)
		#self.lines.append(AppendLine(self.chatview, message, tag=tag, username=user, usertag=usertag))
		AppendLine(self.ui.ChatLog, message, tag)
		#if self.frame.username is not None:
			#if user != self.frame.username and self.frame.username in message:
				#self.chatrooms.request_hilite(self.Main)
			#else:
				#self.chatrooms.request_changed(self.Main)
			#self.frame.RequestIcon(self.frame.ChatRoomLabel)
			
	
			
			
	def UserJoinedRoom(self, username):
		if self.users.has_key(username):
			return

		status, speed, downloads, files, dirs = self.frame.user_stats[username]
		AppendLine(self.ui.StatusLog, _("%s joined the room") % username) #, self.tag_log)
		img = self.frame.GetStatusImage(username, status)
		hspeed = self.frame.HumanSpeed(speed)
		hfiles = self.frame.Humanize(files)
		self.users[username] = QTreeWidgetItem(self.ui.UserList.invisibleRootItem())
		hspeed = self.frame.HumanSpeed(speed)
		hfiles = self.frame.Humanize(files)
		self.users[username].setIcon(0, self.frame.GetStatusImage(username, status))
		self.users[username].setText(1, username)
		self.users[username].setText(2, hspeed)
		self.users[username].setTextAlignment(2, Qt.AlignRight)
		self.users[username].setText(3, hfiles)
		self.users[username].setTextAlignment(3, Qt.AlignRight)
		self.users[username].setText(4, str(status))
		self.users[username].setData(5, 0, QVariant(speed))
		self.users[username].setData(6, 0, QVariant(files))
		#iter = username.ui.append([img, username, hfiles, hspeed, status])
		#self.users[username] = iter
		#color = self.getUserStatusColor(status)
		#if username in self.tag_users.keys():
			#self.changecolour(self.tag_users[username], color)
		#else:
			#self.tag_users[username] = self.makecolour(self.chatview.get_buffer(), color, username=username)
	
	def UserLeftRoom(self, username):
		if not self.users.has_key(username):
			return
		AppendLine(self.ui.StatusLog, _("%s left the room") % username, self.tag_log)
		#self.usersmodel.remove(self.users[username])
		#self.users[username].close()
		self.ui.UserList.invisibleRootItem().removeChild(self.users[username])
		del self.users[username]