Re: [PyQt] Weird pyqtSignal behaviour
On 27/06/2011 17:23, Giuseppe Corbelli wrote: Hi all I have two boxes: Linux with PyQt-GPL 4.8.3/Qt 4.7.0/Python 2.6.6 Windows 7 with PyQt-Commercial 4.8.4/Qt 4.7.3/ActivePython 2.6.6.18 Forgot: sip 4.12.1 on Linux machine sip 4.12.3 on Linux machine -- Giuseppe Corbelli WASP Software Engineer, Copan Italia S.p.A Phone: +390303666104 Fax: +390302659932 E-mail: giuseppe.corbe...@copanitalia.com ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Designer issues, WYS-is not-WYG
I like Designer and have been using it more and more... but I've been noticing that many times what you see in the Designer window ends up not matching when you run your program later. For example, small offsets in X and Y...look good in Designer, but don't end up in the same place in the program. Many times, it's not that consequential, but in a more complex UI, with very precise positioning, this can be very frustrating. One example,...create a MainWindow, drop a horizontal slider into it, and make it's height 60, so you get a kinda' tall main marker. Save it as a .ui file,...load it into your program, and the tall marker is now short. ( I dynamically load my UI's with uic.loadUiType(), but the same phenomena happens either way.) Using Designer's preview is consistent with what's in Designer, but something is lost in translation later when it goes into the program. I often get positon offset weirdness using QFrames, QGroupBoxes,etc... They look good in Designer, then off in main program, so I have to make them look off in Designer, so they'll end up in the right place when they're used. I'm using Python 2.6.6, Qt 4.5.3, and PyQt4 Does anybody else experience this? Does anybody know what causes it, and is there a workaround? Thanks, -Jim ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] safely closing QThread when application exits.
hi, I am pyqt beginner and followed tutorials on the internet to learn it until recently. Then I have wanted to develop my own application. I am developing a simple chat application. I want to have 2 windows running independently (in other words two separate applications), one for server and one for client. When server starts to run, it is going to wait for client to run, and they will chat. So far, I could only start doing server side. I am using QThread, which is a subject rather unclear to me. I am getting this error when I close my application from X button: QThread: Destroyed while thread is still running I am guessing that this occurs because I am not closing the thread safely before application exists. I was wondering how I can make my thread respond to application exist so that it can close itself. Here is my code: chat_server.py import sys from PyQt4 import QtCore,QtGui from chat_ui import Ui_MainWindow import socket class Server(QtGui.QMainWindow): def __init__(self,parent=None): super(Server,self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.textEdit.append(Waiting for inbound connections) self.netconnector = NetConnectWorker(self) self.netconnector.attemptConnect() self.connect(self.netconnector,QtCore.SIGNAL(Connected()),self.connected) self.connect(self.netconnector,QtCore.SIGNAL(dataRecieved(QString)),self.messageRecieved) self.connect(self.netconnector,QtCore.SIGNAL(socketError(QString)),self.socketError) def connected(self): self.ui.textEdit.append(Connected) def messageRecieved(self,data): self.ui.textEdit.append(data) def socketError(self,msg): print msg self.ui.textEdit.append(Encountered a socket error:\n %s % msg) class NetConnectWorker(QtCore.QThread): def __init__(self,parent=None): super(NetConnectWorker,self).__init__(parent) self.exiting = False self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.host = '' self.port = 5 self.backlog = 5 self.address = self.client = def __del__(self): self.exiting = True self.wait() if self.client: self.client.close() def attemptConnect(self): self.start() def run(self): try: self.socket.bind((self.host,self.port)) except socket.error,error: print dir(error) self.emit(QtCore.SIGNAL(socketError(QString)),error.message) self.exit() self.socket.listen(self.backlog) self.client , self.address = self.socket.accept() if self.client: self.emit(QtCore.SIGNAL(Connected())) while not self.exiting: data = self.client.recv(1024) if data: self.emit(QtCore.SIGNAL(dataRecieved(QString)),data) if __name__ == __main__: app = QtGui.QApplication(sys.argv) ex=Server() ex.show() sys.exit(app.exec_()) #!/usr/bin/python # -*- coding: utf-8 -*- # chat_server import sys from PyQt4 import QtCore,QtGui from chat_ui import Ui_MainWindow import socket class Server(QtGui.QMainWindow): def __init__(self,parent=None): super(Server,self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.textEdit.append(Waiting for inbound connections) self.netconnector = NetConnectWorker(self) self.netconnector.attemptConnect() self.connect(self.netconnector,QtCore.SIGNAL(Connected()),self.connected) self.connect(self.netconnector,QtCore.SIGNAL(dataRecieved(QString)),self.messageRecieved) self.connect(self.netconnector,QtCore.SIGNAL(socketError(QString)),self.socketError) def connected(self): self.ui.textEdit.append(Connected) def messageRecieved(self,data): self.ui.textEdit.append(data) def socketError(self,msg): print msg self.ui.textEdit.append(Encountered a socket error:\n %s % msg) class NetConnectWorker(QtCore.QThread): def __init__(self,parent=None): super(NetConnectWorker,self).__init__(parent) self.exiting = False self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.host = '' self.port = 5 self.backlog = 5 self.address = self.client = def __del__(self): self.exiting = True self.wait() if self.client: self.client.close() def attemptConnect(self): self.start() def run(self): try: self.socket.bind((self.host,self.port)) except socket.error,error: print dir(error) self.emit(QtCore.SIGNAL(socketError(QString)),error.message) self.exit() self.socket.listen(self.backlog) self.client ,
[PyQt] QString, QTextEdit and Encoding problem
Hi, I am havin an encoding problem. If you have read my earlier post, I was doing a simple chat application. Here is how it goes. === Client Class === def on_lineEdit_returnPressed(self): text= self.ui.lineEdit.text() self.ui.lineEdit.selectAll() self.ui.lineEdit.cut() self.ui.textEdit.paste() self.netconnector.sendMessage(text) === netconnector === def sendMessage(self,msg): if self.isConnected: self.socket.send(msg.toUtf8().trimmed()) === Server Side: === === Server Class === self.connect(self.netconnector,QtCore.SIGNAL(dataRecieved(QString)),self.messageRecieved) === server side netconnector: === def messageRecieved(self,data): self.ui.textEdit.append(data) What happens is that, when I type non-ascii characters into client side line edit, it becomes distorted at server side, like şğü -- ÅÄü Any idea how to fix this? You can find whole code as attachment. #!/usr/bin/python # -*- coding: utf-8 -*- # chat_server import sys from PyQt4 import QtCore,QtGui from chat_ui import Ui_MainWindow import socket class Client(QtGui.QMainWindow): def __init__(self,parent=None): super(Client,self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.textEdit.append(Trying to connect to server) self.netconnector = NetConnectWorker(self) self.netconnector.attemptConnect() self.connect(self.netconnector,QtCore.SIGNAL(Connected()),self.connected) #self.connect(self.netconnector,QtCore.SIGNAL(dataRecieved(QString)),self.messageRecieved) self.connect(self.netconnector,QtCore.SIGNAL(socketError()),self.socketError) self.ui.lineEdit def on_lineEdit_returnPressed(self): text= self.ui.lineEdit.text() self.ui.lineEdit.selectAll() self.ui.lineEdit.cut() self.ui.textEdit.paste() self.netconnector.sendMessage(text) def connected(self): self.ui.textEdit.append(Connected) #def messageRecieved(self,data): #self.ui.textEdit.append(data) # def socketError(self): self.ui.textEdit.append(Couldn't connect lol :S) class NetConnectWorker(QtCore.QThread): def __init__(self,parent=None): super(NetConnectWorker,self).__init__(parent) self.exiting = False self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.host = 'localhost' self.port = 5 self.size = 5 self.isConnected=False def __del__(self): self.exiting = True self.wait() def attemptConnect(self): self.start() def sendMessage(self,msg): if self.isConnected: self.socket.send(msg.toUtf8().trimmed()) def run(self): try: self.socket.connect((self.host,self.port)) self.isConnected = True except socket.error: self.emit(QtCore.SIGNAL(socketError())) return self.emit(QtCore.SIGNAL(Connected())) if __name__ == __main__: app = QtGui.QApplication(sys.argv) sv=Client() sv.show() sys.exit(app.exec_())#!/usr/bin/python # -*- coding: utf-8 -*- # chat_server import sys from PyQt4 import QtCore,QtGui from chat_ui import Ui_MainWindow import socket class Server(QtGui.QMainWindow): def __init__(self,parent=None): super(Server,self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.textEdit.append(Waiting for inbound connections) self.netconnector = NetConnectWorker(self) self.netconnector.attemptConnect() self.connect(self.netconnector,QtCore.SIGNAL(Connected()),self.connected) self.connect(self.netconnector,QtCore.SIGNAL(dataRecieved(QString)),self.messageRecieved) self.connect(self.netconnector,QtCore.SIGNAL(socketError(QString)),self.socketError) def connected(self): self.ui.textEdit.append(Connected) def messageRecieved(self,data): self.ui.textEdit.append(data) def socketError(self,msg): print msg self.ui.textEdit.append(Encountered a socket error:\n %s % msg) class NetConnectWorker(QtCore.QThread): def __init__(self,parent=None): super(NetConnectWorker,self).__init__(parent) self.exiting = False self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.host = '' self.port = 5 self.backlog = 5 self.address = self.client = def __del__(self): self.exiting = True self.wait() if self.client: self.client.close() def attemptConnect(self): self.start() def run(self): try: self.socket.bind((self.host,self.port)) except
Re: [PyQt] QString, QTextEdit and Encoding problem
On 28.06.11 06:26:24, Yaşar Arabacı wrote: Hi, I am havin an encoding problem. If you have read my earlier post, I was doing a simple chat application. Here is how it goes. You're not converting your data correctly. On the sending side you do it properly, decoding to utf-8 and then sending the bytes through the network. On the receiving side you're using Python's socket API, which gives you a byte-stream and then create a QString from it implicitly. That uses whatever your systems default-encoding is to decode the bytes into a string. The error is in NetConnectorWorker.run, but its not that easy to fix since you currently do not send the amount of bytes you cannot know on the receiving side wether all data has been received or not and hence you cannot do a correct decoding. I suggest to switch to use Qt's network stack, that'll make these things a bit easier since you can use QDataStream on the network socket which handles sending QString's just fine. If thats not possible, you'll have to add the length of the message into the byte-stream or always read up to the first \n and decode the content then and make sure the sender always sends at least 1 \n. Andreas ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] QString, QTextEdit and Encoding problem
Thanks for the info. Do you know any decent example, tutorial, documents etc. about qt network stack? 2011/6/28 Andreas Pakulat ap...@gmx.de On 28.06.11 06:26:24, Yaşar Arabacı wrote: Hi, I am havin an encoding problem. If you have read my earlier post, I was doing a simple chat application. Here is how it goes. You're not converting your data correctly. On the sending side you do it properly, decoding to utf-8 and then sending the bytes through the network. On the receiving side you're using Python's socket API, which gives you a byte-stream and then create a QString from it implicitly. That uses whatever your systems default-encoding is to decode the bytes into a string. The error is in NetConnectorWorker.run, but its not that easy to fix since you currently do not send the amount of bytes you cannot know on the receiving side wether all data has been received or not and hence you cannot do a correct decoding. I suggest to switch to use Qt's network stack, that'll make these things a bit easier since you can use QDataStream on the network socket which handles sending QString's just fine. If thats not possible, you'll have to add the length of the message into the byte-stream or always read up to the first \n and decode the content then and make sure the sender always sends at least 1 \n. Andreas ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt