Re: [PyQt] Processing signals from a called method while the method executes
On 01.07.10 21:35:44, alan moore wrote: > I've encountered this problem twice now in subtle ways, I think this > is at the root of my last question about the QWebView; I've included > sample code this time to illustrate. > > In the attached script, I have a widget class and a processor class. > The processor represents some kind of processing engine that's going > to do a lengthy multi-part routine of some kind. The widget class > is the gui for the engine. > > The "go" button is connected to the "process" method of the > processor object. The process() method emits a signal with a > string, does process A for 10 seconds, emits a signal with a string, > does process B for 10 seconds, and emits a final signal with a > string. > > The widget class is supposed to be picking up the signals and > displaying the strings. So the expected output is: > > > first message displays > > second message displays > > final message displays > > The actual output is that nothing happens for 20 seconds, then all > the text displays. Because the widget isn't going to process any > received signals until the called method exits. > > How do I produce the expected behavior here? Don't block the event-loop with your processor. The signals are delivered as you expect, but the widget is not redrawn with that message. The reason is that your processing blocks the Qt event loop and hence no painting is done. Possible options to not block the event loop that long would be to use a QTimer to schedule each part of your processing after the next event-loop run. The other option would be moving the processing into a separate thread, you should only go this route after making familiar with multi-threading though. Andreas -- Break into jail and claim police brutality. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Synchronous WebView.load()
As I understand it, the webview doesn't actually load the page and update itself until the method call returns; at which point it loads the new page and updates the history. To illustrate the problem I'm having a little more clearly, I've attached a sample script. The script is supposed to conduct a brief tour of a list of websites when you hit the "go" button on the browser toolbar. Each site shows for five seconds, then the next on loads. Only that's not what happens. If you run it, you'll see that hitting "go" causes the browser to hang for about 20 seconds, then the final comment is all that shows. In other words, for the whole duration of the method call, the main window is asleep. I guess this is just another instance of the trouble I was running into on my other program, which I posted a demonstration script for earlier today. I would really appreciate any help on this matter. #!/usr/bin/python from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * from time import sleep import sys class MyBrowser(QMainWindow): """My Browser demonstrates a problem I'm having with manipulating a webview via called methods """ def __init__(self): """ Build a browser workshop """ super(QMainWindow, self).__init__() self.webview = QWebView() self.setCentralWidget(self.webview) self.navbar = self.addToolBar("Navigation") #Not totally necessary, but let's make it look like a browser self.navbar.addAction(self.webview.pageAction(QWebPage.Back)) self.navbar.addAction(self.webview.pageAction(QWebPage.Forward)) self.navbar.addAction(self.webview.pageAction(QWebPage.Reload)) self.navbar.addAction(self.webview.pageAction(QWebPage.Stop)) self.go_button = QPushButton("Go") self.navbar.addWidget(self.go_button) self.connect(self.go_button, SIGNAL("clicked()"), self.tour_of_internet) self.webview.setHtml("Click 'go' to get a tour of the best sites on the Internet.") def tour_of_internet(self): """ This is supposed to give you a tour of several sites, for five seconds each. """ sites = ["http://www.google.com";, "http://doc.qt.nokia.com";, "http://www.alandmoore.com";, "http://www.kde.org";] for site in sites: self.webview.setUrl(QUrl(site)) self.webview.update() sleep(5) self.webview.setHtml("Wow, wasn't that awesome???") if __name__ == '__main__': app = QApplication(sys.argv) w = MyBrowser() w.show() app.exec_() ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Processing signals from a called method while the method executes
I've encountered this problem twice now in subtle ways, I think this is at the root of my last question about the QWebView; I've included sample code this time to illustrate. In the attached script, I have a widget class and a processor class. The processor represents some kind of processing engine that's going to do a lengthy multi-part routine of some kind. The widget class is the gui for the engine. The "go" button is connected to the "process" method of the processor object. The process() method emits a signal with a string, does process A for 10 seconds, emits a signal with a string, does process B for 10 seconds, and emits a final signal with a string. The widget class is supposed to be picking up the signals and displaying the strings. So the expected output is: first message displays second message displays final message displays The actual output is that nothing happens for 20 seconds, then all the text displays. Because the widget isn't going to process any received signals until the called method exits. How do I produce the expected behavior here? from PyQt4.QtGui import * from PyQt4.QtCore import * import sys from time import sleep class mywidget(QWidget): def __init__(self): super(QWidget, self).__init__() self.gobutton = QPushButton("Go") self.logwindow = QTextEdit() self.setLayout(QVBoxLayout()) self.layout().addWidget(self.gobutton) self.layout().addWidget(self.logwindow) self.processor = processor() self.connect(self.processor, SIGNAL("statusChanged(str)"), self.logwindow.append) self.connect(self.gobutton, SIGNAL("clicked()"), self.processor.process) class processor(QObject): def __init__(self): super(QObject, self).__init__() def process(self): self.emit (SIGNAL("statusChanged(str)"), "Starting A\n") #simulating some lengthy process A sleep(10) self.emit (SIGNAL("statusChanged(str)"), "A done, starting B\n") #simulating some lengthy process B sleep(10) self.emit (SIGNAL("statusChanged(str)"), "B done. Finished\n") if __name__ == '__main__': app = QApplication(sys.argv) w = mywidget() w.show() app.exec_() ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] SIP Bug: virtual function wrapped twice due to deep inheritance from base class and ABC
Phil, It's not code specific to that class. It's due to the deep inheritance tree. You should be able to run my test code and get the same results. Basically to sum it up: PTCPSocket <- PIPDataGramSocket <- PIPSocket <- PSocket (ABC) PTCPSocket, PIPSocket and PSocket all define a virtual function called 'Listen'. Commenting 'Listen' out from PSocket, and SIP does not include the function twice. Listen is NOT a pure virtual function in the ABC, it has a body. Listen is fully defined in PTCPSocket, and the other classes except PIPDataGramSocket. Phil Thompson-5 wrote: > > On Sat, 19 Jun 2010 10:27:55 -0700 (PDT), Demetrius Cassidy > wrote: >> Basically I have a Listen() function in a derived class, that is also in >> the >> base and ABC. For some reason sip ends up wrapping the same function > twice >> (it >> has a body in the ABC), even though it's a virtual function in all of the > >> derived classes. If I comment out this function in the ABC, everything >> works >> fine, but otherwise I get a C2535 compiler error with Visual C++. >> >> Here is what sip comes up with: >> >> class sipPUDPSocket : public PUDPSocket >> { >> >> /* >> * There is a protected method for every virtual method visible from >> * this class. >> */ >> protected: >> PBoolean Listen(unsigned,WORD,PIPSocket::Reusability); >> /*more wrapped functions*/ >> PBoolean Listen(unsigned,WORD,PIPSocket::Reusability); // <-- > duplicate >> function >> }; >> >> C++ nmake errors: >> >> sippyptlibPTCPSocket.cpp >> .\sippyptlibPTCPSocket.cpp(121) : error C2535: 'PBoolean >> sipPTCPSocket::Listen(unsigned int,WORD,PSocket::Reusability)' >> : member function already defined or declared >> .\sippyptlibPTCPSocket.cpp(102) : see declaration of >> 'sipPTCPSocket::Listen' >> >> >> .\sippyptlibPTCPSocket.cpp(506) : error C2084: function 'PBoolean >> sipPTCPSocket: >> :Listen(unsigned int,WORD,PSocket::Reusability)' already has a body >> .\sippyptlibPTCPSocket.cpp(102) : see previous definition of >> 'Listen' >> >> >> Basic code structure based on what I am wrapping - note that I only >> included >> the >> offending function here, as it would be too much code to include >> everything. > > But you at least need to include the definition of PUDPSocket. > >> typedef bool PBoolean; >> >> class PTCPSocket : PIPDataGramSocket >> { >> public: >> virtual PBoolean Listen(unsigned int, WORD, PSocket::Reusability); >> } >> >> class PIPDataGramSocket : PIPSocket >> { >> protected: >> PIPDataGramSocket(); >> } >> >> class PIPSocket : PSocket >> { >> public: >> virtual PBoolean Listen(unsigned int, WORD, PSocket::Reusability); >> } >> >> class PSocket /Abstract/ >> { >> public: >> /// Flags to reuse of port numbers in Listen() function. >> enum Reusability { >> CanReuseAddress, >> AddressIsExclusive >> }; >> >> virtual PBoolean Listen(unsigned int, WORD, PSocket::Reusability); // >> commenting this function out fixes this problem >> >> protected: >> /*This function calls os_socket() with the correct parameters for the > >>socket protocol type. >> */ >> virtual PBoolean OpenSocket() = 0; >> >> }; > > Phil > ___ > PyQt mailing listPyQt@riverbankcomputing.com > http://www.riverbankcomputing.com/mailman/listinfo/pyqt > > -- View this message in context: http://old.nabble.com/SIP-Bug%3A-virtual-function-wrapped-twice-due-to-deep-inheritance-from-base-class-and-ABC-tp28936011p29051687.html Sent from the PyQt mailing list archive at Nabble.com. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] multiple inheritance and MappedType
Hi, I've got an existing library with python wrappers generated with a different tool, and I've successfully used MappedType to interface with that and I'm getting the interoperability I'm looking for. But now I want to use sip to wrap a class that derives from two classes, one is QObject, and the other is a MappedType. I'm getting an error from sip: "A class, exception, namespace or mapped type has already been defined with the same name" Is inheritance from a MappedType not supported? Thanks, Clint ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] signal twice emit
On Thu, 01 Jul 2010 19:50:14 +0200, Csaba Toth wrote: > Hi! > > last evening recompiled the program with PyQt 4.6.2 (it has Qt 4.5.3), > and today the problem gone, no one complained. > > Phil, what you think, is it a good idea to compile PyQt 4.6.2+Qt 4.6.3, > or PyQt 4.7.3+Qt 4.5.3? Or have a better idea? I need a test case so that I can reproduce the problem. Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Synchronous WebView.load()
On Thursday 01 July 2010 2:13:47 pm alanm wrote: > I have an app with a QWebView, and I'm trying to implement a "reset" button > that will clear the history and return the user to the start page. > > The method looks like this: > > def reset_browser(self): > self.webview.load(self.startUrl) > self.webview.history().clear() > After some experimenting, it turns out that the problem isn't quite what I thought it was. In fact, it's almost the opposite problem. I put self.webview.load() in a while loop so that it would continue to load while the history.currentItem().url() is not equal to the startUrl(). The loop turned out to be infinite. As I understand it, the webview doesn't actually load the page and update itself until the method call returns; at which point it loads the new page and updates the history. It seems like there's no way to do what I want in one function then, is there? ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Getting stuck in an infinite loop in QGraphicsPixmapItem::boundingRect()
I realized if I don't set the pixmaps on the QGraphicsPixmapItems, I don't have this problem. This only happens when they have a pixmap. -- View this message in context: http://old.nabble.com/Getting-stuck-in-an-infinite-loop-in-QGraphicsPixmapItem%3A%3AboundingRect%28%29-tp29047302p29049585.html Sent from the PyQt mailing list archive at Nabble.com. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Getting stuck in an infinite loop in QGraphicsPixmapItem::boundingRect()
David Boddie-4 wrote: > > When you stop the program, do you get a Python Traceback? > > If so, what does it show? > > David > -- > David Boddie > Senior Technical Writer > Nokia, Qt > ___ > PyQt mailing listPyQt@riverbankcomputing.com > http://www.riverbankcomputing.com/mailman/listinfo/pyqt > > No I do not. I went through the program with a debugger, and I ended up in the boundingRect() function. I go into that function right as I execute the "fileName = QFileDialog.getOpenFileName" command -- View this message in context: http://old.nabble.com/Getting-stuck-in-an-infinite-loop-in-QGraphicsPixmapItem%3A%3AboundingRect%28%29-tp29047302p29049479.html Sent from the PyQt mailing list archive at Nabble.com. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Synchronous WebView.load()
I have an app with a QWebView, and I'm trying to implement a "reset" button that will clear the history and return the user to the start page. The method looks like this: def reset_browser(self): self.webview.load(self.startUrl) self.webview.history().clear() The problem with the method is that QWebView.load() is asynchronous; so the page starts loading, then the history clears, then the page finishes loading and the previous page is put in to history. The net result is that the last page visited before the reset is still in history. I can see solutions to this problem if there is a way to: - Tell load() to run synchronously - Tell history to clear everything, including the current page Any thoughts? ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Getting stuck in an infinite loop in QGraphicsPixmapItem::boundingRect()
On Thu Jul 1 16:46:56 BST 2010, dizou wrote: > The QGraphicsScene contains a bunch of QGraphicsPixmapItems in it. The > QGraphicsView displays them on the screen. When I click a "Open" button, I > enter into the Open() function in my widget. When this happens, I go into > an infinite loop where python will continuously go through each > QGraphicsPixmapItem's boundingRect() function. When you stop the program, do you get a Python Traceback? If so, what does it show? David -- David Boddie Senior Technical Writer Nokia, Qt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] problem with connection to mysql
Hi I have a problem connecting to a server from Windows install mysql PyQt-Py2.6-gpl-4.7.3-2.exe tells me (with database support for MySQL, PostgreSQL, SQLite3 and ODBC) but I can not connect to mysql, which I do. Windows Vista, Xp , Seven Python 2.6.4 _ ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] signal twice emit
Hi! last evening recompiled the program with PyQt 4.6.2 (it has Qt 4.5.3), and today the problem gone, no one complained. Phil, what you think, is it a good idea to compile PyQt 4.6.2+Qt 4.6.3, or PyQt 4.7.3+Qt 4.5.3? Or have a better idea? thanks in advance, Csaba 2010.06.30. 21:28 keltezéssel, Csaba Toth írta: > Hi! > >> On Tue, Jun 29, 2010 at 3:06 PM, Csaba Toth wrote: >>> >>> def p(self, clicked=False): >>> print('emitted') >>> self.connect(self.btn_save, QtCore.SIGNAL("clicked(bool)"), self.p) >> >> Initially, I thought this could be a problem with both the clicked() > and the >> clicked(bool) signals being connected to the slot, but that shouldn't > happen >> if the signature is used like this. You could check to see if the behavior >> changes by decorating p() like this: >> >> @pyqtSlot("bool") >> def p(self, clicked=False): >> print('emitted') >> >> It's difficult to know exactly what could cause this without some more >> context. I've seen code that uses signal-slot auto-connection and also >> includes connect() calls, resulting in double connections. > > There is no double connection, checked it manually with a print next to > the connect. > > And i tried this decorator today, from the 20 people 3 people dropped an > email to me that they had this problem showed up today. The first did > after 3 work hour with the program, and after a few double invokioning > it started to work normally. > (this is a simple data store program. There is one dialog with a lot > check box and an ID lineEdit field. If they click on the save button it > first store the datas in a postgres table, and than clears the form. if > the lineedit is empty they had a warning pops up. the error looks like a > worker fills up the form, click on the save button, than the warning > shows up they haven't filled up the ID lineedit, but they did. This > happens because at the first invokion of the click event it save than > clear the form, and at the second run the ID lineedit truly empty. > during the day they didn't touch the progrma, they don't exit, just fill > up the form and save.) > > looks like a memory leak for me :( > > 2010.06.29. 21:14 keltezéssel, David Boddie írta: >> On Tue Jun 29 18:42:37 BST 2010, Csaba Toth wrote: >> >> It would be interesting to try it with an earlier version if possible, though >> I could understand if that's not possible. > > Yes, i will try this tomorrow, first will go back to PyQt 4.6.* version. > > I have a lot installers saved, becase sadly from the website no old > versions downloadable. :( > > thanks for helping, let see what will happen tomorrow with older version! > > regards, > Csaba > > >> >> >> David > > ___ > PyQt mailing listPyQt@riverbankcomputing.com > http://www.riverbankcomputing.com/mailman/listinfo/pyqt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] QActions on a toolbar and mnemonics
I have a QToolBar created from a QMainWindow's addToolBar() method. I have created a number of QActions with mnemonics in the name and shortcut keys assigned by using the QKeySequence.mnemonic() method to extract the mnemonic from the QAction's name. The problem is that when I add the QActions to the toolbar (with no icons, so that they display text), the mnemonic is not being underlined on the button. I have searched for this and someone mentioned this is a feature of the Desktop / Windowing environment, but the problem shows up on multiple environments: - my kiosks, running matchbox window manager - my desktop, running KDE 4.4.5 - my virtual machine, running windows XP (even when pressing alt, they don't get underlined) Is there a way to force mnemonics to underline all the time? ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Getting stuck in an infinite loop with boundingRect()
I have a widget with a QTreeView, QGraphicsScene, and a QGraphicsView: MainWidget.py: class MainWidget(ControlWidget): def __init__(self, parent): ControlWidget.__init__(self, parent) self.tree = TreeArea(self) #TreeArea inherits QTreeView self.display = DisplayScene(self) #DisplayScene inherits QGraphicsScene self.view = DisplayView(self.display) #DisplayView inherits QGraphicsView self.view.show() #code to set up layout def Open(self): fileName = QFileDialog.getOpenFileName(self, "Open File", QDir.currentPath(), "(*.xml *.xmf *.xmn)") The QGraphicsScene contains a bunch of QGraphicsPixmapItems in it. The QGraphicsView displays them on the screen. When I click a "Open" button, I enter into the Open() function in my widget. When this happens, I go into an infinite loop where python will continuously go through each QGraphicsPixmapItem's boundingRect() function. Here is my class that inherits QGraphicsPixmapItem: class DisplayItem(QGraphicsPixmapItem): def __init__(self, parent, pixmap=None, graphView=None): if pixmap: self.HasPixmap = True QGraphicsPixmapItem.__init__(self, pixmap) self.setAcceptHoverEvents(True) self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsSelectable) self.setZValue(1) self.setOffset(-9, -9) def boundingRect(self): adjust = 2.0 return QRectF(-10 - adjust, -10 - adjust, 23 + adjust, 23 + adjust) So what is going on? -- View this message in context: http://old.nabble.com/Getting-stuck-in-an-infinite-loop-with-boundingRect%28%29-tp29047302p29047302.html Sent from the PyQt mailing list archive at Nabble.com. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Signal number 10
Hey there! New to this list and to PyQt in general. Sorry if this problem has been already discussed ( probably ) I am using Qt designer along with TextMatte and osx 10.5. At some point, when closing a pyqt app run from TextMatte, the app will close with the following error message Uncought signal number 10" or something like that. Sometimes it does it, sometimes not. The app has no problem while running, but its just very annoying to get an error message everytime I close the app Thanks! -- Hugo Leveille Digital compositor Vision Globale hu...@fastmail.net Sent from my iPhone ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] adding signalling to QGraphicsItems
On 01.07.2010 16:21, Phil Thompson wrote: On Thu, 01 Jul 2010 16:10:32 +0200, "Christopher M. Nahler" wrote: On 01.07.2010 12:29, Phil Thompson wrote: On Thu, 01 Jul 2010 11:58:01 +0200, "Christopher M. Nahler" wrote: I want to add signalling functionality to scene items. In my case they are usually QGraphicsRectItems.. I thought I could do this with deriving from QGraphicsObject but then I loose all the funtionality for the rectangle, handling pens and brushes, shapes etc. Isn't it easier to just derive from QGraphicsRectItem and QObject? Or should I derive from QGraphicsRectItem and QGraphicsObject instead? Neither. You can't multiply inherit from more than one PyQt class. Or are there any other ways to do this? Create a QObject subclass that implements your signals as an attribute of your QGraphicsRectItem. Phil Thanks for the quick reply. I have tried to implement it that way but stumbled over another problem I have in this case. I want to announce that a MyRectangle was created (or has changed). When I want to add a signalling object to my rectangle class I have to def it before. But when I define the signal there I have to specify the data type which is not yet defined. #!/usr/bin/env python # -*- coding: utf-8 -*- from PyQt4.QtCore import * from PyQt4.QtGui import * class Communicator(QObject): MyRectangleCreated = pyqtSignal(MyRectangle)<-- MyRectangle not defined yet! def __init(self): super(Communicator, self).__init__(parent) class MyRectangle(QGraphicsRectItem): def __init__(self, rect=QRectF(0, 0, 0, 0), parent=None, scene=None): super(MyRectangle, self).__init__(parent, scene) self.myCommunicator = Communicator() self.myCommunicator.MyRectangleCreated.emit(self) This can never work. You will always be emitting the signal before anything has had a chance to connect to it. Yes, that was obvious. Just wanted to present my dilemma :-) if __name__ == "__main__": r = MyRectangle() In genereal what I want to do is synchronize the QGraphicsItems from the scene with a list of data objects. So when I create a graphics item a data object in the data manager should be created and when I change a graphics object the corresponding data block object should be updated. BTW right now I have the handling of the events (which creates and changes graphics items) in a widget derived from a view. Any hints on the best approach for that? You need some sort of rectangle manager (maybe the QGraphicsScene) that has a method that will create a new MyRectangle instance and emit a signal that it has done so. Phil I am just reading the diagramscene example (where they do the signalling in the scene) and I think this will be the best path to follow. Thanks for pointing me in the right direction. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] SIP Bug: virtual function wrapped twice due to deep inheritance from base class and ABC
On Sat, 19 Jun 2010 10:27:55 -0700 (PDT), Demetrius Cassidy wrote: > Basically I have a Listen() function in a derived class, that is also in > the > base and ABC. For some reason sip ends up wrapping the same function twice > (it > has a body in the ABC), even though it's a virtual function in all of the > derived classes. If I comment out this function in the ABC, everything > works > fine, but otherwise I get a C2535 compiler error with Visual C++. > > Here is what sip comes up with: > > class sipPUDPSocket : public PUDPSocket > { > > /* > * There is a protected method for every virtual method visible from > * this class. > */ > protected: > PBoolean Listen(unsigned,WORD,PIPSocket::Reusability); > /*more wrapped functions*/ > PBoolean Listen(unsigned,WORD,PIPSocket::Reusability); // <-- duplicate > function > }; > > C++ nmake errors: > > sippyptlibPTCPSocket.cpp > .\sippyptlibPTCPSocket.cpp(121) : error C2535: 'PBoolean > sipPTCPSocket::Listen(unsigned int,WORD,PSocket::Reusability)' > : member function already defined or declared > .\sippyptlibPTCPSocket.cpp(102) : see declaration of > 'sipPTCPSocket::Listen' > > > .\sippyptlibPTCPSocket.cpp(506) : error C2084: function 'PBoolean > sipPTCPSocket: > :Listen(unsigned int,WORD,PSocket::Reusability)' already has a body > .\sippyptlibPTCPSocket.cpp(102) : see previous definition of > 'Listen' > > > Basic code structure based on what I am wrapping - note that I only > included > the > offending function here, as it would be too much code to include > everything. But you at least need to include the definition of PUDPSocket. > typedef bool PBoolean; > > class PTCPSocket : PIPDataGramSocket > { > public: > virtual PBoolean Listen(unsigned int, WORD, PSocket::Reusability); > } > > class PIPDataGramSocket : PIPSocket > { > protected: > PIPDataGramSocket(); > } > > class PIPSocket : PSocket > { > public: > virtual PBoolean Listen(unsigned int, WORD, PSocket::Reusability); > } > > class PSocket /Abstract/ > { > public: > /// Flags to reuse of port numbers in Listen() function. > enum Reusability { > CanReuseAddress, > AddressIsExclusive > }; > > virtual PBoolean Listen(unsigned int, WORD, PSocket::Reusability); // > commenting this function out fixes this problem > > protected: > /*This function calls os_socket() with the correct parameters for the >socket protocol type. > */ > virtual PBoolean OpenSocket() = 0; > > }; Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] adding signalling to QGraphicsItems
On Thu, 01 Jul 2010 16:10:32 +0200, "Christopher M. Nahler" wrote: > On 01.07.2010 12:29, Phil Thompson wrote: >> On Thu, 01 Jul 2010 11:58:01 +0200, "Christopher M. Nahler" >> wrote: >> >>> I want to add signalling functionality to scene items. In my case they >>> are usually QGraphicsRectItems.. >>> >>> I thought I could do this with deriving from QGraphicsObject but then I >>> loose all the funtionality for the rectangle, handling pens and brushes, >>> shapes etc. >>> >>> Isn't it easier to just derive from QGraphicsRectItem and QObject? Or >>> should I derive from QGraphicsRectItem and QGraphicsObject instead? >>> >> Neither. You can't multiply inherit from more than one PyQt class. >> >> >>> Or are there any other ways to do this? >>> >> Create a QObject subclass that implements your signals as an attribute of >> your QGraphicsRectItem. >> >> Phil >> > > Thanks for the quick reply. I have tried to implement it that way but > stumbled over another problem I have in this case. I want to announce > that a MyRectangle was created (or has changed). When I want to add a > signalling object to my rectangle class I have to def it before. But > when I define the signal there I have to specify the data type which is > not yet defined. > > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > from PyQt4.QtCore import * > from PyQt4.QtGui import * > > class Communicator(QObject): > MyRectangleCreated = pyqtSignal(MyRectangle) <-- MyRectangle not > defined yet! > > def __init(self): > super(Communicator, self).__init__(parent) > > > class MyRectangle(QGraphicsRectItem): > > def __init__(self, rect=QRectF(0, 0, 0, 0), parent=None, scene=None): > super(MyRectangle, self).__init__(parent, scene) > self.myCommunicator = Communicator() > self.myCommunicator.MyRectangleCreated.emit(self) This can never work. You will always be emitting the signal before anything has had a chance to connect to it. > if __name__ == "__main__": > r = MyRectangle() > > In genereal what I want to do is synchronize the QGraphicsItems from the > scene with a list of data objects. So when I create a graphics item a > data object in the data manager should be created and when I change a > graphics object the corresponding data block object should be updated. > > BTW right now I have the handling of the events (which creates and > changes graphics items) in a widget derived from a view. > > Any hints on the best approach for that? You need some sort of rectangle manager (maybe the QGraphicsScene) that has a method that will create a new MyRectangle instance and emit a signal that it has done so. Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] adding signalling to QGraphicsItems
On 01.07.2010 12:29, Phil Thompson wrote: On Thu, 01 Jul 2010 11:58:01 +0200, "Christopher M. Nahler" wrote: I want to add signalling functionality to scene items. In my case they are usually QGraphicsRectItems.. I thought I could do this with deriving from QGraphicsObject but then I loose all the funtionality for the rectangle, handling pens and brushes, shapes etc. Isn't it easier to just derive from QGraphicsRectItem and QObject? Or should I derive from QGraphicsRectItem and QGraphicsObject instead? Neither. You can't multiply inherit from more than one PyQt class. Or are there any other ways to do this? Create a QObject subclass that implements your signals as an attribute of your QGraphicsRectItem. Phil Thanks for the quick reply. I have tried to implement it that way but stumbled over another problem I have in this case. I want to announce that a MyRectangle was created (or has changed). When I want to add a signalling object to my rectangle class I have to def it before. But when I define the signal there I have to specify the data type which is not yet defined. #!/usr/bin/env python # -*- coding: utf-8 -*- from PyQt4.QtCore import * from PyQt4.QtGui import * class Communicator(QObject): MyRectangleCreated = pyqtSignal(MyRectangle) <-- MyRectangle not defined yet! def __init(self): super(Communicator, self).__init__(parent) class MyRectangle(QGraphicsRectItem): def __init__(self, rect=QRectF(0, 0, 0, 0), parent=None, scene=None): super(MyRectangle, self).__init__(parent, scene) self.myCommunicator = Communicator() self.myCommunicator.MyRectangleCreated.emit(self) if __name__ == "__main__": r = MyRectangle() In genereal what I want to do is synchronize the QGraphicsItems from the scene with a list of data objects. So when I create a graphics item a data object in the data manager should be created and when I change a graphics object the corresponding data block object should be updated. BTW right now I have the handling of the events (which creates and changes graphics items) in a widget derived from a view. Any hints on the best approach for that? Thanks Chris ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] I want my GUI to change appearance based on what happens in a for-statement as it happens. Instead it changes after the whole for-statement ends.
In my GUI I have a for-statement that opens a text file and changes the color of a QFrame depending on the first letter of each line in the file. The relevent part of the code is attached as a text file, and so is the sample text file I've been using. The raw_input lines were added so I could pause it and see when the color changes. I expected it to change color when I had to raw_input, but instead it waits until the line of the text file to change color. How do I make the QFrames change color as it goes through the file? Thank you, David infile = open("initialize_processor.txt") for line in infile: if line.startswith("P") == True: self.QFrame1.setStyleSheet(QApplication.translate("MainWindow", "background-color: rgb(102,255,102);", None, QApplication.UnicodeUTF8)) raw_input("P") if line.startswith("R") == True or line.startswith("I") == True: self.QFrame2.setStyleSheet(QApplication.translate("MainWindow", "background-color: rgb(102,255,102);", None, QApplication.UnicodeUTF8)) raw_input("R or I")P 1 P 2 I 3 D 4 I 5 R 6 R 7___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Strange error with latest PyQt4 snapshot
On Sun, 20 Jun 2010 13:25:27 +0200, detlev wrote: > Hi, > > I just upgraded to latest PyQt4 snapshot and got the following error while > executing this lines of code > > self.__index = self.__engine.indexWidget() > self.__index.installEventFilter(self) > > self.__engine is a QHelpEngine and self.__index is a QHelpIndexWidget. > The error is: > > : > type 'QMap > What has changed here? The code works fine with latest stable PyQt4. Should be fixed in tonight's PyQt snapshot. Thanks, Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] comparing two QItemSelection always return False ?
On Wed, 30 Jun 2010 20:35:02 +0200, Zoltan Szalai wrote: > Hello, > > What's the proper way to compare two QItemSelection instances? It seems > that using the == operation always returns False. > Comparing their indexes() can do the job but it seems a bit redundant. > > The attached code tries to demonstrate the problem. Make any selection > in the view and check the result of the three prints. > The first one will always return False, while the second and third one > will always return True. > Am I doing something wrong? No, it's a bug. Fixed in tonight's PyQt snapshot. Thanks, Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] adding signalling to QGraphicsItems
On Thu, 01 Jul 2010 11:58:01 +0200, "Christopher M. Nahler" wrote: > I want to add signalling functionality to scene items. In my case they > are usually QGraphicsRectItems.. > > I thought I could do this with deriving from QGraphicsObject but then I > loose all the funtionality for the rectangle, handling pens and brushes, > shapes etc. > > Isn't it easier to just derive from QGraphicsRectItem and QObject? Or > should I derive from QGraphicsRectItem and QGraphicsObject instead? Neither. You can't multiply inherit from more than one PyQt class. > Or are there any other ways to do this? Create a QObject subclass that implements your signals as an attribute of your QGraphicsRectItem. Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] adding signalling to QGraphicsItems
I want to add signalling functionality to scene items. In my case they are usually QGraphicsRectItems.. I thought I could do this with deriving from QGraphicsObject but then I loose all the funtionality for the rectangle, handling pens and brushes, shapes etc. Isn't it easier to just derive from QGraphicsRectItem and QObject? Or should I derive from QGraphicsRectItem and QGraphicsObject instead? Or are there any other ways to do this? Thanks in advance Chris ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Cannot import Qtcore
Hi I am having a slight problem with PyQt4 toolkit. Every time i try to import QtCore or QtGui, i get this error message: Traceback (most recent call last): File "", line 1, in from PyQt4 import QtCore SystemError: NULL result without error in PyObject_Call It used to work fine until last night, when I tried(unsuccessfully) to install Eric5 IDE. Please assist -- "No trees were killed in the sending of this message. However a large number of electrons were terribly inconvenienced. " ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] adding signalling to QGraphicsItems
I want to add signalling functionality to scene items. In my case they are usually QGraphicsRectItems.. I thought I could do this with deriving from QGraphicsObject but then I loose all the funtionality for the rectangle, handling pens and brushes, shapes etc. Isn't it easier to just derive from QGraphicsRectItem and QObject? Or should I derive from QGraphicsRectItem and QGraphicsObject instead? Or are there any other ways to do this? Thanks in advance Chris ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Select text in QMessageBox
How do I make the text selectable (for mouse copy and paste) in a QMessageBox? On Linux, it works by default, but on windows, the text cannot be selected. Any clues? Best regards, Mads -- +--+ | Mads Ipsen, Scientific developer | +---+--+ | QuantumWise A/S | phone: +45-29716388 | | Nørre Søgade 27A | www: www.quantumwise.com | | DK-1370 Copenhagen K, Denmark | email: mads.ip...@gmail.com | +---+--+ ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] how to set up a timer to call a method after a d elay?
On Thu, 01 Jul 2010 01:37:00 -0700, Steve Castellotti wrote: > On Thu, 2010-07-01 at 09:09 +0100, Phil Thompson wrote: >> > I'm still getting this error: >> > >> > QObject::startTimer: QTimer can only be used with threads started with >> > QThread >> >> I think that is a misleading message - you need to provide a test case. >> >> Because Qt sockets are handled with the event loop you usually do not >> need >> to use threads to handle multiple connections. > > > Thanks again for the replies. > > > I've got my server (and test client) working to the point where it > handles multiple connections and disconnections, though there is still > some cleanup work left around things like timeouts. > > > I'm not 100% certain I'm doing everything "right" but here's roughly how > it looks now (translated to pseudo code): > > > class server: > def __init__(self, parent=None): > self.connections = [] > self.packet_queue = [] > self.socket = QtNetwork.QTcpServer() > self.socket.newConnection.connect(self.processConnection) > self.updateTimer = QtCore.QTimer() > QtCore.QObject.connect(self.updateTimer, QtCore.SIGNAL("timeout()"), > self.timerEvent) > self.updateTimer.start(1000) > > > def processConnection(self): > client = self.socket.nextPendingConnection() > client.disconnected.connect(self.deleteDisconnected) > self.connections.append(client) > > > def deleteDisconnected(self): > index = 0 > for connection in self.connections: >state = connection.state() >if ((state != QtNetwork.QAbstractSocket.ConnectingState) and \ >(state != QtNetwork.QAbstractSocket.ConnectedState)): > connection.deleteLater() > del(self.connections[index] >index += 1 > > > def timerEvent(self): > if self.connections != []: > self.updateStatus() > self.sendPacketQueue() > > > def sendPacketQueue(self): > while (len(self.packet_queue) > 0): > packet = self.packet_queue[0] > del self.packet_queue[0] > index = 0 > for connection in self.connections: > state = connection.state() > if state == QtNetwork.QAbstractSocket.ConnectedState: > self.sendResponse(connection, packet) > index += 1 > > > > ... where "sendResponse" handles the actual data preparation for > transmission and writing to the connected socket, and "updateStatus" > appends packets of data to the packet_queue. > > > I'm not sure if its wise to delete all connections which aren't either > in a Connected or Connecting state when any single one disconnects, but > otherwise I couldn't figure out how to track connections and make sure > all references to a disconnecting client were deleted. For example if I > just attached "deleteLater" directly to the client.disconnect signal, > the reference would remain in the self.connections list and next time > the timer came around to call sendPacketQueue I would get a segfault. > > > For the moment it seems to be behaving well but I would be curious to > know if there's a smarter way to handle managing multiple connected > clients. I don't see why you are using a timer at all - it can only slow things down. Have you looked at the loopback.py example included with PyQt? Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] how to set up a timer to call a method after a delay?
On Thu, 2010-07-01 at 09:09 +0100, Phil Thompson wrote: > > I'm still getting this error: > > > > QObject::startTimer: QTimer can only be used with threads started with > > QThread > > I think that is a misleading message - you need to provide a test case. > > Because Qt sockets are handled with the event loop you usually do not need > to use threads to handle multiple connections. Thanks again for the replies. I've got my server (and test client) working to the point where it handles multiple connections and disconnections, though there is still some cleanup work left around things like timeouts. I'm not 100% certain I'm doing everything "right" but here's roughly how it looks now (translated to pseudo code): class server: def __init__(self, parent=None): self.connections = [] self.packet_queue = [] self.socket = QtNetwork.QTcpServer() self.socket.newConnection.connect(self.processConnection) self.updateTimer = QtCore.QTimer() QtCore.QObject.connect(self.updateTimer, QtCore.SIGNAL("timeout()"), self.timerEvent) self.updateTimer.start(1000) def processConnection(self): client = self.socket.nextPendingConnection() client.disconnected.connect(self.deleteDisconnected) self.connections.append(client) def deleteDisconnected(self): index = 0 for connection in self.connections: state = connection.state() if ((state != QtNetwork.QAbstractSocket.ConnectingState) and \ (state != QtNetwork.QAbstractSocket.ConnectedState)): connection.deleteLater() del(self.connections[index] index += 1 def timerEvent(self): if self.connections != []: self.updateStatus() self.sendPacketQueue() def sendPacketQueue(self): while (len(self.packet_queue) > 0): packet = self.packet_queue[0] del self.packet_queue[0] index = 0 for connection in self.connections: state = connection.state() if state == QtNetwork.QAbstractSocket.ConnectedState: self.sendResponse(connection, packet) index += 1 ... where "sendResponse" handles the actual data preparation for transmission and writing to the connected socket, and "updateStatus" appends packets of data to the packet_queue. I'm not sure if its wise to delete all connections which aren't either in a Connected or Connecting state when any single one disconnects, but otherwise I couldn't figure out how to track connections and make sure all references to a disconnecting client were deleted. For example if I just attached "deleteLater" directly to the client.disconnect signal, the reference would remain in the self.connections list and next time the timer came around to call sendPacketQueue I would get a segfault. For the moment it seems to be behaving well but I would be curious to know if there's a smarter way to handle managing multiple connected clients. Cheers Steve Castellotti ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] how to set up a timer to call a method after a d elay?
On Wed, 30 Jun 2010 17:53:38 -0700, Steve Castellotti wrote: > On Wed, 2010-06-30 at 18:19 +0100, Phil Thompson wrote: >> > self.timer = QtCore.QTimer() >> > self.timer.connect(self.timer, QtCore.SIGNAL("timeout()"), >> > self.sendData) >> > self.timer.start(1000) # 1 second >> > >> > ...but received an exception that "QTimer can only be used with >> > threads started with QThread" which leads me to believe I will need to >> > implement threading for my server (also I expected to need to send >> > "parent=self" when instantiating the QTimer object so I know I must be >> > doing something wrong). >> >> QTimer.singleShot(1000, self.sendData) >> >> ...is the normal way of doing it. > > Yes and thank you, that gets me closer to the style I was using > under Twisted, however, with my code looking like this: > > self.timer = QtCore.QTimer.singleShot(1000, self.sendData) singleShot() is a static method - it doesn't return a value. > I'm still getting this error: > > QObject::startTimer: QTimer can only be used with threads started with > QThread I think that is a misleading message - you need to provide a test case. > Comparing to an example I found online here: > > http://www.rkblog.rk.edu.pl/w/p/qtimer-making-timers-pyqt4/ ...which makes the same mistake regarding singleShot() - the "stimer" QTimer is unused (but it won't make a difference). > The main difference that I can see is that example is using > QApplication to start up, whereas I am only running from the console (no > Gui at this point). > > That said, QApplication inherits from QCoreApplication, which inherits > from QObject. QThread also inherits form QObject, but there's nothing > obvious I see that would indicate QApplication inherits from QThread > directly. Is there some other component related to Gui applications > which are creating QThreads which I need to replicated? I don't think this will have anything to do with the problem. > I tried setting up my program to inherit from QtCore.QThread just to see > if that would cover it, but no joy. > > Do I need to re-code my program to open each connection as distinct > objects in dedicated threads and perform the timers within those > objects, or again is there something simple and obvious which I am just > missing? Because Qt sockets are handled with the event loop you usually do not need to use threads to handle multiple connections. Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt