Still trying to learn PyQt from a book about several Python GUI
toolkits, I seem to learn first what doesn't work. The following small
script seems to work, but after closing the window I get the error
message "Fatal Python error: PyEval_RestoreT hread: NULL tstate".
Without the line "self.app = app" the error goes away. So I suppose the
main window can't have a reference to the application class. Right?
Using the global variable qApp instead of self.app doesn't work either:
qApp seems to be an instance of QApplication, not an instance of HelloApp.
Should the GUI independent actions of the application rather be methods
of the main window? Or methods of some class not derived from QObject,
with a reference to an instance of this class in the main window
instance and not in the application instance? Comparing with Delphi I
suppose this might be the better way. I'd like to use the same class
with different GUI toolkits (Tkinter, wxPython), so all the GUI
independent stuff should be separate.
#!/usr/bin/python
# -*- coding: latin-1 -*-
# hello2.py
import sys
from qt import *
class HelloWindow(QMa inWindow):
def __init__(self, app, *args):
QMainWindow.__i nit__(self, *args)
self.app = app #### this seems to be the problem ####
self.button = QPushButton(sel f.app.knopftext , self)
# self.button = QPushButton(qAp p.knopftext, self) #### won't run at
all ####
self.setCentral Widget(self.but ton)
self.connect(se lf.button, SIGNAL('clicked ()'), self,
SLOT('close()') )
class HelloApp(QAppli cation):
def __init__(self, *args):
QApplication.__ init__(self, *args)
self.knopftext = 'HelloApp'
self.connect(se lf, SIGNAL('lastWin dowClosed()'),
self, SLOT('quit()'))
self.MainWindow = HelloWindow(sel f)
self.setMainWid get(self.MainWi ndow)
self.MainWindow .show()
def main(args):
app = HelloApp(args)
app.exec_loop()
if __name__ == '__main__':
main(sys.argv)
Thank you,
Koczian
--
Dr. Sibylle Koczian
Universitaetsbi bliothek, Abt. Naturwiss.
D-86135 Augsburg
Tel.: (0821) 598-2400, Fax : (0821) 598-2410
e-mail : Sibylle.Koczian @Bibliothek.Uni-Augsburg.DE
toolkits, I seem to learn first what doesn't work. The following small
script seems to work, but after closing the window I get the error
message "Fatal Python error: PyEval_RestoreT hread: NULL tstate".
Without the line "self.app = app" the error goes away. So I suppose the
main window can't have a reference to the application class. Right?
Using the global variable qApp instead of self.app doesn't work either:
qApp seems to be an instance of QApplication, not an instance of HelloApp.
Should the GUI independent actions of the application rather be methods
of the main window? Or methods of some class not derived from QObject,
with a reference to an instance of this class in the main window
instance and not in the application instance? Comparing with Delphi I
suppose this might be the better way. I'd like to use the same class
with different GUI toolkits (Tkinter, wxPython), so all the GUI
independent stuff should be separate.
#!/usr/bin/python
# -*- coding: latin-1 -*-
# hello2.py
import sys
from qt import *
class HelloWindow(QMa inWindow):
def __init__(self, app, *args):
QMainWindow.__i nit__(self, *args)
self.app = app #### this seems to be the problem ####
self.button = QPushButton(sel f.app.knopftext , self)
# self.button = QPushButton(qAp p.knopftext, self) #### won't run at
all ####
self.setCentral Widget(self.but ton)
self.connect(se lf.button, SIGNAL('clicked ()'), self,
SLOT('close()') )
class HelloApp(QAppli cation):
def __init__(self, *args):
QApplication.__ init__(self, *args)
self.knopftext = 'HelloApp'
self.connect(se lf, SIGNAL('lastWin dowClosed()'),
self, SLOT('quit()'))
self.MainWindow = HelloWindow(sel f)
self.setMainWid get(self.MainWi ndow)
self.MainWindow .show()
def main(args):
app = HelloApp(args)
app.exec_loop()
if __name__ == '__main__':
main(sys.argv)
Thank you,
Koczian
--
Dr. Sibylle Koczian
Universitaetsbi bliothek, Abt. Naturwiss.
D-86135 Augsburg
Tel.: (0821) 598-2400, Fax : (0821) 598-2410
e-mail : Sibylle.Koczian @Bibliothek.Uni-Augsburg.DE
Comment