[PyQt] Help with Login Dialog / QThread issues
Eric Frederich
eric.frederich at gmail.com
Thu Jul 7 17:38:26 BST 2011
Hello,
I am trying to create a login dialog for my application.
Logging in can take a couple of seconds so I wanted to show a progress
bar during the login process.
I think that for my QProgressBar to animate during this time, I need
to log in on a different thread. Is this true?
So, below I have what I think is a working example.
Is there a better way to call QDialog's accept slot when the login
thread is finished than how I am doing it via functools.partial?
It seems a bit hacky.
from functools import partial
class LoginThread(QThread):
def __init__(self, username, password, parent=None):
super(LoginThread, self).__init__(parent)
self.username = username
self.password = password
def run(self):
LOGIN(
self.username,
self.password,
)
class LoginDialog(QDialog, Ui_LoginDialog):
def __init__(self, *args, **kwargs):
super(LoginDialog, self).__init__(*args, **kwargs)
self.setupUi(self)
self.progressbar.hide()
def accept(self):
self.progressbar.setMinimum(0)
self.progressbar.setMaximum(0)
self.progressbar.show()
self.lt = LoginThread(
str(self.username_edit.text()),
str(self.password_edit.text())
)
self.connect(self.lt, SIGNAL('finished()'),
partial(QDialog.accept, self))
self.lt.start()
More information about the PyQt
mailing list