[PyKDE] Newbie PyQt question
Ulrich Berning
ulrich.berning at desys.de
Tue Mar 8 11:10:12 GMT 2005
Andreas Pauley schrieb:
> Hi all,
>
> I've started writing an app (point of sale) that needs to first show a
> login dialog (and succesfully authenticate a user) before showing the
> main window.
>
> I've managed to do this, but my program fails to exit and return to
> the command prompt whenever the authentication failed and the main
> window never gets showed. The login window closes, but the command I
> use to start the app (python main.py) just hangs until I manually kill
> the proccess.
> The problem doesn't occur when the program exits after the main window
> is shown.
>
> I'm using QT 3.3.3 with PyQt 3.13.
>
> Regards,
> Andreas
>
After closing the login window, the application is waiting for events in
qapp.exec_loop but you don't have any window that can generate events.
The login window is a modal dialog with it's own exec_loop.
---
Try the following changes:
1.) In qtforms/loginbase[.ui/.py] remove the connection from the OK
button to the accept slot.
2.) Change the class Login in login.py
class Login(LoginBase):
def __init__(self, poswindow):
LoginBase.__init__(self)
- self.authenticated = False
self.poswindow = poswindow
def authenticate(self):
username=str(self.lnedUsername.text())
password=str(self.lnedPassword.text())
user=User.getUser(username, password)
if user:
self.poswindow.show()
- self.authenticated = True
+ self.accept()
else:
self.authenticated = False
QMessageBox.warning(None,
self.trUtf8("Login Incorrect"),
self.trUtf8("""The user id and password you entered is
incorrect."""),
None,
None,
None,
0, -1)
+ # If the authentication fails, the whole application ends as
requested.
+ # Do this only, if the user shouldn't get a second chance.
+ # Normally, the user should be able to try it again.
+ self.reject()
- return self.authenticated
3.) Change the login method in the class QualityPos in qualitypos.py
class QualityPOS(QualityPOSBase):
def login(self):
loginwindow = Login(self)
loginwindow.show()
- loginwindow.exec_loop()
+ return loginwindow.exec_loop()
4.) Change main.py:
qapp = QApplication(sys.argv)
QObject.connect(qapp,SIGNAL("lastWindowClosed()"),qapp,SLOT("quit()"))
poswindow = QualityPOS()
qapp.setMainWidget(poswindow)
- qapp.exec_loop()
+ if poswindow.login() == QDialog.Accepted:
+ qapp.exec_loop()
---
Now it should work as desired.
Ulli
More information about the PyQt
mailing list