[PyQt] thread in pyqt ... simple example needed
Hi All, i'm doing my first experience using pyqt and tring to learn more about it unlucky i'm not able to solve some problems by myself :-( i googled a lot about and i tried to use QTassistant but i'm pretty new to programming and i've some difficoult to learn. i tried to resume my problem in a sample script, that is : import sys from PyQt4 import QtCore, QtGui import time class Gui(QtGui.QWidget): def __init__(self, parent=None): QtGui.QGroupBox.__init__(self, parent) self.gcenter = QtGui.QPushButton(X, self) self.gcenter.setAutoRepeat(True) self.connect(self.gcenter, QtCore.SIGNAL(clicked()),self.count) guiLayout = QtGui.QGridLayout() guiLayout.addWidget(self.gcenter,1,0) self.setLayout(guiLayout) def count(self): n = 0 step = 1 while True: n += step print n time.sleep(0.5) if __name__ == __main__: app = QtGui.QApplication(sys.argv) gui = Gui() gui.show() sys.exit(app.exec_()) as you can see the gui do not exit from the while statment and it freeze ... i know, i need to learn more about QTrhead usage... an example on how to change the previouse code, will give me a great help! thanks for help me !!! Massimo Di Stefano massimodisa...@yahoo.it epifanio on irc.freenode.net /join gfoss Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Help about the use of OpenGL with PyQt
That seems to be very good. Thanks a lot. Christophe David Boddie a écrit : On Sat Apr 4 17:43:29 BST 2009, Jamie Riotto wrote: OpenGL Tutorial: http://cs.uccs.edu/~semwal/indexGLTutorial.html Also NeHe productions does a realy great job breaking down OpenGL into lessons: My favorite! http://nehe.gamedev.net/ Also, since your accessing OpenGL through PyOpenGL, you should look at: http://pyopengl.sourceforge.net/documentation/ for other links and examples. Enjoy - jaime Another good source of information is the Red Book. You can find an old version online here: http://www.opengl.org/documentation/red_book/ Although it only covers OpenGL 1.1, it should contain all the basic information you need to help you get started. 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
Re: [PyQt] thread in pyqt ... simple example needed
.. done little step ahead : import sys from PyQt4 import QtCore, QtGui import time class MyThread(QtCore.QThread): def run(self): n = 0 step = 1 while True: n += step print n class Gui(QtGui.QWidget): def __init__(self, parent=None): QtGui.QGroupBox.__init__(self, parent) self.gcenter = QtGui.QPushButton(X, self) self.gcenter.setAutoRepeat(True) guiLayout = QtGui.QGridLayout() guiLayout.addWidget(self.gcenter,1,0) self.setLayout(guiLayout) self.thread = MyThread() self.connect(self.gcenter, QtCore.SIGNAL(clicked()), self.thread.start) if __name__ == __main__: app = QtGui.QApplication(sys.argv) gui = Gui() gui.show() sys.exit(app.exec_()) now i need to stop it when i release the button, tried with : self.connect(self.gcenter, QtCore.SIGNAL(released()), self.thread.quit) but give : AttributeError: stop Il giorno 05/apr/09, alle ore 19:56, massimo di stefano ha scritto: Hi All, i'm doing my first experience using pyqt and tring to learn more about it unlucky i'm not able to solve some problems by myself :-( i googled a lot about and i tried to use QTassistant but i'm pretty new to programming and i've some difficoult to learn. i tried to resume my problem in a sample script, that is : import sys from PyQt4 import QtCore, QtGui import time class Gui(QtGui.QWidget): def __init__(self, parent=None): QtGui.QGroupBox.__init__(self, parent) self.gcenter = QtGui.QPushButton(X, self) self.gcenter.setAutoRepeat(True) self.connect(self.gcenter, QtCore.SIGNAL(clicked()),self.count) guiLayout = QtGui.QGridLayout() guiLayout.addWidget(self.gcenter,1,0) self.setLayout(guiLayout) def count(self): n = 0 step = 1 while True: n += step print n time.sleep(0.5) if __name__ == __main__: app = QtGui.QApplication(sys.argv) gui = Gui() gui.show() sys.exit(app.exec_()) as you can see the gui do not exit from the while statment and it freeze ... i know, i need to learn more about QTrhead usage... an example on how to change the previouse code, will give me a great help! thanks for help me !!! Massimo Di Stefano massimodisa...@yahoo.it epifanio on irc.freenode.net /join gfoss Chiacchiera con i tuoi amici in tempo reale!http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] thread in pyqt ... simple example needed
On Sunday 05 April 2009 19:56:59 massimo di stefano wrote: Hi All, i'm doing my first experience using pyqt and tring to learn more about it unlucky i'm not able to solve some problems by myself :-( i tried to resume my problem in a sample script, that is : class Gui(QtGui.QWidget): def __init__(self, parent=None): QtGui.QGroupBox.__init__(self, parent) self.gcenter = QtGui.QPushButton(X, self) self.gcenter.setAutoRepeat(True) self.connect(self.gcenter, QtCore.SIGNAL(clicked()),self.count) guiLayout = QtGui.QGridLayout() guiLayout.addWidget(self.gcenter,1,0) self.setLayout(guiLayout) def count(self): n = 0 step = 1 while True: n += step print n time.sleep(0.5) This is a so called busy-loop, a programming technic back from the days of DOS (the operating system). Don't use it. While the sleep-statement actually makes your app sleep for a certain time (so its not really a busy-loop), it still stops your app from execution during that time. Which means there are no repaints, button-clicks or anything else possible. You encounter that as my app freezes. The correct Qt-like way for such a loop is: - Either execute QCoreApplication.processEvents() inside the loop. - Or make your heavy work a slot that does just a little of the stuff in one step and then re-schedules itself either by QTimer.singleShot(...) or by adding a QTimer to your object and let it run continuously and connecting the timeout signal to your slot. as you can see the gui do not exit from the while statment and it freeze ... i know, i need to learn more about QTrhead usage... No, if your level of experience is anywhere near the level I think it is, you will want to postpone any threads to a later day. There are actually very few problems that definitely need threads, Qt's slots combined with Qt's eventloop (automaticly used by the slots in my examples above) do a pretty good job for that. Have fun, Arnold signature.asc Description: This is a digitally signed message part. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] thread in pyqt ... simple example needed
massimo di stefano wrote: .. done little step ahead : import sys from PyQt4 import QtCore, QtGui import time class MyThread(QtCore.QThread): def run(self): n = 0 step = 1 while True: n += step print n class Gui(QtGui.QWidget): def __init__(self, parent=None): QtGui.QGroupBox.__init__(self, parent) self.gcenter = QtGui.QPushButton(X, self) self.gcenter.setAutoRepeat(True) guiLayout = QtGui.QGridLayout() guiLayout.addWidget(self.gcenter,1,0) self.setLayout(guiLayout) self.thread = MyThread() self.connect(self.gcenter, QtCore.SIGNAL(clicked()), self.thread.start) if __name__ == __main__: app = QtGui.QApplication(sys.argv) gui = Gui() gui.show() sys.exit(app.exec_()) now i need to stop it when i release the button, tried with : self.connect(self.gcenter, QtCore.SIGNAL(released()), self.thread.quit) but give : AttributeError: stop I'd suggest expanding your MyThread class to something like this: class MyThread(QtCore.QThread): def __init__(self, parent = None): QtCore.QThread.__init__(self, parent) self.running = 1 def run(self): n = 0 step = 1 while self.running: n += step print n self.msleep(100) def stop(self): self.running = 0 You should also look at the QtCore.QMutex() class, which provides a way to synchronize (via locking) between the thread process and other processes. -Hazen ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] [TreeWidget] Text and/or image over a node
Hello, I would like to show a text or a little picture (and why not the both at the same time) when the mouse is over a node of a TreeWidget. How can I try to do that ? Thanks a lot. Christophe. # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'C:\Program Files\EasyPHP 2.0b1\www\Python 07-2008\DebuterAvecPythonEtPyQT\CodesProjets\03-Proj3_VueArborescente\dial_Projet3.ui ' # # Created: Tue Jul 29 23:37:30 2008 # by: PyQt4 UI code generator 4.3.3 # # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui class Ui_dial_Projet3(object): def setupUi(self, dial_Projet3): dial_Projet3.setObjectName(dial_Projet3) dial_Projet3.resize(QtCore.QSize(QtCore.QRect(0,0,520,390).size()).expandedTo(dial_Projet3.minimumSizeHint())) dial_Projet3.setAutoFillBackground(True) self.treeWidget = QtGui.QTreeWidget(dial_Projet3) self.treeWidget.setGeometry(QtCore.QRect(270,40,240,340)) self.treeWidget.setObjectName(treeWidget) self.textUtilisateur = QtGui.QTextEdit(dial_Projet3) self.textUtilisateur.setGeometry(QtCore.QRect(10,40,240,340)) self.textUtilisateur.setObjectName(textUtilisateur) self.lineTitre_1 = QtGui.QLineEdit(dial_Projet3) self.lineTitre_1.setEnabled(False) self.lineTitre_1.setGeometry(QtCore.QRect(10,10,241,20)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(0,0,0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active,QtGui.QPalette.WindowText,brush) brush = QtGui.QBrush(QtGui.QColor(0,0,0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active,QtGui.QPalette.Dark,brush) brush = QtGui.QBrush(QtGui.QColor(0,0,0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active,QtGui.QPalette.Text,brush) brush = QtGui.QBrush(QtGui.QColor(0,0,0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active,QtGui.QPalette.ButtonText,brush) brush = QtGui.QBrush(QtGui.QColor(255,255,255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active,QtGui.QPalette.Base,brush) brush = QtGui.QBrush(QtGui.QColor(255,255,255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active,QtGui.QPalette.Window,brush) brush = QtGui.QBrush(QtGui.QColor(0,0,0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive,QtGui.QPalette.WindowText,brush) brush = QtGui.QBrush(QtGui.QColor(0,0,0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive,QtGui.QPalette.Dark,brush) brush = QtGui.QBrush(QtGui.QColor(0,0,0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive,QtGui.QPalette.Text,brush) brush = QtGui.QBrush(QtGui.QColor(0,0,0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive,QtGui.QPalette.ButtonText,brush) brush = QtGui.QBrush(QtGui.QColor(255,255,255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive,QtGui.QPalette.Base,brush) brush = QtGui.QBrush(QtGui.QColor(255,255,255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive,QtGui.QPalette.Window,brush) brush = QtGui.QBrush(QtGui.QColor(0,0,0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled,QtGui.QPalette.WindowText,brush) brush = QtGui.QBrush(QtGui.QColor(0,0,0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled,QtGui.QPalette.Dark,brush) brush = QtGui.QBrush(QtGui.QColor(0,0,0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled,QtGui.QPalette.Text,brush) brush = QtGui.QBrush(QtGui.QColor(0,0,0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled,QtGui.QPalette.ButtonText,brush) brush = QtGui.QBrush(QtGui.QColor(255,255,255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled,QtGui.QPalette.Base,brush) brush = QtGui.QBrush(QtGui.QColor(255,255,255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled,QtGui.QPalette.Window,brush) self.lineTitre_1.setPalette(palette) font = QtGui.QFont() font.setWeight(50) font.setBold(False) self.lineTitre_1.setFont(font) self.lineTitre_1.setAlignment(QtCore.Qt.AlignCenter) self.lineTitre_1.setObjectName(lineTitre_1) self.lineTitre_2 = QtGui.QLineEdit(dial_Projet3)
[PyQt] Problem with QWebView
I am having an issue with QWebView. If I use a QWebView, then after I close my application I get the following error: QWaitCondition: Destroyed while threads are still waiting This error only comes up if I actually load a web page (with either load() or setUrl()). What am I doing wrong here? Do I need to explicitly call something to destroy the QWebView widget? Novi # Main application class. # def showHelpDialog(self): help = HelpWindow(self) help.show() class HelpWindow(QtGui.QMainWindow): def __init__(self, parent): QtGui.QMainWindow.__init__(self, parent) self.setWindowTitle('TrackChanges Help') help_browser = HelpWebBrowser(self) self.setCentralWidget(help_browser) self.resize(700,500) class HelpWebBrowser(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) # We load this on the fly to reduce memory footprint. from PyQt4 import QtWebKit self.browser_main = QtWebKit.QWebView(self) url_main = QtCore.QUrl('http://qtsoftware.com') self.browser_main.setUrl(url_main) # Set the layout main_layout = QtGui.QHBoxLayout() main_layout.addWidget(self.browser_main) self.setLayout(main_layout) ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] thread in pyqt ... simple example needed
On Sunday 05 April 2009 21:29:44 Hazen Babcock wrote: I'd suggest expanding your MyThread class to something like this: class MyThread(QtCore.QThread): def __init__(self, parent = None): QtCore.QThread.__init__(self, parent) self.running = 1 def run(self): n = 0 step = 1 while self.running: n += step print n self.msleep(100) def stop(self): self.running = 0 You should also look at the QtCore.QMutex() class, which provides a way to synchronize (via locking) between the thread process and other processes. Another reason while this will not work as expected is the Big Intepreter Lock. Unless QThread releases the BIL in its *sleep-functions, the thread will block the execution of the main-thread... Arnold signature.asc Description: This is a digitally signed message part. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] thread in pyqt ... simple example needed
Arnold Krille wrote: On Sunday 05 April 2009 21:29:44 Hazen Babcock wrote: I'd suggest expanding your MyThread class to something like this: class MyThread(QtCore.QThread): def __init__(self, parent = None): QtCore.QThread.__init__(self, parent) self.running = 1 def run(self): n = 0 step = 1 while self.running: n += step print n self.msleep(100) def stop(self): self.running = 0 You should also look at the QtCore.QMutex() class, which provides a way to synchronize (via locking) between the thread process and other processes. Another reason while this will not work as expected is the Big Intepreter Lock. Unless QThread releases the BIL in its *sleep-functions, the thread will block the execution of the main-thread... Arnold Yeah that wasn't such a good suggestion. I actually tested this one and it works as expected for me: import sys from PyQt4 import QtCore, QtGui import time class MyThread(QtCore.QThread): def __init__(self, parent = None): QtCore.QThread.__init__(self, parent) self.alive = 1 self.running = 0 self.n = 0 def run(self): while self.alive: step = 1 n = 0 while self.running: n += step print n self.msleep(100) self.msleep(100) def toggle(self): if self.running: self.running = 0 else: self.running = 1 def stop(self): self.alive = 0 class Gui(QtGui.QWidget): def __init__(self, parent=None): QtGui.QGroupBox.__init__(self, parent) self.gcenter = QtGui.QPushButton(X, self) self.gcenter.setAutoRepeat(True) guiLayout = QtGui.QGridLayout() guiLayout.addWidget(self.gcenter,1,0) self.setLayout(guiLayout) self.thread = MyThread() self.thread.start() self.connect(self.gcenter, QtCore.SIGNAL(clicked()), self.thread.toggle) if __name__ == __main__: app = QtGui.QApplication(sys.argv) gui = Gui() gui.show() sys.exit(app.exec_()) I assume that QThread must be releasing the GIL while sleeping. -Hazen ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Help about the use of OpenGL with PyQt
On Sat, Apr 4, 2009 at 6:43 PM, Jamie Riotto jamie.rio...@gmail.com wrote: OpenGL Tutorial: http://cs.uccs.edu/~semwal/indexGLTutorial.htmlhttp://cs.uccs.edu/%7Esemwal/indexGLTutorial.html Also NeHe productions does a realy great job breaking down OpenGL into lessons: My favorite! http://nehe.gamedev.net/ Also, since your accessing OpenGL through PyOpenGL, you should look at: http://pyopengl.sourceforge.net/documentation/ for other links and examples. Enjoy - jaime There are also the QGLViewer/PyQGLViewer couple. Basically QGLViewer is build on top of the Qt4 OpenGL widget and PyQGLViewer is its python bindings. http://www.libqglviewer.com/ http://pyqglviewer.gforge.inria.fr/wiki/doku.php bye Gianluca ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] thread in pyqt ... simple example needed
Hazen, All, reaalythanks for your hel, it works for me ! thanks to these example i can explore it to learn more about thread, pyQt and programming in general! i'll give a deep look in QtAssistant too i'l try to translate what can i read for c++ (is a bit hard for a non programmer) and compare the class and methods used to in your python-code. . really thanks for the help !!! have good Q-time :-) Massimo Di Stefano massimodisa...@yahoo.it epifanio on irc.freenode.net /join gfoss Il giorno 06/apr/09, alle ore 00:04, Hazen Babcock ha scritto: Arnold Krille wrote: On Sunday 05 April 2009 21:29:44 Hazen Babcock wrote: I'd suggest expanding your MyThread class to something like this: class MyThread(QtCore.QThread): def __init__(self, parent = None): QtCore.QThread.__init__(self, parent) self.running = 1 def run(self): n = 0 step = 1 while self.running: n += step print n self.msleep(100) def stop(self): self.running = 0 You should also look at the QtCore.QMutex() class, which provides a way to synchronize (via locking) between the thread process and other processes. Another reason while this will not work as expected is the Big Intepreter Lock. Unless QThread releases the BIL in its *sleep- functions, the thread will block the execution of the main-thread... Arnold Yeah that wasn't such a good suggestion. I actually tested this one and it works as expected for me: import sys from PyQt4 import QtCore, QtGui import time class MyThread(QtCore.QThread): def __init__(self, parent = None): QtCore.QThread.__init__(self, parent) self.alive = 1 self.running = 0 self.n = 0 def run(self): while self.alive: step = 1 n = 0 while self.running: n += step print n self.msleep(100) self.msleep(100) def toggle(self): if self.running: self.running = 0 else: self.running = 1 def stop(self): self.alive = 0 class Gui(QtGui.QWidget): def __init__(self, parent=None): QtGui.QGroupBox.__init__(self, parent) self.gcenter = QtGui.QPushButton(X, self) self.gcenter.setAutoRepeat(True) guiLayout = QtGui.QGridLayout() guiLayout.addWidget(self.gcenter,1,0) self.setLayout(guiLayout) self.thread = MyThread() self.thread.start() self.connect(self.gcenter, QtCore.SIGNAL(clicked()), self.thread.toggle) if __name__ == __main__: app = QtGui.QApplication(sys.argv) gui = Gui() gui.show() sys.exit(app.exec_()) I assume that QThread must be releasing the GIL while sleeping. -Hazen ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt