[PyKDE] Hi everyone...
Ken Kozman
kkozman at zyvex.com
Fri Feb 9 23:59:49 GMT 2001
I'm having some weird things occur with PyQt2.2.
Below is an example .py script for a silly little test application. Under
Windows however I get really strange behavior whenever I create a sub dialog
as a result of getting a "pressed( )" signal from a parent dialog. The
strangeness ranges from the original button "pressed( )" not popping back
out (which happens with a QMessageBox and also when the user cancels from a
QFileDialog.getSaveFileName call.) to the parent dialog not responding to
any user input until it is repainted (which is the case with a home brew
QFileDialog.) Has anyone else experienced this? I'm sure I am just being
dumb, but I can not figure out where.
Any help would be greatly appreciated.
Ken
Code Follows:
#
# An example to show my problems.
#
import sys
from qt import *
class TestDialog(QDialog):
def __init__(self,parent = None,name = None,modal = 0,fl = 0):
QDialog.__init__(self,parent,name,modal,fl)
if name == None:
self.setName('Python_Generator')
self.setCaption(self.tr('Test'))
self.resize(413,333)
self.hBox = QHBoxLayout( self )
self.PushButton3 = QPushButton(self,'PushButton3')
self.PushButton3.setText(self.tr('Message Box'))
self.hBox.addWidget(self.PushButton3)
self.PushButton2 = QPushButton(self,'PushButton2')
self.PushButton2.setText(self.tr('File Dialog'))
self.hBox.addWidget(self.PushButton2)
self.PushButton = QPushButton(self,'PushButton')
self.PushButton.setText(self.tr('Qt File Dialog'))
self.hBox.addWidget(self.PushButton2)
class TestDialogFinal( TestDialog ):
def __init__( self, parent ):
TestDialog.__init__( self, parent, "test", 1, 0 )
QObject.connect( self.PushButton3, SIGNAL( "pressed( )" ),
self.OnMessageBox )
QObject.connect( self.PushButton2, SIGNAL( "pressed( )" ),
self.OnFileDialog )
QObject.connect( self.PushButton, SIGNAL( "pressed( )" ),
self.OnQtFileDialog )
def OnMessageBox( self ):
QMessageBox.critical( self, "Interface Error", "This is an error,
neat huh?" )
# Note, if we do not do the following the button stays down...
weird...
#self.PushButton2.setDown( 0 )
def OnFileDialog( self ):
# The following works...
outputString = str( QFileDialog.getSaveFileName( "", "Python source
files (*.py;*.pyo)", self, "", "Please choose an output file name..." ) )
if 0 == len( outputString ):
# They cancelled.
# Note, if we do not do the following the button stays down...
weird...
# This only matters if they hit cancel...
#self.PushButton2.setDown( 0 )
return
def OnQtFileDialog( self ):
tempDialog = QFileDialog( "", "Python source files (*.py;*.pyo)",
self, "", 1 )
tempDialog.exec_loop( )
# After this we have to click elsewhere and back to make this work
again...
class ApplicationWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self, None, 'example application main window',
Qt.WDestructiveClose)
self.toolBar = QToolBar(self, 'file operations')
self.tempOpen = QToolButton(QPixmap( ), 'Open File', 'Open a file',
self.ButtonPressed, self.toolBar, 'open temp')
self.tempOpen.setText( "Test" )
def ButtonPressed( self ):
# There is not difference between me passing in None vs. self as
parent...
#dialog = TestDialogFinal( None )
dialog = TestDialogFinal( self )
dialog.exec_loop( )
app = QApplication(sys.argv)
mw = ApplicationWindow()
mw.show( )
app.connect( app, SIGNAL('lastWindowClosed()'), app, SLOT('quit()') )
app.exec_loop()
More information about the PyQt
mailing list