Created
June 10, 2012 12:04
-
-
Save anonymous/2905180 to your computer and use it in GitHub Desktop.
gui.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import sys | |
from PyQt4.QtGui import * | |
from PyQt4.QtCore import * | |
from PyQt4.QtNetwork import * | |
class Example(QWidget): | |
def __init__(self): | |
super(Example, self).__init__() | |
self.initUI() | |
@pyqtSlot() | |
def sendAndRecive(self): | |
textToSend = QByteArray(); | |
textToSend.append(self.textSend.text()); | |
self.socket.writeData(textToSend); | |
self.socket.flush() | |
print(self.socket.bytesAvailable()) | |
def initUI(self): | |
self.setFixedSize(250, 150); | |
self.move(100, 100); | |
self.setWindowTitle('Client') | |
btnSend = QPushButton('Send') | |
btnExit = QPushButton('Exit') | |
self.textSend = QLineEdit(); | |
self.textRecive = QLineEdit(); | |
self.textRecive.setReadOnly(True); | |
mainLayout = QGridLayout(); | |
self.setLayout(mainLayout); | |
mainLayout.addWidget(self.textRecive, 0, 0, 1, 0); | |
mainLayout.addWidget(self.textSend, 1, 0); | |
mainLayout.addWidget(btnSend, 1, 1); | |
mainLayout.addWidget(btnExit, 2, 0, 1, 0); | |
mainLayout.setSpacing(0); | |
self.show() | |
self.connect(btnExit, SIGNAL("clicked()"), qApp, SLOT("quit()") ) | |
self.connect(btnSend, SIGNAL("clicked()"), self, SLOT("sendAndRecive()") ) | |
self.socket = QTcpSocket(); | |
self.socket.connectToHost("localhost", 8080); | |
def main(): | |
app = QApplication(sys.argv) | |
ex = Example() | |
sys.exit(app.exec_()) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment