Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt4.QtGui import *
- from PyQt4.QtCore import *
- from PyQt4 import QtGui
- from PyQt4 import QtCore
- from socket import *
- import thread,sys,select,string
- HOST = '192.168.10.34'
- PORT = 5001
- BUFSIZE = 1024
- ADDR = (HOST, PORT)
- global data
- tcpCliSock = socket(AF_INET, SOCK_STREAM)
- tcpCliSock.connect(ADDR)
- class MainWindow(QtGui.QMainWindow):
- def __init__(self, parent=None):
- super(MainWindow, self).__init__(parent)
- self.thread = listener()
- self.thread.recv.connect(self.add)
- self.thread.start()
- roomLabel = QtGui.QLabel('room')
- self.browser = QtGui.QTextBrowser()
- self.browser.backwardAvailable
- self.textEdit = QtGui.QTextEdit()
- self.textEdit.setMaximumSize(QtCore.QSize(400,60))
- self.connect(self.browser, QtCore.SIGNAL("returnPressed()"),self.callback)
- SendButton = QtGui.QPushButton('Send')
- SendButton.setMaximumSize(QtCore.QSize(400,60))
- SendButton.clicked.connect(self.callback)
- layoutINlayout = QtGui.QHBoxLayout()
- layoutINlayout.addWidget(self.textEdit)
- layoutINlayout.addWidget(SendButton)
- widget = QtGui.QWidget()
- self.setCentralWidget(widget)
- self.layout = QtGui.QVBoxLayout()
- self.layout.addWidget(self.browser)
- mainwindow = QtGui.QVBoxLayout()
- mainwindow.addLayout (self.layout )
- mainwindow.addLayout (layoutINlayout )
- widget.setLayout(mainwindow)
- self.setWindowFlags(QtCore.Qt.WindowTitleHint )
- def callback(self, event):
- message = self.textEdit.toPlainText()
- tcpCliSock.send(message)
- def add(self):
- data = tcpCliSock.recv(4096)
- self.browser.setText(data)
- class listener(QThread,QtCore.QObject):
- recv = QtCore.pyqtSignal()
- def __init__(self):
- QThread.__init__(self)
- self.exiting = False
- def __del__(self):
- self.exiting = True
- self.wait()
- def run(self):
- print 'Connected to remote host. Start sending messages'
- while 1:
- data = tcpCliSock.recv(BUFSIZE)
- if data:
- self.recv.emit()
- if __name__ == '__main__':
- app = QtGui.QApplication(sys.argv)
- app.setStyle('chat')
- window = MainWindow()
- window.setWindowTitle("CHAT BOX")
- window.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement